* Re: + procfs-provide-stack-information-for-threads-v08.patch added to -mm tree [not found] <200906152202.n5FM25VD021536@imap1.linux-foundation.org> @ 2009-06-15 22:33 ` Alexey Dobriyan 2009-06-16 6:17 ` Stefani Seibold 0 siblings, 1 reply; 4+ messages in thread From: Alexey Dobriyan @ 2009-06-15 22:33 UTC (permalink / raw) To: akpm; +Cc: linux-kernel, stefani, a.p.zijlstra, ebiederm, mingo On Mon, Jun 15, 2009 at 03:02:05PM -0700, akpm@linux-foundation.org wrote: > procfs-provide-stack-information-for-threads-v08.patch > --- a/fs/proc/array.c~procfs-provide-stack-information-for-threads-v08 > +++ a/fs/proc/array.c > @@ -321,6 +321,54 @@ static inline void task_context_switch_c > p->nivcsw); > } > > +static inline unsigned long get_stack_usage_in_bytes(struct vm_area_struct *vma, > + struct task_struct *p) > +{ > + unsigned long i; > + struct page *page; > + unsigned long stkpage; > + > + stkpage = KSTK_ESP(p) & PAGE_MASK; > + > +#ifdef CONFIG_STACK_GROWSUP > + for (i = vma->vm_end; i-PAGE_SIZE > stkpage; i -= PAGE_SIZE) { > + > + page = follow_page(vma, i-PAGE_SIZE, 0); How can this work? If stack page got swapped out, you'll get smaller than actual result. > + > + if (!IS_ERR(page) && page) > + break; > + } > + return i - (p->stack_start & PAGE_MASK); > +#else > + for (i = vma->vm_start; i+PAGE_SIZE <= stkpage; i += PAGE_SIZE) { > + > + page = follow_page(vma, i, 0); > + > + if (!IS_ERR(page) && page) > + break; > + } > + return (p->stack_start & PAGE_MASK) - i + PAGE_SIZE; > +#endif > +} > + > +static inline void task_show_stack_usage(struct seq_file *m, > + struct task_struct *task) > +{ > + struct vm_area_struct *vma; > + struct mm_struct *mm = get_task_mm(task); > + > + if (mm) { > + down_read(&mm->mmap_sem); > + vma = find_vma(mm, task->stack_start); > + if (vma) > + seq_printf(m, "Stack usage:\t%lu kB\n", > + get_stack_usage_in_bytes(vma, task) >> 10); > + > + up_read(&mm->mmap_sem); > + mmput(mm); > + } > +} ^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: + procfs-provide-stack-information-for-threads-v08.patch added to -mm tree 2009-06-15 22:33 ` + procfs-provide-stack-information-for-threads-v08.patch added to -mm tree Alexey Dobriyan @ 2009-06-16 6:17 ` Stefani Seibold 2009-06-16 19:39 ` Eric W. Biederman 0 siblings, 1 reply; 4+ messages in thread From: Stefani Seibold @ 2009-06-16 6:17 UTC (permalink / raw) To: Alexey Dobriyan; +Cc: akpm, linux-kernel, a.p.zijlstra, ebiederm, mingo Am Dienstag, den 16.06.2009, 02:33 +0400 schrieb Alexey Dobriyan: > On Mon, Jun 15, 2009 at 03:02:05PM -0700, akpm@linux-foundation.org wrote: > > procfs-provide-stack-information-for-threads-v08.patch > > --- a/fs/proc/array.c~procfs-provide-stack-information-for-threads-v08 > > > +++ a/fs/proc/array.c > > @@ -321,6 +321,54 @@ static inline void task_context_switch_c > > p->nivcsw); > > } > > > > +static inline unsigned long get_stack_usage_in_bytes(struct vm_area_struct *vma, > > + struct task_struct *p) > > +{ > > + unsigned long i; > > + struct page *page; > > + unsigned long stkpage; > > + > > + stkpage = KSTK_ESP(p) & PAGE_MASK; > > + > > +#ifdef CONFIG_STACK_GROWSUP > > + for (i = vma->vm_end; i-PAGE_SIZE > stkpage; i -= PAGE_SIZE) { > > + > > + page = follow_page(vma, i-PAGE_SIZE, 0); > > How can this work? > > If stack page got swapped out, you'll get smaller than actual result. > If you tell me how to do it in the right way, i can fix it! ^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: + procfs-provide-stack-information-for-threads-v08.patch added to -mm tree 2009-06-16 6:17 ` Stefani Seibold @ 2009-06-16 19:39 ` Eric W. Biederman 2009-06-16 21:30 ` Alexey Dobriyan 0 siblings, 1 reply; 4+ messages in thread From: Eric W. Biederman @ 2009-06-16 19:39 UTC (permalink / raw) To: Stefani Seibold; +Cc: Alexey Dobriyan, akpm, linux-kernel, a.p.zijlstra, mingo Stefani Seibold <stefani@seibold.net> writes: > Am Dienstag, den 16.06.2009, 02:33 +0400 schrieb Alexey Dobriyan: >> On Mon, Jun 15, 2009 at 03:02:05PM -0700, akpm@linux-foundation.org wrote: >> > procfs-provide-stack-information-for-threads-v08.patch >> > --- a/fs/proc/array.c~procfs-provide-stack-information-for-threads-v08 >> >> > +++ a/fs/proc/array.c >> > @@ -321,6 +321,54 @@ static inline void task_context_switch_c >> > p->nivcsw); >> > } >> > >> > +static inline unsigned long get_stack_usage_in_bytes(struct vm_area_struct *vma, >> > + struct task_struct *p) >> > +{ >> > + unsigned long i; >> > + struct page *page; >> > + unsigned long stkpage; >> > + >> > + stkpage = KSTK_ESP(p) & PAGE_MASK; >> > + >> > +#ifdef CONFIG_STACK_GROWSUP >> > + for (i = vma->vm_end; i-PAGE_SIZE > stkpage; i -= PAGE_SIZE) { >> > + >> > + page = follow_page(vma, i-PAGE_SIZE, 0); >> >> How can this work? >> >> If stack page got swapped out, you'll get smaller than actual result. >> > > If you tell me how to do it in the right way, i can fix it! You are attempting to answer two questions here. 1) Where do the thread stacks reside. 2) What is the maximum stack space that has been used. Just listing the thread stacks seems like a small O(1) change. Computing how much stack space has been used looks trickier. Perhaps you could map them with MAP_GROWSDOWN? Of course that has the problem that you don't stop growing your stack until it bumps into something else. Not ideal for a thread stack. Eric ^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: + procfs-provide-stack-information-for-threads-v08.patch added to -mm tree 2009-06-16 19:39 ` Eric W. Biederman @ 2009-06-16 21:30 ` Alexey Dobriyan 0 siblings, 0 replies; 4+ messages in thread From: Alexey Dobriyan @ 2009-06-16 21:30 UTC (permalink / raw) To: Eric W. Biederman Cc: Stefani Seibold, akpm, linux-kernel, a.p.zijlstra, mingo On Tue, Jun 16, 2009 at 12:39:28PM -0700, Eric W. Biederman wrote: > Stefani Seibold <stefani@seibold.net> writes: > > > Am Dienstag, den 16.06.2009, 02:33 +0400 schrieb Alexey Dobriyan: > >> On Mon, Jun 15, 2009 at 03:02:05PM -0700, akpm@linux-foundation.org wrote: > >> > procfs-provide-stack-information-for-threads-v08.patch > >> > --- a/fs/proc/array.c~procfs-provide-stack-information-for-threads-v08 > >> > >> > +++ a/fs/proc/array.c > >> > @@ -321,6 +321,54 @@ static inline void task_context_switch_c > >> > p->nivcsw); > >> > } > >> > > >> > +static inline unsigned long get_stack_usage_in_bytes(struct vm_area_struct *vma, > >> > + struct task_struct *p) > >> > +{ > >> > + unsigned long i; > >> > + struct page *page; > >> > + unsigned long stkpage; > >> > + > >> > + stkpage = KSTK_ESP(p) & PAGE_MASK; > >> > + > >> > +#ifdef CONFIG_STACK_GROWSUP > >> > + for (i = vma->vm_end; i-PAGE_SIZE > stkpage; i -= PAGE_SIZE) { > >> > + > >> > + page = follow_page(vma, i-PAGE_SIZE, 0); > >> > >> How can this work? > >> > >> If stack page got swapped out, you'll get smaller than actual result. > >> > > > > If you tell me how to do it in the right way, i can fix it! > > You are attempting to answer two questions here. > 1) Where do the thread stacks reside. Kernel doesn't know. Application stack is somewhere below/above some SP register. > 2) What is the maximum stack space that has been used. > > Just listing the thread stacks seems like a small O(1) change. > > Computing how much stack space has been used looks trickier. > Perhaps you could map them with MAP_GROWSDOWN? Of course that > has the problem that you don't stop growing your stack until > it bumps into something else. Not ideal for a thread stack. ^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2009-06-16 21:30 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
[not found] <200906152202.n5FM25VD021536@imap1.linux-foundation.org>
2009-06-15 22:33 ` + procfs-provide-stack-information-for-threads-v08.patch added to -mm tree Alexey Dobriyan
2009-06-16 6:17 ` Stefani Seibold
2009-06-16 19:39 ` Eric W. Biederman
2009-06-16 21:30 ` Alexey Dobriyan
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox