All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/1] proc: add /proc/pid/shmaps
@ 2012-08-08 13:04 Qiaowei Ren
  2012-08-08 21:10 ` David Rientjes
  0 siblings, 1 reply; 4+ messages in thread
From: Qiaowei Ren @ 2012-08-08 13:04 UTC (permalink / raw)
  To: Andrew Morton, Al Viro, Oleg Nesterov, Cyrill Gorcunov,
	David Rientjes, Vasiliy Kulikov, Hugh Dickins, Naoya Horiguchi,
	Konstantin Khlebnikov
  Cc: linux-kernel, qiaowei.ren

Add a shmaps entry to /proc/pid: show information about shared memory in an address space.

People that use shared memory and want to perform an analyzing about it. For example, judge whether any memory address is shared. This file just contains 'share' part of /proc/pid/maps now. There are too many contents in maps, and so we have to do a lot of analysis to obtain relative information every time.

Signed-off-by: Qiaowei Ren <qiaowei.ren@intel.com>
---
 fs/proc/base.c     |    2 ++
 fs/proc/internal.h |    2 ++
 fs/proc/task_mmu.c |   67 +++++++++++++++++++++++++++++++++++++++++++++++-----
 3 files changed, 65 insertions(+), 6 deletions(-)

diff --git a/fs/proc/base.c b/fs/proc/base.c
index 1b6c84c..d49057a 100644
--- a/fs/proc/base.c
+++ b/fs/proc/base.c
@@ -3047,6 +3047,7 @@ static const struct pid_entry tgid_base_stuff[] = {
 	ONE("stat",       S_IRUGO, proc_tgid_stat),
 	ONE("statm",      S_IRUGO, proc_pid_statm),
 	REG("maps",       S_IRUGO, proc_pid_maps_operations),
+	REG("shmaps",      S_IRUGO, proc_pid_shmaps_operations),
 #ifdef CONFIG_NUMA
 	REG("numa_maps",  S_IRUGO, proc_pid_numa_maps_operations),
 #endif
@@ -3411,6 +3412,7 @@ static const struct pid_entry tid_base_stuff[] = {
 	ONE("stat",      S_IRUGO, proc_tid_stat),
 	ONE("statm",     S_IRUGO, proc_pid_statm),
 	REG("maps",      S_IRUGO, proc_tid_maps_operations),
+	REG("shmaps",      S_IRUGO, proc_tid_shmaps_operations),
 #ifdef CONFIG_CHECKPOINT_RESTORE
 	REG("children",  S_IRUGO, proc_tid_children_operations),
 #endif
diff --git a/fs/proc/internal.h b/fs/proc/internal.h
index e1167a1..3f2882c 100644
--- a/fs/proc/internal.h
+++ b/fs/proc/internal.h
@@ -57,6 +57,8 @@ extern loff_t mem_lseek(struct file *file, loff_t offset, int orig);
 extern const struct file_operations proc_tid_children_operations;
 extern const struct file_operations proc_pid_maps_operations;
 extern const struct file_operations proc_tid_maps_operations;
+extern const struct file_operations proc_pid_shmaps_operations;
+extern const struct file_operations proc_tid_shmaps_operations;
 extern const struct file_operations proc_pid_numa_maps_operations;
 extern const struct file_operations proc_tid_numa_maps_operations;
 extern const struct file_operations proc_pid_smaps_operations;
diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c
index 4540b8f..59daebf 100644
--- a/fs/proc/task_mmu.c
+++ b/fs/proc/task_mmu.c
@@ -210,7 +210,8 @@ static int do_maps_open(struct inode *inode, struct file *file,
 }
 
 static void
-show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
+show_map_vma(struct seq_file *m, struct vm_area_struct *vma,
+	     int is_pid, int only_shmap)
 {
 	struct mm_struct *mm = vma->vm_mm;
 	struct file *file = vma->vm_file;
@@ -224,6 +225,9 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
 	int len;
 	const char *name = NULL;
 
+	if (only_shmap && !(flags & VM_MAYSHARE))
+		return;
+
 	if (file) {
 		struct inode *inode = vma->vm_file->f_path.dentry->d_inode;
 		dev = inode->i_sb->s_dev;
@@ -300,13 +304,13 @@ done:
 	seq_putc(m, '\n');
 }
 
-static int show_map(struct seq_file *m, void *v, int is_pid)
+static int show_map(struct seq_file *m, void *v, int is_pid, int only_shmap)
 {
 	struct vm_area_struct *vma = v;
 	struct proc_maps_private *priv = m->private;
 	struct task_struct *task = priv->task;
 
-	show_map_vma(m, vma, is_pid);
+	show_map_vma(m, vma, is_pid, only_shmap);
 
 	if (m->count < m->size)  /* vma is copied successfully */
 		m->version = (vma != get_gate_vma(task->mm))
@@ -316,12 +320,12 @@ static int show_map(struct seq_file *m, void *v, int is_pid)
 
 static int show_pid_map(struct seq_file *m, void *v)
 {
-	return show_map(m, v, 1);
+	return show_map(m, v, 1, 0);
 }
 
 static int show_tid_map(struct seq_file *m, void *v)
 {
-	return show_map(m, v, 0);
+	return show_map(m, v, 0, 0);
 }
 
 static const struct seq_operations proc_pid_maps_op = {
@@ -363,6 +367,57 @@ const struct file_operations proc_tid_maps_operations = {
 };
 
 /*
+ * /proc/pid/shmaps - just contains 'share' part of /proc/maps
+ */
+static int show_pid_shmap(struct seq_file *m, void *v)
+{
+	return show_map(m, v, 1, 1);
+}
+
+static int show_tid_shmap(struct seq_file *m, void *v)
+{
+	return show_map(m, v, 0, 1);
+}
+
+static const struct seq_operations proc_pid_shmaps_op = {
+	.start	= m_start,
+	.next	= m_next,
+	.stop	= m_stop,
+	.show	= show_pid_shmap
+};
+
+static const struct seq_operations proc_tid_shmaps_op = {
+	.start	= m_start,
+	.next	= m_next,
+	.stop	= m_stop,
+	.show	= show_tid_shmap
+};
+
+static int pid_shmaps_open(struct inode *inode, struct file *file)
+{
+	return do_maps_open(inode, file, &proc_pid_shmaps_op);
+}
+
+static int tid_shmaps_open(struct inode *inode, struct file *file)
+{
+	return do_maps_open(inode, file, &proc_tid_shmaps_op);
+}
+
+const struct file_operations proc_pid_shmaps_operations = {
+	.open		= pid_shmaps_open,
+	.read		= seq_read,
+	.llseek		= seq_lseek,
+	.release	= seq_release_private,
+};
+
+const struct file_operations proc_tid_shmaps_operations = {
+	.open		= tid_shmaps_open,
+	.read		= seq_read,
+	.llseek		= seq_lseek,
+	.release	= seq_release_private,
+};
+
+/*
  * Proportional Set Size(PSS): my share of RSS.
  *
  * PSS of a process is the count of pages it has in memory, where each
@@ -498,7 +553,7 @@ static int show_smap(struct seq_file *m, void *v, int is_pid)
 	if (vma->vm_mm && !is_vm_hugetlb_page(vma))
 		walk_page_range(vma->vm_start, vma->vm_end, &smaps_walk);
 
-	show_map_vma(m, vma, is_pid);
+	show_map_vma(m, vma, is_pid, 0);
 
 	seq_printf(m,
 		   "Size:           %8lu kB\n"
-- 
1.7.9.5


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

* Re: [PATCH 1/1] proc: add /proc/pid/shmaps
  2012-08-08 13:04 [PATCH 1/1] proc: add /proc/pid/shmaps Qiaowei Ren
@ 2012-08-08 21:10 ` David Rientjes
  2012-08-09  0:49   ` Ren, Qiaowei
  0 siblings, 1 reply; 4+ messages in thread
From: David Rientjes @ 2012-08-08 21:10 UTC (permalink / raw)
  To: Qiaowei Ren
  Cc: Andrew Morton, Al Viro, Oleg Nesterov, Cyrill Gorcunov,
	Vasiliy Kulikov, Hugh Dickins, Naoya Horiguchi,
	Konstantin Khlebnikov, linux-kernel

On Wed, 8 Aug 2012, Qiaowei Ren wrote:

> Add a shmaps entry to /proc/pid: show information about shared memory in an address space.
> 
> People that use shared memory and want to perform an analyzing about it. For example, judge whether any memory address is shared. This file just contains 'share' part of /proc/pid/maps now. There are too many contents in maps, and so we have to do a lot of analysis to obtain relative information every time.
> 
> Signed-off-by: Qiaowei Ren <qiaowei.ren@intel.com>

Nack as unnecessary; /proc/pid/maps already explicitly emits 's' for 
VM_MAYSHARE and 'p' otherwise so this information is already available to 
userspace.

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

* RE: [PATCH 1/1] proc: add /proc/pid/shmaps
  2012-08-08 21:10 ` David Rientjes
