linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 2/2] Add mem_type in /syfs to show memblock migrate type
@ 2007-10-25 15:55 Badari Pulavarty
  2007-10-25 16:07 ` Mel Gorman
  2007-10-25 16:52 ` Dave Hansen
  0 siblings, 2 replies; 15+ messages in thread
From: Badari Pulavarty @ 2007-10-25 15:55 UTC (permalink / raw)
  To: KAMEZAWA Hiroyuki, melgor, haveblue; +Cc: linux-mm

Kame & Mel,

Here is the updated patch, which checks all the pages in the section
to cover all archs. Are you okay with this ? 

Thanks,
Badari

Here is the output:

./memory0/mem_type: Multiple
./memory1/mem_type: Multiple
./memory2/mem_type: Movable
./memory3/mem_type: Movable
./memory4/mem_type: Movable
./memory5/mem_type: Movable
./memory6/mem_type: Movable
./memory7/mem_type: Movable
..

Each section of the memory has attributes in /sysfs. This patch adds 
file "mem_type" to show that memory section's migrate type. This is useful
to identify section of the memory for hotplug memory remove.

Signed-off-by: Badari Pulavarty <pbadari@us.ibm.com> 
 drivers/base/memory.c |   33 +++++++++++++++++++++++++++++++++
 1 file changed, 33 insertions(+)

Index: linux-2.6.23/drivers/base/memory.c
===================================================================
--- linux-2.6.23.orig/drivers/base/memory.c	2007-10-23 15:19:14.000000000 -0700
+++ linux-2.6.23/drivers/base/memory.c	2007-10-25 10:34:41.000000000 -0700
@@ -105,6 +105,35 @@ static ssize_t show_mem_phys_index(struc
 }
 
 /*
+ * show memory migrate type
+ */
+static ssize_t show_mem_type(struct sys_device *dev, char *buf)
+{
+	struct page *page;
+	int type;
+	int i = pageblock_nr_pages;
+	struct memory_block *mem =
+		container_of(dev, struct memory_block, sysdev);
+
+	/*
+	 * Get the type of first page in the block
+	 */
+	page = pfn_to_page(section_nr_to_pfn(mem->phys_index));
+	type = get_pageblock_migratetype(page);
+
+	/*
+	 * Check the migrate type of other pages in this section.
+	 * If the type doesn't match, report it.
+	 */
+	while (i < PAGES_PER_SECTION) {
+		if (type != get_pageblock_migratetype(page + i))
+			return sprintf(buf, "Multiple\n");
+		i += pageblock_nr_pages;
+	}
+	return sprintf(buf, "%s\n", migratetype_names[type]);
+}
+
+/*
  * online, offline, going offline, etc.
  */
 static ssize_t show_mem_state(struct sys_device *dev, char *buf)
