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=-16.7 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham 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 4BA73C433B4 for ; Fri, 21 May 2021 10:29:30 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id EE84E613D0 for ; Fri, 21 May 2021 10:29:29 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org EE84E613D0 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=techsingularity.net Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 915908E002E; Fri, 21 May 2021 06:29:29 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 8C5158E0022; Fri, 21 May 2021 06:29:29 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 7664D8E002E; Fri, 21 May 2021 06:29:29 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0202.hostedemail.com [216.40.44.202]) by kanga.kvack.org (Postfix) with ESMTP id 416F38E0022 for ; Fri, 21 May 2021 06:29:29 -0400 (EDT) Received: from smtpin30.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id D4921D23C for ; Fri, 21 May 2021 10:29:28 +0000 (UTC) X-FDA: 78164866416.30.38D1DD6 Received: from outbound-smtp46.blacknight.com (outbound-smtp46.blacknight.com [46.22.136.58]) by imf27.hostedemail.com (Postfix) with ESMTP id E03BE801911F for ; Fri, 21 May 2021 10:29:25 +0000 (UTC) Received: from mail.blacknight.com (pemlinmail01.blacknight.ie [81.17.254.10]) by outbound-smtp46.blacknight.com (Postfix) with ESMTPS id 76A32FADC2 for ; Fri, 21 May 2021 11:29:27 +0100 (IST) Received: (qmail 23960 invoked from network); 21 May 2021 10:29:27 -0000 Received: from unknown (HELO stampy.112glenside.lan) (mgorman@techsingularity.net@[84.203.23.168]) by 81.17.254.9 with ESMTPA; 21 May 2021 10:29:27 -0000 From: Mel Gorman To: Linux-MM Cc: Dave Hansen , Matthew Wilcox , Vlastimil Babka , Michal Hocko , Nicholas Piggin , LKML , Mel Gorman Subject: [PATCH 5/6] mm/page_alloc: Limit the number of pages on PCP lists when reclaim is active Date: Fri, 21 May 2021 11:28:25 +0100 Message-Id: <20210521102826.28552-6-mgorman@techsingularity.net> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210521102826.28552-1-mgorman@techsingularity.net> References: <20210521102826.28552-1-mgorman@techsingularity.net> MIME-Version: 1.0 X-Rspamd-Queue-Id: E03BE801911F Authentication-Results: imf27.hostedemail.com; dkim=none; spf=pass (imf27.hostedemail.com: domain of mgorman@techsingularity.net designates 46.22.136.58 as permitted sender) smtp.mailfrom=mgorman@techsingularity.net; dmarc=none X-Rspamd-Server: rspam03 X-Stat-Signature: snnuoj9qo7oyz884xwez41ju3rikunoo X-HE-Tag: 1621592965-347972 Content-Transfer-Encoding: quoted-printable 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: When kswapd is active then direct reclaim is potentially active. In either case, it is possible that a zone would be balanced if pages were not trapped on PCP lists. Instead of draining remote pages, simply limit the size of the PCP lists while kswapd is active. Signed-off-by: Mel Gorman --- include/linux/mmzone.h | 1 + mm/page_alloc.c | 19 ++++++++++++++++++- mm/vmscan.c | 35 +++++++++++++++++++++++++++++++++++ 3 files changed, 54 insertions(+), 1 deletion(-) diff --git a/include/linux/mmzone.h b/include/linux/mmzone.h index 92182e0299b2..a0606239a167 100644 --- a/include/linux/mmzone.h +++ b/include/linux/mmzone.h @@ -647,6 +647,7 @@ enum zone_flags { ZONE_BOOSTED_WATERMARK, /* zone recently boosted watermarks. * Cleared when kswapd is woken. */ + ZONE_RECLAIM_ACTIVE, /* kswapd may be scanning the zone. */ }; =20 static inline unsigned long zone_managed_pages(struct zone *zone) diff --git a/mm/page_alloc.c b/mm/page_alloc.c index c3da6401f138..d8f8044781c4 100644 --- a/mm/page_alloc.c +++ b/mm/page_alloc.c @@ -3286,6 +3286,23 @@ static int nr_pcp_free(struct per_cpu_pages *pcp, = int high, int batch) return batch; } =20 +static int nr_pcp_high(struct per_cpu_pages *pcp, struct zone *zone) +{ + int high =3D READ_ONCE(pcp->high); + + if (unlikely(!high)) + return 0; + + if (!test_bit(ZONE_RECLAIM_ACTIVE, &zone->flags)) + return high; + + /* + * If reclaim is active, limit the number of pages that can be + * stored on pcp lists + */ + return READ_ONCE(pcp->batch) << 2; +} + static void free_unref_page_commit(struct page *page, unsigned long pfn, int migratetype) { @@ -3297,7 +3314,7 @@ static void free_unref_page_commit(struct page *pag= e, unsigned long pfn, pcp =3D this_cpu_ptr(zone->per_cpu_pageset); list_add(&page->lru, &pcp->lists[migratetype]); pcp->count++; - high =3D READ_ONCE(pcp->high); + high =3D nr_pcp_high(pcp, zone); if (pcp->count >=3D high) { int batch =3D READ_ONCE(pcp->batch); =20 diff --git a/mm/vmscan.c b/mm/vmscan.c index 5199b9696bab..c3c2100a80b8 100644 --- a/mm/vmscan.c +++ b/mm/vmscan.c @@ -3722,6 +3722,38 @@ static bool kswapd_shrink_node(pg_data_t *pgdat, return sc->nr_scanned >=3D sc->nr_to_reclaim; } =20 +/* Page allocator PCP high watermark is lowered if reclaim is active. */ +static inline void +update_reclaim_active(pg_data_t *pgdat, int highest_zoneidx, bool active= ) +{ + int i; + struct zone *zone; + + for (i =3D 0; i <=3D highest_zoneidx; i++) { + zone =3D pgdat->node_zones + i; + + if (!managed_zone(zone)) + continue; + + if (active) + set_bit(ZONE_RECLAIM_ACTIVE, &zone->flags); + else + clear_bit(ZONE_RECLAIM_ACTIVE, &zone->flags); + } +} + +static inline void +set_reclaim_active(pg_data_t *pgdat, int highest_zoneidx) +{ + update_reclaim_active(pgdat, highest_zoneidx, true); +} + +static inline void +clear_reclaim_active(pg_data_t *pgdat, int highest_zoneidx) +{ + update_reclaim_active(pgdat, highest_zoneidx, false); +} + /* * For kswapd, balance_pgdat() will reclaim pages across a node from zon= es * that are eligible for use by the caller until at least one zone is @@ -3774,6 +3806,7 @@ static int balance_pgdat(pg_data_t *pgdat, int orde= r, int highest_zoneidx) boosted =3D nr_boost_reclaim; =20 restart: + set_reclaim_active(pgdat, highest_zoneidx); sc.priority =3D DEF_PRIORITY; do { unsigned long nr_reclaimed =3D sc.nr_reclaimed; @@ -3907,6 +3940,8 @@ static int balance_pgdat(pg_data_t *pgdat, int orde= r, int highest_zoneidx) pgdat->kswapd_failures++; =20 out: + clear_reclaim_active(pgdat, highest_zoneidx); + /* If reclaim was boosted, account for the reclaim done in this pass */ if (boosted) { unsigned long flags; --=20 2.26.2