]> git.kernelconcepts.de Git - karo-tx-linux.git/commitdiff
mm: memcontrol: report kernel stack usage in cgroup2 memory.stat
authorVladimir Davydov <vdavydov@virtuozzo.com>
Thu, 17 Mar 2016 21:17:38 +0000 (14:17 -0700)
committerLinus Torvalds <torvalds@linux-foundation.org>
Thu, 17 Mar 2016 22:09:34 +0000 (15:09 -0700)
Show how much memory is allocated to kernel stacks.

Signed-off-by: Vladimir Davydov <vdavydov@virtuozzo.com>
Acked-by: Johannes Weiner <hannes@cmpxchg.org>
Cc: Michal Hocko <mhocko@kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Documentation/cgroup-v2.txt
include/linux/memcontrol.h
kernel/fork.c
mm/memcontrol.c

index e4e0c1d78ceee0efce7ced1e945e813b44950648..e2f4e7948a666128d048abc3ca7c67212228380b 100644 (file)
@@ -843,6 +843,10 @@ PAGE_SIZE multiple when read back.
                Amount of memory used to cache filesystem data,
                including tmpfs and shared memory.
 
+         kernel_stack
+
+               Amount of memory allocated to kernel stacks.
+
          slab
 
                Amount of memory used for storing in-kernel data
index e7af4834ffea74ef3d7bc059b2a8784a09467f86..d6300313b2980ad8e41999072500fb66bd6c8a7e 100644 (file)
@@ -52,9 +52,10 @@ enum mem_cgroup_stat_index {
        MEM_CGROUP_STAT_SWAP,           /* # of pages, swapped out */
        MEM_CGROUP_STAT_NSTATS,
        /* default hierarchy stats */
-       MEMCG_SOCK = MEM_CGROUP_STAT_NSTATS,
+       MEMCG_KERNEL_STACK = MEM_CGROUP_STAT_NSTATS,
        MEMCG_SLAB_RECLAIMABLE,
        MEMCG_SLAB_UNRECLAIMABLE,
+       MEMCG_SOCK,
        MEMCG_NR_STAT,
 };
 
index 2e391c754ae730bd2d8520c2ab497c403220c6e3..accb7221d54751ecbd8f440e89066116c3ae8586 100644 (file)
@@ -164,12 +164,20 @@ static struct thread_info *alloc_thread_info_node(struct task_struct *tsk,
        struct page *page = alloc_kmem_pages_node(node, THREADINFO_GFP,
                                                  THREAD_SIZE_ORDER);
 
+       if (page)
+               memcg_kmem_update_page_stat(page, MEMCG_KERNEL_STACK,
+                                           1 << THREAD_SIZE_ORDER);
+
        return page ? page_address(page) : NULL;
 }
 
 static inline void free_thread_info(struct thread_info *ti)
 {
-       free_kmem_pages((unsigned long)ti, THREAD_SIZE_ORDER);
+       struct page *page = virt_to_page(ti);
+
+       memcg_kmem_update_page_stat(page, MEMCG_KERNEL_STACK,
+                                   -(1 << THREAD_SIZE_ORDER));
+       __free_kmem_pages(page, THREAD_SIZE_ORDER);
 }
 # else
 static struct kmem_cache *thread_info_cache;
index 3ad64bf464fd62a843cb60e23b5c34bf6c977619..4b7dda7c2e74d000493bea0230ed3f75ad44268f 100644 (file)
@@ -5106,6 +5106,8 @@ static int memory_stat_show(struct seq_file *m, void *v)
                   (u64)stat[MEM_CGROUP_STAT_RSS] * PAGE_SIZE);
        seq_printf(m, "file %llu\n",
                   (u64)stat[MEM_CGROUP_STAT_CACHE] * PAGE_SIZE);
+       seq_printf(m, "kernel_stack %llu\n",
+                  (u64)stat[MEMCG_KERNEL_STACK] * PAGE_SIZE);
        seq_printf(m, "slab %llu\n",
                   (u64)(stat[MEMCG_SLAB_RECLAIMABLE] +
                         stat[MEMCG_SLAB_UNRECLAIMABLE]) * PAGE_SIZE);