Skip to contentSkip to conversation

memory-hotplug: add automatic onlining policy for the newly added memory

RFC PATCH In review Vitaly Kuznetsov 3 participants 7 messages Dec 15, 2015 – Dec 16, 2015

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

RFC PATCH 1/1 memory-hotplug: add automatic onlining policy for the newly added memory

Currently, all newly added memory blocks remain in 'offline' state unless someone onlines them, some linux distributions carry special udev rules like:

SUBSYSTEM=="memory", ACTION=="add", ATTR{state}=="offline", ATTR{state}="online"

to make this happen automatically. This is not a great solution for virtual machines where memory hotplug is being used to address high memory pressure situations as such onlining is slow and a userspace process doing this (udev) has a chance of being killed by the OOM killer as it will probably require to allocate some memory.

Introduce default policy for the newly added memory blocks in /sys/devices/system/memory/hotplug_autoonline file with two possible
values: "offline" (the default) which preserves the current behavior and "online" which causes all newly added memory blocks to go online as soon as they're added.

Cc Jonathan Corbet <[email protected]>
Cc Greg Kroah-Hartman <[email protected]>
Cc Daniel Kiper <[email protected]>
Cc Dan Williams <[email protected]>
Cc Tang Chen <[email protected]>
Cc David Vrabel <[email protected]>
Cc David Rientjes <[email protected]>
Cc Andrew Morton <[email protected]>
Cc Naoya Horiguchi <[email protected]>
Cc Gu Zheng <[email protected]>
Cc Xishi Qiu <[email protected]>
Cc Mel Gorman <[email protected]>
Cc "K. Y. Srinivasan" <[email protected]>

---
- I was able to find previous attempts to fix the issue, e.g.:
http://marc.info/?l=linux-kernel&m=137425951924598&w=2
http://marc.info/?l=linux-acpi&m=127186488905382
but I'm not completely sure why it didn't work out and the solution I suggest is not 'smart enough', thus 'RFC'.

---
 Documentation/memory-hotplug.txt | 21 +++++++++++++++++----
 drivers/base/memory.c            | 35 +++++++++++++++++++++++++++++++++++
 include/linux/memory_hotplug.h   |  2 ++
 mm/memory_hotplug.c              |  8 ++++++++
 4 files changed, 62 insertions(+), 4 deletions(-)
Documentation/memory-hotplug.txt +17 -4
index ce2cfcf..fe576d9 100644
@@ -254,12 +254,25 @@ If the memory block is online, you'll read "online".
 If the memory block is offline, you'll read "offline".
 
 
-5.2. How to online memory
+5.2. Memory onlining
 ------------
-Even if the memory is hot-added, it is not at ready-to-use state.
-For using newly added memory, you have to "online" the memory block.
+When the memory is hot-added, the kernel decides whether or not to "online"
+it according to the policy which can be read from "hotplug_autoonline" file:
 
-For onlining, you have to write "online" to the memory block's state file as:
+% cat /sys/devices/system/memory/hotplug_autoonline
+
+The default is "offline" which means the newly added memory will not be at
+ready-to-use state and you have to "online" the newly added memory blocks
+manually.
+
+Automatic onlining can be requested by writing "online" to "hotplug_autoonline"
+file:
+
+% echo online > /sys/devices/system/memory/hotplug_autoonline
+
+If the automatic onlining wasn't requested or some memory block was offlined
+it is possible to change the individual block's state by writing to the "state"
+file:
 
 % echo online > /sys/devices/system/memory/memoryXXX/state
 
drivers/base/memory.c +35 -0
index 25425d3..001fefe 100644
@@ -438,6 +438,40 @@ print_block_size(struct device *dev, struct device_attribute *attr,
 
 static DEVICE_ATTR(block_size_bytes, 0444, print_block_size, NULL);
 
+
+/*
+ * Memory auto online policy.
+ */
+
+static ssize_t
+show_memhp_autoonline(struct device *dev, struct device_attribute *attr,
+		      char *buf)
+{
+	if (memhp_autoonline == MMOP_ONLINE_KEEP)
+		return sprintf(buf, "online\n");
+	else if (memhp_autoonline == MMOP_OFFLINE)
+		return sprintf(buf, "offline\n");
+	else
+		return sprintf(buf, "unknown\n");
+}
+
+static ssize_t
+store_memhp_autoonline(struct device *dev, struct device_attribute *attr,
+		       const char *buf, size_t count)
+{
+	if (sysfs_streq(buf, "online"))
+		memhp_autoonline = MMOP_ONLINE_KEEP;
+	else if (sysfs_streq(buf, "offline"))
+		memhp_autoonline = MMOP_OFFLINE;
+	else
+		return -EINVAL;
+
+	return count;
+}
+
+static DEVICE_ATTR(hotplug_autoonline, 0644, show_memhp_autoonline,
+		   store_memhp_autoonline);
+
 /*
  * Some architectures will have custom drivers to do this, and
  * will not need to do it from userspace.  The fake hot-add code
@@ -737,6 +771,7 @@ static struct attribute *memory_root_attrs[] = {
 #endif
 
 	&dev_attr_block_size_bytes.attr,
+	&dev_attr_hotplug_autoonline.attr,
 	NULL
 };
 
include/linux/memory_hotplug.h +2 -0
index 2ea574f..fb64eea 100644
@@ -99,6 +99,8 @@ extern void __online_page_free(struct page *page);
 
 extern int try_online_node(int nid);
 
+extern int memhp_autoonline;
+
 #ifdef CONFIG_MEMORY_HOTREMOVE
 extern bool is_pageblock_removable_nolock(struct page *page);
 extern int arch_remove_memory(u64 start, u64 size);
mm/memory_hotplug.c +8 -0
index 67d488a..37a190e 100644
@@ -76,6 +76,9 @@ static struct {
 #define memhp_lock_acquire()      lock_map_acquire(&mem_hotplug.dep_map)
 #define memhp_lock_release()      lock_map_release(&mem_hotplug.dep_map)
 
+int memhp_autoonline = MMOP_OFFLINE;
+EXPORT_SYMBOL_GPL(memhp_autoonline);
+
 void get_online_mems(void)
 {
 	might_sleep();
@@ -1292,6 +1295,11 @@ int __ref add_memory_resource(int nid, struct resource *res)
 	/* create new memmap entry */
 	firmware_map_add_hotplug(start, start + size, "System RAM");
 
+	/* online the region if it is requested by current policy */
+	if (memhp_autoonline != MMOP_OFFLINE)
+		online_pages(start >> PAGE_SHIFT, size >> PAGE_SHIFT,
+			     memhp_autoonline);
+
 	goto out;
 
 error:
Signature · 7 lines
2.4.3

--
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>
#1 lore raw

Hey Vitaly,

Quoted 12 lines · Vitaly Kuznetsov

Currently, all newly added memory blocks remain in 'offline' state unless someone onlines them, some linux distributions carry special udev rules like:

SUBSYSTEM=="memory", ACTION=="add", ATTR{state}=="offline", ATTR{state}="online"

to make this happen automatically. This is not a great solution for virtual machines where memory hotplug is being used to address high memory pressure situations as such onlining is slow and a userspace process doing this (udev) has a chance of being killed by the OOM killer as it will probably require to allocate some memory.

Quoted 5 lines

Introduce default policy for the newly added memory blocks in /sys/devices/system/memory/hotplug_autoonline file with two possible
values: "offline" (the default) which preserves the current behavior and "online" which causes all newly added memory blocks to go online as soon as they're added.

In general idea make sense for me but...

Quoted 74 lines
Cc Jonathan Corbet <[email protected]>
Cc Greg Kroah-Hartman <[email protected]>
Cc Daniel Kiper <[email protected]>
Cc Dan Williams <[email protected]>
Cc Tang Chen <[email protected]>
Cc David Vrabel <[email protected]>
Cc David Rientjes <[email protected]>
Cc Andrew Morton <[email protected]>
Cc Naoya Horiguchi <[email protected]>
Cc Gu Zheng <[email protected]>
Cc Xishi Qiu <[email protected]>
Cc Mel Gorman <[email protected]>
Cc "K. Y. Srinivasan" <[email protected]>

---
- I was able to find previous attempts to fix the issue, e.g.:
http://marc.info/?l=linux-kernel&m=137425951924598&w=2
http://marc.info/?l=linux-acpi&m=127186488905382
but I'm not completely sure why it didn't work out and the solution I suggest is not 'smart enough', thus 'RFC'.

---
 Documentation/memory-hotplug.txt | 21 +++++++++++++++++----
 drivers/base/memory.c            | 35 +++++++++++++++++++++++++++++++++++
 include/linux/memory_hotplug.h   |  2 ++
 mm/memory_hotplug.c              |  8 ++++++++
 4 files changed, 62 insertions(+), 4 deletions(-)
Documentation/memory-hotplug.txt +17 -4
index ce2cfcf..fe576d9 100644
@@ -254,12 +254,25 @@ If the memory block is online, you'll read "online".
 If the memory block is offline, you'll read "offline".
 
 
-5.2. How to online memory
+5.2. Memory onlining
 ------------
-Even if the memory is hot-added, it is not at ready-to-use state.
-For using newly added memory, you have to "online" the memory block.
+When the memory is hot-added, the kernel decides whether or not to "online"
+it according to the policy which can be read from "hotplug_autoonline" file:
 
-For onlining, you have to write "online" to the memory block's state file as:
+% cat /sys/devices/system/memory/hotplug_autoonline
+
+The default is "offline" which means the newly added memory will not be at
+ready-to-use state and you have to "online" the newly added memory blocks
+manually.
+
+Automatic onlining can be requested by writing "online" to "hotplug_autoonline"
+file:
+
+% echo online > /sys/devices/system/memory/hotplug_autoonline
+
+If the automatic onlining wasn't requested or some memory block was offlined
+it is possible to change the individual block's state by writing to the "state"
+file:
 
 % echo online > /sys/devices/system/memory/memoryXXX/state
 
drivers/base/memory.c +5 -0
index 25425d3..001fefe 100644
@@ -438,6 +438,40 @@ print_block_size(struct device *dev, struct device_attribute *attr,
 
 static DEVICE_ATTR(block_size_bytes, 0444, print_block_size, NULL);
 
+
+/*
+ * Memory auto online policy.
+ */
+

drivers/base/memory.c print_block_size(struct device *dev, struct device_attribute *attr, · line 455

Quoted 10 lines
drivers/base/memory.c +10 -0
+static ssize_t
+show_memhp_autoonline(struct device *dev, struct device_attribute *attr,
+		      char *buf)
+{
+	if (memhp_autoonline == MMOP_ONLINE_KEEP)
+		return sprintf(buf, "online\n");
+	else if (memhp_autoonline == MMOP_OFFLINE)
+		return sprintf(buf, "offline\n");
+	else
+		return sprintf(buf, "unknown\n");

You do not allow unknown state below, so, I do not know how it can appear here. If it appears out of the blue then I think that we should be alert because something magic happens around us. Hence, if you wish to leave this unknown stuff then I suppose we should at least call WARN_ON() if not BUG_ON() there too (well, I am not convinced about latter).

drivers/base/memory.c print_block_size(struct device *dev, struct device_attribute *attr, · line 467

Quoted 12 lines
drivers/base/memory.c +12 -0
+}
+
+static ssize_t
+store_memhp_autoonline(struct device *dev, struct device_attribute *attr,
+		       const char *buf, size_t count)
+{
+	if (sysfs_streq(buf, "online"))
+		memhp_autoonline = MMOP_ONLINE_KEEP;
+	else if (sysfs_streq(buf, "offline"))
+		memhp_autoonline = MMOP_OFFLINE;
+	else
+		return -EINVAL;

Here you are not able to set anything which is not allowed. So, please look above.

Daniel

--
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>

#3 lore raw
In reply to Vitaly Kuznetsov
Quoted 32 lines · Vitaly Kuznetsov

Currently, all newly added memory blocks remain in 'offline' state unless someone onlines them, some linux distributions carry special udev rules like:

SUBSYSTEM=="memory", ACTION=="add", ATTR{state}=="offline", ATTR{state}="online"

to make this happen automatically. This is not a great solution for virtual machines where memory hotplug is being used to address high memory pressure situations as such onlining is slow and a userspace process doing this (udev) has a chance of being killed by the OOM killer as it will probably require to allocate some memory.

Introduce default policy for the newly added memory blocks in /sys/devices/system/memory/hotplug_autoonline file with two possible
values: "offline" (the default) which preserves the current behavior and "online" which causes all newly added memory blocks to go online as soon as they're added.

Cc Jonathan Corbet <[email protected]>
Cc Greg Kroah-Hartman <[email protected]>
Cc Daniel Kiper <[email protected]>
Cc Dan Williams <[email protected]>
Cc Tang Chen <[email protected]>
Cc David Vrabel <[email protected]>
Cc David Rientjes <[email protected]>
Cc Andrew Morton <[email protected]>
Cc Naoya Horiguchi <[email protected]>
Cc Gu Zheng <[email protected]>
Cc Xishi Qiu <[email protected]>
Cc Mel Gorman <[email protected]>
Cc "K. Y. Srinivasan" <[email protected]>
Quoted 6 lines

---
- I was able to find previous attempts to fix the issue, e.g.:
http://marc.info/?l=linux-kernel&m=137425951924598&w=2
http://marc.info/?l=linux-acpi&m=127186488905382
but I'm not completely sure why it didn't work out and the solution I suggest is not 'smart enough', thus 'RFC'.

+ CC:
[email protected]
[email protected]

Hi Vitaly,

Why not use udev rule? I think it can online pages automatically.

Thanks,
Xishi Qiu

--
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>

#4 lore raw
Quoted 41 lines · Xishi Qiu
Quoted 32 lines · Vitaly Kuznetsov

Currently, all newly added memory blocks remain in 'offline' state unless someone onlines them, some linux distributions carry special udev rules like:

SUBSYSTEM=="memory", ACTION=="add", ATTR{state}=="offline", ATTR{state}="online"

to make this happen automatically. This is not a great solution for virtual machines where memory hotplug is being used to address high memory pressure situations as such onlining is slow and a userspace process doing this (udev) has a chance of being killed by the OOM killer as it will probably require to allocate some memory.

Introduce default policy for the newly added memory blocks in /sys/devices/system/memory/hotplug_autoonline file with two possible
values: "offline" (the default) which preserves the current behavior and "online" which causes all newly added memory blocks to go online as soon as they're added.

Cc Jonathan Corbet <[email protected]>
Cc Greg Kroah-Hartman <[email protected]>
Cc Daniel Kiper <[email protected]>
Cc Dan Williams <[email protected]>
Cc Tang Chen <[email protected]>
Cc David Vrabel <[email protected]>
Cc David Rientjes <[email protected]>
Cc Andrew Morton <[email protected]>
Cc Naoya Horiguchi <[email protected]>
Cc Gu Zheng <[email protected]>
Cc Xishi Qiu <[email protected]>
Cc Mel Gorman <[email protected]>
Cc "K. Y. Srinivasan" <[email protected]>
Quoted 6 lines

---
- I was able to find previous attempts to fix the issue, e.g.:
http://marc.info/?l=linux-kernel&m=137425951924598&w=2
http://marc.info/?l=linux-acpi&m=127186488905382
but I'm not completely sure why it didn't work out and the solution I suggest is not 'smart enough', thus 'RFC'.

Quoted 8 lines

+ CC:
[email protected]
[email protected]

Hi Vitaly,

Why not use udev rule? I think it can online pages automatically.

Two main reasons:
1) I remember someone saying "You never need a mouse in order to add another mouse to the kernel" -- but we we need memory to add more memory. Udev has a chance of being killed by the OOM killer as performing an action will probably require to allocate some memory. Other than that udev actions are generally slow compared to what we can do in kernel.

2) I agree with Kay that '... unconditional hotplug loop through userspace is absolutely pointless' (https://lkml.org/lkml/2013/7/25/354).
(... and I should had add him to CC, adding now). Udev maintainers refused to add a rule for unconditional memory onlining to udev and now linux distros have to carry such custom rules.

Signature · 7 lines
  Vitaly

--
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>
#2 lore raw
In reply to Daniel Kiper
Quoted 105 lines · Daniel Kiper

Hey Vitaly,

Quoted 12 lines · Vitaly Kuznetsov

Currently, all newly added memory blocks remain in 'offline' state unless someone onlines them, some linux distributions carry special udev rules like:

SUBSYSTEM=="memory", ACTION=="add", ATTR{state}=="offline", ATTR{state}="online"

to make this happen automatically. This is not a great solution for virtual machines where memory hotplug is being used to address high memory pressure situations as such onlining is slow and a userspace process doing this (udev) has a chance of being killed by the OOM killer as it will probably require to allocate some memory.

Quoted 5 lines

Introduce default policy for the newly added memory blocks in /sys/devices/system/memory/hotplug_autoonline file with two possible
values: "offline" (the default) which preserves the current behavior and "online" which causes all newly added memory blocks to go online as soon as they're added.

In general idea make sense for me but...

Quoted 82 lines
Cc Jonathan Corbet <[email protected]>
Cc Greg Kroah-Hartman <[email protected]>
Cc Daniel Kiper <[email protected]>
Cc Dan Williams <[email protected]>
Cc Tang Chen <[email protected]>
Cc David Vrabel <[email protected]>
Cc David Rientjes <[email protected]>
Cc Andrew Morton <[email protected]>
Cc Naoya Horiguchi <[email protected]>
Cc Gu Zheng <[email protected]>
Cc Xishi Qiu <[email protected]>
Cc Mel Gorman <[email protected]>
Cc "K. Y. Srinivasan" <[email protected]>

---
- I was able to find previous attempts to fix the issue, e.g.:
http://marc.info/?l=linux-kernel&m=137425951924598&w=2
http://marc.info/?l=linux-acpi&m=127186488905382
but I'm not completely sure why it didn't work out and the solution I suggest is not 'smart enough', thus 'RFC'.

---
 Documentation/memory-hotplug.txt | 21 +++++++++++++++++----
 drivers/base/memory.c            | 35 +++++++++++++++++++++++++++++++++++
 include/linux/memory_hotplug.h   |  2 ++
 mm/memory_hotplug.c              |  8 ++++++++
 4 files changed, 62 insertions(+), 4 deletions(-)
Documentation/memory-hotplug.txt +17 -4
index ce2cfcf..fe576d9 100644
@@ -254,12 +254,25 @@ If the memory block is online, you'll read "online".
 If the memory block is offline, you'll read "offline".
 
 
-5.2. How to online memory
+5.2. Memory onlining
 ------------
-Even if the memory is hot-added, it is not at ready-to-use state.
-For using newly added memory, you have to "online" the memory block.
+When the memory is hot-added, the kernel decides whether or not to "online"
+it according to the policy which can be read from "hotplug_autoonline" file:
 
-For onlining, you have to write "online" to the memory block's state file as:
+% cat /sys/devices/system/memory/hotplug_autoonline
+
+The default is "offline" which means the newly added memory will not be at
+ready-to-use state and you have to "online" the newly added memory blocks
+manually.
+
+Automatic onlining can be requested by writing "online" to "hotplug_autoonline"
+file:
+
+% echo online > /sys/devices/system/memory/hotplug_autoonline
+
+If the automatic onlining wasn't requested or some memory block was offlined
+it is possible to change the individual block's state by writing to the "state"
+file:
 
 % echo online > /sys/devices/system/memory/memoryXXX/state
 
drivers/base/memory.c +13 -0
index 25425d3..001fefe 100644
@@ -438,6 +438,40 @@ print_block_size(struct device *dev, struct device_attribute *attr,
 
 static DEVICE_ATTR(block_size_bytes, 0444, print_block_size, NULL);
 
+
+/*
+ * Memory auto online policy.
+ */
+
+static ssize_t
+show_memhp_autoonline(struct device *dev, struct device_attribute *attr,
+		      char *buf)
+{
+	if (memhp_autoonline == MMOP_ONLINE_KEEP)
+		return sprintf(buf, "online\n");
+	else if (memhp_autoonline == MMOP_OFFLINE)
+		return sprintf(buf, "offline\n");
Quoted 9 lines

drivers/base/memory.c print_block_size(struct device *dev, struct device_attribute *attr, · line 455

Quoted 2 lines
drivers/base/memory.c +2 -0
+	else
+		return sprintf(buf, "unknown\n");

You do not allow unknown state below, so, I do not know how it can appear here. If it appears out of the blue then I think that we should be alert because something magic happens around us. Hence, if you wish to leave this unknown stuff then I suppose we should at least call WARN_ON() if not BUG_ON() there too (well, I am not convinced about latter).

Sure,

it is definitelly impossible to see 'unknown' with the current code. The one (small) reason I added it is that there are two more possible values for /sys/devices/system/memory/memoryXXX/state: online_movable and online_kernel. While I don't see how 'online_kernel' can be used for automatic hotplug (all new memory blocks are being added to ZONE_NORMAL) 'online_movable' could (in theory) be used here so all new memroy blocks will go to ZONE_MOVABLE. To achieve that someone could set memhp_autoonline to MMOP_ONLINE_MOVABLE and it will (in theory) work but I didn't want to add such option to the /sys/devices/system/memory/hotplug_autoonline interface without a reason.

I can of course remove this (or replace with WARN_ON) for now.

Thanks,

Quoted 17 lines

drivers/base/memory.c print_block_size(struct device *dev, struct device_attribute *attr, · line 467

Quoted 12 lines
drivers/base/memory.c +12 -0
+}
+
+static ssize_t
+store_memhp_autoonline(struct device *dev, struct device_attribute *attr,
+		       const char *buf, size_t count)
+{
+	if (sysfs_streq(buf, "online"))
+		memhp_autoonline = MMOP_ONLINE_KEEP;
+	else if (sysfs_streq(buf, "offline"))
+		memhp_autoonline = MMOP_OFFLINE;
+	else
+		return -EINVAL;

Here you are not able to set anything which is not allowed. So, please look above.

Daniel

Signature · 7 lines
  Vitaly

--
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>
#5 lore raw
In reply to Vitaly Kuznetsov
Quoted 52 lines · Vitaly Kuznetsov
Quoted 41 lines · Xishi Qiu
Quoted 32 lines · Vitaly Kuznetsov

Currently, all newly added memory blocks remain in 'offline' state unless someone onlines them, some linux distributions carry special udev rules like:

SUBSYSTEM=="memory", ACTION=="add", ATTR{state}=="offline", ATTR{state}="online"

to make this happen automatically. This is not a great solution for virtual machines where memory hotplug is being used to address high memory pressure situations as such onlining is slow and a userspace process doing this (udev) has a chance of being killed by the OOM killer as it will probably require to allocate some memory.

Introduce default policy for the newly added memory blocks in /sys/devices/system/memory/hotplug_autoonline file with two possible
values: "offline" (the default) which preserves the current behavior and "online" which causes all newly added memory blocks to go online as soon as they're added.

Cc Jonathan Corbet <[email protected]>
Cc Greg Kroah-Hartman <[email protected]>
Cc Daniel Kiper <[email protected]>
Cc Dan Williams <[email protected]>
Cc Tang Chen <[email protected]>
Cc David Vrabel <[email protected]>
Cc David Rientjes <[email protected]>
Cc Andrew Morton <[email protected]>
Cc Naoya Horiguchi <[email protected]>
Cc Gu Zheng <[email protected]>
Cc Xishi Qiu <[email protected]>
Cc Mel Gorman <[email protected]>
Cc "K. Y. Srinivasan" <[email protected]>
Quoted 6 lines

---
- I was able to find previous attempts to fix the issue, e.g.:
http://marc.info/?l=linux-kernel&m=137425951924598&w=2
http://marc.info/?l=linux-acpi&m=127186488905382
but I'm not completely sure why it didn't work out and the solution I suggest is not 'smart enough', thus 'RFC'.

Quoted 8 lines

+ CC:
[email protected]
[email protected]

Hi Vitaly,

Why not use udev rule? I think it can online pages automatically.

Quoted 7 lines

Two main reasons:
1) I remember someone saying "You never need a mouse in order to add another mouse to the kernel" -- but we we need memory to add more memory. Udev has a chance of being killed by the OOM killer as performing an action will probably require to allocate some memory. Other than that udev actions are generally slow compared to what we can do in kernel.

Hi Vitaly,

So why we add memory when there is almost no free memory left? I think the administrator should add memory when the free memory is low or he should do something to stop free memory become worse.

Quoted 7 lines

2) I agree with Kay that '... unconditional hotplug loop through userspace is absolutely pointless' (https://lkml.org/lkml/2013/7/25/354).
(... and I should had add him to CC, adding now). Udev maintainers refused to add a rule for unconditional memory onlining to udev and now linux distros have to carry such custom rules.

If the administrator don't know how to config the udev, he could use sysfs (echo 1 > /sys/devices/system/node/nodeXX/memoryXX/online) to online it, or write a script to do this.

Thanks,
Xishi Qiu

--
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>

#6 lore raw
Quoted 62 lines · Xishi Qiu
Quoted 52 lines · Vitaly Kuznetsov
Quoted 41 lines · Xishi Qiu
Quoted 32 lines · Vitaly Kuznetsov

Currently, all newly added memory blocks remain in 'offline' state unless someone onlines them, some linux distributions carry special udev rules like:

SUBSYSTEM=="memory", ACTION=="add", ATTR{state}=="offline", ATTR{state}="online"

to make this happen automatically. This is not a great solution for virtual machines where memory hotplug is being used to address high memory pressure situations as such onlining is slow and a userspace process doing this (udev) has a chance of being killed by the OOM killer as it will probably require to allocate some memory.

Introduce default policy for the newly added memory blocks in /sys/devices/system/memory/hotplug_autoonline file with two possible
values: "offline" (the default) which preserves the current behavior and "online" which causes all newly added memory blocks to go online as soon as they're added.

Cc Jonathan Corbet <[email protected]>
Cc Greg Kroah-Hartman <[email protected]>
Cc Daniel Kiper <[email protected]>
Cc Dan Williams <[email protected]>
Cc Tang Chen <[email protected]>
Cc David Vrabel <[email protected]>
Cc David Rientjes <[email protected]>
Cc Andrew Morton <[email protected]>
Cc Naoya Horiguchi <[email protected]>
Cc Gu Zheng <[email protected]>
Cc Xishi Qiu <[email protected]>
Cc Mel Gorman <[email protected]>
Cc "K. Y. Srinivasan" <[email protected]>
Quoted 6 lines

---
- I was able to find previous attempts to fix the issue, e.g.:
http://marc.info/?l=linux-kernel&m=137425951924598&w=2
http://marc.info/?l=linux-acpi&m=127186488905382
but I'm not completely sure why it didn't work out and the solution I suggest is not 'smart enough', thus 'RFC'.

Quoted 8 lines

+ CC:
[email protected]
[email protected]

Hi Vitaly,

Why not use udev rule? I think it can online pages automatically.

Quoted 7 lines

Two main reasons:
1) I remember someone saying "You never need a mouse in order to add another mouse to the kernel" -- but we we need memory to add more memory. Udev has a chance of being killed by the OOM killer as performing an action will probably require to allocate some memory. Other than that udev actions are generally slow compared to what we can do in kernel.

Quoted 5 lines

Hi Vitaly,

So why we add memory when there is almost no free memory left? I think the administrator should add memory when the free memory is low or he should do something to stop free memory become worse.

I have virtual machines use-case in my mind where hypervisor adds new memory on high memory pressure reports from the guest (e.g. Hyper-V behaves like that). This is an automatic action.

Quoted 9 lines
Quoted 8 lines

2) I agree with Kay that '... unconditional hotplug loop through userspace is absolutely pointless' (https://lkml.org/lkml/2013/7/25/354).
(... and I should had add him to CC, adding now). Udev maintainers refused to add a rule for unconditional memory onlining to udev and now linux distros have to carry such custom rules.

Quoted 3 lines

If the administrator don't know how to config the udev, he could use sysfs (echo 1 > /sys/devices/system/node/nodeXX/memoryXX/online) to online it, or write a script to do this.

Oh, no, I'm not taking about manual actions here. My suggestion doesn't eliminate this possibility and it doesn't even change the default -- memory blocks stay in 'offline' state unless someone requests the auto-online policy.

Signature · 7 lines
  Vitaly

--
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>