@ 2012-08-09  0:49   ` Ren, Qiaowei
  2012-08-09  3:09     ` Hugh Dickins
  0 siblings, 1 reply; 4+ messages in thread
From: Ren, Qiaowei @ 2012-08-09  0:49 UTC (permalink / raw)
  To: David Rientjes
  Cc: Andrew Morton, Al Viro, Oleg Nesterov, Cyrill Gorcunov,
	Vasiliy Kulikov, Hugh Dickins, Naoya Horiguchi,
	Konstantin Khlebnikov, linux-kernel

Thanks for your reply. There are so many contents in /proc/pid/maps, and usually only a very small minority of those are about shared memory in address space of every process. So I hope that a new file maybe provide some convenience. Could you tell me how to get such information except analyzing 'maps' file?

-----Original Message-----
From: David Rientjes [mailto:rientjes@google.com] 
Sent: Thursday, August 09, 2012 5:10 AM
To: Ren, Qiaowei
Cc: Andrew Morton; Al Viro; Oleg Nesterov; Cyrill Gorcunov; Vasiliy Kulikov; Hugh Dickins; Naoya Horiguchi; Konstantin Khlebnikov; linux-kernel@vger.kernel.org
Subject: Re: [PATCH 1/1] proc: add /proc/pid/shmaps

