Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1326771

[PATCH 3/3] mm: memcontrol: report kernel stack usage in cgroup2 memory.stat

From Vladimir Davydov <vdavydov@virtuozzo.com>
Newsgroups linux.kernel
Subject [PATCH 3/3] mm: memcontrol: report kernel stack usage in cgroup2 memory.stat
Date 2016-02-04 14:10 +0100
Message-ID <qYrPA-Co-29@gated-at.bofh.it> (permalink)
References <qYrPA-Co-27@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw


Show how much memory is allocated to kernel stacks.

Signed-off-by: Vladimir Davydov <vdavydov@virtuozzo.com>
---
 Documentation/cgroup-v2.txt |  4 ++++
 include/linux/memcontrol.h  |  1 +
 kernel/fork.c               | 10 +++++++++-
 mm/memcontrol.c             |  2 ++
 4 files changed, 16 insertions(+), 1 deletion(-)

diff --git a/Documentation/cgroup-v2.txt b/Documentation/cgroup-v2.txt
index e4e0c1d78cee..e2f4e7948a66 100644
--- a/Documentation/cgroup-v2.txt
+++ b/Documentation/cgroup-v2.txt
@@ -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
diff --git a/include/linux/memcontrol.h b/include/linux/memcontrol.h
index e7af4834ffea..aaf564881303 100644
--- a/include/linux/memcontrol.h
+++ b/include/linux/memcontrol.h
@@ -55,6 +55,7 @@ enum mem_cgroup_stat_index {
 	MEMCG_SOCK = MEM_CGROUP_STAT_NSTATS,
 	MEMCG_SLAB_RECLAIMABLE,
 	MEMCG_SLAB_UNRECLAIMABLE,
+	MEMCG_KERNEL_STACK,
 	MEMCG_NR_STAT,
 };
 
diff --git a/kernel/fork.c b/kernel/fork.c
index f9c2a24615c1..e439932b82fa 100644
--- a/kernel/fork.c
+++ b/kernel/fork.c
@@ -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;
diff --git a/mm/memcontrol.c b/mm/memcontrol.c
index b198ed5a8928..59f74074c04c 100644
--- a/mm/memcontrol.c
+++ b/mm/memcontrol.c
@@ -5100,6 +5100,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);
-- 
2.1.4

Back to linux.kernel | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

[PATCH 1/3] mm: memcontrol: make tree_{stat,events} fetch all stats Vladimir Davydov <vdavydov@virtuozzo.com> - 2016-02-04 14:10 +0100
  [PATCH 3/3] mm: memcontrol: report kernel stack usage in cgroup2 memory.stat Vladimir Davydov <vdavydov@virtuozzo.com> - 2016-02-04 14:10 +0100
    Re: [PATCH 3/3] mm: memcontrol: report kernel stack usage in cgroup2  memory.stat Johannes Weiner <hannes@cmpxchg.org> - 2016-02-04 22:00 +0100
      Re: [PATCH 3/3] mm: memcontrol: report kernel stack usage in cgroup2  memory.stat Vladimir Davydov <vdavydov@virtuozzo.com> - 2016-02-05 11:10 +0100
  [PATCH 2/3] mm: memcontrol: report slab usage in cgroup2 memory.stat Vladimir Davydov <vdavydov@virtuozzo.com> - 2016-02-04 14:10 +0100
    Re: [PATCH 2/3] mm: memcontrol: report slab usage in cgroup2  memory.stat Johannes Weiner <hannes@cmpxchg.org> - 2016-02-04 21:50 +0100
  Re: [PATCH 1/3] mm: memcontrol: make tree_{stat,events} fetch all  stats Johannes Weiner <hannes@cmpxchg.org> - 2016-02-04 21:50 +0100
    Re: [PATCH 1/3] mm: memcontrol: make tree_{stat,events} fetch all  stats Vladimir Davydov <vdavydov@virtuozzo.com> - 2016-02-05 11:00 +0100
      Re: [PATCH 1/3] mm: memcontrol: make tree_{stat,events} fetch all  stats Johannes Weiner <hannes@cmpxchg.org> - 2016-02-05 16:40 +0100

csiph-web