From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wm1-f53.google.com (mail-wm1-f53.google.com [209.85.128.53]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E32C5362138 for ; Fri, 10 Jul 2026 15:23:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.53 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1783697009; cv=none; b=WhC4MjLQ0URF/h8+RDmneHpMQwM4arP1ggTzvBJ7CvlR3lRGlBYpkg8W7HXp6TtG4tv4BTdMQv5hZnbMeauQUfBGYzZITQZw3MwScI56SOexXvJzSLGiamnIV01fP/DDEQM+qicpA1OTv/xEvkK+QwCfGiOdgyX0lWiX2T2iuK0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1783697009; c=relaxed/simple; bh=a+1R/i+AQkak7Z+Fze+AjGgQS9LWW0wqQLpBENYtIRc=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=esq7QOm4LcjYoTAZPtw0/Q+DhD4w6IP9WLQRux4dfcMVkuPKIQJ6YXU+w4UPHBYhnsaR7o5XqPZFIiQuVhdQuK42P1vyTQY7Gj61k22dtejoCeYBY4bXW6OuE3D8RaxuMPsjuKdhpiZ7Yrj976vQuhkGx37eh6DwcC9ANt2XyPU= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com; spf=pass smtp.mailfrom=suse.com; dkim=pass (2048-bit key) header.d=suse.com header.i=@suse.com header.b=ArDhXHgh; arc=none smtp.client-ip=209.85.128.53 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=suse.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=suse.com header.i=@suse.com header.b="ArDhXHgh" Received: by mail-wm1-f53.google.com with SMTP id 5b1f17b1804b1-490d6730461so824385e9.3 for ; Fri, 10 Jul 2026 08:23:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=google; t=1783697004; x=1784301804; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to:content-type; bh=QWE7xPSwPltB6r6UMmtvXNm8Cw2p/v8eUDinWtX74Ps=; b=ArDhXHgh+ExcHRAHw9JLJHTHAYTxWiu3emvzVuAHiJcS4XBtboyJ5ilC7V+oWLJMIP FAQQsvC0DhkBzIVdt40sS6Z92PBY6ssCqKg0kTHMDbHcp/XxEusbjyickmg/4mmBOqcQ GJnnt7R7tD3z/uUrXH4Nzxs28abw9WFhZVjWYNRWJzm4eAXS4lB+H0FxCDModzI9Memq GtFpacNDFZ0cgUaPHumCbD8G9E0houOlePdhrgY/vmcZLdzpjayw+4hVMBdeex0aRyfF tuAqgGAFMHEKtb6M+l4ES/ufE7bDxClETAtxGreDj1NDpg4At70tVE3gm1ApcCKWhjFE A6aw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1783697004; x=1784301804; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=QWE7xPSwPltB6r6UMmtvXNm8Cw2p/v8eUDinWtX74Ps=; b=Mdc+ZO0MII8AoICkOU4mFPGbsQUxbMv/u0ukvQk2tCMG7wk5IjyDGF9uQFjRCNQQbe RjV4X0hRk2Qeqc+E09t6n+D89XojAPEVcloCn0aZJVi0tDnsdiVqidBE3piftCRMg+fs wiZcCvBqPDGtA6haUhBB6XS7zolFdt3c+fxF7uwhBpZlZiYM8TCAJa1Lrtl6y05nzhMA OeRILYYFamxHhKIkL3exFV6BSLj93WCfjlRfNyGgDgT6s1V5kAfiGCeLgyjxl28uttl8 1k8ECY3gILavWMU74SFqP9A+ofYte/IM4r73aTe1kSgGvCHGIHowHq1CPR2WrU8AcCB2 akMg== X-Forwarded-Encrypted: i=1; AHgh+RoJAZYAY9mgXKuVVhwSc5pBF3VUIFas2sBS3NNJGd5nQ+FDt1LlSwUlDT5wlN0ed8+jrQesjDE7u0SVtsI=@vger.kernel.org X-Gm-Message-State: AOJu0YzViF88lBXcxswSnTwXxsq0vRGUk1pJJIXpBPsawLEScNWoVjEN hv4+fehEGzKv8sSZTWaW4GuJ1oAS/miTdVIYl/zaz+lvgaFrfG8/Q78fGMvLQMtfcgZS8xsA6Iy oTn7TC1w= X-Gm-Gg: AfdE7cmxSSBmL6rixQBE7x96MO9UluYNDiYnxZ1+48mGjqXhBrwG2irfc2lduq8HfnH ETKahyNJAk79vBGZGpvflbamdDZNOBLvhTXCgMM5sh4/fImmhb4M3RaUsDPc4HFaxkn0tF8xHiU bJ543EpsEEOs5y7fSnip1XpM5ckBUCL1sBOhgxMjr4jJf/70RbnwEnhKyl/UaSlnFtkusa4Jkbg zMvwfTJIwc/vsgpdUqT6L0YUcv4rx+LQJ7OktHt/xV4H4ervjxkFGJgF0RKf+0IwIpbvdg7/KCZ 3dOxK9Cf9otuODYSrY5VLd18WZ7H9N4lfJgNi5uJlMMVd3w7fA67HaQunGIRlxHCAfduGAcyLg0 dIdKjV9T+E7ycqmiqlps24EBE8p3JSNxJMmbdcbRtH8/zSQACTNR2o7lsKSx/WP7U1emAgiwytw qFgYK5fGqvf56BgXuJkDljFftrz6uMvjQixJpted0Vq3gUAKtYFlwENDvT2+F4sNEvdCBtOnE4H uw7poc= X-Received: by 2002:a05:600c:828c:b0:490:b227:da9b with SMTP id 5b1f17b1804b1-493e6820934mr72249405e9.1.1783697003790; Fri, 10 Jul 2026 08:23:23 -0700 (PDT) Received: from localhost (dynamic-2a00-1028-83b8-1e7a-3010-3bd6-8521-caf1.ipv6.o2.cz. [2a00:1028:83b8:1e7a:3010:3bd6:8521:caf1]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-493f2dd8376sm41088125e9.2.2026.07.10.08.23.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 10 Jul 2026 08:23:23 -0700 (PDT) From: Petr Tesarik To: Andrew Morton , David Hildenbrand , Lorenzo Stoakes , "Liam R. Howlett" , Vlastimil Babka , Mike Rapoport , Suren Baghdasaryan , Michal Hocko , linux-mm@kvack.org Cc: Brendan Jackman , Johannes Weiner , Zi Yan , linux-kernel@vger.kernel.org, Petr Tesarik Subject: [PATCH v3 1/1] mm: let node_reclaim() return the number of pages reclaimed Date: Fri, 10 Jul 2026 17:23:20 +0200 Message-ID: <20260710152320.2024283-1-ptesarik@suse.com> X-Mailer: git-send-email 2.54.0 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit There is only one caller, get_page_from_freelist(), and it does not make any use of the reason for skipping the reclaim, nor does it make any distinction between a full and partially successful reclaim. Therefore, node_reclaim() can simply return the number of pages that have been reclaimed, same as __node_reclaim(), and the NODE_RECLAIM_xxx macros can be removed. There is one small change of behavior when __node_reclaim() was attempted but returned zero. The allocation now skips the zone immediately; before this patch, the zone watermarks were checked first. I believe it was an oversight rather than intention, because the chances that zone watermark is OK after __node_reclaim() did not reclaim any pages are very close to zero. Originally, I was looking for occurences of NODE_RECLAIM_SOME and NODE_RECLAIM_SUCCESS, but I couldn't find any. That's because they are typecast from the result of a relational operator. This seemed a bit fragile, so I dug a bit deeper and came up with this proposed cleanup. Signed-off-by: Petr Tesarik -- Changes from v2: - remove the enum and return the number of pages reclaimed Changes from v1: - use an enum instead of a bool --- mm/internal.h | 9 +++++---- mm/page_alloc.c | 19 ++++--------------- mm/vmscan.c | 16 ++++++++-------- 3 files changed, 17 insertions(+), 27 deletions(-) diff --git a/mm/internal.h b/mm/internal.h index e5dcab69eb4f6..585705daad1a5 100644 --- a/mm/internal.h +++ b/mm/internal.h @@ -1102,15 +1102,16 @@ static inline void mlock_drain_remote(int cpu) { } #ifdef CONFIG_NUMA extern int node_reclaim_mode; -extern int node_reclaim(struct pglist_data *, gfp_t, unsigned int); +extern unsigned long node_reclaim(struct pglist_data *pgdat, + gfp_t gfp_mask, unsigned int order); extern int find_next_best_node(int node, nodemask_t *used_node_mask); #else #define node_reclaim_mode 0 -static inline int node_reclaim(struct pglist_data *pgdat, gfp_t mask, - unsigned int order) +static inline unsigned long node_reclaim(struct pglist_data *pgdat, + gfp_t mask, unsigned int order) { - return NODE_RECLAIM_NOSCAN; + return 0; } static inline int find_next_best_node(int node, nodemask_t *used_node_mask) { diff --git a/mm/page_alloc.c b/mm/page_alloc.c index 9c97a86da2b9f..af63558391345 100644 --- a/mm/page_alloc.c +++ b/mm/page_alloc.c @@ -3908,8 +3908,6 @@ get_page_from_freelist(gfp_t gfp_mask, unsigned int order, int alloc_flags, if (!zone_watermark_fast(zone, order, mark, ac->highest_zoneidx, alloc_flags, gfp_mask)) { - int ret; - if (cond_accept_memory(zone, order, alloc_flags)) goto try_this_zone; @@ -3930,22 +3928,13 @@ get_page_from_freelist(gfp_t gfp_mask, unsigned int order, int alloc_flags, !zone_allows_reclaim(zonelist_zone(ac->preferred_zoneref), zone)) continue; - ret = node_reclaim(zone->zone_pgdat, gfp_mask, order); - switch (ret) { - case NODE_RECLAIM_NOSCAN: - /* did not scan */ - continue; - case NODE_RECLAIM_FULL: - /* scanned but unreclaimable */ + if (!node_reclaim(zone->zone_pgdat, gfp_mask, order)) continue; - default: - /* did we reclaim enough */ - if (zone_watermark_ok(zone, order, mark, - ac->highest_zoneidx, alloc_flags)) - goto try_this_zone; + /* did we reclaim enough */ + if (!zone_watermark_ok(zone, order, mark, + ac->highest_zoneidx, alloc_flags)) continue; - } } try_this_zone: diff --git a/mm/vmscan.c b/mm/vmscan.c index f8faa7d06329b..639ea6175c98d 100644 --- a/mm/vmscan.c +++ b/mm/vmscan.c @@ -7800,9 +7800,9 @@ static unsigned long __node_reclaim(struct pglist_data *pgdat, gfp_t gfp_mask, return sc->nr_reclaimed; } -int node_reclaim(struct pglist_data *pgdat, gfp_t gfp_mask, unsigned int order) +unsigned long node_reclaim(struct pglist_data *pgdat, gfp_t gfp_mask, unsigned int order) { - int ret; + unsigned long ret; /* Minimum pages needed in order to stay on node */ const unsigned long nr_pages = 1 << order; struct scan_control sc = { @@ -7829,13 +7829,13 @@ int node_reclaim(struct pglist_data *pgdat, gfp_t gfp_mask, unsigned int order) if (node_pagecache_reclaimable(pgdat) <= pgdat->min_unmapped_pages && node_page_state_pages(pgdat, NR_SLAB_RECLAIMABLE_B) <= pgdat->min_slab_pages) - return NODE_RECLAIM_FULL; + return 0; /* * Do not scan if the allocation should not be delayed. */ if (!gfpflags_allow_blocking(gfp_mask) || (current->flags & PF_MEMALLOC)) - return NODE_RECLAIM_NOSCAN; + return 0; /* * Only run node reclaim on the local node or on nodes that do not @@ -7844,15 +7844,15 @@ int node_reclaim(struct pglist_data *pgdat, gfp_t gfp_mask, unsigned int order) * as wide as possible. */ if (node_state(pgdat->node_id, N_CPU) && pgdat->node_id != numa_node_id()) - return NODE_RECLAIM_NOSCAN; + return 0; if (test_and_set_bit_lock(PGDAT_RECLAIM_LOCKED, &pgdat->flags)) - return NODE_RECLAIM_NOSCAN; + return 0; - ret = __node_reclaim(pgdat, gfp_mask, nr_pages, &sc) >= nr_pages; + ret = __node_reclaim(pgdat, gfp_mask, nr_pages, &sc); clear_bit_unlock(PGDAT_RECLAIM_LOCKED, &pgdat->flags); - if (ret) + if (ret >= nr_pages) count_vm_event(PGSCAN_ZONE_RECLAIM_SUCCESS); else count_vm_event(PGSCAN_ZONE_RECLAIM_FAILED); -- 2.54.0