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=1796382526; b=1sDTvF2j8+W7L1SSzdts/5sYoqM5Z3i+1FBHzeyvBRCgkGpddnbdJr+LGuGZwW9fgYhs ExehVmsKJUVH8ebSPmENdG3Rc9dIUZVZVOrp0SjYEgfsqlQA1SoOHGfx8ZP0XcsTnnfA3 pRrqC7dpY2wvnmTl4H7RtXZEnoJw0bn5eDKaRVGNdUZ2puhjO9+8IvpeCq0SO0Hd8QnRl Fm7IwOJuO33oT1RIB8o4FC8n21M6aTBPe0sxPBqNIrk4CwKFI47odY1dk/e5Yzy47/BXV 7cHCvXKorNmEaSwjZ4ScWtgR23DBQihG9wz4MNONQIB3QJkBERLxYioCjAZYIrEBh8A== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796382526; 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=dKoDAks9/51aYld6tXkX11mJ0M7CR6ZLpDgK+f7tyLI=; b=oWeiazVXa50IAGhrzeIy2qqAjATAmslv4kWu09NDs9X8v2F/0Dl+1RsjYaGTUPTJMrsK O0aIJNuQTjkA1m43HZzuPzlLae7k8TP2lfXztBxqSfLEO7D84hJm/s7iVc7EuKmWqXAMm QWJot38j1mDKjwd+Bhay9eV1jwdT6B9CD/giRAjpqPNKqffgm1l2Mhurw+BV5GzpkVMGY uFbzx5mmRC/JK+OvhVu3xm2s4/amAwnIBB6sD6BkeReh1Aei6aKvqScaFBHqQkbtbsrH6 7EwT9vNmTkicBNpkPl5dNBAmHI0iWLwTWOBR3djKwkyyynD61wHxzibtZfiuMCmLaPQ== 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=K8eCxFTT; 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 3FFDF606A322; Fri, 4 Dec 2026 11:08:46 +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=K8eCxFTT Received: by smtp.kernel.org (Postfix) with ESMTPSA id BA66E1F000C2; Fri, 4 Dec 2026 11:08:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796382526; bh=dKoDAks9/51aYld6tXkX11mJ0M7CR6ZLpDgK+f7tyLI=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=K8eCxFTT0gxMhZpHjZspuoDXmbQpnspLUDLMy+ZYAbnRaw8Xv4lSwDOy2Mt02t9rn 2SjRyamDtqXW8nFYdo73FKZmct4BnopoQIlVav6Ey/MjwcwOjfRI4MZMle8K2Ydu4L qs8fE9z6T7cHs0lKcX3Y18FxhIxGX7+qwvpALqeo= 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 6.18 490/703] mm/migrate: move NR_KERNEL_FILE_PAGES on cross-node migration Date: Fri, 4 Dec 2026 19:06:29 +0900 Message-ID: <20261204100640.837900731@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261204100627.522266145@linuxfoundation.org> References: <20261204100627.522266145@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore X-Mailing-List: patches@lists.linux.dev List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.18-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 @@ -687,6 +687,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);