]> www.infradead.org Git - users/jedix/linux-maple.git/commitdiff
mm: add vmstat for kernel_file pages
authorBoris Burkov <boris@bur.io>
Thu, 21 Aug 2025 21:55:36 +0000 (14:55 -0700)
committerAndrew Morton <akpm@linux-foundation.org>
Fri, 12 Sep 2025 00:25:20 +0000 (17:25 -0700)
Kernel file pages are tricky to track because they are indistinguishable
from files whose usage is accounted to the root cgroup.

To maintain good accounting, introduce a vmstat counter tracking kernel
file pages.

Confirmed that these work as expected at a high level by mounting a btrfs
using AS_KERNEL_FILE for metadata pages, and seeing the counter rise with
fs usage then go back to a minimal level after drop_caches and finally
down to 0 after unmounting the fs.

Link: https://lkml.kernel.org/r/08ff633e3a005ed5f7691bfd9f58a5df8e474339.1755812945.git.boris@bur.io
Signed-off-by: Boris Burkov <boris@bur.io>
Suggested-by: Shakeel Butt <shakeel.butt@linux.dev>
Acked-by: Shakeel Butt <shakeel.butt@linux.dev>
Tested-by: syzbot@syzkaller.appspotmail.com
Cc: Johannes Weiner <hannes@cmpxchg.org>
Cc: Matthew Wilcox (Oracle) <willy@infradead.org>
Cc: Michal Hocko <mhocko@kernel.org>
Cc: Muchun Song <muchun.song@linux.dev>
Cc: Qu Wenruo <wqu@suse.com>
Cc: Roman Gushchin <roman.gushchin@linux.dev>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
include/linux/mmzone.h
mm/filemap.c
mm/vmstat.c

index fe13ad175fed8a473c8f5f11b733eab03bfed02a..f3272ef5131badc425ea20e96f29a1369588f835 100644 (file)
@@ -259,6 +259,7 @@ enum node_stat_item {
        NR_HUGETLB,
 #endif
        NR_BALLOON_PAGES,
+       NR_KERNEL_FILE_PAGES,
        NR_VM_NODE_STAT_ITEMS
 };
 
index 92ea20356f227d1e37510b0176ae5f7cd2206577..cd9387b0a5b50063cf96960e977d31eb0b7f82b4 100644 (file)
@@ -190,6 +190,9 @@ static void filemap_unaccount_folio(struct address_space *mapping,
                __lruvec_stat_mod_folio(folio, NR_FILE_THPS, -nr);
                filemap_nr_thps_dec(mapping);
        }
+       if (test_bit(AS_KERNEL_FILE, &folio->mapping->flags))
+               mod_node_page_state(folio_pgdat(folio),
+                                   NR_KERNEL_FILE_PAGES, -nr);
 
        /*
         * At this point folio must be either written or cleaned by
@@ -989,6 +992,10 @@ int filemap_add_folio(struct address_space *mapping, struct folio *folio,
                if (!(gfp & __GFP_WRITE) && shadow)
                        workingset_refault(folio, shadow);
                folio_add_lru(folio);
+               if (kernel_file)
+                       mod_node_page_state(folio_pgdat(folio),
+                                           NR_KERNEL_FILE_PAGES,
+                                           folio_nr_pages(folio));
        }
        return ret;
 }
index e74f0b2a10215c7e7c598f76bd316d52636b4457..e522decf6a72f741aa16605566db61ce958878e2 100644 (file)
@@ -1290,6 +1290,7 @@ const char * const vmstat_text[] = {
        [I(NR_HUGETLB)]                         = "nr_hugetlb",
 #endif
        [I(NR_BALLOON_PAGES)]                   = "nr_balloon_pages",
+       [I(NR_KERNEL_FILE_PAGES)]               = "nr_kernel_file_pages",
 #undef I
 
        /* system-wide enum vm_stat_item counters */