mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com>
To: linux-kernel@vger.kernel.org
Cc: Dave Hansen <haveblue@us.ibm.com>,
	"Hariprasad Nellitheertha [imap]" <hari@in.ibm.com>
Subject: [RFC][PATCH] nameing reserved pages [3/3]
Date: Wed, 20 Apr 2005 21:12:36 +0900	[thread overview]
Message-ID: <42664734.4060901@jp.fujitsu.com> (raw)

[-- Attachment #1: Type: text/plain, Size: 50 bytes --]

showing state of memmap by /dev/memstate.
-- Kame

[-- Attachment #2: show_memstate.patch --]
[-- Type: text/plain, Size: 3086 bytes --]


/dev/memstate shows status of memmap.
A user can read state of a page as a byte.
This feature is useful for Memory-hotplug and other stuffs,
where we have to investigate for what a page is.

Signed-off-by: KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com>



---

 linux-2.6.12-rc2-kamezawa/drivers/char/mem.c |   63 +++++++++++++++++++++++++++
 1 files changed, 63 insertions(+)

diff -puN drivers/char/mem.c~show_memstate drivers/char/mem.c
--- linux-2.6.12-rc2/drivers/char/mem.c~show_memstate	2005-04-20 10:39:40.000000000 +0900
+++ linux-2.6.12-rc2-kamezawa/drivers/char/mem.c	2005-04-20 16:51:45.000000000 +0900
@@ -715,6 +715,59 @@ static int open_port(struct inode * inod
 	return capable(CAP_SYS_RAWIO) ? 0 : -EPERM;
 }
 
+static inline unsigned char get_page_type(struct page *page)
+{
+	if ( !PageReserved(page) )
+		return Page_Common;
+	return reserved_page_type(page);
+}
+
+static ssize_t read_memstate(struct file *file, char __user *buf,
+			     size_t count, loff_t *ppos)
+{
+	unsigned long pfn = *ppos;
+	unsigned long left, written;
+	ssize_t ret;
+	int len, i;
+	struct page *page;
+	char *kbuf;
+
+	if (!count)
+		return 0;
+
+	if (!access_ok(VERIFY_WRITE, buf, count))
+		return -EFAULT;
+
+	left = count;
+	written = 0;
+	kbuf = (char *)__get_free_page(GFP_KERNEL);
+
+	if (!kbuf)
+		return -ENOMEM;
+	ret = -EFAULT;
+	/* copy data */
+	while (left) {
+		len = (left < PAGE_SIZE) ? left : PAGE_SIZE;
+		for (i = 0; i < len; i++, pfn++) {
+			if ( !pfn_valid(pfn) ) {
+				kbuf[i] = Page_Invalid;
+				continue;
+			}
+			page = pfn_to_page(pfn);
+			kbuf[i] = get_page_type(page);
+		}
+		if (copy_to_user(buf, kbuf, len))
+			goto err_out;
+		written += len;
+		left -= len;
+	}
+	*ppos = pfn;
+	ret = written;
+ err_out:
+	free_page((unsigned long)kbuf);
+	return ret;
+}
+
 #define zero_lseek	null_lseek
 #define full_lseek      null_lseek
 #define write_zero	write_null
@@ -770,6 +823,11 @@ static struct file_operations full_fops 
 	.write		= write_full,
 };
 
+static struct file_operations memstate_fops = {
+	.llseek		= memory_lseek,
+	.read		= read_memstate,
+};
+
 static ssize_t kmsg_write(struct file * file, const char __user * buf,
 			  size_t count, loff_t *ppos)
 {
@@ -825,6 +883,9 @@ static int memory_open(struct inode * in
 		case 11:
 			filp->f_op = &kmsg_fops;
 			break;
+		case 12:
+			filp->f_op = &memstate_fops;
+			break;
 		default:
 			return -ENXIO;
 	}
@@ -854,6 +915,7 @@ static const struct {
 	{8, "random",  S_IRUGO | S_IWUSR,           &random_fops},
 	{9, "urandom", S_IRUGO | S_IWUSR,           &urandom_fops},
 	{11,"kmsg",    S_IRUGO | S_IWUSR,           &kmsg_fops},
+	{12,"memstate", S_IRUSR | S_IRGRP,          &memstate_fops},
 };
 
 static struct class_simple *mem_class;
@@ -870,6 +932,7 @@ static int __init chr_dev_init(void)
 		class_simple_device_add(mem_class,
 					MKDEV(MEM_MAJOR, devlist[i].minor),
 					NULL, devlist[i].name);
+		printk("creating mem device %d %d\n",i,devlist[i].minor);
 		devfs_mk_cdev(MKDEV(MEM_MAJOR, devlist[i].minor),
 				S_IFCHR | devlist[i].mode, devlist[i].name);
 	}

_

                 reply	other threads:[~2005-04-20 12:08 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=42664734.4060901@jp.fujitsu.com \
    --to=kamezawa.hiroyu@jp.fujitsu.com \
    --cc=hari@in.ibm.com \
    --cc=haveblue@us.ibm.com \
    --cc=linux-kernel@vger.kernel.org \
    /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

Powered by JetHome