linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] Show kernel stack usage to /proc/meminfo and OOM log
@ 2009-06-30  6:03 KOSAKI Motohiro
  2009-06-30  6:29 ` KOSAKI Motohiro
  2009-06-30 14:13 ` Christoph Lameter
  0 siblings, 2 replies; 11+ messages in thread
From: KOSAKI Motohiro @ 2009-06-30  6:03 UTC (permalink / raw)
  To: Minchan Kim, Johannes Weiner, David Howells, riel, Andrew Morton,
	LKML, Christoph Lameter, peterz, tytso, linux-mm, elladan,
	npiggin, Barnes, Jesse
  Cc: kosaki.motohiro

Recent "Found the commit that causes the OOMs" discussion notice us that kernel
stack usage should be showed in OOM log.

At least, I think ;)

this patch provide it.


========
Subject: [PATCH] Show kernel stack usage to /proc/meminfo and OOM log

if the system have a lot of thread, kernel stack consume unignorable large size
memory.
IOW, it make a lot of unaccountable memory.

Tons unaccountable memory bring to harder analyse memory related trouble.

Then, kernel stack account is useful.
---
 fs/proc/meminfo.c      |    2 ++
 include/linux/mmzone.h |    3 ++-
 kernel/fork.c          |   13 +++++++++++++
 mm/page_alloc.c        |    6 ++++--
 mm/vmstat.c            |    1 +
 5 files changed, 22 insertions(+), 3 deletions(-)

diff --git a/fs/proc/meminfo.c b/fs/proc/meminfo.c
index d5c410d..1fbf8c0 100644
--- a/fs/proc/meminfo.c
+++ b/fs/proc/meminfo.c
@@ -85,6 +85,7 @@ static int meminfo_proc_show(struct seq_file *m, void *v)
 		"SReclaimable:   %8lu kB\n"
 		"SUnreclaim:     %8lu kB\n"
 		"PageTables:     %8lu kB\n"
+		"KernelStack     %8lu kB\n"
 #ifdef CONFIG_QUICKLIST
 		"Quicklists:     %8lu kB\n"
 #endif
@@ -129,6 +130,7 @@ static int meminfo_proc_show(struct seq_file *m, void *v)
 		K(global_page_state(NR_SLAB_RECLAIMABLE)),
 		K(global_page_state(NR_SLAB_UNRECLAIMABLE)),
 		K(global_page_state(NR_PAGETABLE)),
+		K(global_page_state(NR_KERNEL_STACK)),
 #ifdef CONFIG_QUICKLIST
 		K(quicklist_total_size()),
 #endif
diff --git a/include/linux/mmzone.h b/include/linux/mmzone.h
index 8895985..d9335b8 100644
--- a/include/linux/mmzone.h
+++ b/include/linux/mmzone.h
@@ -94,10 +94,11 @@ enum zone_stat_item {
 	NR_SLAB_RECLAIMABLE,
 	NR_SLAB_UNRECLAIMABLE,
 	NR_PAGETABLE,		/* used for pagetables */
+	NR_KERNEL_STACK,
+	/* Second 128 byte cacheline */
 	NR_UNSTABLE_NFS,	/* NFS unstable pages */
 	NR_BOUNCE,
 	NR_VMSCAN_WRITE,
-	/* Second 128 byte cacheline */
 	NR_WRITEBACK_TEMP,	/* Writeback using temporary buffers */
 #ifdef CONFIG_NUMA
 	NUMA_HIT,		/* allocated in intended node */
diff --git a/kernel/fork.c b/kernel/fork.c
index 467746b..21cd4aa 100644
--- a/kernel/fork.c
+++ b/kernel/fork.c
@@ -137,9 +137,19 @@ struct kmem_cache *vm_area_cachep;
 /* SLAB cache for mm_struct structures (tsk->mm) */
 static struct kmem_cache *mm_cachep;
 
+static void account_kernel_stack(struct thread_info *ti, int on)
+{
+	struct zone* zone = page_zone(virt_to_page(ti));
+	int sign = on ? 1 : -1;
+	long acct = sign * (THREAD_SIZE / PAGE_SIZE);
+
+	mod_zone_page_state(zone, NR_KERNEL_STACK, acct);
+}
+
 void free_task(struct task_struct *tsk)
 {
 	prop_local_destroy_single(&tsk->dirties);
+	account_kernel_stack(tsk->stack, 0);
 	free_thread_info(tsk->stack);
 	rt_mutex_debug_task_free(tsk);
 	ftrace_graph_exit_task(tsk);
@@ -255,6 +265,9 @@ static struct task_struct *dup_task_struct(struct task_struct *orig)
 	tsk->btrace_seq = 0;
 #endif
 	tsk->splice_pipe = NULL;
+
+	account_kernel_stack(ti, 1);
+
 	return tsk;
 
 out:
diff --git a/mm/page_alloc.c b/mm/page_alloc.c
index 30d5093..0edec1c 100644
--- a/mm/page_alloc.c
+++ b/mm/page_alloc.c
@@ -2119,7 +2119,8 @@ void show_free_areas(void)
 		" inactive_file:%lu"
 		" unevictable:%lu"
 		" dirty:%lu writeback:%lu unstable:%lu\n"
-		" free:%lu slab:%lu mapped:%lu pagetables:%lu bounce:%lu\n",
+		" free:%lu slab:%lu mapped:%lu pagetables:%lu bounce:%lu\n"
+		" kernel_stack:%lu\n",
 		global_page_state(NR_ACTIVE_ANON),
 		global_page_state(NR_ACTIVE_FILE),
 		global_page_state(NR_INACTIVE_ANON),
@@ -2133,7 +2134,8 @@ void show_free_areas(void)
 			global_page_state(NR_SLAB_UNRECLAIMABLE),
 		global_page_state(NR_FILE_MAPPED),
 		global_page_state(NR_PAGETABLE),
-		global_page_state(NR_BOUNCE));
+		global_page_state(NR_BOUNCE),
+		global_page_state(NR_KERNEL_STACK));
 
 	for_each_populated_zone(zone) {
 		int i;
diff --git a/mm/vmstat.c b/mm/vmstat.c
index 138bed5..ceda39b 100644
--- a/mm/vmstat.c
+++ b/mm/vmstat.c
@@ -639,6 +639,7 @@ static const char * const vmstat_text[] = {
 	"nr_slab_reclaimable",
 	"nr_slab_unreclaimable",
 	"nr_page_table_pages",
+	"nr_kernel_stack",
 	"nr_unstable",
 	"nr_bounce",
 	"nr_vmscan_write",
-- 
1.6.0.GIT




--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH] Show kernel stack usage to /proc/meminfo and OOM log
  2009-06-30  6:03 [PATCH] Show kernel stack usage to /proc/meminfo and OOM log KOSAKI Motohiro
@ 2009-06-30  6:29 ` KOSAKI Motohiro
  2009-06-30 14:13 ` Christoph Lameter
  1 sibling, 0 replies; 11+ messages in thread
From: KOSAKI Motohiro @ 2009-06-30  6:29 UTC (permalink / raw)
  To: KOSAKI Motohiro
  Cc: Minchan Kim, Johannes Weiner, David Howells, riel, Andrew Morton,
	LKML, Christoph Lameter, peterz, tytso, linux-mm, elladan,
	npiggin, Barnes, Jesse

> Recent "Found the commit that causes the OOMs" discussion notice us that kernel
> stack usage should be showed in OOM log.
> 
> At least, I think ;)
> 
> this patch provide it.
> 
> 
> ========
> Subject: [PATCH] Show kernel stack usage to /proc/meminfo and OOM log
> 
> if the system have a lot of thread, kernel stack consume unignorable large size
> memory.
> IOW, it make a lot of unaccountable memory.
> 
> Tons unaccountable memory bring to harder analyse memory related trouble.
> 
> Then, kernel stack account is useful.

I forgot to insert most important one line ;-)

Signed-off-by: KOSAKI Motohiro <kosaki.motohiro@jp.fujitsu.com>

