memory-hotplug: add sysfs zones_online_to attribute
Subsystems (4)
A message that is not in the archive (sent off-list or not yet received): [email protected]
PATCH v2 1/1 memory-hotplug: add sysfs zones_online_to attribute
Currently memory-hotplug has two limits:
1. If the memory block is in ZONE_NORMAL, you can change it to ZONE_MOVABLE, but this memory block must be adjacent to ZONE_MOVABLE.
2. If the memory block is in ZONE_MOVABLE, you can change it to ZONE_NORMAL, but this memory block must be adjacent to ZONE_NORMAL.
With this patch, we can easy to know a memory block can be onlined to which zone, and don't need to know the above two limits.
Updated the related Documentation.
Change v1 -> v2:
- optimize the implementation following Dave Hansen's suggestion
--- Documentation/ABI/testing/sysfs-devices-memory | 8 ++++ Documentation/memory-hotplug.txt | 4 +- drivers/base/memory.c | 62 ++++++++++++++++++++++++++ include/linux/memory_hotplug.h | 1 + mm/memory_hotplug.c | 2 +- 5 files changed, 75 insertions(+), 2 deletions(-)
Documentation/ABI/testing/sysfs-devices-memory +8 -0
@@ -61,6 +61,14 @@ Users: hotplug memory remove tools http://www.ibm.com/developerworks/wikis/display/LinuxP/powerpc-utils +What: /sys/devices/system/memory/memoryX/zones_online_to +Date: July 2014 +Contact: Zhang Zhen <[email protected]> +Description: + The file /sys/devices/system/memory/memoryX/zones_online_to + is read-only and is designed to show which zone this memory block can + be onlined to. + What: /sys/devices/system/memoryX/nodeY Date: October 2009 Contact: Linux Memory Management list <[email protected]>
Documentation/memory-hotplug.txt +3 -1
@@ -155,6 +155,7 @@ Under each memory block, you can see 4 files: /sys/devices/system/memory/memoryXXX/phys_device /sys/devices/system/memory/memoryXXX/state /sys/devices/system/memory/memoryXXX/removable +/sys/devices/system/memory/memoryXXX/zones_online_to 'phys_index' : read-only and contains memory block id, same as XXX. 'state' : read-write
@@ -170,6 +171,8 @@ Under each memory block, you can see 4 files: block is removable and a value of 0 indicates that it is not removable. A memory block is removable only if every section in the block is removable. +'zones_online_to' : read-only: designed to show which zone this memory block + can be onlined to. NOTE: These directories/files appear after physical memory hotplug phase.
@@ -408,7 +411,6 @@ node if necessary. - allowing memory hot-add to ZONE_MOVABLE. maybe we need some switch like sysctl or new control file. - showing memory block and physical device relationship. - - showing memory block is under ZONE_MOVABLE or not - test and make it better memory offlining. - support HugeTLB page migration and offlining. - memmap removing at memory offline.
drivers/base/memory.c +62 -0
78 lines not on this page · raw message
include/linux/memory_hotplug.h +1 -0
@@ -84,6 +84,7 @@ extern int zone_grow_waitqueues(struct zone *zone, unsigned long nr_pages);extern int add_one_highpage (struct page *page,int pfn,int bad_ppro);/* VM interface that may be used by firmware interface */ extern int online_pages (unsigned long ,unsigned long ,int ); +extern int test_pages_in_a_zone (unsigned long ,unsigned long );extern void __offline_isolated_pages (unsigned long ,unsigned long );typedef void (*online_page_callback_t )(struct page *page);
mm/memory_hotplug.c +1 -1
@@ -1307,7 +1307,7 @@ int is_mem_section_removable(unsigned long start_pfn, unsigned long nr_pages)/* * Confirm all pages in a range [start, end) is belongs to the same zone. */ -static int test_pages_in_a_zone (unsigned long start_pfn,unsigned long end_pfn) +int test_pages_in_a_zone (unsigned long start_pfn,unsigned long end_pfn) {unsigned long pfn;struct zone *zone =NULL ;
Signature · 4 lines
1.8.1.2 .
Quoted 28 lines · Zhang Zhen
Currently memory-hotplug has two limits:
1. If the memory block is inZONE_NORMAL, you can change it toZONE_MOVABLE, but this memory block must be adjacent toZONE_MOVABLE.
2. If the memory block is inZONE_MOVABLE, you can change it toZONE_NORMAL, but this memory block must be adjacent toZONE_NORMAL.With this patch, we can easy to know a memory block can be onlined to which zone, and don't need to know the above two limits.
Updated the related Documentation.
Change v1 -> v2:
- optimize the implementation following Dave Hansen's suggestionSigned-off-by Zhang Zhen <[email protected]>--- Documentation/ABI/testing/sysfs-devices-memory | 8 ++++ Documentation/memory-hotplug.txt | 4 +- drivers/base/memory.c | 62 ++++++++++++++++++++++++++ include/linux/memory_hotplug.h | 1 + mm/memory_hotplug.c | 2 +- 5 files changed, 75 insertions(+), 2 deletions(-)Documentation/ABI/testing/sysfs-devices-memory +0
-0
Documentation/ABI/testing/sysfs-devices-memory Users: hotplug memory remove tools · line 64
Quoted 4 lines
Documentation/ABI/testing/sysfs-devices-memory +1
-0@@ -61,6 +61,14 @@ Users: hotplug memory remove tools http://www.ibm.com/developerworks/wikis/display/LinuxP/powerpc-utils +What: /sys/devices/system/memory/memoryX/zones_online_to
I think this name is a bit confusing. How about "valid_online_types"?
Thanks,
-Toshi
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Quoted 32 lines · Toshi Kani
Quoted 31 lines · Zhang Zhen
Currently memory-hotplug has two limits:
1. If the memory block is inZONE_NORMAL, you can change it toZONE_MOVABLE, but this memory block must be adjacent toZONE_MOVABLE.
2. If the memory block is inZONE_MOVABLE, you can change it toZONE_NORMAL, but this memory block must be adjacent toZONE_NORMAL.With this patch, we can easy to know a memory block can be onlined to which zone, and don't need to know the above two limits.
Updated the related Documentation.
Change v1 -> v2:
- optimize the implementation following Dave Hansen's suggestionSigned-off-by Zhang Zhen <[email protected]>--- Documentation/ABI/testing/sysfs-devices-memory | 8 ++++ Documentation/memory-hotplug.txt | 4 +- drivers/base/memory.c | 62 ++++++++++++++++++++++++++ include/linux/memory_hotplug.h | 1 + mm/memory_hotplug.c | 2 +- 5 files changed, 75 insertions(+), 2 deletions(-)Documentation/ABI/testing/sysfs-devices-memory +0
-0@@ -61,6 +61,14 @@ Users: hotplug memory remove tools http://www.ibm.com/developerworks/wikis/display/LinuxP/powerpc-utils
Quoted 4 lines
Documentation/ABI/testing/sysfs-devices-memory Users: hotplug memory remove tools · line 64
Quoted 1 line
Documentation/ABI/testing/sysfs-devices-memory +1
-0+What: /sys/devices/system/memory/memoryX/zones_online_toI think this name is a bit confusing. How about "
valid_online_types"?
Thanks for your suggestion.
This patch has been added to -mm tree.
If most people think so, i would like to modify the interface name. If not, let's leave it as it is.
Best regards!
Quoted 12 lines
Thanks,
-Toshi--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Quoted 34 lines · Zhang Zhen
Quoted 32 lines · Toshi Kani
Quoted 31 lines · Zhang Zhen
Currently memory-hotplug has two limits:
1. If the memory block is inZONE_NORMAL, you can change it toZONE_MOVABLE, but this memory block must be adjacent toZONE_MOVABLE.
2. If the memory block is inZONE_MOVABLE, you can change it toZONE_NORMAL, but this memory block must be adjacent toZONE_NORMAL.With this patch, we can easy to know a memory block can be onlined to which zone, and don't need to know the above two limits.
Updated the related Documentation.
Change v1 -> v2:
- optimize the implementation following Dave Hansen's suggestionSigned-off-by Zhang Zhen <[email protected]>--- Documentation/ABI/testing/sysfs-devices-memory | 8 ++++ Documentation/memory-hotplug.txt | 4 +- drivers/base/memory.c | 62 ++++++++++++++++++++++++++ include/linux/memory_hotplug.h | 1 + mm/memory_hotplug.c | 2 +- 5 files changed, 75 insertions(+), 2 deletions(-)Documentation/ABI/testing/sysfs-devices-memory +0
-0@@ -61,6 +61,14 @@ Users: hotplug memory remove tools http://www.ibm.com/developerworks/wikis/display/LinuxP/powerpc-utils
Quoted 8 lines
Quoted 4 lines
Documentation/ABI/testing/sysfs-devices-memory Users: hotplug memory remove tools · line 64
Quoted 1 line
Documentation/ABI/testing/sysfs-devices-memory +1
-0+What: /sys/devices/system/memory/memoryX/zones_online_toI think this name is a bit confusing. How about "
valid_online_types"?Thanks for your suggestion.
This patch has been added to -mm tree.
If most people think so, i would like to modify the interface name.
I like Toshi's idea (valid_online_types).
Thanks,
Yasuaki Ishimatsu
Quoted 17 lines
If not, let's leave it as it is.
Best regards!
Quoted 12 lines
Thanks,
-Toshi--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Andrew Morton
maintainerQuoted 37 lines · On Mon, 18 Aug 2014 11:25:36 +0800 Zhang Zhen <[email protected]>…
Quoted 32 lines · Toshi Kani
Quoted 31 lines · Zhang Zhen
Currently memory-hotplug has two limits:
1. If the memory block is inZONE_NORMAL, you can change it toZONE_MOVABLE, but this memory block must be adjacent toZONE_MOVABLE.
2. If the memory block is inZONE_MOVABLE, you can change it toZONE_NORMAL, but this memory block must be adjacent toZONE_NORMAL.With this patch, we can easy to know a memory block can be onlined to which zone, and don't need to know the above two limits.
Updated the related Documentation.
Change v1 -> v2:
- optimize the implementation following Dave Hansen's suggestionSigned-off-by Zhang Zhen <[email protected]>--- Documentation/ABI/testing/sysfs-devices-memory | 8 ++++ Documentation/memory-hotplug.txt | 4 +- drivers/base/memory.c | 62 ++++++++++++++++++++++++++ include/linux/memory_hotplug.h | 1 + mm/memory_hotplug.c | 2 +- 5 files changed, 75 insertions(+), 2 deletions(-)Documentation/ABI/testing/sysfs-devices-memory +0
-0@@ -61,6 +61,14 @@ Users: hotplug memory remove tools http://www.ibm.com/developerworks/wikis/display/LinuxP/powerpc-utilsQuoted 4 lines
Documentation/ABI/testing/sysfs-devices-memory Users: hotplug memory remove tools · line 64
Quoted 1 line
Documentation/ABI/testing/sysfs-devices-memory +1
-0+What: /sys/devices/system/memory/memoryX/zones_online_toI think this name is a bit confusing. How about "
valid_online_types"?
Quoted 5 lines
Thanks for your suggestion.
This patch has been added to -mm tree.
If most people think so, i would like to modify the interface name. If not, let's leave it as it is.
Yes, the name could be better. Do we actually need "online" in there? How about "valid_zones"?
Also, it's not really clear to me why we need this sysfs file at all. Do people really read sysfs files, make onlining decisions and manually type in commands? Or is this stuff all automated? If the latter then the script can take care of all this? For example, attempt to online the memory into the desired zone and report failure if that didn't succeed?
IOW, please update the changelog to show
a) example output from /sys/devices/system/memory/memoryX/whatever-we-call-it and
b) example use-cases which help reviewers understand why this feature will be valuable to users.
Also, please do address the error which Yasuaki Ishimatsu identified.
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Quoted 6 lines · Andrew Morton
Also, it's not really clear to me why we need this sysfs file at all. Do people really read sysfs files, make onlining decisions and manually type in commands? Or is this stuff all automated? If the latter then the script can take care of all this? For example, attempt to online the memory into the desired zone and report failure if that didn't succeed?
I guess we can just iterate over all possible zone types from userspace until we find one. Seems a bit hokey, but it would work at least until we add a new zone type and we have to teach the scripts about the new type. But that's a pretty rare event I guess. Let's hope the script writers get this right, and don't make omissions like ZONE_MOVABLE because it's not that common in practice.
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Quoted 39 lines · Andrew Morton
Quoted 37 lines · On Mon, 18 Aug 2014 11:25:36 +0800 Zhang Zhen <[email protected]>…
Quoted 36 lines · Toshi Kani
Quoted 28 lines · Zhang Zhen
Currently memory-hotplug has two limits:
1. If the memory block is inZONE_NORMAL, you can change it toZONE_MOVABLE, but this memory block must be adjacent toZONE_MOVABLE.
2. If the memory block is inZONE_MOVABLE, you can change it toZONE_NORMAL, but this memory block must be adjacent toZONE_NORMAL.With this patch, we can easy to know a memory block can be onlined to which zone, and don't need to know the above two limits.
Updated the related Documentation.
Change v1 -> v2:
- optimize the implementation following Dave Hansen's suggestionSigned-off-by Zhang Zhen <[email protected]>--- Documentation/ABI/testing/sysfs-devices-memory | 8 ++++ Documentation/memory-hotplug.txt | 4 +- drivers/base/memory.c | 62 ++++++++++++++++++++++++++ include/linux/memory_hotplug.h | 1 + mm/memory_hotplug.c | 2 +- 5 files changed, 75 insertions(+), 2 deletions(-)Documentation/ABI/testing/sysfs-devices-memory +0
-0Documentation/ABI/testing/sysfs-devices-memory Users: hotplug memory remove tools · line 64
Quoted 4 lines
Documentation/ABI/testing/sysfs-devices-memory +1
-0@@ -61,6 +61,14 @@ Users: hotplug memory remove tools http://www.ibm.com/developerworks/wikis/display/LinuxP/powerpc-utils +What: /sys/devices/system/memory/memoryX/zones_online_toI think this name is a bit confusing. How about "
valid_online_types"?
Quoted 8 lines
Quoted 5 lines
Thanks for your suggestion.
This patch has been added to -mm tree.
If most people think so, i would like to modify the interface name. If not, let's leave it as it is.Yes, the name could be better. Do we actually need "online" in there? How about "
valid_zones"?
Ok, i will change it to valid_zones.
Quoted 7 lines
Also, it's not really clear to me why we need this sysfs file at all. Do people really read sysfs files, make onlining decisions and manually type in commands? Or is this stuff all automated? If the latter then the script can take care of all this? For example, attempt to online the memory into the desired zone and report failure if that didn't succeed?
Just like Dave Hansen says, the scripts should be changed when we add a new zone type. And ZONE_MOVABLE may be missed by the scripts writer.
Quoted 8 lines
IOW, please update the changelog to show
a) example output from
/sys/devices/system/memory/memoryX/whatever-we-call-itandb) example use-cases which help reviewers understand why this feature will be valuable to users.
Sorry, this patch has been added to -next tree. I can't modify the changelog.
Quoted 3 lines
Also, please do address the error which Yasuaki Ishimatsu identified.
Yeah, i have been waiting for http://ozlabs.org/~akpm/mmots/broken-out/memory-hotplug-add-sysfs-zones_online_to-attribute-fix-2.patch
added to -mm tree.
So i can send a patch based on -mm tree to address the error which Yasuaki Ishimatsu identified.
Otherwise, conflicts may occur.
Thanks!
Quoted 3 lines
.
Quoted 39 lines · Andrew Morton
Quoted 37 lines · On Mon, 18 Aug 2014 11:25:36 +0800 Zhang Zhen <[email protected]>…
Quoted 36 lines · Toshi Kani
Quoted 28 lines · Zhang Zhen
Currently memory-hotplug has two limits:
1. If the memory block is inZONE_NORMAL, you can change it toZONE_MOVABLE, but this memory block must be adjacent toZONE_MOVABLE.
2. If the memory block is inZONE_MOVABLE, you can change it toZONE_NORMAL, but this memory block must be adjacent toZONE_NORMAL.With this patch, we can easy to know a memory block can be onlined to which zone, and don't need to know the above two limits.
Updated the related Documentation.
Change v1 -> v2:
- optimize the implementation following Dave Hansen's suggestionSigned-off-by Zhang Zhen <[email protected]>--- Documentation/ABI/testing/sysfs-devices-memory | 8 ++++ Documentation/memory-hotplug.txt | 4 +- drivers/base/memory.c | 62 ++++++++++++++++++++++++++ include/linux/memory_hotplug.h | 1 + mm/memory_hotplug.c | 2 +- 5 files changed, 75 insertions(+), 2 deletions(-)Documentation/ABI/testing/sysfs-devices-memory +0
-0Documentation/ABI/testing/sysfs-devices-memory Users: hotplug memory remove tools · line 64
Quoted 4 lines
Documentation/ABI/testing/sysfs-devices-memory +1
-0@@ -61,6 +61,14 @@ Users: hotplug memory remove tools http://www.ibm.com/developerworks/wikis/display/LinuxP/powerpc-utils +What: /sys/devices/system/memory/memoryX/zones_online_toI think this name is a bit confusing. How about "
valid_online_types"?
Quoted 8 lines
Quoted 5 lines
Thanks for your suggestion.
This patch has been added to -mm tree.
If most people think so, i would like to modify the interface name. If not, let's leave it as it is.Yes, the name could be better. Do we actually need "online" in there? How about "
valid_zones"?
I suggested using "online" because a user specifies a zone type during an online operation as follows.
$ echo online_movable > /sys/devices/system/memory/memoryXXX/state
I also like "valid_zones" and it well represents what it is (and the name is shorter :-). I am fine with this name as well.
Thanks,
-Toshi
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Quoted 78 lines · Zhang Zhen
Currently memory-hotplug has two limits:
1. If the memory block is inZONE_NORMAL, you can change it toZONE_MOVABLE, but this memory block must be adjacent toZONE_MOVABLE.
2. If the memory block is inZONE_MOVABLE, you can change it toZONE_NORMAL, but this memory block must be adjacent toZONE_NORMAL.With this patch, we can easy to know a memory block can be onlined to which zone, and don't need to know the above two limits.
Updated the related Documentation.
Change v1 -> v2:
- optimize the implementation following Dave Hansen's suggestionSigned-off-by Zhang Zhen <[email protected]>--- Documentation/ABI/testing/sysfs-devices-memory | 8 ++++ Documentation/memory-hotplug.txt | 4 +- drivers/base/memory.c | 62 ++++++++++++++++++++++++++ include/linux/memory_hotplug.h | 1 + mm/memory_hotplug.c | 2 +- 5 files changed, 75 insertions(+), 2 deletions(-)Documentation/ABI/testing/sysfs-devices-memory +8
-0@@ -61,6 +61,14 @@ Users: hotplug memory remove tools http://www.ibm.com/developerworks/wikis/display/LinuxP/powerpc-utils +What: /sys/devices/system/memory/memoryX/zones_online_to +Date: July 2014 +Contact: Zhang Zhen <[email protected]> +Description: + The file /sys/devices/system/memory/memoryX/zones_online_to + is read-only and is designed to show which zone this memory block can + be onlined to. + What: /sys/devices/system/memoryX/nodeY Date: October 2009 Contact: Linux Memory Management list <[email protected]>Documentation/memory-hotplug.txt +3
-1@@ -155,6 +155,7 @@ Under each memory block, you can see 4 files: /sys/devices/system/memory/memoryXXX/phys_device /sys/devices/system/memory/memoryXXX/state /sys/devices/system/memory/memoryXXX/removable +/sys/devices/system/memory/memoryXXX/zones_online_to 'phys_index' : read-only and contains memory block id, same as XXX. 'state' : read-write@@ -170,6 +171,8 @@ Under each memory block, you can see 4 files: block is removable and a value of 0 indicates that it is not removable. A memory block is removable only if every section in the block is removable. +'zones_online_to' : read-only: designed to show which zone this memory block + can be onlined to. NOTE: These directories/files appear after physical memory hotplug phase.@@ -408,7 +411,6 @@ node if necessary. - allowing memory hot-add to ZONE_MOVABLE. maybe we need some switch like sysctl or new control file. - showing memory block and physical device relationship. - - showing memory block is under ZONE_MOVABLE or not - test and make it better memory offlining. - support HugeTLB page migration and offlining. - memmap removing at memory offline.drivers/base/memory.c +0
-0@@ -373,10 +373,71 @@ static ssize_t show_phys_device(struct device *dev,return sprintf (buf,"%d\n" , mem->phys_device); }
drivers/base/memory.c static ssize_t show_phys_device(struct device *dev, · line 384
Quoted 10 lines
drivers/base/memory.c +8
-0+static int __zones_online_to (unsigned long end_pfn, +struct page *first_page,unsigned long nr_pages) +{ +struct zone *zone_next; + +/*The mem block is the last block of memory.*/ +if (!pfn_valid (end_pfn +1 )) +return 1 ;
The check is not enough if memory has hole as follows:
PFN 0x00 0xd0 0xe0 0xf0
+-------------+-------------+-------------+
zone type | Normal | hole | Normal |
+-------------+-------------+-------------+In this case, 0xd1 is invalid pfn. But __zones_online_to should return 0 since 0xe0-0xf0 is Normal zone.
Thanks,
Yasuaki Ishimatsu
Quoted 94 lines
drivers/base/memory.c +53
-0+ zone_next =page_zone (first_page + nr_pages); +if (zone_idx (zone_next) ==ZONE_MOVABLE ) +return 1 ; +return 0 ; +} + +static ssize_t show_zones_online_to (struct device *dev, +struct device_attribute *attr,char *buf) +{ +struct memory_block *mem =to_memory_block (dev); +unsigned long start_pfn, end_pfn; +unsigned long nr_pages =PAGES_PER_SECTION * sections_per_block; +struct page *first_page; +struct zone *zone, *zone_prev; + + start_pfn =section_nr_to_pfn (mem->start_section_nr); + end_pfn = start_pfn + nr_pages; + first_page =pfn_to_page (start_pfn); + +/*The block contains more than one zone can not be offlined.*/ +if (!test_pages_in_a_zone (start_pfn, end_pfn)) +return sprintf (buf,"none\n" ); + + zone =page_zone (first_page); + +#ifdef CONFIG_HIGHMEM +if (zone_idx (zone) ==ZONE_HIGHMEM ) { +if (__zones_online_to (end_pfn, first_page, nr_pages)) +return sprintf (buf,"%s %s\n" , + zone->name, (zone +1 )->name); + } +#else +if (zone_idx (zone) ==ZONE_NORMAL ) { +if (__zones_online_to (end_pfn, first_page, nr_pages)) +return sprintf (buf,"%s %s\n" , + zone->name, (zone +1 )->name); + } +#endif + +if (zone_idx (zone) ==ZONE_MOVABLE ) { +if (!pfn_valid (start_pfn - nr_pages)) +return sprintf (buf,"%s %s\n" , + zone->name, (zone -1 )->name); + zone_prev =page_zone (first_page - nr_pages); +if (zone_idx (zone_prev) !=ZONE_MOVABLE ) +return sprintf (buf,"%s %s\n" , + zone->name, (zone -1 )->name); + } + +return sprintf (buf,"%s\n" , zone->name); +} + static DEVICE_ATTR(phys_index, 0444, show_mem_start_phys_index, NULL); static DEVICE_ATTR(state, 0644, show_mem_state, store_mem_state); static DEVICE_ATTR(phys_device, 0444, show_phys_device, NULL); static DEVICE_ATTR(removable, 0444, show_mem_removable, NULL); +static DEVICE_ATTR(zones_online_to, 0444, show_zones_online_to, NULL);/* * Block size attribute stuff
drivers/base/memory.c +1
-0@@ -523,6 +584,7 @@ static struct attribute *memory_memblk_attrs[] = { &dev_attr_state.attr, &dev_attr_phys_device.attr, &dev_attr_removable.attr, + &dev_attr_zones_online_to.attr, NULL };include/linux/memory_hotplug.h +1
-0@@ -84,6 +84,7 @@ extern int zone_grow_waitqueues(struct zone *zone, unsigned long nr_pages);extern int add_one_highpage (struct page *page,int pfn,int bad_ppro);/* VM interface that may be used by firmware interface */ extern int online_pages (unsigned long ,unsigned long ,int ); +extern int test_pages_in_a_zone (unsigned long ,unsigned long );extern void __offline_isolated_pages (unsigned long ,unsigned long );typedef void (*online_page_callback_t )(struct page *page);mm/memory_hotplug.c +1
-1@@ -1307,7 +1307,7 @@ int is_mem_section_removable(unsigned long start_pfn, unsigned long nr_pages)/* * Confirm all pages in a range [start, end) is belongs to the same zone. */ -static int test_pages_in_a_zone (unsigned long start_pfn,unsigned long end_pfn) +int test_pages_in_a_zone (unsigned long start_pfn,unsigned long end_pfn) {unsigned long pfn;struct zone *zone =NULL ;
Quoted 97 lines · Yasuaki Ishimatsu
Quoted 78 lines · Zhang Zhen
Currently memory-hotplug has two limits:
1. If the memory block is inZONE_NORMAL, you can change it toZONE_MOVABLE, but this memory block must be adjacent toZONE_MOVABLE.
2. If the memory block is inZONE_MOVABLE, you can change it toZONE_NORMAL, but this memory block must be adjacent toZONE_NORMAL.With this patch, we can easy to know a memory block can be onlined to which zone, and don't need to know the above two limits.
Updated the related Documentation.
Change v1 -> v2:
- optimize the implementation following Dave Hansen's suggestionSigned-off-by Zhang Zhen <[email protected]>--- Documentation/ABI/testing/sysfs-devices-memory | 8 ++++ Documentation/memory-hotplug.txt | 4 +- drivers/base/memory.c | 62 ++++++++++++++++++++++++++ include/linux/memory_hotplug.h | 1 + mm/memory_hotplug.c | 2 +- 5 files changed, 75 insertions(+), 2 deletions(-)Documentation/ABI/testing/sysfs-devices-memory +8
-0@@ -61,6 +61,14 @@ Users: hotplug memory remove tools http://www.ibm.com/developerworks/wikis/display/LinuxP/powerpc-utils +What: /sys/devices/system/memory/memoryX/zones_online_to +Date: July 2014 +Contact: Zhang Zhen <[email protected]> +Description: + The file /sys/devices/system/memory/memoryX/zones_online_to + is read-only and is designed to show which zone this memory block can + be onlined to. + What: /sys/devices/system/memoryX/nodeY Date: October 2009 Contact: Linux Memory Management list <[email protected]>Documentation/memory-hotplug.txt +3
-1@@ -155,6 +155,7 @@ Under each memory block, you can see 4 files: /sys/devices/system/memory/memoryXXX/phys_device /sys/devices/system/memory/memoryXXX/state /sys/devices/system/memory/memoryXXX/removable +/sys/devices/system/memory/memoryXXX/zones_online_to 'phys_index' : read-only and contains memory block id, same as XXX. 'state' : read-write@@ -170,6 +171,8 @@ Under each memory block, you can see 4 files: block is removable and a value of 0 indicates that it is not removable. A memory block is removable only if every section in the block is removable. +'zones_online_to' : read-only: designed to show which zone this memory block + can be onlined to. NOTE: These directories/files appear after physical memory hotplug phase.@@ -408,7 +411,6 @@ node if necessary. - allowing memory hot-add to ZONE_MOVABLE. maybe we need some switch like sysctl or new control file. - showing memory block and physical device relationship. - - showing memory block is under ZONE_MOVABLE or not - test and make it better memory offlining. - support HugeTLB page migration and offlining. - memmap removing at memory offline.drivers/base/memory.c +0
-0@@ -373,10 +373,71 @@ static ssize_t show_phys_device(struct device *dev,return sprintf (buf,"%d\n" , mem->phys_device); }drivers/base/memory.c static ssize_t show_phys_device(struct device *dev, · line 384
Quoted 10 lines
drivers/base/memory.c +8
-0+static int __zones_online_to (unsigned long end_pfn, +struct page *first_page,unsigned long nr_pages) +{ +struct zone *zone_next; + +/*The mem block is the last block of memory.*/ +if (!pfn_valid (end_pfn +1 )) +return 1 ;The check is not enough if memory has hole as follows:
PFN
0x000xd00xe00xf0+-------------+-------------+-------------+ zone type | Normal | hole | Normal | +-------------+-------------+-------------+
Quoted 6 lines
In this case,
0xd1is invalid pfn. But__zones_online_toshould return 0 since 0xe0-0xf0 is Normal zone.Thanks,
Yasuaki Ishimatsu
You are right, it is not enough.
Here we should make a check as follows.
if ((end_pfn + 1) > zone_end_pfn(page_zone(first_page)))
return 1;
I will send a patch to fix it.
Thanks !
Quoted 105 lines
Quoted 95 lines
drivers/base/memory.c +53
-0+ zone_next =page_zone (first_page + nr_pages); +if (zone_idx (zone_next) ==ZONE_MOVABLE ) +return 1 ; +return 0 ; +} + +static ssize_t show_zones_online_to (struct device *dev, +struct device_attribute *attr,char *buf) +{ +struct memory_block *mem =to_memory_block (dev); +unsigned long start_pfn, end_pfn; +unsigned long nr_pages =PAGES_PER_SECTION * sections_per_block; +struct page *first_page; +struct zone *zone, *zone_prev; + + start_pfn =section_nr_to_pfn (mem->start_section_nr); + end_pfn = start_pfn + nr_pages; + first_page =pfn_to_page (start_pfn); + +/*The block contains more than one zone can not be offlined.*/ +if (!test_pages_in_a_zone (start_pfn, end_pfn)) +return sprintf (buf,"none\n" ); + + zone =page_zone (first_page); + +#ifdef CONFIG_HIGHMEM +if (zone_idx (zone) ==ZONE_HIGHMEM ) { +if (__zones_online_to (end_pfn, first_page, nr_pages)) +return sprintf (buf,"%s %s\n" , + zone->name, (zone +1 )->name); + } +#else +if (zone_idx (zone) ==ZONE_NORMAL ) { +if (__zones_online_to (end_pfn, first_page, nr_pages)) +return sprintf (buf,"%s %s\n" , + zone->name, (zone +1 )->name); + } +#endif + +if (zone_idx (zone) ==ZONE_MOVABLE ) { +if (!pfn_valid (start_pfn - nr_pages)) +return sprintf (buf,"%s %s\n" , + zone->name, (zone -1 )->name); + zone_prev =page_zone (first_page - nr_pages); +if (zone_idx (zone_prev) !=ZONE_MOVABLE ) +return sprintf (buf,"%s %s\n" , + zone->name, (zone -1 )->name); + } + +return sprintf (buf,"%s\n" , zone->name); +} + static DEVICE_ATTR(phys_index, 0444, show_mem_start_phys_index, NULL); static DEVICE_ATTR(state, 0644, show_mem_state, store_mem_state); static DEVICE_ATTR(phys_device, 0444, show_phys_device, NULL); static DEVICE_ATTR(removable, 0444, show_mem_removable, NULL); +static DEVICE_ATTR(zones_online_to, 0444, show_zones_online_to, NULL);/* * Block size attribute stuff
drivers/base/memory.c +1
-0@@ -523,6 +584,7 @@ static struct attribute *memory_memblk_attrs[] = { &dev_attr_state.attr, &dev_attr_phys_device.attr, &dev_attr_removable.attr, + &dev_attr_zones_online_to.attr, NULL };include/linux/memory_hotplug.h +1
-0@@ -84,6 +84,7 @@ extern int zone_grow_waitqueues(struct zone *zone, unsigned long nr_pages);extern int add_one_highpage (struct page *page,int pfn,int bad_ppro);/* VM interface that may be used by firmware interface */ extern int online_pages (unsigned long ,unsigned long ,int ); +extern int test_pages_in_a_zone (unsigned long ,unsigned long );extern void __offline_isolated_pages (unsigned long ,unsigned long );typedef void (*online_page_callback_t )(struct page *page);mm/memory_hotplug.c +1
-1@@ -1307,7 +1307,7 @@ int is_mem_section_removable(unsigned long start_pfn, unsigned long nr_pages)/* * Confirm all pages in a range [start, end) is belongs to the same zone. */ -static int test_pages_in_a_zone (unsigned long start_pfn,unsigned long end_pfn) +int test_pages_in_a_zone (unsigned long start_pfn,unsigned long end_pfn) {unsigned long pfn;struct zone *zone =NULL ;Signature · 6 lines
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a> .
Quoted 104 lines · Zhang Zhen
Quoted 97 lines · Yasuaki Ishimatsu
Quoted 78 lines · Zhang Zhen
Currently memory-hotplug has two limits:
1. If the memory block is inZONE_NORMAL, you can change it toZONE_MOVABLE, but this memory block must be adjacent toZONE_MOVABLE.
2. If the memory block is inZONE_MOVABLE, you can change it toZONE_NORMAL, but this memory block must be adjacent toZONE_NORMAL.With this patch, we can easy to know a memory block can be onlined to which zone, and don't need to know the above two limits.
Updated the related Documentation.
Change v1 -> v2:
- optimize the implementation following Dave Hansen's suggestionSigned-off-by Zhang Zhen <[email protected]>--- Documentation/ABI/testing/sysfs-devices-memory | 8 ++++ Documentation/memory-hotplug.txt | 4 +- drivers/base/memory.c | 62 ++++++++++++++++++++++++++ include/linux/memory_hotplug.h | 1 + mm/memory_hotplug.c | 2 +- 5 files changed, 75 insertions(+), 2 deletions(-)Documentation/ABI/testing/sysfs-devices-memory +8
-0@@ -61,6 +61,14 @@ Users: hotplug memory remove tools http://www.ibm.com/developerworks/wikis/display/LinuxP/powerpc-utils +What: /sys/devices/system/memory/memoryX/zones_online_to +Date: July 2014 +Contact: Zhang Zhen <[email protected]> +Description: + The file /sys/devices/system/memory/memoryX/zones_online_to + is read-only and is designed to show which zone this memory block can + be onlined to. + What: /sys/devices/system/memoryX/nodeY Date: October 2009 Contact: Linux Memory Management list <[email protected]>Documentation/memory-hotplug.txt +3
-1@@ -155,6 +155,7 @@ Under each memory block, you can see 4 files: /sys/devices/system/memory/memoryXXX/phys_device /sys/devices/system/memory/memoryXXX/state /sys/devices/system/memory/memoryXXX/removable +/sys/devices/system/memory/memoryXXX/zones_online_to 'phys_index' : read-only and contains memory block id, same as XXX. 'state' : read-write@@ -170,6 +171,8 @@ Under each memory block, you can see 4 files: block is removable and a value of 0 indicates that it is not removable. A memory block is removable only if every section in the block is removable. +'zones_online_to' : read-only: designed to show which zone this memory block + can be onlined to. NOTE: These directories/files appear after physical memory hotplug phase.@@ -408,7 +411,6 @@ node if necessary. - allowing memory hot-add to ZONE_MOVABLE. maybe we need some switch like sysctl or new control file. - showing memory block and physical device relationship. - - showing memory block is under ZONE_MOVABLE or not - test and make it better memory offlining. - support HugeTLB page migration and offlining. - memmap removing at memory offline.drivers/base/memory.c +0
-0@@ -373,10 +373,71 @@ static ssize_t show_phys_device(struct device *dev,return sprintf (buf,"%d\n" , mem->phys_device); }drivers/base/memory.c static ssize_t show_phys_device(struct device *dev, · line 384
Quoted 10 lines
drivers/base/memory.c +8
-0+static int __zones_online_to (unsigned long end_pfn, +struct page *first_page,unsigned long nr_pages) +{ +struct zone *zone_next; + +/*The mem block is the last block of memory.*/ +if (!pfn_valid (end_pfn +1 )) +return 1 ;The check is not enough if memory has hole as follows:
PFN
0x000xd00xe00xf0+-------------+-------------+-------------+ zone type | Normal | hole | Normal | +-------------+-------------+-------------+Quoted 6 lines
In this case,
0xd1is invalid pfn. But__zones_online_toshould return 0 since 0xe0-0xf0 is Normal zone.Thanks,
Yasuaki Ishimatsu
Quoted 7 lines
You are right, it is not enough.
Here we should make a check as follows.
if ((end_pfn+ 1) > zone_end_pfn(page_zone(first_page)))return 1;I will send a patch to fix it.
It's looks good to me.
Thanks,
Yasuaki Ishimatsu
Quoted 109 lines
Thanks !
Quoted 105 lines
Quoted 87 lines
drivers/base/memory.c +53
-0+ zone_next =page_zone (first_page + nr_pages); +if (zone_idx (zone_next) ==ZONE_MOVABLE ) +return 1 ; +return 0 ; +} + +static ssize_t show_zones_online_to (struct device *dev, +struct device_attribute *attr,char *buf) +{ +struct memory_block *mem =to_memory_block (dev); +unsigned long start_pfn, end_pfn; +unsigned long nr_pages =PAGES_PER_SECTION * sections_per_block; +struct page *first_page; +struct zone *zone, *zone_prev; + + start_pfn =section_nr_to_pfn (mem->start_section_nr); + end_pfn = start_pfn + nr_pages; + first_page =pfn_to_page (start_pfn); + +/*The block contains more than one zone can not be offlined.*/ +if (!test_pages_in_a_zone (start_pfn, end_pfn)) +return sprintf (buf,"none\n" ); + + zone =page_zone (first_page); + +#ifdef CONFIG_HIGHMEM +if (zone_idx (zone) ==ZONE_HIGHMEM ) { +if (__zones_online_to (end_pfn, first_page, nr_pages)) +return sprintf (buf,"%s %s\n" , + zone->name, (zone +1 )->name); + } +#else +if (zone_idx (zone) ==ZONE_NORMAL ) { +if (__zones_online_to (end_pfn, first_page, nr_pages)) +return sprintf (buf,"%s %s\n" , + zone->name, (zone +1 )->name); + } +#endif + +if (zone_idx (zone) ==ZONE_MOVABLE ) { +if (!pfn_valid (start_pfn - nr_pages)) +return sprintf (buf,"%s %s\n" , + zone->name, (zone -1 )->name); + zone_prev =page_zone (first_page - nr_pages); +if (zone_idx (zone_prev) !=ZONE_MOVABLE ) +return sprintf (buf,"%s %s\n" , + zone->name, (zone -1 )->name); + } + +return sprintf (buf,"%s\n" , zone->name); +} + static DEVICE_ATTR(phys_index, 0444, show_mem_start_phys_index, NULL); static DEVICE_ATTR(state, 0644, show_mem_state, store_mem_state); static DEVICE_ATTR(phys_device, 0444, show_phys_device, NULL); static DEVICE_ATTR(removable, 0444, show_mem_removable, NULL); +static DEVICE_ATTR(zones_online_to, 0444, show_zones_online_to, NULL);/* * Block size attribute stuff
drivers/base/memory.c +1
-0@@ -523,6 +584,7 @@ static struct attribute *memory_memblk_attrs[] = { &dev_attr_state.attr, &dev_attr_phys_device.attr, &dev_attr_removable.attr, + &dev_attr_zones_online_to.attr, NULL };include/linux/memory_hotplug.h +1
-0@@ -84,6 +84,7 @@ extern int zone_grow_waitqueues(struct zone *zone, unsigned long nr_pages);extern int add_one_highpage (struct page *page,int pfn,int bad_ppro);/* VM interface that may be used by firmware interface */ extern int online_pages (unsigned long ,unsigned long ,int ); +extern int test_pages_in_a_zone (unsigned long ,unsigned long );extern void __offline_isolated_pages (unsigned long ,unsigned long );typedef void (*online_page_callback_t )(struct page *page);mm/memory_hotplug.c +0
-0mm/memory_hotplug.c int is_mem_section_removable(unsigned long start_pfn, unsigned long nr_pages) · line 1313
Quoted 8 lines
mm/memory_hotplug.c +1
-1@@ -1307,7 +1307,7 @@ int is_mem_section_removable(unsigned long start_pfn, unsigned long nr_pages)/* * Confirm all pages in a range [start, end) is belongs to the same zone. */ -static int test_pages_in_a_zone (unsigned long start_pfn,unsigned long end_pfn) +int test_pages_in_a_zone (unsigned long start_pfn,unsigned long end_pfn) {unsigned long pfn;struct zone *zone =NULL ;--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>.
Quoted 9 lines · Zhang Zhen
Currently memory-hotplug has two limits:
1. If the memory block is inZONE_NORMAL, you can change it toZONE_MOVABLE, but this memory block must be adjacent toZONE_MOVABLE.
2. If the memory block is inZONE_MOVABLE, you can change it toZONE_NORMAL, but this memory block must be adjacent toZONE_NORMAL.With this patch, we can easy to know a memory block can be onlined to which zone, and don't need to know the above two limits.
Quoted 6 lines
Updated the related Documentation.
Change v1 -> v2:
- optimize the implementation following Dave Hansen's suggestionSigned-off-by Zhang Zhen <[email protected]>
linux-next build failure:
drivers/built-in.o: In function `show_zones_online_to':
memory.c:(.text+0x13ee09): undefined reference to `test_pages_in_a_zone'
Quoted 16 lines · David Rientjes
Quoted 14 lines · Zhang Zhen
Currently memory-hotplug has two limits:
1. If the memory block is inZONE_NORMAL, you can change it toZONE_MOVABLE, but this memory block must be adjacent toZONE_MOVABLE.
2. If the memory block is inZONE_MOVABLE, you can change it toZONE_NORMAL, but this memory block must be adjacent toZONE_NORMAL.With this patch, we can easy to know a memory block can be onlined to which zone, and don't need to know the above two limits.
Updated the related Documentation.
Change v1 -> v2:
- optimize the implementation following Dave Hansen's suggestion
Quoted 7 lines
Quoted 1 line
Signed-off-by Zhang Zhen <[email protected]>linux-next build failure:
drivers/built-in.o: In function `show_zones_online_to':
memory.c:(.text+0x13ee09): undefined reference to `test_pages_in_a_zone'
The function implementation in mm/memory_hotplug.c is only built if CONFIG_MEMORY_HOTREMOVE is enabled.
A fix has been proposed.
http://ozlabs.org/~akpm/mmots/broken-out/memory-hotplug-add-sysfs-zones_online_to-attribute-fix-2.patch
Thanks!