mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Qiaowei Ren <qiaowei.ren@intel.com>
To: Andrew Morton <akpm@linux-foundation.org>,
	Al Viro <viro@zeniv.linux.org.uk>,
	Oleg Nesterov <oleg@redhat.com>,
	Cyrill Gorcunov <gorcunov@openvz.org>,
	David Rientjes <rientjes@google.com>,
	Vasiliy Kulikov <segoon@openwall.com>,
	Hugh Dickins <hughd@google.com>,
	Naoya Horiguchi <n-horiguchi@ah.jp.nec.com>,
	Konstantin Khlebnikov <khlebnikov@openvz.org>
Cc: linux-kernel@vger.kernel.org, qiaowei.ren@intel.com
Subject: [PATCH 1/1] proc: add /proc/pid/shmaps
Date: Wed,  8 Aug 2012 21:04:19 +0800	[thread overview]
Message-ID: <1344431059-12514-1-git-send-email-qiaowei.ren@intel.com> (raw)

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


             reply	other threads:[~2012-08-08  5:06 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-08-08 13:04 Qiaowei Ren [this message]
2012-08-08 21:10 ` David Rientjes
2012-08-09  0:49   ` Ren, Qiaowei
2012-08-09  3:09     ` Hugh Dickins

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=1344431059-12514-1-git-send-email-qiaowei.ren@intel.com \
    --to=qiaowei.ren@intel.com \
    --cc=akpm@linux-foundation.org \
    --cc=gorcunov@openvz.org \
    --cc=hughd@google.com \
    --cc=khlebnikov@openvz.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=n-horiguchi@ah.jp.nec.com \
    --cc=oleg@redhat.com \
    --cc=rientjes@google.com \
    --cc=segoon@openwall.com \
    --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

all inboxes | Powered by JetHome®