> ---
>  fs/proc/meminfo.c      |    2 ++
>  include/linux/mmzone.h |    3 ++-
>  kernel/fork.c          |   13 +++++++++++++
>  mm/page_alloc.c        |    6 ++++--
>  mm/vmstat.c            |    1 +
>  5 files changed, 22 insertions(+), 3 deletions(-)
> 
> diff --git a/fs/proc/meminfo.c b/fs/proc/meminfo.c
> index d5c410d..1fbf8c0 100644
> --- a/fs/proc/meminfo.c
> +++ b/fs/proc/meminfo.c
> @@ -85,6 +85,7 @@ static int meminfo_proc_show(struct seq_file *m, void *v)
>  		"SReclaimable:   %8lu kB\n"
>  		"SUnreclaim:     %8lu kB\n"
>  		"PageTables:     %8lu kB\n"
> +		"KernelStack     %8lu kB\n"
>  #ifdef CONFIG_QUICKLIST
>  		"Quicklists:     %8lu kB\n"
>  #endif
> @@ -129,6 +130,7 @@ static int meminfo_proc_show(struct seq_file *m, void *v)
>  		K(global_page_state(NR_SLAB_RECLAIMABLE)),
>  		K(global_page_state(NR_SLAB_UNRECLAIMABLE)),
>  		K(global_page_state(NR_PAGETABLE)),
> +		K(global_page_state(NR_KERNEL_STACK)),
>  #ifdef CONFIG_QUICKLIST
>  		K(quicklist_total_size()),
>  #endif
> diff --git a/include/linux/mmzone.h b/include/linux/mmzone.h
> index 8895985..d9335b8 100644
> --- a/include/linux/mmzone.h
> +++ b/include/linux/mmzone.h
> @@ -94,10 +94,11 @@ enum zone_stat_item {
>  	NR_SLAB_RECLAIMABLE,
>  	NR_SLAB_UNRECLAIMABLE,
>  	NR_PAGETABLE,		/* used for pagetables */
> +	NR_KERNEL_STACK,
> +	/* Second 128 byte cacheline */
>  	NR_UNSTABLE_NFS,	/* NFS unstable pages */
>  	NR_BOUNCE,
>  	NR_VMSCAN_WRITE,
> -	/* Second 128 byte cacheline */
>  	NR_WRITEBACK_TEMP,	/* Writeback using temporary buffers */
>  #ifdef CONFIG_NUMA
>  	NUMA_HIT,		/* allocated in intended node */
> diff --git a/kernel/fork.c b/kernel/fork.c
> index 467746b..21cd4aa 100644
> --- a/kernel/fork.c
> +++ b/kernel/fork.c
> @@ -137,9 +137,19 @@ struct kmem_cache *vm_area_cachep;
>  /* SLAB cache for mm_struct structures (tsk->mm) */
>  static struct kmem_cache *mm_cachep;
>  
> +static void account_kernel_stack(struct thread_info *ti, int on)
> +{
> +	struct zone* zone = page_zone(virt_to_page(ti));
> +	int sign = on ? 1 : -1;
> +	long acct = sign * (THREAD_SIZE / PAGE_SIZE);
> +
> +	mod_zone_page_state(zone, NR_KERNEL_STACK, acct);
> +}
> +
>  void free_task(struct task_struct *tsk)
>  {
>  	prop_local_destroy_single(&tsk->dirties);
> +	account_kernel_stack(tsk->stack, 0);
>  	free_thread_info(tsk->stack);
>  	rt_mutex_debug_task_free(tsk);
>  	ftrace_graph_exit_task(tsk);
> @@ -255,6 +265,9 @@ static struct task_struct *dup_task_struct(struct task_struct *orig)
>  	tsk->btrace_seq = 0;
>  #endif
>  	tsk->splice_pipe = NULL;
> +
> +	account_kernel_stack(ti, 1);
> +
>  	return tsk;
>  
>  out:
> diff --git a/mm/page_alloc.c b/mm/page_alloc.c
> index 30d5093..0edec1c 100644
> --- a/mm/page_alloc.c
> +++ b/mm/page_alloc.c
> @@ -2119,7 +2119,8 @@ void show_free_areas(void)
>  		" inactive_file:%lu"
>  		" unevictable:%lu"
>  		" dirty:%lu writeback:%lu unstable:%lu\n"
> -		" free:%lu slab:%lu mapped:%lu pagetables:%lu bounce:%lu\n",
> +		" free:%lu slab:%lu mapped:%lu pagetables:%lu bounce:%lu\n"
> +		" kernel_stack:%lu\n",
>  		global_page_state(NR_ACTIVE_ANON),
>  		global_page_state(NR_ACTIVE_FILE),
>  		global_page_state(NR_INACTIVE_ANON),
> @@ -2133,7 +2134,8 @@ void show_free_areas(void)
>  			global_page_state(NR_SLAB_UNRECLAIMABLE),
>  		global_page_state(NR_FILE_MAPPED),
>  		global_page_state(NR_PAGETABLE),
> -		global_page_state(NR_BOUNCE));
> +		global_page_state(NR_BOUNCE),
> +		global_page_state(NR_KERNEL_STACK));
>  
>  	for_each_populated_zone(zone) {
>  		int i;
> diff --git a/mm/vmstat.c b/mm/vmstat.c
> index 138bed5..ceda39b 100644
> --- a/mm/vmstat.c
> +++ b/mm/vmstat.c
> @@ -639,6 +639,7 @@ static const char * const vmstat_text[] = {
>  	"nr_slab_reclaimable",
>  	"nr_slab_unreclaimable",
>  	"nr_page_table_pages",
> +	"nr_kernel_stack",
>  	"nr_unstable",
>  	"nr_bounce",
>  	"nr_vmscan_write",
> -- 
> 1.6.0.GIT
> 
> 
> 
> 



--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH] Show kernel stack usage to /proc/meminfo and OOM log
  2009-06-30  6:03 [PATCH] Show kernel stack usage to /proc/meminfo and OOM log KOSAKI Motohiro
  2009-06-30  6:29 ` KOSAKI Motohiro
@ 2009-06-30 14:13 ` Christoph Lameter
  2009-06-30 23:26   ` KOSAKI Motohiro
  1 sibling, 1 reply; 11+ messages in thread
From: Christoph Lameter @ 2009-06-30 14:13 UTC (permalink / raw)
  To: KOSAKI Motohiro
  Cc: Minchan Kim, Johannes Weiner, David Howells, riel, Andrew Morton,
	LKML, peterz, tytso, linux-mm, elladan, npiggin, Barnes, Jesse

On Tue, 30 Jun 2009, KOSAKI Motohiro wrote:

> +static void account_kernel_stack(struct thread_info *ti, int on)

static inline?

> +{
> +	struct zone* zone = page_zone(virt_to_page(ti));
> +	int sign = on ? 1 : -1;
> +	long acct = sign * (THREAD_SIZE / PAGE_SIZE);

int pages = THREAD_SIZE / PAGE_SIZE;

?

> +
> +	mod_zone_page_state(zone, NR_KERNEL_STACK, acct);

mod_zone_page_state(zone, NR_KERNEL_STACK, on ? pages : -pages);


--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH] Show kernel stack usage to /proc/meminfo and OOM log
  2009-06-30 14:13 ` Christoph Lameter
@ 2009-06-30 23:26   ` KOSAKI Motohiro
  2009-07-01  1:37     ` [PATCH v2] " KOSAKI Motohiro
  2009-07-01 14:44     ` David Howells
  0 siblings, 2 replies; 11+ messages in thread
From: KOSAKI Motohiro @ 2009-06-30 23:26 UTC (permalink / raw)
  To: Christoph Lameter
  Cc: kosaki.motohiro, Minchan Kim, Johannes Weiner, David Howells,
	riel, Andrew Morton, LKML, peterz, tytso, linux-mm, elladan,
	npiggin, Barnes, Jesse

> On Tue, 30 Jun 2009, KOSAKI Motohiro wrote:
> 
> > +static void account_kernel_stack(struct thread_info *ti, int on)
> 
> static inline?

gcc automatically inlined, IMHO.

> > +{
> > +	struct zone* zone = page_zone(virt_to_page(ti));
> > +	int sign = on ? 1 : -1;
> > +	long acct = sign * (THREAD_SIZE / PAGE_SIZE);
> 
> int pages = THREAD_SIZE / PAGE_SIZE;
> 
> ?

Will fix. thanks cleaner code advise.

> 
> > +
> > +	mod_zone_page_state(zone, NR_KERNEL_STACK, acct);
> 
> mod_zone_page_state(zone, NR_KERNEL_STACK, on ? pages : -pages);

yes, will fix.



--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

^ permalink raw reply	[flat|nested] 11+ messages in thread

* [PATCH v2] Show kernel stack usage to /proc/meminfo and OOM log
  2009-06-30 23:26   ` KOSAKI Motohiro
@ 2009-07-01  1:37     ` KOSAKI Motohiro
  2009-07-01  2:11       ` David Rientjes
  2009-07-01 14:44     ` David Howells
  1 sibling, 1 reply; 11+ messages in thread
From: KOSAKI Motohiro @ 2009-07-01  1:37 UTC (permalink / raw)
  To: Christoph Lameter
  Cc: kosaki.motohiro, Minchan Kim, Johannes Weiner, David Howells,
	riel, Andrew Morton, LKML, peterz, tytso, linux-mm, elladan,
	npiggin, Barnes, Jesse

Subject: [PATCH] Show kernel stack usage to /proc/meminfo and OOM log

if the system have a lot of thread, kernel stack consume unignorable large size
memory.
IOW, it make a lot of unaccountable memory.

Tons unaccountable memory bring to harder analyse memory related trouble.

Then, kernel stack account is useful.


Signed-off-by: KOSAKI Motohiro <kosaki.motohiro@jp.fujitsu.com>
---
 fs/proc/meminfo.c      |    2 ++
 include/linux/mmzone.h |    3 ++-
 kernel/fork.c          |   12 ++++++++++++
 mm/page_alloc.c        |    6 ++++--
 mm/vmstat.c            |    1 +
 5 files changed, 21 insertions(+), 3 deletions(-)

Index: b/fs/proc/meminfo.c
===================================================================
--- a/fs/proc/meminfo.c
+++ b/fs/proc/meminfo.c
@@ -85,6 +85,7 @@ static int meminfo_proc_show(struct seq_
 		"SReclaimable:   %8lu kB\n"
 		"SUnreclaim:     %8lu kB\n"
 		"PageTables:     %8lu kB\n"
+		"KernelStack     %8lu kB\n"
 #ifdef CONFIG_QUICKLIST
 		"Quicklists:     %8lu kB\n"
 #endif
@@ -129,6 +130,7 @@ static int meminfo_proc_show(struct seq_
 		K(global_page_state(NR_SLAB_RECLAIMABLE)),
 		K(global_page_state(NR_SLAB_UNRECLAIMABLE)),
 		K(global_page_state(NR_PAGETABLE)),
+		K(global_page_state(NR_KERNEL_STACK)),
 #ifdef CONFIG_QUICKLIST
 		K(quicklist_total_size()),
 #endif
Index: b/include/linux/mmzone.h
===================================================================
--- a/include/linux/mmzone.h
+++ b/include/linux/mmzone.h
@@ -94,10 +94,11 @@ enum zone_stat_item {
 	NR_SLAB_RECLAIMABLE,
 	NR_SLAB_UNRECLAIMABLE,
 	NR_PAGETABLE,		/* used for pagetables */
+	NR_KERNEL_STACK,
+	/* Second 128 byte cacheline */
 	NR_UNSTABLE_NFS,	/* NFS unstable pages */
 	NR_BOUNCE,
 	NR_VMSCAN_WRITE,
-	/* Second 128 byte cacheline */
 	NR_WRITEBACK_TEMP,	/* Writeback using temporary buffers */
 #ifdef CONFIG_NUMA
 	NUMA_HIT,		/* allocated in intended node */
Index: b/kernel/fork.c
===================================================================
--- a/kernel/fork.c
+++ b/kernel/fork.c
@@ -137,9 +137,18 @@ struct kmem_cache *vm_area_cachep;
 /* SLAB cache for mm_struct structures (tsk->mm) */
 static struct kmem_cache *mm_cachep;
 
+static void account_kernel_stack(struct thread_info *ti, int on)
+{
+	struct zone *zone = page_zone(virt_to_page(ti));
+	int pages = THREAD_SIZE / PAGE_SIZE;
+
+	mod_zone_page_state(zone, NR_KERNEL_STACK, on ? pages : -pages);
+}
+
 void free_task(struct task_struct *tsk)
 {
 	prop_local_destroy_single(&tsk->dirties);
+	account_kernel_stack(tsk->stack, 0);
 	free_thread_info(tsk->stack);
 	rt_mutex_debug_task_free(tsk);
 	ftrace_graph_exit_task(tsk);
@@ -255,6 +264,9 @@ static struct task_struct *dup_task_stru
 	tsk->btrace_seq = 0;
 #endif
 	tsk->splice_pipe = NULL;
+
+	account_kernel_stack(ti, 1);
+
 	return tsk;
 
 out:
Index: b/mm/page_alloc.c
===================================================================
--- a/mm/page_alloc.c
+++ b/mm/page_alloc.c
@@ -2119,7 +2119,8 @@ void show_free_areas(void)
 		" inactive_file:%lu"
 		" unevictable:%lu"
 		" dirty:%lu writeback:%lu unstable:%lu\n"
-		" free:%lu slab:%lu mapped:%lu pagetables:%lu bounce:%lu\n",
+		" free:%lu slab:%lu mapped:%lu pagetables:%lu bounce:%lu\n"
+		" kernel_stack:%lu\n",
 		global_page_state(NR_ACTIVE_ANON),
 		global_page_state(NR_ACTIVE_FILE),
 		global_page_state(NR_INACTIVE_ANON),
@@ -2133,7 +2134,8 @@ void show_free_areas(void)
 			global_page_state(NR_SLAB_UNRECLAIMABLE),
 		global_page_state(NR_FILE_MAPPED),
 		global_page_state(NR_PAGETABLE),
-		global_page_state(NR_BOUNCE));
+		global_page_state(NR_BOUNCE),
+		global_page_state(NR_KERNEL_STACK));
 
 	for_each_populated_zone(zone) {
 		int i;
Index: b/mm/vmstat.c
===================================================================
--- a/mm/vmstat.c
+++ b/mm/vmstat.c
@@ -639,6 +639,7 @@ static const char * const vmstat_text[] 
 	"nr_slab_reclaimable",
 	"nr_slab_unreclaimable",
 	"nr_page_table_pages",
+	"nr_kernel_stack",
 	"nr_unstable",
 	"nr_bounce",
 	"nr_vmscan_write",


--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH v2] Show kernel stack usage to /proc/meminfo and OOM log
  2009-07-01  1:37     ` [PATCH v2] " KOSAKI Motohiro
@ 2009-07-01  2:11       ` David Rientjes
  2009-07-01  2:52         ` KOSAKI Motohiro
  0 siblings, 1 reply; 11+ messages in thread
From: David Rientjes @ 2009-07-01  2:11 UTC (permalink / raw)
  To: KOSAKI Motohiro
  Cc: Christoph Lameter, Minchan Kim, Johannes Weiner, David Howells,
	Rik van Riel, Andrew Morton, linux-kernel, Peter Zijlstra, tytso,
	linux-mm, elladan, Barnes, Jesse, Nick Piggin

On Wed, 1 Jul 2009, KOSAKI Motohiro wrote:

> Subject: [PATCH] Show kernel stack usage to /proc/meminfo and OOM log
> 
> if the system have a lot of thread, kernel stack consume unignorable large size
> memory.
> IOW, it make a lot of unaccountable memory.
> 
> Tons unaccountable memory bring to harder analyse memory related trouble.
> 
> Then, kernel stack account is useful.
> 
> 

I know this is the second revision of the patch, apologies for not 
responding to the first.

> Signed-off-by: KOSAKI Motohiro <kosaki.motohiro@jp.fujitsu.com>
> ---
>  fs/proc/meminfo.c      |    2 ++
>  include/linux/mmzone.h |    3 ++-
>  kernel/fork.c          |   12 ++++++++++++
>  mm/page_alloc.c        |    6 ++++--
>  mm/vmstat.c            |    1 +
>  5 files changed, 21 insertions(+), 3 deletions(-)
> 
> Index: b/fs/proc/meminfo.c
> ===================================================================
> --- a/fs/proc/meminfo.c
> +++ b/fs/proc/meminfo.c
> @@ -85,6 +85,7 @@ static int meminfo_proc_show(struct seq_
>  		"SReclaimable:   %8lu kB\n"
>  		"SUnreclaim:     %8lu kB\n"
>  		"PageTables:     %8lu kB\n"
> +		"KernelStack     %8lu kB\n"

Missing :.

>  #ifdef CONFIG_QUICKLIST
>  		"Quicklists:     %8lu kB\n"
>  #endif
> @@ -129,6 +130,7 @@ static int meminfo_proc_show(struct seq_
>  		K(global_page_state(NR_SLAB_RECLAIMABLE)),
>  		K(global_page_state(NR_SLAB_UNRECLAIMABLE)),
>  		K(global_page_state(NR_PAGETABLE)),
> +		K(global_page_state(NR_KERNEL_STACK)),
>  #ifdef CONFIG_QUICKLIST
>  		K(quicklist_total_size()),
>  #endif
> Index: b/include/linux/mmzone.h
> ===================================================================
> --- a/include/linux/mmzone.h
> +++ b/include/linux/mmzone.h
> @@ -94,10 +94,11 @@ enum zone_stat_item {
>  	NR_SLAB_RECLAIMABLE,
>  	NR_SLAB_UNRECLAIMABLE,
>  	NR_PAGETABLE,		/* used for pagetables */
> +	NR_KERNEL_STACK,
> +	/* Second 128 byte cacheline */
>  	NR_UNSTABLE_NFS,	/* NFS unstable pages */
>  	NR_BOUNCE,
>  	NR_VMSCAN_WRITE,
> -	/* Second 128 byte cacheline */
>  	NR_WRITEBACK_TEMP,	/* Writeback using temporary buffers */
>  #ifdef CONFIG_NUMA
>  	NUMA_HIT,		/* allocated in intended node */
> Index: b/kernel/fork.c
> ===================================================================
> --- a/kernel/fork.c
> +++ b/kernel/fork.c
> @@ -137,9 +137,18 @@ struct kmem_cache *vm_area_cachep;
>  /* SLAB cache for mm_struct structures (tsk->mm) */
>  static struct kmem_cache *mm_cachep;
>  
> +static void account_kernel_stack(struct thread_info *ti, int on)
> +{
> +	struct zone *zone = page_zone(virt_to_page(ti));
> +	int pages = THREAD_SIZE / PAGE_SIZE;
> +
> +	mod_zone_page_state(zone, NR_KERNEL_STACK, on ? pages : -pages);
> +}
> +
>  void free_task(struct task_struct *tsk)
>  {
>  	prop_local_destroy_single(&tsk->dirties);
> +	account_kernel_stack(tsk->stack, 0);

I think it would be better to do

	#define THREAD_PAGES	(THREAD_SIZE / PAGE_SIZE)

since it's currently unused and then

	struct zone *zone = page_zone(virt_to_page(tsk->stack));
	mod_zone_page_state(zone, NR_KERNEL_STACK, THREAD_PAGES);

in free_task() and

	struct zone *zone = page_zone(virt_to_page(ti));
	mod_zone_page_state(zone, NR_KERNEL_STACK, -THREAD_PAGES);

in dup_task_struct().

>  	free_thread_info(tsk->stack);
>  	rt_mutex_debug_task_free(tsk);
>  	ftrace_graph_exit_task(tsk);
> @@ -255,6 +264,9 @@ static struct task_struct *dup_task_stru
>  	tsk->btrace_seq = 0;
>  #endif
>  	tsk->splice_pipe = NULL;
> +
> +	account_kernel_stack(ti, 1);
> +
>  	return tsk;
>  
>  out:
> Index: b/mm/page_alloc.c
> ===================================================================
> --- a/mm/page_alloc.c
> +++ b/mm/page_alloc.c
> @@ -2119,7 +2119,8 @@ void show_free_areas(void)
>  		" inactive_file:%lu"
>  		" unevictable:%lu"
>  		" dirty:%lu writeback:%lu unstable:%lu\n"
> -		" free:%lu slab:%lu mapped:%lu pagetables:%lu bounce:%lu\n",
> +		" free:%lu slab:%lu mapped:%lu pagetables:%lu bounce:%lu\n"
> +		" kernel_stack:%lu\n",

Does kernel_stack really need to be printed on its own line?

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH v2] Show kernel stack usage to /proc/meminfo and OOM log
  2009-07-01  2:11       ` David Rientjes
@ 2009-07-01  2:52         ` KOSAKI Motohiro
  0 siblings, 0 replies; 11+ messages in thread
From: KOSAKI Motohiro @ 2009-07-01  2:52 UTC (permalink / raw)
  To: David Rientjes
  Cc: kosaki.motohiro, Christoph Lameter, Minchan Kim, Johannes Weiner,
	David Howells, Rik van Riel, Andrew Morton, linux-kernel,
	Peter Zijlstra, tytso, linux-mm, elladan, Barnes, Jesse,
	Nick Piggin

> On Wed, 1 Jul 2009, KOSAKI Motohiro wrote:
> 
> > Subject: [PATCH] Show kernel stack usage to /proc/meminfo and OOM log
> > 
> > if the system have a lot of thread, kernel stack consume unignorable large size
> > memory.
> > IOW, it make a lot of unaccountable memory.
> > 
> > Tons unaccountable memory bring to harder analyse memory related trouble.
> > 
> > Then, kernel stack account is useful.
> > 
> > 
> 
> I know this is the second revision of the patch, apologies for not 
> responding to the first.

Thanks, good review.

> 
> > Signed-off-by: KOSAKI Motohiro <kosaki.motohiro@jp.fujitsu.com>
> > ---
> >  fs/proc/meminfo.c      |    2 ++
> >  include/linux/mmzone.h |    3 ++-
> >  kernel/fork.c          |   12 ++++++++++++
> >  mm/page_alloc.c        |    6 ++++--
> >  mm/vmstat.c            |    1 +
> >  5 files changed, 21 insertions(+), 3 deletions(-)
> > 
> > Index: b/fs/proc/meminfo.c
> > ===================================================================
> > --- a/fs/proc/meminfo.c
> > +++ b/fs/proc/meminfo.c
> > @@ -85,6 +85,7 @@ static int meminfo_proc_show(struct seq_
> >  		"SReclaimable:   %8lu kB\n"
> >  		"SUnreclaim:     %8lu kB\n"
> >  		"PageTables:     %8lu kB\n"
> > +		"KernelStack     %8lu kB\n"
> 
> Missing :.

Grr, thanks. Will fix.

> 
> >  #ifdef CONFIG_QUICKLIST
> >  		"Quicklists:     %8lu kB\n"
> >  #endif
> > @@ -129,6 +130,7 @@ static int meminfo_proc_show(struct seq_
> >  		K(global_page_state(NR_SLAB_RECLAIMABLE)),
> >  		K(global_page_state(NR_SLAB_UNRECLAIMABLE)),
> >  		K(global_page_state(NR_PAGETABLE)),
> > +		K(global_page_state(NR_KERNEL_STACK)),
> >  #ifdef CONFIG_QUICKLIST
> >  		K(quicklist_total_size()),
> >  #endif
> > Index: b/include/linux/mmzone.h
> > ===================================================================
> > --- a/include/linux/mmzone.h
> > +++ b/include/linux/mmzone.h
> > @@ -94,10 +94,11 @@ enum zone_stat_item {
> >  	NR_SLAB_RECLAIMABLE,
> >  	NR_SLAB_UNRECLAIMABLE,
> >  	NR_PAGETABLE,		/* used for pagetables */
> > +	NR_KERNEL_STACK,
> > +	/* Second 128 byte cacheline */
> >  	NR_UNSTABLE_NFS,	/* NFS unstable pages */
> >  	NR_BOUNCE,
> >  	NR_VMSCAN_WRITE,
> > -	/* Second 128 byte cacheline */
> >  	NR_WRITEBACK_TEMP,	/* Writeback using temporary buffers */
> >  #ifdef CONFIG_NUMA
> >  	NUMA_HIT,		/* allocated in intended node */
> > Index: b/kernel/fork.c
> > ===================================================================
> > --- a/kernel/fork.c
> > +++ b/kernel/fork.c
> > @@ -137,9 +137,18 @@ struct kmem_cache *vm_area_cachep;
> >  /* SLAB cache for mm_struct structures (tsk->mm) */
> >  static struct kmem_cache *mm_cachep;
> >  
> > +static void account_kernel_stack(struct thread_info *ti, int on)
> > +{
> > +	struct zone *zone = page_zone(virt_to_page(ti));
> > +	int pages = THREAD_SIZE / PAGE_SIZE;
> > +
> > +	mod_zone_page_state(zone, NR_KERNEL_STACK, on ? pages : -pages);
> > +}
> > +
> >  void free_task(struct task_struct *tsk)
> >  {
> >  	prop_local_destroy_single(&tsk->dirties);
> > +	account_kernel_stack(tsk->stack, 0);
> 
> I think it would be better to do
> 
> 	#define THREAD_PAGES	(THREAD_SIZE / PAGE_SIZE)
> 
> since it's currently unused and then
> 
> 	struct zone *zone = page_zone(virt_to_page(tsk->stack));
> 	mod_zone_page_state(zone, NR_KERNEL_STACK, THREAD_PAGES);
> 
> in free_task() and
> 
> 	struct zone *zone = page_zone(virt_to_page(ti));
> 	mod_zone_page_state(zone, NR_KERNEL_STACK, -THREAD_PAGES);
> 
> in dup_task_struct().

maybe, gcc makes same code. then I keep current code. because
"struct zone *zone = page_zone(virt_to_page(tsk->stack))" line is a bit 
complicate statement and I don't hope sprinkle it.

> 
> >  	free_thread_info(tsk->stack);
> >  	rt_mutex_debug_task_free(tsk);
> >  	ftrace_graph_exit_task(tsk);
> > @@ -255,6 +264,9 @@ static struct task_struct *dup_task_stru
> >  	tsk->btrace_seq = 0;
> >  #endif
> >  	tsk->splice_pipe = NULL;
> > +
> > +	account_kernel_stack(ti, 1);
> > +
> >  	return tsk;
> >  
> >  out:
> > Index: b/mm/page_alloc.c
> > ===================================================================
> > --- a/mm/page_alloc.c
> > +++ b/mm/page_alloc.c
> > @@ -2119,7 +2119,8 @@ void show_free_areas(void)
> >  		" inactive_file:%lu"
> >  		" unevictable:%lu"
> >  		" dirty:%lu writeback:%lu unstable:%lu\n"
> > -		" free:%lu slab:%lu mapped:%lu pagetables:%lu bounce:%lu\n",
> > +		" free:%lu slab:%lu mapped:%lu pagetables:%lu bounce:%lu\n"
> > +		" kernel_stack:%lu\n",
> 
> Does kernel_stack really need to be printed on its own line?

Well, my another patch (Makes slab pages field in show_free_areas() separate two field)
already used full space of previous line. new line is really needed.





--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH v2] Show kernel stack usage to /proc/meminfo and OOM log
  2009-06-30 23:26   ` KOSAKI Motohiro
  2009-07-01  1:37     ` [PATCH v2] " KOSAKI Motohiro
@ 2009-07-01 14:44     ` David Howells
  2009-07-01 17:16       ` Christoph Lameter
  1 sibling, 1 reply; 11+ messages in thread
From: David Howells @ 2009-07-01 14:44 UTC (permalink / raw)
  To: KOSAKI Motohiro
  Cc: dhowells, Christoph Lameter, Minchan Kim, Johannes Weiner, riel,
	Andrew Morton, LKML, peterz, tytso, linux-mm, elladan, npiggin,
	Barnes, Jesse

KOSAKI Motohiro <kosaki.motohiro@jp.fujitsu.com> wrote:

> +	int pages = THREAD_SIZE / PAGE_SIZE;

Bad assumption.  On FRV, for example, THREAD_SIZE is 8K and PAGE_SIZE is 16K.

David

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH v2] Show kernel stack usage to /proc/meminfo and OOM log
  2009-07-01 14:44     ` David Howells
@ 2009-07-01 17:16       ` Christoph Lameter
  2009-07-01 17:23         ` Rik van Riel
  0 siblings, 1 reply; 11+ messages in thread
From: Christoph Lameter @ 2009-07-01 17:16 UTC (permalink / raw)
  To: David Howells
  Cc: KOSAKI Motohiro, Minchan Kim, Johannes Weiner, riel,
	Andrew Morton, LKML, peterz, tytso, linux-mm, elladan, npiggin,
	Barnes,                         Jesse

On Wed, 1 Jul 2009, David Howells wrote:

> KOSAKI Motohiro <kosaki.motohiro@jp.fujitsu.com> wrote:
>
> > +	int pages = THREAD_SIZE / PAGE_SIZE;
>
> Bad assumption.  On FRV, for example, THREAD_SIZE is 8K and PAGE_SIZE is 16K.

Guess that means we need arch specific accounting for this counter.

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH v2] Show kernel stack usage to /proc/meminfo and OOM log
  2009-07-01 17:16       ` Christoph Lameter
@ 2009-07-01 17:23         ` Rik van Riel
  2009-07-03  0:03           ` KOSAKI Motohiro
  0 siblings, 1 reply; 11+ messages in thread
From: Rik van Riel @ 2009-07-01 17:23 UTC (permalink / raw)
  To: Christoph Lameter
  Cc: David Howells, KOSAKI Motohiro, Minchan Kim, Johannes Weiner,
	Andrew Morton, LKML, peterz, tytso, linux-mm, elladan, npiggin,
	Barnes, Jesse

Christoph Lameter wrote:
> On Wed, 1 Jul 2009, David Howells wrote:
> 
>> KOSAKI Motohiro <kosaki.motohiro@jp.fujitsu.com> wrote:
>>
>>> +	int pages = THREAD_SIZE / PAGE_SIZE;
>> Bad assumption.  On FRV, for example, THREAD_SIZE is 8K and PAGE_SIZE is 16K.
> 
> Guess that means we need arch specific accounting for this counter.

Or we count the number of stacks internally and only
convert to pages whenever we display the value.

-- 
All rights reversed.

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH v2] Show kernel stack usage to /proc/meminfo and OOM log
  2009-07-01 17:23         ` Rik van Riel
@ 2009-07-03  0:03           ` KOSAKI Motohiro
  0 siblings, 0 replies; 11+ messages in thread
From: KOSAKI Motohiro @ 2009-07-03  0:03 UTC (permalink / raw)
  To: Rik van Riel
  Cc: kosaki.motohiro, Christoph Lameter, David Howells, Minchan Kim,
	Johannes Weiner, Andrew Morton, LKML, peterz, tytso, linux-mm,
	elladan, npiggin, Barnes, Jesse

> Christoph Lameter wrote:
> > On Wed, 1 Jul 2009, David Howells wrote:
> > 
> >> KOSAKI Motohiro <kosaki.motohiro@jp.fujitsu.com> wrote:
> >>
> >>> +	int pages = THREAD_SIZE / PAGE_SIZE;
> >> Bad assumption.  On FRV, for example, THREAD_SIZE is 8K and PAGE_SIZE is 16K.
> > 
> > Guess that means we need arch specific accounting for this counter.
> 
> Or we count the number of stacks internally and only
> convert to pages whenever we display the value.

Thanks good idea. I'll implement this today (or tommorow).


--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2009-07-02 23:55 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-06-30  6:03 [PATCH] Show kernel stack usage to /proc/meminfo and OOM log KOSAKI Motohiro
2009-06-30  6:29 ` KOSAKI Motohiro
2009-06-30 14:13 ` Christoph Lameter
2009-06-30 23:26   ` KOSAKI Motohiro
2009-07-01  1:37     ` [PATCH v2] " KOSAKI Motohiro
2009-07-01  2:11       ` David Rientjes
2009-07-01  2:52         ` KOSAKI Motohiro
2009-07-01 14:44     ` David Howells
2009-07-01 17:16       ` Christoph Lameter
2009-07-01 17:23         ` Rik van Riel
2009-07-03  0:03           ` KOSAKI Motohiro

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox