Re: [PATCH mm-new] mm/migrate: move NR_KERNEL_FILE_PAGES on cross-node migration
From: Shakeel Butt
Date: Thu Oct 29 2026 - 22:02:46 EST
On Thu, Oct 29, 2026 at 06:03:26PM -0700, Andrew Morton wrote:
> On Tue, 27 Oct 2026 12:32:14 +0800 Ridong Chen <ridong.chen@xxxxxxxxx> wrote:
>
> > From: Ridong Chen <chenridong@xxxxxxxxxx>
> >
> > 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.
> >
>
> Thanks.
>
> This and your "mm/migrate: move NR_FILE_THPS on cross-node migration"
> "only" address accounting errors, but a bug is a bug and these bugs
> might mess up people's memory-monitoring and NUMA-management tools. So
> I think cc:stable.
>
> What do people think?
Yes this is stable material.