From: Siddhesh Poyarekar <siddhesh.poyarekar@gmail.com>
To: Andrew Morton <akpm@linux-foundation.org>
Cc: KOSAKI Motohiro <kosaki.motohiro@gmail.com>,
Alexander Viro <viro@zeniv.linux.org.uk>,
Jamie Lokier <jamie@shareable.org>,
Mike Frysinger <vapier@gentoo.org>,
Alexey Dobriyan <adobriyan@gmail.com>,
Matt Mackall <mpm@selenic.com>,
linux-kernel@vger.kernel.org, Oleg Nesterov <oleg@redhat.com>,
Siddhesh Poyarekar <siddhesh.poyarekar@gmail.com>
Subject: [PATCH 2/2] procfs: Mark stack vma with pid of the owning task
Date: Thu, 1 Mar 2012 10:50:59 +0530 [thread overview]
Message-ID: <1330579259-3456-2-git-send-email-siddhesh.poyarekar@gmail.com> (raw)
In-Reply-To: <1330579259-3456-1-git-send-email-siddhesh.poyarekar@gmail.com>
This is a usability tweak to the earlier patch to mark thread stack
vmas based on which vma a task is using as stack. With this patch,
each marked stack is also marked with the pid of the task to make
things that little bit easier while troubleshooting issues. I have
tested to confirm that this does not break current procps
behaviour. Thanks Mike Frysinger <vapier@gentoo.org> for the idea.
An example output of cat /proc/self/maps with this patch:
$ cat /proc/self/maps
00400000-0040b000 r-xp 00000000 fd:00 1048598 /bin/cat
0060a000-0060b000 r--p 0000a000 fd:00 1048598 /bin/cat
0060b000-0060c000 rw-p 0000b000 fd:00 1048598 /bin/cat
02370000-02391000 rw-p 00000000 00:00 0 [heap]
7fc8fbf93000-7fc9023b6000 r--p 00000000 fd:00 1714381 /usr/lib/locale/locale-archive
7fc9023b6000-7fc902561000 r-xp 00000000 fd:00 2097482 /lib64/libc-2.14.90.so
7fc902561000-7fc902761000 ---p 001ab000 fd:00 2097482 /lib64/libc-2.14.90.so
7fc902761000-7fc902765000 r--p 001ab000 fd:00 2097482 /lib64/libc-2.14.90.so
7fc902765000-7fc902767000 rw-p 001af000 fd:00 2097482 /lib64/libc-2.14.90.so
7fc902767000-7fc90276c000 rw-p 00000000 00:00 0
7fc90276c000-7fc90278e000 r-xp 00000000 fd:00 2097348 /lib64/ld-2.14.90.so
7fc90295f000-7fc902962000 rw-p 00000000 00:00 0
7fc90298c000-7fc90298d000 rw-p 00000000 00:00 0
7fc90298d000-7fc90298e000 r--p 00021000 fd:00 2097348 /lib64/ld-2.14.90.so
7fc90298e000-7fc90298f000 rw-p 00022000 fd:00 2097348 /lib64/ld-2.14.90.so
7fc90298f000-7fc902990000 rw-p 00000000 00:00 0
7fff5fb8d000-7fff5fbae000 rw-p 00000000 00:00 0 [stack:2663]
7fff5fbff000-7fff5fc00000 r-xp 00000000 00:00 0 [vdso]
ffffffffff600000-ffffffffff601000 r-xp 00000000 00:00 0 [vsyscall]
Signed-off-by: Siddhesh Poyarekar <siddhesh.poyarekar@gmail.com>
---
Documentation/filesystems/proc.txt | 12 ++++++------
fs/proc/task_mmu.c | 16 ++++++++++++----
fs/proc/task_nommu.c | 5 +++--
include/linux/mm.h | 2 +-
mm/memory.c | 13 +++++++------
5 files changed, 29 insertions(+), 19 deletions(-)
diff --git a/Documentation/filesystems/proc.txt b/Documentation/filesystems/proc.txt
index e0f9de3..a31434e 100644
--- a/Documentation/filesystems/proc.txt
+++ b/Documentation/filesystems/proc.txt
@@ -337,7 +337,7 @@ a8024000-a8027000 rw-p 00000000 00:00 0
a8027000-a8043000 r-xp 00000000 03:00 8317 /lib/ld-linux.so.2
a8043000-a8044000 r--p 0001b000 03:00 8317 /lib/ld-linux.so.2
a8044000-a8045000 rw-p 0001c000 03:00 8317 /lib/ld-linux.so.2
-aff35000-aff4a000 rw-p 00000000 00:00 0 [stack]
+aff35000-aff4a000 rw-p 00000000 00:00 0 [stack:1001]
ffffe000-fffff000 r-xp 00000000 00:00 0 [vdso]
where "address" is the address space in the process that it occupies, "perms"
@@ -356,8 +356,8 @@ The "pathname" shows the name associated file for this mapping. If the mapping
is not associated with a file:
[heap] = the heap of the program
- [stack] = the mapping is used as a stack by one
- of the threads of the process
+ [stack:1001] = the mapping is used as a stack by the thread
+ with tid 1001
[vdso] = the "virtual dynamic shared object",
the kernel system call handler
@@ -365,9 +365,9 @@ is not associated with a file:
The /proc/PID/task/TID/maps is a view of the virtual memory from the viewpoint
of the individual tasks of a process. In this file you will see a mapping marked
-as [stack] only if that task sees it as a stack. This is a key difference from
-the content of /proc/PID/maps, where you will see all mappings that are being
-used as stack by all of those tasks.
+as [stack:TID] only if that task sees it as a stack. This is a key difference
+from the content of /proc/PID/maps, where you will see all mappings that are
+being used as stack by all of those tasks.
The /proc/PID/smaps is an extension based on maps, showing the memory
consumption for each of the process's mappings. For each of mappings there
diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c
index f94a12a..8e32e28 100644
--- a/fs/proc/task_mmu.c
+++ b/fs/proc/task_mmu.c
@@ -262,8 +262,14 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
if (vma->vm_start <= mm->brk &&
vma->vm_end >= mm->start_brk) {
name = "[heap]";
- } else if (vm_is_stack(task, vma, is_pid)) {
- name = "[stack]";
+ } else {
+ pid_t tid =
+ vm_is_stack(task, vma, is_pid);
+ if (tid != 0) {
+ pad_len_spaces(m, len);
+ seq_printf(m, "[stack:%d]",
+ tid);
+ }
}
} else {
name = "[vdso]";
@@ -1099,8 +1105,10 @@ static int show_numa_map(struct seq_file *m, void *v, int is_pid)
seq_path(m, &file->f_path, "\n\t= ");
} else if (vma->vm_start <= mm->brk && vma->vm_end >= mm->start_brk) {
seq_printf(m, " heap");
- } else if (vm_is_stack(proc_priv->task, vma, is_pid)) {
- seq_printf(m, " stack");
+ } else {
+ pid_t tid = vm_is_stack(proc_priv->task, vma, is_pid);
+ if (tid != 0)
+ seq_printf(m, " stack:%d", tid);
}
if (is_vm_hugetlb_page(vma))
diff --git a/fs/proc/task_nommu.c b/fs/proc/task_nommu.c
index bdfff69..8aaba8c 100644
--- a/fs/proc/task_nommu.c
+++ b/fs/proc/task_nommu.c
@@ -170,9 +170,10 @@ static int nommu_vma_show(struct seq_file *m, struct vm_area_struct *vma,
pad_len_spaces(m, len);
seq_path(m, &file->f_path, "");
} else if (mm) {
- if (vm_is_stack(priv->task, vma, is_pid))
+ pid_t tid = vm_is_stack(priv->task, vma, is_pid);
+ if (tid != 0) {
pad_len_spaces(m, len);
- seq_puts(m, "[stack]");
+ seq_printf(m, "[stack:%d]", tid);
}
}
diff --git a/include/linux/mm.h b/include/linux/mm.h
index 58d47ae..53c3e75 100644
--- a/include/linux/mm.h
+++ b/include/linux/mm.h
@@ -1040,7 +1040,7 @@ static inline int stack_guard_page_end(struct vm_area_struct *vma,
!vma_growsup(vma->vm_next, addr);
}
-extern int
+extern pid_t
vm_is_stack(struct task_struct *task, struct vm_area_struct *vma, int in_group);
extern unsigned long move_page_tables(struct vm_area_struct *vma,
diff --git a/mm/memory.c b/mm/memory.c
index d44b180..2533d9f 100644
--- a/mm/memory.c
+++ b/mm/memory.c
@@ -3919,22 +3919,23 @@ void print_vma_addr(char *prefix, unsigned long ip)
/*
* Check if the vma is being used as a stack.
* If is_group is non-zero, check in the entire thread group or else
- * just check in the current task.
+ * just check in the current task. Returns the pid of the task that
+ * the vma is stack for.
*/
-int vm_is_stack(struct task_struct *task,
- struct vm_area_struct *vma, int in_group)
+pid_t vm_is_stack(struct task_struct *task,
+ struct vm_area_struct *vma, int in_group)
{
- int ret = 0;
+ pid_t ret = 0;
if (vm_is_stack_for_task(task, vma))
- return 1;
+ return task->pid;
if (in_group) {
struct task_struct *t = task;
rcu_read_lock();
while_each_thread(task, t) {
if (vm_is_stack_for_task(t, vma)) {
- ret = 1;
+ ret = t->pid;
goto done;
}
}
--
1.7.7.4
next prev parent reply other threads:[~2012-03-01 5:26 UTC|newest]
Thread overview: 42+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-01-14 12:35 [PATCH] Mark thread stack correctly in proc/<pid>/maps Siddhesh Poyarekar
2012-01-16 11:28 ` Jamie Lokier
2012-01-16 13:08 ` Siddhesh Poyarekar
2012-01-16 16:31 ` Jamie Lokier
2012-01-16 17:01 ` Siddhesh Poyarekar
2012-01-17 4:54 ` Siddhesh Poyarekar
2012-02-02 6:24 ` [RESEND][PATCH] " Siddhesh Poyarekar
2012-02-02 21:40 ` KOSAKI Motohiro
2012-02-03 7:09 ` Siddhesh Poyarekar
2012-02-03 8:01 ` KOSAKI Motohiro
2012-02-03 9:49 ` Siddhesh Poyarekar
2012-02-03 10:29 ` Mike Frysinger
2012-02-03 18:34 ` Siddhesh Poyarekar
2012-02-08 4:00 ` Siddhesh Poyarekar
2012-02-08 17:57 ` KOSAKI Motohiro
2012-02-11 10:19 ` Siddhesh Poyarekar
2012-02-11 15:03 ` [PATCH] " Siddhesh Poyarekar
2012-02-21 4:24 ` [RESEND][PATCH] " Siddhesh Poyarekar
2012-02-22 23:00 ` Andrew Morton
2012-02-23 4:03 ` [PATCH] " Siddhesh Poyarekar
2012-02-23 20:22 ` Andrew Morton
2012-02-24 13:05 ` Siddhesh Poyarekar
2012-02-26 16:17 ` [PATCH] x86_64: Record stack pointer before task execution begins Siddhesh Poyarekar
2012-02-27 6:17 ` [tip:x86/process] " tip-bot for Siddhesh Poyarekar
2012-02-23 23:47 ` [PATCH] Mark thread stack correctly in proc/<pid>/maps Mike Frysinger
2012-02-24 5:47 ` Siddhesh Poyarekar
2012-02-24 16:12 ` Mike Frysinger
2012-02-24 18:23 ` Siddhesh Poyarekar
2012-03-01 5:20 ` [PATCH 1/2] Take rcu read lock when iterating through thread group Siddhesh Poyarekar
2012-03-01 5:20 ` Siddhesh Poyarekar [this message]
2012-03-01 23:17 ` [PATCH 2/2] procfs: Mark stack vma with pid of the owning task Andrew Morton
2012-03-01 16:51 ` [PATCH 1/2] Take rcu read lock when iterating through thread group Oleg Nesterov
2012-03-01 23:21 ` Andrew Morton
2012-03-04 20:04 ` Siddhesh Poyarekar
2012-02-23 23:17 ` [PATCH] Mark thread stack correctly in proc/<pid>/maps KOSAKI Motohiro
2012-02-24 0:49 ` KOSAKI Motohiro
2012-02-24 5:29 ` Siddhesh Poyarekar
2012-02-24 16:14 ` KOSAKI Motohiro
2012-02-24 18:58 ` Siddhesh Poyarekar
2012-02-28 17:04 + procfs-mark-thread-stack-correctly-in-proc-pid-maps.patch added to -mm tree Oleg Nesterov
2012-02-28 17:18 ` Siddhesh Poyarekar
2012-02-28 17:40 ` Oleg Nesterov
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=1330579259-3456-2-git-send-email-siddhesh.poyarekar@gmail.com \
--to=siddhesh.poyarekar@gmail.com \
--cc=adobriyan@gmail.com \
--cc=akpm@linux-foundation.org \
--cc=jamie@shareable.org \
--cc=kosaki.motohiro@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mpm@selenic.com \
--cc=oleg@redhat.com \
--cc=vapier@gentoo.org \
--cc=viro@zeniv.linux.org.uk \
/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;
as well as URLs for NNTP newsgroup(s).