Received: by 2002:a05:7412:d8a:b0:e2:908c:2ebd with SMTP id b10csp803452rdg; Wed, 11 Oct 2023 06:08:37 -0700 (PDT) X-Google-Smtp-Source: AGHT+IE0E/Q7JfzOgC5hcCNGaQpjX+JJsHGYm1Mu6AAVAgFo7zAAKu4iD8dlh8dAS6Eveal9QPN1 X-Received: by 2002:a17:90b:4f8c:b0:268:b66b:d9f6 with SMTP id qe12-20020a17090b4f8c00b00268b66bd9f6mr17013734pjb.18.1697029717192; Wed, 11 Oct 2023 06:08:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697029717; cv=none; d=google.com; s=arc-20160816; b=JFP9BW3+9mJB3kUp43FLG0MpnlkQjlokMlgp07lF+Jle2JESgt5AWfl2yHZd4LXdZM ZGAEWAky+wM1DKHMcO+7P+RnizZBKuCi/9358RvEF4GJCW1N/HVdfkm6dz3xCUxQll00 xO3Ip+Tk3bh80ABU4B6tfgK5jDqgkDR0jTqhhCoCfsBvMoSoMFV3QiKG/ZWInIX7G4UJ 0jkBO2zV9oF2cUpsxrW0Nk42zWcnqbK3Lo+B28xeNNvAh6QGAyGjqwY3QGm2uqQQoQPf 2soxEsgb44Mice6OwrIj5OOIKjDYJMyYTOos84Tyh2tJ90/4kQL0kCQ6duVvA95fCHb/ Cg3Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date; bh=+pmMqgHD3CXtOWG/nTFvWarn5b15d+FB8IBCIRUK09o=; fh=ukqztD1M2m5XsR/Os+/aO0Vc+vHqgDcAt7WzoiZcIPw=; b=0dNwAxEbQ2n8tlo1ndtGRcIBWBbhv3+uCbt8Mjd6Q284R3eko0w0RuVjQdXL9oLZwY b+OIdOwTEph0Fe0l6I8kMdMkB692q2MawLLd6p0PfFcxcWRuAxdimnrHNujuTW6ONeQ7 /4T9qIMQWFTkVqNCC/ghVzyKGlXfAKhkBiZmSrTrE+T29XWAJg6QdnY4HYZ8cXTkxP1l A8OWTtCS+p+FvwbJDZ7V72gmarG6Vz46kdhkg4lvHvpNqD0UzfHEBMaTdzRy6bie3uy/ y0KVq4iP7NBeahRRX8zd7ECCbX+kTt4kHkW22RRyX0Gw0bobgMRIm7p8AIrzFs9WoyIA Qk1w== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from snail.vger.email (snail.vger.email. [23.128.96.37]) by mx.google.com with ESMTPS id ob6-20020a17090b390600b0027468369b4fsi17174508pjb.177.2023.10.11.06.08.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Oct 2023 06:08:37 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) client-ip=23.128.96.37; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id 0EA77802A728; Wed, 11 Oct 2023 06:08:36 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232206AbjJKNId (ORCPT + 99 others); Wed, 11 Oct 2023 09:08:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39164 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232381AbjJKNIb (ORCPT ); Wed, 11 Oct 2023 09:08:31 -0400 Received: from outbound-smtp62.blacknight.com (outbound-smtp62.blacknight.com [46.22.136.251]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E16E1E0 for ; Wed, 11 Oct 2023 06:08:26 -0700 (PDT) Received: from mail.blacknight.com (pemlinmail04.blacknight.ie [81.17.254.17]) by outbound-smtp62.blacknight.com (Postfix) with ESMTPS id D3687FB1CE for ; Wed, 11 Oct 2023 14:08:24 +0100 (IST) Received: (qmail 26269 invoked from network); 11 Oct 2023 13:08:24 -0000 Received: from unknown (HELO techsingularity.net) (mgorman@techsingularity.net@[84.203.197.19]) by 81.17.254.9 with ESMTPSA (AES256-SHA encrypted, authenticated); 11 Oct 2023 13:08:24 -0000 Date: Wed, 11 Oct 2023 14:08:22 +0100 From: Mel Gorman To: Huang Ying Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, Arjan Van De Ven , Andrew Morton , Vlastimil Babka , David Hildenbrand , Johannes Weiner , Dave Hansen , Michal Hocko , Pavel Tatashin , Matthew Wilcox , Christoph Lameter Subject: Re: [PATCH 08/10] mm, pcp: decrease PCP high if free pages < high watermark Message-ID: <20231011130822.dmz4nuidfyk7w34q@techsingularity.net> References: <20230920061856.257597-1-ying.huang@intel.com> <20230920061856.257597-9-ying.huang@intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-15 Content-Disposition: inline In-Reply-To: <20230920061856.257597-9-ying.huang@intel.com> X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Wed, 11 Oct 2023 06:08:36 -0700 (PDT) On Wed, Sep 20, 2023 at 02:18:54PM +0800, Huang Ying wrote: > One target of PCP is to minimize pages in PCP if the system free pages > is too few. To reach that target, when page reclaiming is active for > the zone (ZONE_RECLAIM_ACTIVE), we will stop increasing PCP high in > allocating path, decrease PCP high and free some pages in freeing > path. But this may be too late because the background page reclaiming > may introduce latency for some workloads. So, in this patch, during > page allocation we will detect whether the number of free pages of the > zone is below high watermark. If so, we will stop increasing PCP high > in allocating path, decrease PCP high and free some pages in freeing > path. With this, we can reduce the possibility of the premature > background page reclaiming caused by too large PCP. > > The high watermark checking is done in allocating path to reduce the > overhead in hotter freeing path. > > Signed-off-by: "Huang, Ying" > Cc: Andrew Morton > Cc: Mel Gorman > Cc: Vlastimil Babka > Cc: David Hildenbrand > Cc: Johannes Weiner > Cc: Dave Hansen > Cc: Michal Hocko > Cc: Pavel Tatashin > Cc: Matthew Wilcox > Cc: Christoph Lameter > --- > include/linux/mmzone.h | 1 + > mm/page_alloc.c | 22 ++++++++++++++++++++-- > 2 files changed, 21 insertions(+), 2 deletions(-) > > diff --git a/include/linux/mmzone.h b/include/linux/mmzone.h > index d6cfb5023f3e..8a19e2af89df 100644 > --- a/include/linux/mmzone.h > +++ b/include/linux/mmzone.h > @@ -1006,6 +1006,7 @@ enum zone_flags { > * Cleared when kswapd is woken. > */ > ZONE_RECLAIM_ACTIVE, /* kswapd may be scanning the zone. */ > + ZONE_BELOW_HIGH, /* zone is below high watermark. */ > }; > > static inline unsigned long zone_managed_pages(struct zone *zone) > diff --git a/mm/page_alloc.c b/mm/page_alloc.c > index 225abe56752c..3f8c7dfeed23 100644 > --- a/mm/page_alloc.c > +++ b/mm/page_alloc.c > @@ -2409,7 +2409,13 @@ static int nr_pcp_high(struct per_cpu_pages *pcp, struct zone *zone, > return min(batch << 2, pcp->high); > } > > - if (pcp->count >= high && high_min != high_max) { > + if (high_min == high_max) > + return high; > + > + if (test_bit(ZONE_BELOW_HIGH, &zone->flags)) { > + pcp->high = max(high - (batch << pcp->free_factor), high_min); > + high = max(pcp->count, high_min); > + } else if (pcp->count >= high) { > int need_high = (batch << pcp->free_factor) + batch; > > /* pcp->high should be large enough to hold batch freed pages */ > @@ -2459,6 +2465,10 @@ static void free_unref_page_commit(struct zone *zone, struct per_cpu_pages *pcp, > if (pcp->count >= high) { > free_pcppages_bulk(zone, nr_pcp_free(pcp, batch, high, free_high), > pcp, pindex); > + if (test_bit(ZONE_BELOW_HIGH, &zone->flags) && > + zone_watermark_ok(zone, 0, high_wmark_pages(zone), > + ZONE_MOVABLE, 0)) > + clear_bit(ZONE_BELOW_HIGH, &zone->flags); > } > } > > @@ -2765,7 +2775,7 @@ static int nr_pcp_alloc(struct per_cpu_pages *pcp, struct zone *zone, int order) > * If we had larger pcp->high, we could avoid to allocate from > * zone. > */ > - if (high_min != high_max && !test_bit(ZONE_RECLAIM_ACTIVE, &zone->flags)) > + if (high_min != high_max && !test_bit(ZONE_BELOW_HIGH, &zone->flags)) > high = pcp->high = min(high + batch, high_max); > > if (!order) { > @@ -3226,6 +3236,14 @@ get_page_from_freelist(gfp_t gfp_mask, unsigned int order, int alloc_flags, > } > } > > + mark = high_wmark_pages(zone); > + if (zone_watermark_fast(zone, order, mark, > + ac->highest_zoneidx, alloc_flags, > + gfp_mask)) > + goto try_this_zone; > + else if (!test_bit(ZONE_BELOW_HIGH, &zone->flags)) > + set_bit(ZONE_BELOW_HIGH, &zone->flags); > + This absolutely needs a comment explaning why because superficially a consequence of this is that allocator performance is slightly degraded when below the high watermark. Being below the high watermark is completely harmless and can persist indefinitely until something wakes kswapd. -- Mel Gorman SUSE Labs