From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.161.51 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796075581; b=z7GS0Mt513xCNeOpX10FaxD3/m2HVzd0TXPU+kLThMUi+12PMIRRrXVohgZAdPdZDkXw VOBMez19R1LtfSqTwjYPUftf246SjiVcwJ9C9Jp1qBTkCB42Sa+/OlTuCkpVAH730oir1 YPrf1x7g/blRPAUVt2PfEmoGEt2210qYsJPsLOK1ElKQZNzN57PdkIbklOA+yIUQMBUF4 ttcS5yxK9ra4ZA5Bdg5TRtfk7MCQqyOnHdwCcwgodh4X9tIBew8WvSOPwBhPq+dzC8EsC mCU/abAmC+Gm/YeOUa1E0DHLzHZdkwnMHhhyVsoTj2Fx6fRsvqAqniJdg8T8Ch4E38g== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796075581; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Gm-Gg:X-Received:Received: From:To:Cc:Subject:Date:Message-ID:X-Mailer:In-Reply-To:References: MIME-Version:Content-Transfer-Encoding; bh=cO8nZOdISzjhYBc/AO5vTJwTF/d9IbWx6mzJt4L5a20=; b=LuwEl4PljYoRgnofSkVZBgMmV1PbmRaQ/L1S7m4bksmgeqYDpXycDMZwJ0n6XnfRh6c6 w5qrhWfMSgQFJhQ0AhTkyDmoVebf0o7XjzNrJzAsEVWPKk+ZbljFdEvELj9a5iK3+nGjf M+uycNMxX8XrHQHDoOhClAzoWPkAbmeWqTnB96zU22ItOLGXsUYEO06J2LFyvKz/eii7/ Jchp8E6nFoQiP3dUkAqssfE4L4B8MZkCMT2QUv9SLs+InkZAfdu4YuxMq/e6E7s+ykDGe X//a4P27GHPzIVRbQOto3sJe975DDJXXK7YPtXkUZrmefu0iGdUZBmSqc6NMHNrY38g== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=yUszC6HY; arc=none smtp.remote-ip=209.85.161.51 Received: from mail-oo1-f51.google.com (mail-oo1-f51.google.com [209.85.161.51]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3088E606A32A for ; Mon, 30 Nov 2026 21:53:01 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 3088E606A32A Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=yUszC6HY Received: by mail-oo1-f51.google.com with SMTP id 006d021491bc7-716b58a4365so6166411eaf.3 for ; Mon, 30 Nov 2026 13:53:01 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1796075580; x=1796680380; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=cO8nZOdISzjhYBc/AO5vTJwTF/d9IbWx6mzJt4L5a20=; b=yUszC6HYuqadfnvZPIdG+3nMO1iG9GE29XAdGk/A+OCeZgHobqZv8paBbcf7KWEMi0 F3RRkoOP5yi9rUaVl54EuH2BcEJBTpnK7/93IS6mLVsvWkOBkkGFAyoQtXGXKX2G1D8N 9Bl/9gcWfPF3mBZn68OesdMoe0MH1Tiu0DpOtpTn8BbNMZFxnhYXe6Oip+ITxVIoWtch XBYfssWdUs3dndlRvvewBfbRim2v8hxvAsl37vxGVGqC1o+5S803PKNKUxYG9o8bus55 7USqIsfvB7jRchga598T3qhzrZwL5+VtqY4grxlpbcFwUr2BErIClUMSCyGY7XpYt4we uIVg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796075580; x=1796680380; h=content-transfer-encoding:mime-version:references:in-reply-to :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=cO8nZOdISzjhYBc/AO5vTJwTF/d9IbWx6mzJt4L5a20=; b=T0PsTn40oDvfeya+lOB1f40qZ5+T+hgGV11B/X+751xWpk+Piyx6nXzt9wl6+zxZNq zB8HoKlO0X68q/naTrhX+ihTeLBpI838Ea1n70phwtfVNxAPRzS3qfJTrWK4y4EBGypA SmNrZkoxE6+UwIpPotZxiAImFktVVEOyzVMKlmOQCpLGSs1AmBkGdit8hxNx2dMB+s+3 VRsi19HDs3gljRZrLueqC12UhmiTgqORKYl5dJIHhcyjFQQgIpV55NI4K2yohBBWdXBk /7brDDcOnb3nX0XzmedDUEyPNNoRqKNTqahccdUva3c8OJtPvlUnb8rq+j4PJGTK+Uv2 64DA== X-Forwarded-Encrypted: i=1; AL+hErEiND/9sm5AMKetxcAf3VDrgUJPnsCEq7JlREQ2/W55nhhq7SjvgomsQayCPI0cE0eyL4bl6B184SIA6KE=@vger.kernel.org X-Gm-Message-State: APuU4Z+HruWvL+mD26cO71Rx/3VnSeoQJlfUQRpX2ArPWejPL6CcBj6K zWQO5fmKRq8/1GC2XOmsgWBzuloJk1l/8lwzZjYpAuDEoAy1rNNVchOI X-Gm-Gg: AZFdTZc4LhStsl8t2oknsJ+erpt341edLm2Zf484bszBGxteTOMhYmvqk1SSmCUZjWQ 7CtmZYJchEbeDbgbW0VR0S9c/YXEVlig0YOulvJl+G2fShpo9TnZbtMuqbSAPcVsJJPuYbwmGSL IoBhWfDY4iPReSV2BPSkk5XMCbf7YPTVngN23PA6ym2LxaKvBqX0aT76aGW3E26cHi6OUC2AczB XR5+lGuSeU2pgyFC64Ln3tCOqAIToijWoYaIcpAzs3ReUvLlpKZWT6i//gbada3yBGTqLnwTVYE Vnw2cNEQU9IJU1zVJjrJPhTgYbi9wl6mRvngH6dvksgo8tJV9vOD8EzC3IhgAscuKTUh7zQj+Cp E+I+ioIfwJmBfo/okLfir9zC3IjkMlREjFPdiV5FD8iWEQ1vQGjcnIqeAar4ONB3DmLMojtbqFN z5BMwzOQKBvAFCFDZ69q9FoQnB3bNZMLJpx/ZIapyNG657ZqRKDX1I9wNP/KqZY4noo8ZtDNuaj TN1hKmGGwRIApKT3hcjMVdAyjt7mIFitWkCFyDbv8HM0ozIEGqunRTNf3oc2wMABrs6939bzix1 gYQhok8nOCY9oomjRtCaIJafcGlyYXZDjPvIi17dnVBJFH4OF+IQZujLUQuw X-Received: by 2002:a05:6820:2208:b0:71b:bfdb:92e8 with SMTP id 006d021491bc7-71bbfdb933dmr2570400eaf.20.1796075580122; Mon, 30 Nov 2026 13:53:00 -0800 (PST) Received: from localhost ([2a03:2880:10ff:14::]) by smtp.gmail.com with ESMTPSA id 006d021491bc7-71b8590ba0fsm10953504eaf.2.2026.11.30.13.52.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 30 Nov 2026 13:52:59 -0800 (PST) From: Joshua Hahn To: Johannes Weiner Cc: Dave Hansen , Andrew Morton , Michal Hocko , Shakeel Butt , Qi Zheng , David Hildenbrand , Gregory Price , Zi Yan , Rakie Kim , Ying Huang , Kairui Song , Barry Song , Axel Rasmussen , Yuanchu Xie , Wei Xu , Baoquan He , Baolin Wang , linux-mm@kvack.org, linux-kernel@vger.kernel.org, kernel-team@meta.com Subject: [RFC PATCH 1/2] mm/memory-tiers: move pgdat_free_space_enough() out of the scheduler Date: Mon, 30 Nov 2026 13:52:56 -0800 Message-ID: <20261130215258.2202513-2-joshua.hahnjy@gmail.com> X-Mailer: git-send-email 2.53.1 In-Reply-To: <20261130215258.2202513-1-joshua.hahnjy@gmail.com> References: <20261130215258.2202513-1-joshua.hahnjy@gmail.com> X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit pgdat_free_space_enough() decides when a top tier node has enough free memory that NUMA balancing promotes slow memory pages without applying the hot threshold. It is a memory tiering policy, but it lives in kernel/sched/fair.c as a static helper, so mm cannot use it. Move it to mm/memory-tiers.c and declare it in , next to node_is_toptier(), with a stub that returns false when !CONFIG_NUMA_MIGRATION. NUMA balancing depends on CONFIG_NUMA_MIGRATION, so its caller always gets the real function. The next patch uses it in reclaim, so that memcg limit reclaim and promotion share one definition of a top tier node with room. No functional changes intended. Signed-off-by: Joshua Hahn --- include/linux/memory-tiers.h | 11 +++++++++++ kernel/sched/fair.c | 28 ---------------------------- mm/memory-tiers.c | 28 ++++++++++++++++++++++++++++ 3 files changed, 39 insertions(+), 28 deletions(-) diff --git a/include/linux/memory-tiers.h b/include/linux/memory-tiers.h index 7999c58629eeb..e32a02f85f517 100644 --- a/include/linux/memory-tiers.h +++ b/include/linux/memory-tiers.h @@ -56,6 +56,7 @@ void mt_put_memory_types(struct list_head *memory_types); int next_demotion_node(int node, const nodemask_t *allowed_mask); void node_get_allowed_targets(pg_data_t *pgdat, nodemask_t *targets); bool node_is_toptier(int node); +bool pgdat_free_space_enough(pg_data_t *pgdat); #else static inline int next_demotion_node(int node, const nodemask_t *allowed_mask) { @@ -71,6 +72,11 @@ static inline bool node_is_toptier(int node) { return true; } + +static inline bool pgdat_free_space_enough(pg_data_t *pgdat) +{ + return false; +} #endif #else @@ -116,6 +122,11 @@ static inline bool node_is_toptier(int node) return true; } +static inline bool pgdat_free_space_enough(pg_data_t *pgdat) +{ + return false; +} + static inline int register_mt_adistance_algorithm(struct notifier_block *nb) { return 0; diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c index 0c8af1cac2d5b..aadb815960558 100644 --- a/kernel/sched/fair.c +++ b/kernel/sched/fair.c @@ -2764,34 +2764,6 @@ static inline bool cpupid_valid(int cpupid) return cpupid_to_cpu(cpupid) < nr_cpu_ids; } -/* - * For memory tiering mode, if there are enough free pages (more than - * enough watermark defined here) in fast memory node, to take full - * advantage of fast memory capacity, all recently accessed slow - * memory pages will be migrated to fast memory node without - * considering hot threshold. - */ -static bool pgdat_free_space_enough(struct pglist_data *pgdat) -{ - int z; - unsigned long enough_wmark; - - enough_wmark = max(1UL * 1024 * 1024 * 1024 >> PAGE_SHIFT, - pgdat->node_present_pages >> 4); - for (z = pgdat->nr_zones - 1; z >= 0; z--) { - struct zone *zone = pgdat->node_zones + z; - - if (!populated_zone(zone)) - continue; - - if (zone_watermark_ok(zone, 0, - promo_wmark_pages(zone) + enough_wmark, - ZONE_MOVABLE, 0)) - return true; - } - return false; -} - /* * For memory tiering mode, when page tables are scanned, the scan * time will be recorded in struct page in addition to make page diff --git a/mm/memory-tiers.c b/mm/memory-tiers.c index 7fc56a8c66518..caf28ca662f75 100644 --- a/mm/memory-tiers.c +++ b/mm/memory-tiers.c @@ -299,6 +299,34 @@ bool node_is_toptier(int node) return toptier; } +/* + * For memory tiering mode, if there are enough free pages (more than + * enough watermark defined here) in fast memory node, to take full + * advantage of fast memory capacity, all recently accessed slow + * memory pages will be migrated to fast memory node without + * considering hot threshold. + */ +bool pgdat_free_space_enough(pg_data_t *pgdat) +{ + int z; + unsigned long enough_wmark; + + enough_wmark = max(1UL * 1024 * 1024 * 1024 >> PAGE_SHIFT, + pgdat->node_present_pages >> 4); + for (z = pgdat->nr_zones - 1; z >= 0; z--) { + struct zone *zone = pgdat->node_zones + z; + + if (!populated_zone(zone)) + continue; + + if (zone_watermark_ok(zone, 0, + promo_wmark_pages(zone) + enough_wmark, + ZONE_MOVABLE, 0)) + return true; + } + return false; +} + void node_get_allowed_targets(pg_data_t *pgdat, nodemask_t *targets) { struct memory_tier *memtier; -- 2.53.1-Meta