mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Alexey Dobriyan <adobriyan@gmail.com>
To: akpm@linux-foundation.org
Cc: linux-kernel@vger.kernel.org, stefani@seibold.net,
	a.p.zijlstra@chello.nl, ebiederm@xmission.com, mingo@elte.hu
Subject: Re: + procfs-provide-stack-information-for-threads-v08.patch added to -mm tree
Date: Tue, 16 Jun 2009 02:33:33 +0400	[thread overview]
Message-ID: <20090615223333.GA8734@x200.localdomain> (raw)
In-Reply-To: <200906152202.n5FM25VD021536@imap1.linux-foundation.org>

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);
> +	}
> +}

       reply	other threads:[~2009-06-15 22:33 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <200906152202.n5FM25VD021536@imap1.linux-foundation.org>
2009-06-15 22:33 ` Alexey Dobriyan [this message]
2009-06-16  6:17   ` Stefani Seibold
2009-06-16 19:39     ` Eric W. Biederman
2009-06-16 21:30       ` Alexey Dobriyan

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20090615223333.GA8734@x200.localdomain \
    --to=adobriyan@gmail.com \
    --cc=a.p.zijlstra@chello.nl \
    --cc=akpm@linux-foundation.org \
    --cc=ebiederm@xmission.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@elte.hu \
    --cc=stefani@seibold.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®