Re: [PATCH 2/3] proc: add /proc/kpagetype interface

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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

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

Cc: Matt Mackall <mpm@xxxxxxxxxxx>
Signed-off-by: Bartlomiej Zolnierkiewicz <b.zolnierkie@xxxxxxxxxxx>
Signed-off-by: Kyungmin Park <kyungmin.park@xxxxxxxxxxx>
---
v2:
- fix the "no pageblock migratetype available" case defaulting to
  MIGRATE_UNMOVABLE
- fix MIGRATE_ISOLATE and MIGRATE_CMA handling

 fs/proc/page.c                                |   80 ++++++++++++++++++++++++++
 include/linux/kernel-pageblock-migratetypes.h |   12 +++
 2 files changed, 92 insertions(+)

Index: b/fs/proc/page.c
===================================================================
--- a/fs/proc/page.c	2012-06-04 18:25:54.081310797 +0200
+++ b/fs/proc/page.c	2012-06-04 18:32:39.409310913 +0200
@@ -9,6 +9,7 @@
 #include <linux/seq_file.h>
 #include <linux/hugetlb.h>
 #include <linux/kernel-page-flags.h>
+#include <linux/kernel-pageblock-migratetypes.h>
 #include <asm/uaccess.h>
 #include "internal.h"
 
@@ -254,11 +255,90 @@ static const struct file_operations proc
 	.read = kpageorder_read,
 };
 
+static u64 stable_pageblock_migratetypes(struct page *page)
+{
+	int mt = get_pageblock_migratetype(page);
+	u64 u = 0;
+
+	switch (mt) {
+	case MIGRATE_UNMOVABLE:
+		u = KPM_UNMOVABLE;
+		break;
+	case MIGRATE_RECLAIMABLE:
+		u = KPM_RECLAIMABLE;
+		break;
+	case MIGRATE_MOVABLE:
+		u = KPM_MOVABLE;
+		break;
+	case MIGRATE_PCPTYPES:
+		u = KPM_PCPTYPES;
+		break;
+	case MIGRATE_ISOLATE:
+		u = KPM_ISOLATE;
+		break;
+#ifdef CONFIG_CMA
+	case MIGRATE_CMA:
+		u = KPM_CMA;
+		break;
+#endif
+	}
+
+	return u;
+}
+
+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 = stable_pageblock_migratetypes(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);
Index: b/include/linux/kernel-pageblock-migratetypes.h
===================================================================
--- /dev/null	1970-01-01 00:00:00.000000000 +0000
+++ b/include/linux/kernel-pageblock-migratetypes.h	2012-06-04 18:33:49.001310951 +0200
@@ -0,0 +1,12 @@
+#ifndef LINUX_KERNEL_PAGEBLOCK_MIGRATETYPES_H
+#define LINUX_KERNEL_PAGEBLOCK_MIGRATETYPES_H
+
+#define KPM_UNMOVABLE		1
+#define KPM_RECLAIMABLE		2
+#define KPM_MOVABLE		3
+#define KPM_PCPTYPES		4
+#define KPM_RESERVE		KPM_PCPTYPES
+#define KPM_ISOLATE		5
+#define KPM_CMA			6
+
+#endif /* LINUX_KERNEL_PAGEBLOCK_MIGRATETYPES_H */

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@xxxxxxxxx.  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@xxxxxxxxx";> email@xxxxxxxxx </a>


[Index of Archives]     [Linux ARM Kernel]     [Linux ARM]     [Linux Omap]     [Fedora ARM]     [IETF Annouce]     [Bugtraq]     [Linux]     [Linux OMAP]     [Linux MIPS]     [ECOS]     [Asterisk Internet PBX]     [Linux API]