On Wed, 8 Aug 2012, Qiaowei Ren wrote:

> Add a shmaps entry to /proc/pid: show information about shared memory in an address space.
> 
> People that use shared memory and want to perform an analyzing about it. For example, judge whether any memory address is shared. This file just contains 'share' part of /proc/pid/maps now. There are too many contents in maps, and so we have to do a lot of analysis to obtain relative information every time.
> 
> Signed-off-by: Qiaowei Ren <qiaowei.ren@intel.com>

Nack as unnecessary; /proc/pid/maps already explicitly emits 's' for VM_MAYSHARE and 'p' otherwise so this information is already available to userspace.

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

* RE: [PATCH 1/1] proc: add /proc/pid/shmaps
  2012-08-09  0:49   ` Ren, Qiaowei
@ 2012-08-09  3:09     ` Hugh Dickins
  0 siblings, 0 replies; 4+ messages in thread
From: Hugh Dickins @ 2012-08-09  3:09 UTC (permalink / raw)
  To: Ren, Qiaowei
  Cc: David Rientjes, Andrew Morton, Al Viro, Oleg Nesterov,
	Cyrill Gorcunov, Vasiliy Kulikov, Naoya Horiguchi,
	Konstantin Khlebnikov, linux-kernel

On Thu, 9 Aug 2012, Ren, Qiaowei wrote:
> On Wed, 8 Aug 2012, David Rientjes wrote: 
> > On Wed, 8 Aug 2012, Qiaowei Ren wrote:
> >
> > > Add a shmaps entry to /proc/pid: show information about shared memory in an address space.
> > > 
> > > People that use shared memory and want to perform an analyzing about it. For example, judge whether any memory address is shared. This file just contains 'share' part of /proc/pid/maps now. There are too many contents in maps, and so we have to do a lot of analysis to obtain relative information every time.
> > > 
> > > Signed-off-by: Qiaowei Ren <qiaowei.ren@intel.com>
> >  
> > Nack as unnecessary; /proc/pid/maps already explicitly emits 's' for VM_MAYSHARE and 'p' otherwise so this information is already available to userspace.
> >
> 
> Thanks for your reply. There are so many contents in /proc/pid/maps, and usually only a very small minority of those are about shared memory in address space of every process. So I hope that a new file maybe provide some convenience. Could you tell me how to get such information except analyzing 'maps' file?

You are joking?  Please imagine what the kernel and /proc would look like
if it provided a personally tailored /proc file to everybody who could not
be bothered to parse the information already shown there.

Sure, there is already lots of ugly and duplicative junk under /proc,
which usually has to be kept to preserve back compatibility; but please
do not try to add to it.

There is sometimes an excuse if some fields of an existing /proc file are
significantly more expensive for the kernel to compute than others: then
a file which separates them can save processing.  But that is definitely
not the case here.

A side issue would be whether parsing /proc/pid/maps for 's' VM_MAYSHARE
mappings (or your equivalent patch) actually tells you what you want to
know about "shared memory" - that would depend on what you really want
to know, and what you mean by shared memory.

Hugh

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

end of thread, other threads:[~2012-08-09  3:10 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-08-08 13:04 [PATCH 1/1] proc: add /proc/pid/shmaps Qiaowei Ren
2012-08-08 21:10 ` David Rientjes
2012-08-09  0:49   ` Ren, Qiaowei
2012-08-09  3:09     ` Hugh Dickins

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.