linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 2/3] proc: add /proc/kpagetype interface
@ 2012-06-01 16:54 Bartlomiej Zolnierkiewicz
  2012-06-01 20:31 ` KOSAKI Motohiro
  2012-06-04 16:46 ` Bartlomiej Zolnierkiewicz
  0 siblings, 2 replies; 3+ messages in thread
From: Bartlomiej Zolnierkiewicz @ 2012-06-01 16:54 UTC (permalink / raw)
  To: linux-mm; +Cc: Kyungmin Park, Matt Mackall

From: Bartlomiej Zolnierkiewicz <b.zolnierkie@samsung.com>
Subject: [PATCH] proc: add /proc/kpagetype interface

This makes page pageblock type information available to the user-space.

Cc: Matt Mackall <mpm@selenic.com>
Signed-off-by: Bartlomiej Zolnierkiewicz <b.zolnierkie@samsung.com>
Signed-off-by: Kyungmin Park <kyungmin.park@samsung.com>
---
 fs/proc/page.c |   48 ++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 48 insertions(+)

Index: b/fs/proc/page.c
===================================================================
--- a/fs/proc/page.c	2012-05-31 16:30:49.215109568 +0200
+++ b/fs/proc/page.c	2012-05-31 16:30:50.559109495 +0200
@@ -254,11 +254,59 @@ static const struct file_operations proc
 	.read = kpageorder_read,
 };
 
+static ssize_t kpagetype_read(struct file *file, char __user *buf,
+			     size_t count, loff_t *ppos)
+{
+	u64 __user *out = (u64 __user *)buf;
+	struct page *ppage;
+	unsigned long src = *ppos;
+	unsigned long pfn;
+	ssize_t ret = 0;
+	u64 ptype;
+
+	pfn = src / KPMSIZE;
+	count = min_t(unsigned long, count,
+		      ((ARCH_PFN_OFFSET + max_pfn) * KPMSIZE) - src);
+	if (src & KPMMASK || count & KPMMASK)
+		return -EINVAL;
+
+	while (count > 0) {
+		if (pfn_valid(pfn))
+			ppage = pfn_to_page(pfn);
+		else
+			ppage = NULL;
+		if (!ppage)
+			ptype = 0;
+		else
+			ptype = get_pageblock_migratetype(ppage);
+
+		if (put_user(ptype, out)) {
+			ret = -EFAULT;
+			break;
+		}
+
+		pfn++;
+		out++;
+		count -= KPMSIZE;
+	}
+
+	*ppos += (char __user *)out - buf;
+	if (!ret)
+		ret = (char __user *)out - buf;
+	return ret;
+}
+
+static const struct file_operations proc_kpagetype_operations = {
+	.llseek = mem_lseek,
+	.read = kpagetype_read,
+};
+
 static int __init proc_page_init(void)
 {
 	proc_create("kpagecount", S_IRUSR, NULL, &proc_kpagecount_operations);
 	proc_create("kpageflags", S_IRUSR, NULL, &proc_kpageflags_operations);
 	proc_create("kpageorder", S_IRUSR, NULL, &proc_kpageorder_operations);
+	proc_create("kpagetype", S_IRUSR, NULL, &proc_kpagetype_operations);
 	return 0;
 }
 module_init(proc_page_init);

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

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

end of thread, other threads:[~2012-06-04 16:47 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-06-01 16:54 [PATCH 2/3] proc: add /proc/kpagetype interface Bartlomiej Zolnierkiewicz
2012-06-01 20:31 ` KOSAKI Motohiro
2012-06-04 16:46 ` Bartlomiej Zolnierkiewicz

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox