Commit c6a7f5728a1db45d30df55a01adc130b4ab0327c

Authored by KOSAKI Motohiro
Committed by Linus Torvalds
1 parent 71de1ccbe1

mm: oom analysis: Show kernel stack usage in /proc/meminfo and OOM log output

The amount of memory allocated to kernel stacks can become significant and
cause OOM conditions.  However, we do not display the amount of memory
consumed by stacks.

Add code to display the amount of memory used for stacks in /proc/meminfo.

Signed-off-by: KOSAKI Motohiro <kosaki.motohiro@jp.fujitsu.com>
Reviewed-by: Christoph Lameter <cl@linux-foundation.org>
Reviewed-by: Minchan Kim <minchan.kim@gmail.com>
Reviewed-by: Rik van Riel <riel@redhat.com>
Cc: David Rientjes <rientjes@google.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

Showing 6 changed files with 22 additions and 1 deletions Side-by-side Diff

... ... @@ -85,6 +85,7 @@
85 85 "Node %d FilePages: %8lu kB\n"
86 86 "Node %d Mapped: %8lu kB\n"
87 87 "Node %d AnonPages: %8lu kB\n"
  88 + "Node %d KernelStack: %8lu kB\n"
88 89 "Node %d PageTables: %8lu kB\n"
89 90 "Node %d NFS_Unstable: %8lu kB\n"
90 91 "Node %d Bounce: %8lu kB\n"
... ... @@ -116,6 +117,8 @@
116 117 nid, K(node_page_state(nid, NR_FILE_PAGES)),
117 118 nid, K(node_page_state(nid, NR_FILE_MAPPED)),
118 119 nid, K(node_page_state(nid, NR_ANON_PAGES)),
  120 + nid, node_page_state(nid, NR_KERNEL_STACK) *
  121 + THREAD_SIZE / 1024,
119 122 nid, K(node_page_state(nid, NR_PAGETABLE)),
120 123 nid, K(node_page_state(nid, NR_UNSTABLE_NFS)),
121 124 nid, K(node_page_state(nid, NR_BOUNCE)),
... ... @@ -84,6 +84,7 @@
84 84 "Slab: %8lu kB\n"
85 85 "SReclaimable: %8lu kB\n"
86 86 "SUnreclaim: %8lu kB\n"
  87 + "KernelStack: %8lu kB\n"
87 88 "PageTables: %8lu kB\n"
88 89 #ifdef CONFIG_QUICKLIST
89 90 "Quicklists: %8lu kB\n"
... ... @@ -128,6 +129,7 @@
128 129 global_page_state(NR_SLAB_UNRECLAIMABLE)),
129 130 K(global_page_state(NR_SLAB_RECLAIMABLE)),
130 131 K(global_page_state(NR_SLAB_UNRECLAIMABLE)),
  132 + global_page_state(NR_KERNEL_STACK) * THREAD_SIZE / 1024,
131 133 K(global_page_state(NR_PAGETABLE)),
132 134 #ifdef CONFIG_QUICKLIST
133 135 K(quicklist_total_size()),
include/linux/mmzone.h
... ... @@ -94,10 +94,11 @@
94 94 NR_SLAB_RECLAIMABLE,
95 95 NR_SLAB_UNRECLAIMABLE,
96 96 NR_PAGETABLE, /* used for pagetables */
  97 + NR_KERNEL_STACK,
  98 + /* Second 128 byte cacheline */
97 99 NR_UNSTABLE_NFS, /* NFS unstable pages */
98 100 NR_BOUNCE,
99 101 NR_VMSCAN_WRITE,
100   - /* Second 128 byte cacheline */
101 102 NR_WRITEBACK_TEMP, /* Writeback using temporary buffers */
102 103 #ifdef CONFIG_NUMA
103 104 NUMA_HIT, /* allocated in intended node */
... ... @@ -136,9 +136,17 @@
136 136 /* SLAB cache for mm_struct structures (tsk->mm) */
137 137 static struct kmem_cache *mm_cachep;
138 138  
  139 +static void account_kernel_stack(struct thread_info *ti, int account)
  140 +{
  141 + struct zone *zone = page_zone(virt_to_page(ti));
  142 +
  143 + mod_zone_page_state(zone, NR_KERNEL_STACK, account);
  144 +}
  145 +
139 146 void free_task(struct task_struct *tsk)
140 147 {
141 148 prop_local_destroy_single(&tsk->dirties);
  149 + account_kernel_stack(tsk->stack, -1);
142 150 free_thread_info(tsk->stack);
143 151 rt_mutex_debug_task_free(tsk);
144 152 ftrace_graph_exit_task(tsk);
... ... @@ -253,6 +261,9 @@
253 261 tsk->btrace_seq = 0;
254 262 #endif
255 263 tsk->splice_pipe = NULL;
  264 +
  265 + account_kernel_stack(ti, 1);
  266 +
256 267 return tsk;
257 268  
258 269 out:
... ... @@ -2177,6 +2177,7 @@
2177 2177 " mapped:%lukB"
2178 2178 " slab_reclaimable:%lukB"
2179 2179 " slab_unreclaimable:%lukB"
  2180 + " kernel_stack:%lukB"
2180 2181 " pagetables:%lukB"
2181 2182 " unstable:%lukB"
2182 2183 " bounce:%lukB"
... ... @@ -2201,6 +2202,8 @@
2201 2202 K(zone_page_state(zone, NR_FILE_MAPPED)),
2202 2203 K(zone_page_state(zone, NR_SLAB_RECLAIMABLE)),
2203 2204 K(zone_page_state(zone, NR_SLAB_UNRECLAIMABLE)),
  2205 + zone_page_state(zone, NR_KERNEL_STACK) *
  2206 + THREAD_SIZE / 1024,
2204 2207 K(zone_page_state(zone, NR_PAGETABLE)),
2205 2208 K(zone_page_state(zone, NR_UNSTABLE_NFS)),
2206 2209 K(zone_page_state(zone, NR_BOUNCE)),
... ... @@ -639,6 +639,7 @@
639 639 "nr_slab_reclaimable",
640 640 "nr_slab_unreclaimable",
641 641 "nr_page_table_pages",
  642 + "nr_kernel_stack",
642 643 "nr_unstable",
643 644 "nr_bounce",
644 645 "nr_vmscan_write",