* [PATCH] Add "removable" to /sysfs to show memblock removability
@ 2007-10-25 22:35 Badari Pulavarty
2007-10-25 22:45 ` Dave Hansen
2007-10-26 14:47 ` Mel Gorman
0 siblings, 2 replies; 7+ messages in thread
From: Badari Pulavarty @ 2007-10-25 22:35 UTC (permalink / raw)
To: KAMEZAWA Hiroyuki, melgor, Dave Hansen; +Cc: linux-mm
Hi Dave & Mel,
Here is the new version of the patch with your suggestion.
Dave, does this suite your taste ? Mel, Can you handle the
corner case you mentioned earlier ?
Thanks,
Badari
Each section of the memory has attributes in /sysfs. This patch adds
file "removable" to show if this memory block is removable. This
helps user-level agents to identify section of the memory for hotplug
memory remove.
Signed-off-by: Badari Pulavarty <pbadari@us.ibm.com>
drivers/base/memory.c | 21 +++++++++++++++++++++
include/linux/pageblock-flags.h | 2 ++
mm/page_alloc.c | 27 +++++++++++++++++++++++++++
3 files changed, 50 insertions(+)
Index: linux-2.6.24-rc1/drivers/base/memory.c
===================================================================
--- linux-2.6.24-rc1.orig/drivers/base/memory.c 2007-10-23 20:50:57.000000000 -0700
+++ linux-2.6.24-rc1/drivers/base/memory.c 2007-10-25 17:14:32.000000000 -0700
@@ -105,6 +105,23 @@ static ssize_t show_mem_phys_index(struc
}
/*
+ * show memory migrate type
+ */
+static ssize_t show_mem_removable(struct sys_device *dev, char *buf)
+{
+ unsigned long start_pfn;
+ struct memory_block *mem =
+ container_of(dev, struct memory_block, sysdev);
+
+ start_pfn = section_nr_to_pfn(mem->phys_index);
+ if (is_mem_section_removable(start_pfn, PAGES_PER_SECTION))
+ return sprintf(buf, "True\n");
+ else
+ return sprintf(buf, "False\n");
+
+}
+
+/*
* online, offline, going offline, etc.
*/
static ssize_t show_mem_state(struct sys_device *dev, char *buf)
@@ -263,6 +280,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(removable, 0444, show_mem_removable, NULL);
#define mem_create_simple_file(mem, attr_name) \
sysdev_create_file(&mem->sysdev, &attr_##attr_name)
@@ -351,6 +369,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, removable);
return ret;
}
@@ -395,6 +415,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, removable);
unregister_memory(mem, section, NULL);
return 0;
Index: linux-2.6.24-rc1/include/linux/pageblock-flags.h
===================================================================
--- linux-2.6.24-rc1.orig/include/linux/pageblock-flags.h 2007-10-23 20:50:57.000000000 -0700
+++ linux-2.6.24-rc1/include/linux/pageblock-flags.h 2007-10-25 17:14:54.000000000 -0700
@@ -67,6 +67,8 @@ unsigned long get_pageblock_flags_group(
void set_pageblock_flags_group(struct page *page, unsigned long flags,
int start_bitidx, int end_bitidx);
+int is_mem_section_removable(unsigned long pfn, unsigned long nr_pages);
+
#define get_pageblock_flags(page) \
get_pageblock_flags_group(page, 0, NR_PAGEBLOCK_BITS-1)
#define set_pageblock_flags(page) \
Index: linux-2.6.24-rc1/mm/page_alloc.c
===================================================================
--- linux-2.6.24-rc1.orig/mm/page_alloc.c 2007-10-23 20:50:57.000000000 -0700
+++ linux-2.6.24-rc1/mm/page_alloc.c 2007-10-25 17:29:30.000000000 -0700
@@ -4489,6 +4489,33 @@ out:
spin_unlock_irqrestore(&zone->lock, flags);
}
+/*
+ * Find out if this section of the memory is removable.
+ */
+int
+is_mem_section_removable(unsigned long start_pfn, unsigned long nr_pages)
+{
+ int type, i = 0;
+ struct page *page;
+
+ /*
+ * Check all pageblocks in the section to ensure they are all
+ * removable.
+ */
+ page = pfn_to_page(start_pfn);
+ while (i < nr_pages) {
+ type = get_pageblock_migratetype(page + i);
+
+ /*
+ * For now, we can remove sections with only MOVABLE pages.
+ */
+ if (type != MIGRATE_MOVABLE)
+ return 0;
+ i += pageblock_nr_pages;
+ }
+ return 1;
+}
+
#ifdef CONFIG_MEMORY_HOTREMOVE
/*
* All pages in the range must be isolated before calling this.
--
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] 7+ messages in thread
* Re: [PATCH] Add "removable" to /sysfs to show memblock removability
2007-10-25 22:35 [PATCH] Add "removable" to /sysfs to show memblock removability Badari Pulavarty
@ 2007-10-25 22:45 ` Dave Hansen
2007-10-25 23:32 ` Badari Pulavarty
2007-10-26 14:47 ` Mel Gorman
1 sibling, 1 reply; 7+ messages in thread
From: Dave Hansen @ 2007-10-25 22:45 UTC (permalink / raw)
To: Badari Pulavarty; +Cc: KAMEZAWA Hiroyuki, melgor, linux-mm
On Thu, 2007-10-25 at 15:35 -0700, Badari Pulavarty wrote:
>
> +static ssize_t show_mem_removable(struct sys_device *dev, char *buf)
> +{
> + unsigned long start_pfn;
> + struct memory_block *mem =
> + container_of(dev, struct memory_block, sysdev);
> +
> + start_pfn = section_nr_to_pfn(mem->phys_index);
> + if (is_mem_section_removable(start_pfn, PAGES_PER_SECTION))
> + return sprintf(buf, "True\n");
> + else
> + return sprintf(buf, "False\n");
> +
Yeah, that's what I had in mind. The only other thing I might suggest
would be to do a number instead of true/false here. Just so that we
_can_ have scores in the future. Otherwise fine with me.
-- Dave
--
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] 7+ messages in thread
* Re: [PATCH] Add "removable" to /sysfs to show memblock removability
2007-10-25 22:45 ` Dave Hansen
@ 2007-10-25 23:32 ` Badari Pulavarty
2007-10-26 0:27 ` KAMEZAWA Hiroyuki
0 siblings, 1 reply; 7+ messages in thread
From: Badari Pulavarty @ 2007-10-25 23:32 UTC (permalink / raw)
To: Dave Hansen; +Cc: KAMEZAWA Hiroyuki, melgor, linux-mm
On Thu, 2007-10-25 at 15:45 -0700, Dave Hansen wrote:
> On Thu, 2007-10-25 at 15:35 -0700, Badari Pulavarty wrote:
> >
> > +static ssize_t show_mem_removable(struct sys_device *dev, char *buf)
> > +{
> > + unsigned long start_pfn;
> > + struct memory_block *mem =
> > + container_of(dev, struct memory_block, sysdev);
> > +
> > + start_pfn = section_nr_to_pfn(mem->phys_index);
> > + if (is_mem_section_removable(start_pfn, PAGES_PER_SECTION))
> > + return sprintf(buf, "True\n");
> > + else
> > + return sprintf(buf, "False\n");
> > +
>
> Yeah, that's what I had in mind. The only other thing I might suggest
> would be to do a number instead of true/false here. Just so that we
> _can_ have scores in the future. Otherwise fine with me.
Good point. Here is the updated version. Thanks for your suggestions.
Thanks,
Badari
Each section of the memory has attributes in /sysfs. This patch adds
file "removable" to show if this memory block is removable. This
helps user-level agents to identify section of the memory for hotplug
memory remove.
Signed-off-by: Badari Pulavarty <pbadari@us.ibm.com>
drivers/base/memory.c | 19 +++++++++++++++++++
include/linux/pageblock-flags.h | 2 ++
mm/page_alloc.c | 27 +++++++++++++++++++++++++++
3 files changed, 48 insertions(+)
Index: linux-2.6.24-rc1/drivers/base/memory.c
===================================================================
--- linux-2.6.24-rc1.orig/drivers/base/memory.c 2007-10-23 20:50:57.000000000 -0700
+++ linux-2.6.24-rc1/drivers/base/memory.c 2007-10-25 18:25:07.000000000 -0700
@@ -105,6 +105,21 @@ static ssize_t show_mem_phys_index(struc
}
/*
+ * show memory migrate type
+ */
+static ssize_t show_mem_removable(struct sys_device *dev, char *buf)
+{
+ unsigned long start_pfn;
+ int ret;
+ struct memory_block *mem =
+ container_of(dev, struct memory_block, sysdev);
+
+ start_pfn = section_nr_to_pfn(mem->phys_index);
+ ret = is_mem_section_removable(start_pfn, PAGES_PER_SECTION);
+ return sprintf(buf, "%d\n", ret);
+}
+
+/*
* online, offline, going offline, etc.
*/
static ssize_t show_mem_state(struct sys_device *dev, char *buf)
@@ -263,6 +278,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(removable, 0444, show_mem_removable, NULL);
#define mem_create_simple_file(mem, attr_name) \
sysdev_create_file(&mem->sysdev, &attr_##attr_name)
@@ -351,6 +367,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, removable);
return ret;
}
@@ -395,6 +413,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, removable);
unregister_memory(mem, section, NULL);
return 0;
Index: linux-2.6.24-rc1/include/linux/pageblock-flags.h
===================================================================
--- linux-2.6.24-rc1.orig/include/linux/pageblock-flags.h 2007-10-23 20:50:57.000000000 -0700
+++ linux-2.6.24-rc1/include/linux/pageblock-flags.h 2007-10-25 17:14:54.000000000 -0700
@@ -67,6 +67,8 @@ unsigned long get_pageblock_flags_group(
void set_pageblock_flags_group(struct page *page, unsigned long flags,
int start_bitidx, int end_bitidx);
+int is_mem_section_removable(unsigned long pfn, unsigned long nr_pages);
+
#define get_pageblock_flags(page) \
get_pageblock_flags_group(page, 0, NR_PAGEBLOCK_BITS-1)
#define set_pageblock_flags(page) \
Index: linux-2.6.24-rc1/mm/page_alloc.c
===================================================================
--- linux-2.6.24-rc1.orig/mm/page_alloc.c 2007-10-23 20:50:57.000000000 -0700
+++ linux-2.6.24-rc1/mm/page_alloc.c 2007-10-25 17:29:30.000000000 -0700
@@ -4489,6 +4489,33 @@ out:
spin_unlock_irqrestore(&zone->lock, flags);
}
+/*
+ * Find out if this section of the memory is removable.
+ */
+int
+is_mem_section_removable(unsigned long start_pfn, unsigned long nr_pages)
+{
+ int type, i = 0;
+ struct page *page;
+
+ /*
+ * Check all pageblocks in the section to ensure they are all
+ * removable.
+ */
+ page = pfn_to_page(start_pfn);
+ while (i < nr_pages) {
+ type = get_pageblock_migratetype(page + i);
+
+ /*
+ * For now, we can remove sections with only MOVABLE pages.
+ */
+ if (type != MIGRATE_MOVABLE)
+ return 0;
+ i += pageblock_nr_pages;
+ }
+ return 1;
+}
+
#ifdef CONFIG_MEMORY_HOTREMOVE
/*
* All pages in the range must be isolated before calling this.
--
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] 7+ messages in thread
* Re: [PATCH] Add "removable" to /sysfs to show memblock removability
2007-10-25 23:32 ` Badari Pulavarty
@ 2007-10-26 0:27 ` KAMEZAWA Hiroyuki
0 siblings, 0 replies; 7+ messages in thread
From: KAMEZAWA Hiroyuki @ 2007-10-26 0:27 UTC (permalink / raw)
To: Badari Pulavarty; +Cc: Dave Hansen, melgor, linux-mm
On Thu, 25 Oct 2007 16:32:26 -0700
Badari Pulavarty <pbadari@us.ibm.com> wrote:
> On Thu, 2007-10-25 at 15:45 -0700, Dave Hansen wrote:
> > On Thu, 2007-10-25 at 15:35 -0700, Badari Pulavarty wrote:
> > >
> > > +static ssize_t show_mem_removable(struct sys_device *dev, char *buf)
> > > +{
> > > + unsigned long start_pfn;
> > > + struct memory_block *mem =
> > > + container_of(dev, struct memory_block, sysdev);
> > > +
> > > + start_pfn = section_nr_to_pfn(mem->phys_index);
> > > + if (is_mem_section_removable(start_pfn, PAGES_PER_SECTION))
> > > + return sprintf(buf, "True\n");
> > > + else
> > > + return sprintf(buf, "False\n");
> > > +
> >
> > Yeah, that's what I had in mind. The only other thing I might suggest
> > would be to do a number instead of true/false here. Just so that we
> > _can_ have scores in the future. Otherwise fine with me.
>
> Good point. Here is the updated version. Thanks for your suggestions.
>
> Thanks,
> Badari
>
> Each section of the memory has attributes in /sysfs. This patch adds
> file "removable" to show if this memory block is removable. This
> helps user-level agents to identify section of the memory for hotplug
> memory remove.
>
Looks very nice :)
Thank you for this work.
One point is ..why not is_mem_section_removable is not under
CONFIG_MEMORY_HOTREMOVE ?
Thanks,
-Kame
--
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] 7+ messages in thread
* Re: [PATCH] Add "removable" to /sysfs to show memblock removability
2007-10-25 22:35 [PATCH] Add "removable" to /sysfs to show memblock removability Badari Pulavarty
2007-10-25 22:45 ` Dave Hansen
@ 2007-10-26 14:47 ` Mel Gorman
1 sibling, 0 replies; 7+ messages in thread
From: Mel Gorman @ 2007-10-26 14:47 UTC (permalink / raw)
To: Badari Pulavarty; +Cc: KAMEZAWA Hiroyuki, melgor, Dave Hansen, linux-mm
On (25/10/07 15:35), Badari Pulavarty didst pronounce:
> Hi Dave & Mel,
>
> Here is the new version of the patch with your suggestion.
> Dave, does this suite your taste ? Mel, Can you handle the
> corner case you mentioned earlier ?
>
What I had in mind is below. I didn't spit the patch in two as it's both
trivial and I would expect it to be folded into your second patch.
----
A pageblock that is entirely free may be removed regardless of the
pageblock type. Similarly, a pageblock that starts with a reserved page
will not be removable no matter what the pageblock type is. Detect these
two situations when reporting whether a section may be removed or not.
Signed-off-by: Mel Gorman <mel@csn.ul.ie>
---
page_alloc.c | 43 ++++++++++++++++++++++++++++++++++++-------
1 file changed, 36 insertions(+), 7 deletions(-)
diff -rup -X /usr/src/patchset-0.6/bin//dontdiff linux-2.6.23-rc8-mm2-002_add_removable/mm/page_alloc.c linux-2.6.23-rc8-mm2-005_detect_free/mm/page_alloc.c
--- linux-2.6.23-rc8-mm2-002_add_removable/mm/page_alloc.c 2007-10-26 11:05:47.000000000 +0100
+++ linux-2.6.23-rc8-mm2-005_detect_free/mm/page_alloc.c 2007-10-26 15:29:39.000000000 +0100
@@ -4600,30 +4600,59 @@ out:
spin_unlock_irqrestore(&zone->lock, flags);
}
+/* Returns true if the pageblock contains only free pages */
+static inline int pageblock_free(struct page *page)
+{
+ return PageBuddy(page) && page_order(page) >= pageblock_order;
+}
+
+/* Move to the next pageblock that is in use */
+static inline struct page *next_active_pageblock(struct page *page)
+{
+ /* Moving forward by at least 1 * pageblock_nr_pages */
+ int order = 1;
+
+ /* If the entire pageblock is free, move to the end of free page */
+ if (pageblock_free(page) && page_order(page) > pageblock_order)
+ order += page_order(page) - pageblock_order;
+
+ return page + (order * pageblock_nr_pages);
+}
+
/*
* Find out if this section of the memory is removable.
*/
int
is_mem_section_removable(unsigned long start_pfn, unsigned long nr_pages)
{
- int type, i = 0;
- struct page *page;
+ int type;
+ struct page *page, *end_page;
/*
* Check all pageblocks in the section to ensure they are all
* removable.
*/
page = pfn_to_page(start_pfn);
- while (i < nr_pages) {
- type = get_pageblock_migratetype(page + i);
+ end_page = page + nr_pages;
+
+ for (; page < end_page; page = next_active_pageblock(page)) {
+ type = get_pageblock_migratetype(page);
/*
- * For now, we can remove sections with only MOVABLE pages.
+ * For now, we can remove sections with only MOVABLE pages
+ * or contain free pages
*/
- if (type != MIGRATE_MOVABLE)
+ if (type != MIGRATE_MOVABLE && !pageblock_free(page))
+ return 0;
+
+ /*
+ * Check if the first page is reserved, this can happen
+ * for bootmem reserved pages pageblocks
+ */
+ if (PageReserved(page))
return 0;
- i += pageblock_nr_pages;
}
+
return 1;
}
--
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] 7+ messages in thread
* [PATCH] Add "removable" to /sysfs to show memblock removability
@ 2007-10-26 16:56 Badari Pulavarty
2007-10-26 23:57 ` KAMEZAWA Hiroyuki
0 siblings, 1 reply; 7+ messages in thread
From: Badari Pulavarty @ 2007-10-26 16:56 UTC (permalink / raw)
To: Dave Hansen, KAMEZAWA Hiroyuki, melgor, Andrew Morton; +Cc: linux-mm
Here is the latest version with all the concerns/suggestions
addressed. Tested on x86-64 and ppc64 with and without
CONFIG_HOTPLUG_MEMORY option.
Andrew, Can you include it in -mm ?
Sample output:
./memory/memory0/removable: 0
./memory/memory1/removable: 0
./memory/memory2/removable: 0
./memory/memory3/removable: 0
./memory/memory4/removable: 0
./memory/memory5/removable: 0
./memory/memory6/removable: 0
./memory/memory7/removable: 1
./memory/memory8/removable: 0
./memory/memory9/removable: 0
./memory/memory10/removable: 0
./memory/memory11/removable: 0
./memory/memory12/removable: 0
./memory/memory13/removable: 0
./memory/memory14/removable: 0
./memory/memory15/removable: 0
./memory/memory16/removable: 0
./memory/memory17/removable: 1
./memory/memory18/removable: 1
./memory/memory19/removable: 1
./memory/memory20/removable: 1
./memory/memory21/removable: 1
./memory/memory22/removable: 1
Thanks,
Badari
Each section of the memory has attributes in /sysfs. This patch adds
file "removable" to show if this memory block is removable. This
helps user-level agents to identify section of the memory for hotplug
memory remove.
Sections with MOVABLE pageblocks are removable. And also pageblock
that is entirely free may be removed regardless of the pageblock type.
Similarly, a pageblock that starts with a reserved page will not be
removable no matter what the pageblock type is. Detect these
two situations when reporting whether a section may be removed or not.
Signed-off-by: Badari Pulavarty <pbadari@us.ibm.com>
Signed-off-by: Mel Gorman <mel@csn.ul.ie>
drivers/base/memory.c | 19 +++++++++++++
include/linux/memory_hotplug.h | 12 ++++++++
mm/memory_hotplug.c | 57 +++++++++++++++++++++++++++++++++++++++++
3 files changed, 88 insertions(+)
Index: linux-2.6.24-rc1/drivers/base/memory.c
===================================================================
--- linux-2.6.24-rc1.orig/drivers/base/memory.c 2007-10-23 20:50:57.000000000 -0700
+++ linux-2.6.24-rc1/drivers/base/memory.c 2007-10-26 09:00:24.000000000 -0700
@@ -105,6 +105,21 @@ static ssize_t show_mem_phys_index(struc
}
/*
+ * show memory migrate type
+ */
+static ssize_t show_mem_removable(struct sys_device *dev, char *buf)
+{
+ unsigned long start_pfn;
+ int ret;
+ struct memory_block *mem =
+ container_of(dev, struct memory_block, sysdev);
+
+ start_pfn = section_nr_to_pfn(mem->phys_index);
+ ret = is_mem_section_removable(start_pfn, PAGES_PER_SECTION);
+ return sprintf(buf, "%d\n", ret);
+}
+
+/*
* online, offline, going offline, etc.
*/
static ssize_t show_mem_state(struct sys_device *dev, char *buf)
@@ -263,6 +278,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(removable, 0444, show_mem_removable, NULL);
#define mem_create_simple_file(mem, attr_name) \
sysdev_create_file(&mem->sysdev, &attr_##attr_name)
@@ -351,6 +367,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, removable);
return ret;
}
@@ -395,6 +413,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, removable);
unregister_memory(mem, section, NULL);
return 0;
Index: linux-2.6.24-rc1/include/linux/memory_hotplug.h
===================================================================
--- linux-2.6.24-rc1.orig/include/linux/memory_hotplug.h 2007-10-23 20:50:57.000000000 -0700
+++ linux-2.6.24-rc1/include/linux/memory_hotplug.h 2007-10-26 09:00:24.000000000 -0700
@@ -171,6 +171,18 @@ static inline int mhp_notimplemented(con
#endif /* ! CONFIG_MEMORY_HOTPLUG */
+#ifdef CONFIG_MEMORY_HOTREMOVE
+
+extern int is_mem_section_removable(unsigned long pfn, unsigned long nr_pages);
+
+#else
+static inline int is_mem_section_removable(unsigned long pfn,
+ unsigned long nr_pages)
+{
+ return 0;
+}
+#endif /* CONFIG_MEMORY_HOTREMOVE */
+
extern int add_memory(int nid, u64 start, u64 size);
extern int arch_add_memory(int nid, u64 start, u64 size);
extern int remove_memory(u64 start, u64 size);
Index: linux-2.6.24-rc1/mm/memory_hotplug.c
===================================================================
--- linux-2.6.24-rc1.orig/mm/memory_hotplug.c 2007-10-23 20:50:57.000000000 -0700
+++ linux-2.6.24-rc1/mm/memory_hotplug.c 2007-10-26 09:16:59.000000000 -0700
@@ -26,6 +26,7 @@
#include <linux/delay.h>
#include <linux/migrate.h>
#include <linux/page-isolation.h>
+#include "internal.h"
#include <asm/tlbflush.h>
@@ -328,6 +329,62 @@ error:
EXPORT_SYMBOL_GPL(add_memory);
#ifdef CONFIG_MEMORY_HOTREMOVE
+/* Returns true if the pageblock contains only free pages */
+static inline int pageblock_free(struct page *page)
+{
+ return PageBuddy(page) && page_order(page) >= pageblock_order;
+}
+
+/* Move to the next pageblock that is in use */
+static inline struct page *next_active_pageblock(struct page *page)
+{
+ /* Moving forward by at least 1 * pageblock_nr_pages */
+ int order = 1;
+
+ /* If the entire pageblock is free, move to the end of free page */
+ if (pageblock_free(page) && page_order(page) > pageblock_order)
+ order += page_order(page) - pageblock_order;
+
+ return page + (order * pageblock_nr_pages);
+}
+
+/*
+ * Find out if this section of the memory is removable.
+ */
+int
+is_mem_section_removable(unsigned long start_pfn, unsigned long nr_pages)
+{
+ int type;
+ struct page *page, *end_page;
+
+ /*
+ * Check all pageblocks in the section to ensure they are all
+ * removable.
+ */
+ page = pfn_to_page(start_pfn);
+ end_page = page + nr_pages;
+
+ for (; page < end_page; page = next_active_pageblock(page)) {
+ type = get_pageblock_migratetype(page);
+
+ /*
+ * For now, we can remove sections with only MOVABLE pages
+ * or contain free pages
+ */
+ if (type != MIGRATE_MOVABLE && !pageblock_free(page))
+ return 0;
+
+ /*
+ * Check if the first page is reserved, this can happen
+ * for bootmem reserved pages pageblocks
+ */
+ if (PageReserved(page))
+ return 0;
+ }
+
+ return 1;
+}
+
/*
* Confirm all pages in a range [start, end) is belongs to the same zone.
*/
--
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] 7+ messages in thread
* Re: [PATCH] Add "removable" to /sysfs to show memblock removability
2007-10-26 16:56 Badari Pulavarty
@ 2007-10-26 23:57 ` KAMEZAWA Hiroyuki
0 siblings, 0 replies; 7+ messages in thread
From: KAMEZAWA Hiroyuki @ 2007-10-26 23:57 UTC (permalink / raw)
To: Badari Pulavarty; +Cc: haveblue, melgor, akpm, linux-mm
On Fri, 26 Oct 2007 09:56:51 -0700
Badari Pulavarty <pbadari@us.ibm.com> wrote:
> Here is the latest version with all the concerns/suggestions
> addressed. Tested on x86-64 and ppc64 with and without
> CONFIG_HOTPLUG_MEMORY option.
>
> Andrew, Can you include it in -mm ?
>
please :)
Acked-by: KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com>
--
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] 7+ messages in thread
end of thread, other threads:[~2007-10-26 23:57 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-10-25 22:35 [PATCH] Add "removable" to /sysfs to show memblock removability Badari Pulavarty
2007-10-25 22:45 ` Dave Hansen
2007-10-25 23:32 ` Badari Pulavarty
2007-10-26 0:27 ` KAMEZAWA Hiroyuki
2007-10-26 14:47 ` Mel Gorman
-- strict thread matches above, loose matches on Subject: below --
2007-10-26 16:56 Badari Pulavarty
2007-10-26 23:57 ` KAMEZAWA Hiroyuki
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).