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=1796382524; b=loFlTpMId/boTwh7PbmeBRAFvNZj/tQoL4r9m0GCSl+r1ZWof27Zwm4HiU89RN3kFszo tGHuuy/X0o3U6SH4KJbPtOQgp/GlbvUzqZvIhBwki+RMXpEC7K2w5Uxx/Wj+HAMTgmZBs AL+GtnIJQP5vhpIwIgO342Ygh0FTgW+y5FbwYGHDkTio3wAbwNd9wTkZouqUDVxKnnDI3 csqnAU5W2kDZ9Dj9L/28TPO05KCgiTrgk/7eLnmlBWLRR8Z8aJIaGrrDFyw0Mw/W6eV4O hl6bVVjZTxrj1aJ2cF9n80VCuCNvHkU144PfTu9eUkGEwmAWZY5SVXJ2vtfmipn3E7Q== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796382524; 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=VMZNerhpla/asdpkit/RtNfRw1dMDYsQT74V1ulx+/g=; b=miTf58DbF1roIP4C2U0Nda3+Eic9ts1jPTyCjzqCAe20yVmelT9gvSXpIHCpZ/EZa8yQ E/Rm0evjB7RKEYkD2bJxdKfUxIxUAULLYyF0SxLki/QbwExvIovsacDcTB6nZlRF3/bEq GJ8TSrjCCP4JF3pB5bzbETbu/7QkrVjTPxqFoqLMPlRjWHgY0vJhMqQK4wK4G8u6/BLaR /ioMuGbOfvvGQLKBmzmlCIwFo/XeCyTnCt7hJWGjrz75S4V0cN3FgqXYCR2WscIwztCg+ WjV+4rKw+dLLOcpZxC9YTZJVFCyGvqRaOiJT8VdF29/HrGZnV0H2cqQ6RhR1MtwBMmw== 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="juQsdGN/"; 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 84335606A32C; Fri, 4 Dec 2026 11:08:44 +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=juQsdGN/ Received: by smtp.kernel.org (Postfix) with ESMTPSA id AD20B1F000C2; Fri, 4 Dec 2026 11:08:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796382524; bh=VMZNerhpla/asdpkit/RtNfRw1dMDYsQT74V1ulx+/g=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=juQsdGN/z1N89QOUCGXdT4VxGCk9QxC4aJmi3Q9bhdAzlxkL2Rp5Zv5AnHj4GJDi6 GXHg1Qv4Vah04dcVQk5po8tuFUxj0yDzWclKTZUmNXebyZ+9HrZ7Nn0E/wTZhB7hX/ IrGyOKC3nEvShTFmInvUJ+ZhxO90rNtqu46HkjOk= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Ridong Chen , Andrew Morton , "David Hildenbrand (Arm)" , Zi Yan , Matthew Brost , Joshua Hahn , Byungchul Park , Gregory Price , Ying Huang , Alistair Popple , "Matthew Wilcox (Oracle)" , "Garg, Shivank" Subject: [PATCH 6.18 489/703] mm/migrate: move NR_FILE_THPS on cross-node migration Date: Fri, 4 Dec 2026 19:06:28 +0900 Message-ID: <20261204100640.810692242@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 a2108a958143de74b4e5ddca12b01f05ecd030f9 upstream. When a page cache folio is migrated to another node, __folio_migrate_mapping() moves the per-node and per-memcg counters that are keyed off the folio's node: NR_FILE_PAGES, NR_SHMEM, NR_SHMEM_THPS, NR_SWAPCACHE and NR_FILE_DIRTY. NR_FILE_THPS is not moved, although __filemap_add_folio() charges it to the source node and filemap_unaccount_folio() takes it off whatever node the folio lives on when it is removed. Commit 0b52c420350e ("mm: fix shmem THP counters on migration") added the NR_SHMEM_THPS case but not its file-backed counterpart. Now that ext4, xfs, btrfs and erofs can all have PMD-sized page cache folios, migrating them via NUMA balancing, mbind(), migratepages, demotion or memory offlining leaks FileHugePages on the source node and underflows it on the destination, in both /sys/devices/system/node/nodeN/meminfo and memory.numa_stat. The global value is unaffected, which is why this went unnoticed. Reproducer, on a 2-node QEMU guest with THP set to "always": 1. read a 256M ext4 file through a MADV_HUGEPAGE mapping while bound to node 0, so its page cache is 128 PMD-sized folios on node 0; 2. move the mapping to node 1 with mbind(MPOL_MF_MOVE); 3. unmap the file and drop its page cache. nr_file_hugepages in /sys/devices/system/node/nodeN/vmstat after each step (in units of PMD-sized folios): without this patch with this patch node0 node1 node0 node1 1. cached 128 0 128 0 2. migrated 128 0 0 128 3. dropped 128 0 (*) 0 0 (*) the counter has underflowed to -128; negative values read as 0. Without the patch the 128 folios stay accounted to node 0 forever, and every further round adds another 128. The same happens to the per-memcg per-node counter: after step 3, memory.stat of the cgroup shows "file_thp 0", while memory.numa_stat still shows "file_thp N0=268435456 N1=0". With the patch both are 0. Move NR_FILE_THPS together with NR_FILE_PAGES, using the same condition filemap_unaccount_folio() uses to take it off, so that THPs in the swap cache are left alone. Link: https://lore.kernel.org/20261025110209.4105994-1-ridong.chen@linux.dev Fixes: d68eccad3706 ("mm/filemap: Allow large folios to be added to the page cache") Signed-off-by: Ridong Chen Signed-off-by: Andrew Morton Acked-by: David Hildenbrand (Arm) Cc: Zi Yan Cc: Matthew Brost Cc: Joshua Hahn Cc: Byungchul Park Cc: Gregory Price Cc: Ying Huang Cc: Alistair Popple Cc: Matthew Wilcox (Oracle) Cc: "Garg, Shivank" Cc: Signed-off-by: Greg Kroah-Hartman --- mm/migrate.c | 4 ++++ 1 file changed, 4 insertions(+) --- a/mm/migrate.c +++ b/mm/migrate.c @@ -682,6 +682,10 @@ static int __folio_migrate_mapping(struc __mod_lruvec_state(old_lruvec, NR_SHMEM_THPS, -nr); __mod_lruvec_state(new_lruvec, NR_SHMEM_THPS, nr); } + } else if (!folio_test_swapbacked(folio) && + folio_test_pmd_mappable(folio)) { + mod_lruvec_state(old_lruvec, NR_FILE_THPS, -nr); + mod_lruvec_state(new_lruvec, NR_FILE_THPS, nr); } #ifdef CONFIG_SWAP if (folio_test_swapcache(folio)) {