]> git.proxmox.com Git - mirror_ubuntu-kernels.git/commitdiff
mm: memcontrol: add file_thp, shmem_thp to memory.stat
authorJohannes Weiner <hannes@cmpxchg.org>
Tue, 15 Dec 2020 03:06:20 +0000 (19:06 -0800)
committerLinus Torvalds <torvalds@linux-foundation.org>
Tue, 15 Dec 2020 20:13:39 +0000 (12:13 -0800)
As huge page usage in the page cache and for shmem files proliferates in
our production environment, the performance monitoring team has asked for
per-cgroup stats on those pages.

We already track and export anon_thp per cgroup.  We already track file
THP and shmem THP per node, so making them per-cgroup is only a matter of
switching from node to lruvec counters.  All callsites are in places where
the pages are charged and locked, so page->memcg is stable.

[hannes@cmpxchg.org: add documentation]
Link: https://lkml.kernel.org/r/20201026174029.GC548555@cmpxchg.org
Link: https://lkml.kernel.org/r/20201022151844.489337-1-hannes@cmpxchg.org
Signed-off-by: Johannes Weiner <hannes@cmpxchg.org>
Reviewed-by: Rik van Riel <riel@surriel.com>
Reviewed-by: Shakeel Butt <shakeelb@google.com>
Acked-by: David Rientjes <rientjes@google.com>
Acked-by: Michal Hocko <mhocko@suse.com>
Acked-by: Song Liu <songliubraving@fb.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Documentation/admin-guide/cgroup-v2.rst
mm/filemap.c
mm/huge_memory.c
mm/khugepaged.c
mm/memcontrol.c
mm/shmem.c

index 608d7c279396b5832a07dea3a1d5ce3c75c24142..515bb13084a02ff7b89a62a427a1470750b322a4 100644 (file)
@@ -1300,6 +1300,14 @@ PAGE_SIZE multiple when read back.
                Amount of memory used in anonymous mappings backed by
                transparent hugepages
 
+         file_thp
+               Amount of cached filesystem data backed by transparent
+               hugepages
+
+         shmem_thp
+               Amount of shm, tmpfs, shared anonymous mmap()s backed by
+               transparent hugepages
+
          inactive_anon, active_anon, inactive_file, active_file, unevictable
                Amount of memory, swap-backed and filesystem-backed,
                on the internal memory management lists used by the
index 343ba8571ff957dce77d4284762f52f82d51cf1f..39bb88140680a12617e5008e8d219deea9630f48 100644 (file)
@@ -204,9 +204,9 @@ static void unaccount_page_cache_page(struct address_space *mapping,
        if (PageSwapBacked(page)) {
                __mod_lruvec_page_state(page, NR_SHMEM, -nr);
                if (PageTransHuge(page))
-                       __dec_node_page_state(page, NR_SHMEM_THPS);
+                       __dec_lruvec_page_state(page, NR_SHMEM_THPS);
        } else if (PageTransHuge(page)) {
-               __dec_node_page_state(page, NR_FILE_THPS);
+               __dec_lruvec_page_state(page, NR_FILE_THPS);
                filemap_nr_thps_dec(mapping);
        }
 
index ec2bb93f7431438aa4d3f9d44bd5b02c3279e6b9..42b18d4610866aa6d629b44a966dc6219e4f7e09 100644 (file)
@@ -2710,9 +2710,9 @@ int split_huge_page_to_list(struct page *page, struct list_head *list)
                spin_unlock(&ds_queue->split_queue_lock);
                if (mapping) {
                        if (PageSwapBacked(head))
-                               __dec_node_page_state(head, NR_SHMEM_THPS);
+                               __dec_lruvec_page_state(head, NR_SHMEM_THPS);
                        else
-                               __dec_node_page_state(head, NR_FILE_THPS);
+                               __dec_lruvec_page_state(head, NR_FILE_THPS);
                }
 
                __split_huge_page(page, list, end, flags);
index 4e3dff13eb70c5a85d6a91a3b2dd446fe1513b2c..7572925327671de9693b2e2f9108cbad88d9798f 100644 (file)
@@ -1845,9 +1845,9 @@ out_unlock:
        }
 
        if (is_shmem)
-               __inc_node_page_state(new_page, NR_SHMEM_THPS);
+               __inc_lruvec_page_state(new_page, NR_SHMEM_THPS);
        else {
-               __inc_node_page_state(new_page, NR_FILE_THPS);
+               __inc_lruvec_page_state(new_page, NR_FILE_THPS);
                filemap_nr_thps_inc(mapping);
        }
 
index 29459a6ce1c7ad06f00d9cc3873a4126fd1914cb..c3654510fb70c02864e445fe3f4fd122636dd526 100644 (file)
@@ -1512,6 +1512,8 @@ static struct memory_stat memory_stats[] = {
         * constant(e.g. powerpc).
         */
        { "anon_thp", 0, NR_ANON_THPS },
+       { "file_thp", 0, NR_FILE_THPS },
+       { "shmem_thp", 0, NR_SHMEM_THPS },
 #endif
        { "inactive_anon", PAGE_SIZE, NR_INACTIVE_ANON },
        { "active_anon", PAGE_SIZE, NR_ACTIVE_ANON },
@@ -1542,7 +1544,9 @@ static int __init memory_stats_init(void)
 
        for (i = 0; i < ARRAY_SIZE(memory_stats); i++) {
 #ifdef CONFIG_TRANSPARENT_HUGEPAGE
-               if (memory_stats[i].idx == NR_ANON_THPS)
+               if (memory_stats[i].idx == NR_ANON_THPS ||
+                   memory_stats[i].idx == NR_FILE_THPS ||
+                   memory_stats[i].idx == NR_SHMEM_THPS)
                        memory_stats[i].ratio = HPAGE_PMD_SIZE;
 #endif
                VM_BUG_ON(!memory_stats[i].ratio);
index b7361fce50bc48fdf14e16ffe2181d46bd836f9d..67ff829e2f0e4627c7ff61d9b1dd36cd50293f1a 100644 (file)
@@ -713,7 +713,7 @@ next:
                }
                if (PageTransHuge(page)) {
                        count_vm_event(THP_FILE_ALLOC);
-                       __inc_node_page_state(page, NR_SHMEM_THPS);
+                       __inc_lruvec_page_state(page, NR_SHMEM_THPS);
                }
                mapping->nrpages += nr;
                __mod_lruvec_page_state(page, NR_FILE_PAGES, nr);