@@ -263,6 +292,7 @@ static ssize_t show_phys_device(struct s
 static SYSDEV_ATTR(phys_index, 0444, show_mem_phys_index, NULL);
 static SYSDEV_ATTR(state, 0644, show_mem_state, store_mem_state);
 static SYSDEV_ATTR(phys_device, 0444, show_phys_device, NULL);
+static SYSDEV_ATTR(mem_type, 0444, show_mem_type, NULL);
 
 #define mem_create_simple_file(mem, attr_name)	\
 	sysdev_create_file(&mem->sysdev, &attr_##attr_name)
@@ -351,6 +381,8 @@ static int add_memory_block(unsigned lon
 		ret = mem_create_simple_file(mem, state);
 	if (!ret)
 		ret = mem_create_simple_file(mem, phys_device);
+	if (!ret)
+		ret = mem_create_simple_file(mem, mem_type);
 
 	return ret;
 }
@@ -395,6 +427,7 @@ int remove_memory_block(unsigned long no
 	mem_remove_simple_file(mem, phys_index);
 	mem_remove_simple_file(mem, state);
 	mem_remove_simple_file(mem, phys_device);
+	mem_remove_simple_file(mem, mem_type);
 	unregister_memory(mem, section, NULL);
 
 	return 0;


--
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/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

^ permalink raw reply	[flat|nested] 15+ messages in thread
* [PATCH 2/2] Add mem_type in /syfs to show memblock migrate type
@ 2007-10-24 16:37 Badari Pulavarty
  2007-10-25 10:17 ` Mel Gorman
  0 siblings, 1 reply; 15+ messages in thread
From: Badari Pulavarty @ 2007-10-24 16:37 UTC (permalink / raw)
  To: KAMEZAWA Hiroyuki, melgor, haveblue; +Cc: linux-mm

Each memory block of the memory has attributes exported to /sysfs. 
This patch adds file "mem_type" to show that memory block's migrate type. 
This is useful to identify memory blocks for hotplug memory remove.

Signed-off-by: Badari Pulavarty <pbadari@us.ibm.com> 
---
 drivers/base/memory.c |   24 ++++++++++++++++++++++++
 1 file changed, 24 insertions(+)

Index: linux-2.6.23/drivers/base/memory.c
===================================================================
--- linux-2.6.23.orig/drivers/base/memory.c	2007-10-24 09:09:05.000000000 -0700
+++ linux-2.6.23/drivers/base/memory.c	2007-10-24 09:10:05.000000000 -0700
@@ -105,6 +105,26 @@ static ssize_t show_mem_phys_index(struc
 }
 
 /*
+ * show memory migrate type
+ */
+static ssize_t show_mem_type(struct sys_device *dev, char *buf)
+{
+	struct page *first_page;
+	int type;
+	struct memory_block *mem =
+		container_of(dev, struct memory_block, sysdev);
+
+	/*
+	 * Get the type of the firstpage in the memory block.
+	 * For now, assume that entire memory block is of same
+	 * type.
+	 */
+	first_page = pfn_to_page(section_nr_to_pfn(mem->phys_index));
+	type =  get_pageblock_migratetype(first_page);
+	return sprintf(buf, "%s\n", migratetype_names[type]);
+}
+
+/*
  * online, offline, going offline, etc.
  */
 static ssize_t show_mem_state(struct sys_device *dev, char *buf)
@@ -270,6 +290,7 @@ static ssize_t show_phys_device(struct s
 static SYSDEV_ATTR(phys_index, 0444, show_mem_phys_index, NULL);
 static SYSDEV_ATTR(state, 0644, show_mem_state, store_mem_state);
 static SYSDEV_ATTR(phys_device, 0444, show_phys_device, NULL);
+static SYSDEV_ATTR(mem_type, 0444, show_mem_type, NULL);
 
 #define mem_create_simple_file(mem, attr_name)	\
 	sysdev_create_file(&mem->sysdev, &attr_##attr_name)
@@ -358,6 +379,8 @@ static int add_memory_block(unsigned lon
 		ret = mem_create_simple_file(mem, state);
 	if (!ret)
 		ret = mem_create_simple_file(mem, phys_device);
+	if (!ret)
+		ret = mem_create_simple_file(mem, mem_type);
 
 	return ret;
 }
@@ -402,6 +425,7 @@ int remove_memory_block(unsigned long no
 	mem_remove_simple_file(mem, phys_index);
 	mem_remove_simple_file(mem, state);
 	mem_remove_simple_file(mem, phys_device);
+	mem_remove_simple_file(mem, mem_type);
 	unregister_memory(mem, section, NULL);
 
 	return 0;


--
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/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

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

end of thread, other threads:[~2007-10-26 17:18 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-10-25 15:55 [PATCH 2/2] Add mem_type in /syfs to show memblock migrate type Badari Pulavarty
2007-10-25 16:07 ` Mel Gorman
2007-10-25 16:52 ` Dave Hansen
2007-10-25 17:07   ` Badari Pulavarty
2007-10-25 17:15     ` Dave Hansen
2007-10-25 17:36       ` Badari Pulavarty
2007-10-25 17:34         ` Dave Hansen
2007-10-25 18:05         ` Mel Gorman
2007-10-25 18:12           ` Dave Hansen
2007-10-26  9:50             ` Mel Gorman
2007-10-26 15:52               ` Dave Hansen
2007-10-26 16:14                 ` Mel Gorman
2007-10-26 17:18                   ` Dave Hansen
  -- strict thread matches above, loose matches on Subject: below --
2007-10-24 16:37 Badari Pulavarty
2007-10-25 10:17 ` Mel Gorman

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).