Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp238185pxj; Thu, 3 Jun 2021 05:36:39 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyrgF8Al/Sxha36cbS352ZPwfTlxLAQZhkzlIHRv3Tp7cyuRcw/iOteogIW58A1t5x+jiYH X-Received: by 2002:aa7:d648:: with SMTP id v8mr13181278edr.203.1622723799492; Thu, 03 Jun 2021 05:36:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1622723799; cv=none; d=google.com; s=arc-20160816; b=If0F+2Vck87mCL/fz8xKUHDZxErdw2BESAXv1UzmJ9tTJ+e6cqUB5N1crixzmsuwo2 8E0mvd6NmtB8veNbvy2WYf0FsZ4huXNJaX5OLLZKn8YBPgkMHbA+rAplEEvm42MoSoR3 RKfjiaC6Yv3HoWnu/FDfeSur8gnDw59sCsdX6Z4Ieswz9Xr06W9hwbQHRecLYIMYcxQq WTn5QpqfT2OoJzcKb4ng/X3ZSW6T9t6g4YlraBqEzb+29/84Km2JaMOAib0QP6Mu1Rv5 3tENaAMm6c6Rhr8ACxr4iwAIIhrGaPT29PbSt8ujSAhGfRj5w4croOsfiAvzLQmmQa5D 7HUA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:user-agent:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date; bh=2BaBjK/C2/FnwNSNddi8vlBZ5Efxno33g5CgLakqywc=; b=CN2RDat+kFygeEq+8s1T7zSt417X13LEHpq/wCId/P56LnUnsFZ5BNwRMDu0+G/ajN emK4qsgBz5e+382kKwpzasGkDFewU2kSTnpODtmNLacr8U+fXRn1YP0WZgOASk7xLxJX vUg42zXXQPVMzLLNixFHVn0tZsIyeTRfaIS+IZN5NzeQLBh80rt8G7f0ZQeoBaXeYQaf enJLEcnRQtuUH2q/urKvqcpgqMMsFEQj9egw4D8BQmZ2aXApf7OXW4YamLpNf8bQhL/l 6uXq+fqfWwx3PmIZy5TbcMx1A7MBgCqOp2KQU5DErIPHF6zI4eFLjQnBTjM0hRTGy9Lp 4jMQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id dn12si2315476edb.519.2021.06.03.05.36.16; Thu, 03 Jun 2021 05:36:39 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230163AbhFCMgZ (ORCPT + 99 others); Thu, 3 Jun 2021 08:36:25 -0400 Received: from outbound-smtp33.blacknight.com ([81.17.249.66]:39470 "EHLO outbound-smtp33.blacknight.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230128AbhFCMgY (ORCPT ); Thu, 3 Jun 2021 08:36:24 -0400 Received: from mail.blacknight.com (pemlinmail06.blacknight.ie [81.17.255.152]) by outbound-smtp33.blacknight.com (Postfix) with ESMTPS id ED5A4BADCA for ; Thu, 3 Jun 2021 13:34:38 +0100 (IST) Received: (qmail 19116 invoked from network); 3 Jun 2021 12:34:38 -0000 Received: from unknown (HELO techsingularity.net) (mgorman@techsingularity.net@[84.203.17.255]) by 81.17.254.9 with ESMTPSA (AES256-SHA encrypted, authenticated); 3 Jun 2021 12:34:38 -0000 Date: Thu, 3 Jun 2021 13:34:37 +0100 From: Mel Gorman To: Vlastimil Babka Cc: Andrew Morton , Dave Hansen , Michal Hocko , Jesper Dangaard Brouer , LKML , Linux-MM Subject: Re: [PATCH 2/2] mm/page_alloc: Allow high-order pages to be stored on the per-cpu lists Message-ID: <20210603123437.GW30378@techsingularity.net> References: <20210603084621.24109-1-mgorman@techsingularity.net> <20210603084621.24109-3-mgorman@techsingularity.net> <1c15b083-26f8-4473-80e6-bcc2f549ba41@suse.cz> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-15 Content-Disposition: inline In-Reply-To: <1c15b083-26f8-4473-80e6-bcc2f549ba41@suse.cz> User-Agent: Mutt/1.10.1 (2018-07-13) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Jun 03, 2021 at 01:12:10PM +0200, Vlastimil Babka wrote: > > From a functional point of view, a patch like this is necessary to > > make bulk allocation of high-order pages work with similar performance > > to order-0 bulk allocations. The bulk allocator is not updated in this > > series as it would have to be determined by bulk allocation users how > > they want to track the order of pages allocated with the bulk allocator. > > > > Signed-off-by: Mel Gorman > > Acked-by: Vlastimil Babka > Thanks! > > diff --git a/include/linux/mmzone.h b/include/linux/mmzone.h > > index 0ed61f32d898..1ceaa5f44db6 100644 > > --- a/include/linux/mmzone.h > > +++ b/include/linux/mmzone.h > > @@ -333,6 +333,24 @@ enum zone_watermarks { > > NR_WMARK > > }; > > > > +/* > > + * One per migratetype for each PAGE_ALLOC_COSTLY_ORDER plus one additional > > + * for pageblock size for THP if configured. > > + */ > > +#ifdef CONFIG_TRANSPARENT_HUGEPAGE > > +#define NR_PCP_THP 1 > > +#else > > +#define NR_PCP_THP 0 > > +#endif > > +#define NR_PCP_LISTS (MIGRATE_PCPTYPES * (PAGE_ALLOC_COSTLY_ORDER + 1 + NR_PCP_THP)) > > + > > +/* > > + * Shift to encode migratetype in order in the least significant bits and > > + * migratetype in the higher bits. > > Hard for me to understand that comment. I would describe what the code does as > e,g, "Shift to encode migratetype and order in the same integer, with order in > the least significant bit ..." etc. That comment is a lot better :) > > > + */ > > +#define NR_PCP_ORDER_SHIFT 8 > > Also ORDER_SHIFT is a bit misnomer, it's more precisely an ORDER_WIDTH, and we > are shifting migratetype with it, not order. I'm just comparing with how we name > nid/zid/etc bits in page flags. > Ok, I can change that. > > @@ -687,10 +687,53 @@ static void bad_page(struct page *page, const char *reason) > > add_taint(TAINT_BAD_PAGE, LOCKDEP_NOW_UNRELIABLE); > > } > > > > +static inline unsigned int order_to_pindex(int migratetype, int order) > > +{ > > + int base = order; > > + > > +#ifdef CONFIG_TRANSPARENT_HUGEPAGE > > + if (order > PAGE_ALLOC_COSTLY_ORDER) { > > + VM_BUG_ON(order != pageblock_order); > > + base = PAGE_ALLOC_COSTLY_ORDER + 1; > > + } > > +#else > > + VM_BUG_ON(order > PAGE_ALLOC_COSTLY_ORDER); > > +#endif > > + > > + return (MIGRATE_PCPTYPES * base) + migratetype; > > +} > > + > > +static inline int pindex_to_order(unsigned int pindex) > > +{ > > + int order = pindex / PAGE_ALLOC_COSTLY_ORDER; > > This seems wrong, shouldn't we divide by MIGRATE_PCPTYPES? > It just happens to be the same number, so testing won't flag this. > Whoops, yes, basic algebra says you're right so well spotted. If PAGE_ALLOC_COSTLY_ORDER ever changed for some reason, this would blow up. So this? diff --git a/include/linux/mmzone.h b/include/linux/mmzone.h index bbe05289b121..f1bed5b847ec 100644 --- a/include/linux/mmzone.h +++ b/include/linux/mmzone.h @@ -345,11 +345,11 @@ enum zone_watermarks { #define NR_PCP_LISTS (MIGRATE_PCPTYPES * (PAGE_ALLOC_COSTLY_ORDER + 1 + NR_PCP_THP)) /* - * Shift to encode migratetype in order in the least significant bits and - * migratetype in the higher bits. + * Shift to encode migratetype and order in the same integer, with order + * in the least significant bits. */ -#define NR_PCP_ORDER_SHIFT 8 -#define NR_PCP_ORDER_MASK ((1<_watermark[WMARK_MIN] + z->watermark_boost) #define low_wmark_pages(z) (z->_watermark[WMARK_LOW] + z->watermark_boost) diff --git a/mm/page_alloc.c b/mm/page_alloc.c index 49f3c7dcdfca..7be71f9ad9f0 100644 --- a/mm/page_alloc.c +++ b/mm/page_alloc.c @@ -694,7 +694,7 @@ static inline unsigned int order_to_pindex(int migratetype, int order) static inline int pindex_to_order(unsigned int pindex) { - int order = pindex / PAGE_ALLOC_COSTLY_ORDER; + int order = pindex / MIGRATE_PCPTYPES; #ifdef CONFIG_TRANSPARENT_HUGEPAGE if (order > PAGE_ALLOC_COSTLY_ORDER) { @@ -1487,7 +1487,7 @@ static void free_pcppages_bulk(struct zone *zone, int count, batch_free = count; order = pindex_to_order(pindex); - BUILD_BUG_ON(MAX_ORDER >= (1<= (1<index <<= NR_PCP_ORDER_SHIFT; + page->index <<= NR_PCP_ORDER_WIDTH; page->index |= order; list_add_tail(&page->lru, &head); @@ -1537,7 +1537,7 @@ static void free_pcppages_bulk(struct zone *zone, int count, /* mt has been encoded with the order (see above) */ order = mt & NR_PCP_ORDER_MASK; - mt >>= NR_PCP_ORDER_SHIFT; + mt >>= NR_PCP_ORDER_WIDTH; /* MIGRATE_ISOLATE page should not go to pcplists */ VM_BUG_ON_PAGE(is_migrate_isolate(mt), page); -- Mel Gorman SUSE Labs