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=1796381067; b=2IpcAB9kNWXgNW+j92x62QGsIyg9MwAv8TPgmpY81bhueZ60E9uqM/AztIlEhIzNVejP pbYnUJz6S2NYqRtBMHilDQmUL/9rb5hBPi8yz3EIz7z20gaCGLkdLJIdy/hMtNob/euOt I+PA5a9PVt1hN49vMZJpI5NfZI8IEksAVi7axaD4+cHx0wAPdEtok9aEXiY/f29YpI2yT wpQwB4zpC/oiEWCMLW/+h1BgbTj21+ZgUulTwZK4TJq5tFK4sfyidJVUcCE1qLCpCfBo8 fa3SqWRqDuFb6Mk0wr4hxzNREbiLYxnpADhuoX5JnnPchth2RGgwwg2TwDSFm0JdwWQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796381067; 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=XqEG9yuaVb5FNtikZIuQg3vX4Cm1MtGgt0YKsIfey50=; b=SI217YpGyd2Z1/YRcdXuWxgeitYFO7G/gpbFquB+coNPlLXJwkyGMF38rvMlgiLpyKFg XZZP5YFNI2uVLX8hd6YT7NQGubRFNA9TT5+GJypWStLMBvYOP4CTujFpk7L4MyFkk6cCo EmOfzMW0mBB/zcHUMDOODiHo2ypfxBDdxcNwNtPDJLz4Pro8UtOj5SR0mXC6kbtQcyyNv aPRgeeoRhP770QAjpMaWLb2AoMxQdJqZCbldzKUbDzO/C4rzuykd1k1xMBQdI1TFOoq/u zzNOqyijHBN8CIA3Uq2rv/PHvUxSmDh8y0yyr67eA+83hrUQFr8RIAc09kICNeCzuEg== 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=dTbBvOgc; 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 A2EEA606A33E; Fri, 4 Dec 2026 10:44:27 +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=dTbBvOgc Received: by smtp.kernel.org (Postfix) with ESMTPSA id 240531F00936; Fri, 4 Dec 2026 10:44:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796381067; bh=XqEG9yuaVb5FNtikZIuQg3vX4Cm1MtGgt0YKsIfey50=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=dTbBvOgcMTND1ZPoRa9fVUp53SwHpYV40zGXSE66j1rnfPReoD5RvwkSH+qDtmwZP Xo3yxFbnR8qguW5xm6dkJuHJ+mdHPT8r7zheUzkRAZBu9FNe2xCZisyFrfbkegrhlq fXclqNFuIba098SlWbRsahFub9QZ+8GJtXpPk7Ao= 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 7.3 545/742] mm/migrate: move NR_FILE_THPS on cross-node migration Date: Fri, 4 Dec 2026 19:06:49 +0900 Message-ID: <20261204100649.639746239@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: 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 7.3-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 @@ -700,6 +700,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)) {