From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.3 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS, USER_AGENT_SANE_1 autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id B41ABC3F2D0 for ; Wed, 11 Mar 2020 08:51:13 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 7F07420848 for ; Wed, 11 Mar 2020 08:51:13 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 7F07420848 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=suse.cz Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 0DD846B0003; Wed, 11 Mar 2020 04:51:13 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 08E156B0006; Wed, 11 Mar 2020 04:51:13 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id F0BB56B0007; Wed, 11 Mar 2020 04:51:12 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0079.hostedemail.com [216.40.44.79]) by kanga.kvack.org (Postfix) with ESMTP id D7DFD6B0003 for ; Wed, 11 Mar 2020 04:51:12 -0400 (EDT) Received: from smtpin21.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id 717D68248047 for ; Wed, 11 Mar 2020 08:51:12 +0000 (UTC) X-FDA: 76582461984.21.flock37_61ca738d4162e X-HE-Tag: flock37_61ca738d4162e X-Filterd-Recvd-Size: 3609 Received: from mx2.suse.de (mx2.suse.de [195.135.220.15]) by imf25.hostedemail.com (Postfix) with ESMTP for ; Wed, 11 Mar 2020 08:51:11 +0000 (UTC) X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id DABCEAF2F; Wed, 11 Mar 2020 08:51:08 +0000 (UTC) Subject: Re: [PATCH] mm,page_alloc,cma: conditionally prefer cma pageblocks for movable allocations To: Rik van Riel , Andrew Morton Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, kernel-team@fb.com, Roman Gushchin , Qian Cai , Mel Gorman , Anshuman Khandual , Joonsoo Kim References: <20200306150102.3e77354b@imladris.surriel.com> From: Vlastimil Babka Message-ID: <8e67d88f-3ec8-4795-35dc-47e3735e530e@suse.cz> Date: Wed, 11 Mar 2020 09:51:07 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.5.0 MIME-Version: 1.0 In-Reply-To: <20200306150102.3e77354b@imladris.surriel.com> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On 3/6/20 9:01 PM, Rik van Riel wrote: > Posting this one for Roman so I can deal with any upstream feedback and > create a v2 if needed, while scratching my head over the next piece of > this puzzle :) > > ---8<--- > > From: Roman Gushchin > > Currently a cma area is barely used by the page allocator because > it's used only as a fallback from movable, however kswapd tries > hard to make sure that the fallback path isn't used. Few years ago Joonsoo wanted to fix these kinds of weird MIGRATE_CMA corner cases by using ZONE_MOVABLE instead [1]. Unfortunately it was reverted due to unresolved bugs. Perhaps the idea could be resurrected now? [1] https://lore.kernel.org/linux-mm/1512114786-5085-1-git-send-email-iamjoonsoo.kim@lge.com/ > This results in a system evicting memory and pushing data into swap, > while lots of CMA memory is still available. This happens despite the > fact that alloc_contig_range is perfectly capable of moving any movable > allocations out of the way of an allocation. > > To effectively use the cma area let's alter the rules: if the zone > has more free cma pages than the half of total free pages in the zone, > use cma pageblocks first and fallback to movable blocks in the case of > failure. > > Signed-off-by: Rik van Riel > Co-developed-by: Rik van Riel > Signed-off-by: Roman Gushchin > --- > mm/page_alloc.c | 12 ++++++++++++ > 1 file changed, 12 insertions(+) > > diff --git a/mm/page_alloc.c b/mm/page_alloc.c > index 3c4eb750a199..0fb3c1719625 100644 > --- a/mm/page_alloc.c > +++ b/mm/page_alloc.c > @@ -2711,6 +2711,18 @@ __rmqueue(struct zone *zone, unsigned int order, int migratetype, > { > struct page *page; > > + /* > + * Balance movable allocations between regular and CMA areas by > + * allocating from CMA when over half of the zone's free memory > + * is in the CMA area. > + */ > + if (migratetype == MIGRATE_MOVABLE && > + zone_page_state(zone, NR_FREE_CMA_PAGES) > > + zone_page_state(zone, NR_FREE_PAGES) / 2) { > + page = __rmqueue_cma_fallback(zone, order); > + if (page) > + return page; > + } > retry: > page = __rmqueue_smallest(zone, order, migratetype); > if (unlikely(!page)) { >