From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796381069; b=BV9gmyJ64AsWWOPaDJR7S+GFDsV9cBma02/k742fi6EfiRbYR4agekmuQ8T01HF9CB6l FZHD0/vCNUj4KFIRzlF1Dq10fFzmfRDi+bOkVx3NwDJbRNiWK8rFJyNbFVkWeTLeDi8/3 h/p004RESgZycan86bzano5dvM9rqbJlPzoHTjezc8tWA4y8GE6bRCGEdt9aQRMiUfvG8 WiI1gLtuzw8lfcEdGlNpzJiVVRd+MOZe+0THwmdUavAZf3o6XWZe48oQ+QYLrEmbR9xSM QzYDr/wvwSbdqJtPe7na//vheADhCkh7E42LGBNjfVdnvcjzOPI+Vme+yMxAsx7zvPQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796381069; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:User-Agent:X-stable:X-Patchwork-Hint: MIME-Version:Content-Transfer-Encoding; bh=752Tl+/FTILp6rV/efljj+6Y6mQjdBvPOaL60InakRI=; b=03PhomCbmpzCFEuJBZ2+qRJY4Ar7V6QCAtlZ8cjagnjlJFX1f/myNCJBAXZPQOm0H2cV grx/WhTOK4z5cCNd9mS3XeOcn057LQ+DJuw5UE2Y3jRZPSybCVZFWjumiDEpXbREo8lzd h8F7rSt4A4fQvYhfh5JuhOdSVtGpbnk96pWcEraWMrjlMPWsG+JdosUWf2dnLvMTKNw8y nFuXc37IswTlh45Fzi7xbdR7ebJmsAfOAisgUA/USe1UpOd/RDMBv55L/1uodYVNHNoCP N1Xo1vho5VycADpNHp1XZtvVfXiHUYUL74Px9Nc0GecVSnpniKYg/MIaxrEU8b9tHZA== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=0pkQmGDy; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A3387606A32D; Fri, 4 Dec 2026 10:44:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=0pkQmGDy Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2B6AE1F000C2; Fri, 4 Dec 2026 10:44:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796381069; bh=752Tl+/FTILp6rV/efljj+6Y6mQjdBvPOaL60InakRI=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=0pkQmGDytRvLLAjzVUmsEgNTyoSpVzHVVhe5jiokkeG1pGWrBlcmPkOrK4RM6KFEK QU4CA8dBPQgOLoID4LXMpYquFUPtdTceFs6RSYI5PttYQaUrv4lstI2XY27dsD63k1 7cgkWhHncw3pF0ekMzzPnfgw2ZTH0QTJzR3Suilw= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Ridong Chen , Andrew Morton , Shivank Garg , "David Hildenbrand (Arm)" , Zi Yan , Shakeel Butt , Matthew Brost , Joshua Hahn , Byungchul Park , Gregory Price , Ying Huang , Alistair Popple , Boris Burkov Subject: [PATCH 7.3 546/742] mm/migrate: move NR_KERNEL_FILE_PAGES on cross-node migration Date: Fri, 4 Dec 2026 19:06:50 +0900 Message-ID: <20261204100649.665299974@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261204100635.034361255@linuxfoundation.org> References: <20261204100635.034361255@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore X-Mailing-List: stable@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 7.3-stable review patch. If anyone has any objections, please let me know. ------------------ From: Ridong Chen commit 4ac11db025da54f389796920b253221d1afe6aac upstream. NR_KERNEL_FILE_PAGES counts page cache folios of mappings flagged AS_KERNEL_FILE (currently the btrfs btree inode). It is a per-node counter: filemap_add_folio() adds to folio_pgdat() of the new folio and filemap_unaccount_folio() subtracts from folio_pgdat() of the folio being removed. __folio_migrate_mapping() does not move it when such a folio is migrated to another node, so the source node keeps the count forever and the destination node underflows once the folio is freed. btree folios are migratable through btree_migrate_folio(), so demotion, DAMON-based migration (DAMOS_MIGRATE_{HOT,COLD}) or memory offlining all hit this. Reproducer, on a QEMU guest with two memory tiers (node0 is DRAM with all CPUs, node1 is a CPU-less slower node described via HMAT) and /sys/kernel/mm/numa/demotion_enabled set: 1. mount a btrfs and create 20000 empty files, so that btree folios are cached on node0; 2. echo 2G > /sys/devices/system/node/node0/reclaim, which demotes them to node1; 3. umount and drop caches. nr_kernel_file_pages in /sys/devices/system/node/nodeN/vmstat after each step: without this patch with this patch node0 node1 node0 node1 1. cached 1868 0 1868 0 2. demoted 1868 0 36 1832 3. dropped 1832 0 (*) 0 0 (*) the counter has underflowed to -1832; negative values read as 0. The global value in /proc/vmstat is 0 after step 3 in both cases. Move it together with the other node-keyed page cache counters. It is a node-only counter, so use the node accessor, matching how it is accounted elsewhere. Interrupts are disabled here, as for the zone counters below. This was pointed out by Shivank while reviewing the NR_FILE_THPS fix for the same function. Link: https://lore.kernel.org/20261027043214.2248986-1-ridong.chen@linux.dev Fixes: e3a9ac4e866e ("mm: add vmstat for kernel_file pages") Signed-off-by: Ridong Chen Signed-off-by: Andrew Morton Suggested-by: Shivank Garg Acked-by: David Hildenbrand (Arm) Reviewed-by: Shivank Garg Acked-by: Zi Yan Acked-by: Shakeel Butt Cc: Matthew Brost Cc: Joshua Hahn Cc: Byungchul Park Cc: Gregory Price Cc: Ying Huang Cc: Alistair Popple Cc: Boris Burkov Cc: Signed-off-by: Greg Kroah-Hartman --- mm/migrate.c | 6 ++++++ 1 file changed, 6 insertions(+) --- a/mm/migrate.c +++ b/mm/migrate.c @@ -705,6 +705,12 @@ static int __folio_migrate_mapping(struc mod_lruvec_state(old_lruvec, NR_FILE_THPS, -nr); mod_lruvec_state(new_lruvec, NR_FILE_THPS, nr); } + if (test_bit(AS_KERNEL_FILE, &mapping->flags)) { + __mod_node_page_state(oldzone->zone_pgdat, + NR_KERNEL_FILE_PAGES, -nr); + __mod_node_page_state(newzone->zone_pgdat, + NR_KERNEL_FILE_PAGES, nr); + } #ifdef CONFIG_SWAP if (folio_test_swapcache(folio)) { mod_lruvec_state(old_lruvec, NR_SWAPCACHE, -nr);