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 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8160DCD6E67 for ; Wed, 11 Oct 2023 13:08:29 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 153418D0108; Wed, 11 Oct 2023 09:08:29 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 1032E8D0002; Wed, 11 Oct 2023 09:08:29 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id F35E48D0108; Wed, 11 Oct 2023 09:08:28 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id E1B0E8D0002 for ; Wed, 11 Oct 2023 09:08:28 -0400 (EDT) Received: from smtpin17.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id B9373A0141 for ; Wed, 11 Oct 2023 13:08:28 +0000 (UTC) X-FDA: 81333209496.17.FC69AAA Received: from outbound-smtp07.blacknight.com (outbound-smtp07.blacknight.com [46.22.139.12]) by imf02.hostedemail.com (Postfix) with ESMTP id D88688002C for ; Wed, 11 Oct 2023 13:08:26 +0000 (UTC) Authentication-Results: imf02.hostedemail.com; dkim=none; dmarc=none; spf=pass (imf02.hostedemail.com: domain of mgorman@techsingularity.net designates 46.22.139.12 as permitted sender) smtp.mailfrom=mgorman@techsingularity.net ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1697029707; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=+pmMqgHD3CXtOWG/nTFvWarn5b15d+FB8IBCIRUK09o=; b=jdz+MUHQPxjKuF9kP8wJjTMYyY9CtLyb4RowO88VdZS1ELaWSOM1F8ffov/cajt6mMyA/G nZ5DETYGVL5ciF8xX5yVTBlz/PqFQSdZb6/ZVZSco/PSPYWCCymmmbqqAZkDRIpZ+bwB8D HTI6zGZMohCIOUWitvMwiZpQJKp2wSk= ARC-Authentication-Results: i=1; imf02.hostedemail.com; dkim=none; dmarc=none; spf=pass (imf02.hostedemail.com: domain of mgorman@techsingularity.net designates 46.22.139.12 as permitted sender) smtp.mailfrom=mgorman@techsingularity.net ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1697029707; a=rsa-sha256; cv=none; b=D+JNh8vZ4wNpSbszyu7uyEF6JRFgIfeerwESBa2lJ9gfEyrhJq5tbnA533cOeEf6IZy004 KHHE89sbdPCfsWuwU9KgIx/Odv4FGsDXUagUKXNW00yDH+/k+YPX6yvrEpGZnCtgVM/Yrc 1i4kemwXx6BmeirFmX55j2QaFcrzaco= Received: from mail.blacknight.com (pemlinmail04.blacknight.ie [81.17.254.17]) by outbound-smtp07.blacknight.com (Postfix) with ESMTPS id 5DD811C4F22 for ; Wed, 11 Oct 2023 14:08:25 +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-Rspamd-Queue-Id: D88688002C X-Rspam-User: X-Rspamd-Server: rspam02 X-Stat-Signature: kmjwjb6two6kyxffuffamxgnazgzpxdq X-HE-Tag: 1697029706-108704 X-HE-Meta: U2FsdGVkX18cWhiww/+TZQvm4TIfHhnYEpZecSJmeeB6LY5HlgoH6eEt55hICoh7NP0W2smOdJCnbOcgQTyijanMY9Pxt5tTrzyYbsl6tk+sUj32LyX7loTi+Xd+Sm1KcXoQ9Fuyehso298vn17/2cyTlk23UJr0n/LKJWIPfx0sf60m5Znxep8vgqlxwtyVcHXILb3838zUS5CndWatTITDz+yqk37UU8sNsgkWgZ6g/rxjNupymelsxJX7xY3OmBFocWGvIM5xA68LeRCU+LyRfVI83ZNEJmVJrmsPMDsBrgowgp64LiTRJ1/UZVPqdsLwj9SgZtknQFf3XB9F16E19YGoI1hc/Tqtk2w/XyMGius0NZb0BmUCSpGJTRzpu4JhkNKKyuOudU0CLqf1HvnhyE/l7Cw3jiDv5lQjZLOeXbMtSaLOMpZAK/lsl5RjAq7X505Q1Id8VUwLA+NoIATW+LQx1/P3sNTloK1ae54WMxkd+y+w0sIGqyARopFisjQ60vEji4nQMXdfPFJIb9ZDz5uNWbQcNwBEFD3BXIdb8aK6IB6zQL3bnzU+1BkwtEXlKu8xF926vHnDs8k/xFuN0oDtsGL4zinWrZlBMQF6sZ3Kkm0ehdoOOp2Pe8SGQ7U0eZ+xKoG0F2fMgZZpYNXgwOjFh5Palc5gtLU8bHBcAsF8kGmEB2D5LUK5/p7D61hZzoEi7oeAAxVGkujKM+rPwSBJYm38q8O2NDEALEUt3J6ZdON6SUXR7LpTqp4z3GgddJcUYMNFL6SuRbdra/Dvo/VVOQIPD96zT58lPgJYtcgJf8egbh1CtdhROWqbKahFag2xNcaF7GmqTLwPoketaQ8i5MzBldJoCNUibqylGfZEou1vgw1DuvNoOfQci8m6C2BDdhwkb1wnIdr0RIELiDmgi/DoawSppocIFST2A3F4S7SDWbKqX79CdGauli8MKTKl76Re9edcl60 NrxdrHRV 6LmqsHs5Nh6naYR1ldOZV2CnmyIX1aO9Tr+JLWgH674uQUIz4kCbpxtCv0rpfzaMtyZ9s8zowBws1Pd2Aaw4XPN/fLn0Dly4JSBSsNiB8QLwyLMLxR3DQ7GtLhJnS31iouKIzAlIJwFCRy8Q1yi0nREHzakzsxnRuL6ybOHkuUqg/Qr+rCIBBWkXwrvwbgmVKP51CD3WlIuccIrt2AgqfCa8/kZxgfpBOOxpUpJ0PW+se4TCPUtCP/RufYXHKOlhrk2SgxCOWy1MMeDguTOskd5SqdiTs8z/1jlILN0c6p3pzQHt/ZLJrj9OFCkeTv9rtQtD1frg3zMQRgtCDGcVuGFKDzzOXlzHbgRtsxikyaMib8kvCrM4vgYcji00791LtK0e9FAX/j7gDLzZdx7/G8B8TV6vXDJeQmbCVkrXOkSDlaTn90kmfxSF2NiFlZov1K5DIMUuq8D+fi+lxec66Gtz1a3hP/bf3za6WPg2v06Eiu0uz34ioXtrcMCJIRbCwtnNUH3u5vEYF1ta45RnsDMZ0zmpR13T0fbHQGNWAUQ/SbVZAmXKt1RK/eYFHzZuytTca 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 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