Skip to contentSkip to conversation

hotplug, memory: move register_memory_resource out of the lock_memory_hotplug

RFC In review Nathan Zimmer 4 participants 6 messages Jan 14, 2014 – Jan 15, 2014

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

RFC 1/1 hotplug, memory: move register_memory_resource out of the lock_memory_hotplug

We don't need to do register_memory_resource() since it has its own lock and doesn't make any callbacks.

Also register_memory_resource return NULL on failure so we don't have anything to cleanup at this point.

The reason for this rfc is I was doing some experiments with hotplugging of memory on some of our larger systems. While it seems to work, it can be quite slow. With some preliminary digging I found that lock_memory_hotplug is clearly ripe for breakup.

It could be broken up per nid or something but it also covers the online_page_callback. The online_page_callback shouldn't be very hard to break out.

Also there is the issue of various structures(wmarks come to mind) that are only updated under the lock_memory_hotplug that would need to be dealt with.

cc Andrew Morton <[email protected]>
cc Tang Chen <[email protected]>
cc Wen Congyang <[email protected]>
cc Kamezawa Hiroyuki <[email protected]>
cc Yasuaki Ishimatsu <[email protected]>
cc "Rafael J. Wysocki" <[email protected]>
cc Mike Travis <[email protected]>
---
 mm/memory_hotplug.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
mm/memory_hotplug.c +4 -3
index 1ad92b4..62a0cd1 100644
@@ -1097,17 +1097,18 @@ int __ref add_memory(int nid, u64 start, u64 size)
 	struct resource *res;
 	int ret;
 
-	lock_memory_hotplug();
-
 	res = register_memory_resource(start, size);
 	ret = -EEXIST;
 	if (!res)
-		goto out;
+		return ret;
 
 	{	/* Stupid hack to suppress address-never-null warning */
 		void *p = NODE_DATA(nid);
 		new_pgdat = !p;
 	}
+
+	lock_memory_hotplug();
+
 	new_node = !node_online(nid);
 	if (new_node) {
 		pgdat = hotadd_new_pgdat(nid, start);
Signature · 7 lines
1.8.2.1

--
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>
maintainer
#1 lore raw
Quoted 35 lines · On Tue, 14 Jan 2014 12:24:34 -0600 Nathan Zimmer <[email protected]> wrote:

We don't need to do register_memory_resource() since it has its own lock and doesn't make any callbacks.

Also register_memory_resource return NULL on failure so we don't have anything to cleanup at this point.

The reason for this rfc is I was doing some experiments with hotplugging of memory on some of our larger systems. While it seems to work, it can be quite slow. With some preliminary digging I found that lock_memory_hotplug is clearly ripe for breakup.

It could be broken up per nid or something but it also covers the online_page_callback. The online_page_callback shouldn't be very hard to break out.

Also there is the issue of various structures(wmarks come to mind) that are only updated under the lock_memory_hotplug that would need to be dealt with.

...

mm/memory_hotplug.c +1 -3
@@ -1097,17 +1097,18 @@ int __ref add_memory(int nid, u64 start, u64 size)
 	struct resource *res;
 	int ret;
 
-	lock_memory_hotplug();
-
 	res = register_memory_resource(start, size);
 	ret = -EEXIST;
 	if (!res)
-		goto out;
+		return ret;
 

mm/memory_hotplug.c int __ref add_memory(int nid, u64 start, u64 size) · line 1114

Quoted 10 lines
mm/memory_hotplug.c +3 -0
 	{	/* Stupid hack to suppress address-never-null warning */
 		void *p = NODE_DATA(nid);
 		new_pgdat = !p;
 	}
+
+	lock_memory_hotplug();
+
 	new_node = !node_online(nid);
 	if (new_node) {
 		pgdat = hotadd_new_pgdat(nid, start);

Looks sane to me.

register_memory_resource() makes me cry. Please review:

From: Andrew Morton <[email protected]>
Subject: mm/memory_hotplug.c: register_memory_resource() fixes

- register_memory_resource() should not go BUG on ENOMEM. That's appropriate at system boot time, but not at memory-hotplug time. Fix.

- register_memory_resource()'s caller is incorrectly replacing request_resource()'s -EBUSY with -EEXIST. Fix this by propagating errors appropriately.

Cc "Rafael J. Wysocki" <[email protected]>
Cc Kamezawa Hiroyuki <[email protected]>
Cc Mike Travis <[email protected]>
Cc Nathan Zimmer <[email protected]>
Cc Tang Chen <[email protected]>
Cc Wen Congyang <[email protected]>
Cc Yasuaki Ishimatsu <[email protected]>

---

 mm/memory_hotplug.c |   15 +++++++++------
 1 file changed, 9 insertions(+), 6 deletions(-)
mm/memory_hotplug.c renamed from mm/memory_hotplug.c~mm-memory_hotplugc-register_memory_resource-fixes +9 -6
diff -puN mm/memory_hotplug.c~mm-memory_hotplugc-register_memory_resource-fixes mm/memory_hotplug.c
@@ -64,17 +64,21 @@ void unlock_memory_hotplug(void)
 static struct resource *register_memory_resource(u64 start, u64 size)
 {
 	struct resource *res;
+	int err;
+
 	res = kzalloc(sizeof(struct resource), GFP_KERNEL);
-	BUG_ON(!res);
+	if (!res)
+		return ERR_PTR(-ENOMEM);
 
 	res->name = "System RAM";
 	res->start = start;
 	res->end = start + size - 1;
 	res->flags = IORESOURCE_MEM | IORESOURCE_BUSY;
-	if (request_resource(&iomem_resource, res) < 0) {
+	err = request_resource(&iomem_resource, res);
+	if (err) {
 		pr_debug("System RAM resource %pR cannot be added\n", res);
 		kfree(res);
-		res = NULL;
+		res = ERR_PTR(err);
 	}
 	return res;
 }
@@ -1108,9 +1112,8 @@ int __ref add_memory(int nid, u64 start,
 		return ret;
 
 	res = register_memory_resource(start, size);
-	ret = -EEXIST;
-	if (!res)
-		return ret;
+	if (IS_ERR(res))
+		return PTR_ERR(res);
 
 	{	/* Stupid hack to suppress address-never-null warning */
 		void *p = NODE_DATA(nid);

_

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

Acked-by on v1 1/1
#4 lore raw
In reply to Nathan Zimmer
Quoted 3 lines · Nathan Zimmer

We don't need to do register_memory_resource() since it has its own lock and doesn't make any callbacks.

We need to do it, just not under lock_memory_hotplug() :).

Quoted 17 lines

Also register_memory_resource return NULL on failure so we don't have anything to cleanup at this point.

The reason for this rfc is I was doing some experiments with hotplugging of memory on some of our larger systems. While it seems to work, it can be quite slow. With some preliminary digging I found that lock_memory_hotplug is clearly ripe for breakup.

It could be broken up per nid or something but it also covers the online_page_callback. The online_page_callback shouldn't be very hard to break out.

Also there is the issue of various structures(wmarks come to mind) that are only updated under the lock_memory_hotplug that would need to be dealt with.

Quoted 10 lines
cc Andrew Morton <[email protected]>
cc Tang Chen <[email protected]>
cc Wen Congyang <[email protected]>
cc Kamezawa Hiroyuki <[email protected]>
cc Yasuaki Ishimatsu <[email protected]>
cc "Rafael J. Wysocki" <[email protected]>
cc Mike Travis <[email protected]>

Looks like you're modifying a pre-3.12 kernel version that doesn't have 27356f54c8c3 ("mm/hotplug: verify hotplug memory range").

When your patch is signed off, feel free to add

--
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 Andrew Morton
Quoted 10 lines · Andrew Morton

From: Andrew Morton <[email protected]>
Subject: mm/memory_hotplug.c: register_memory_resource() fixes

- register_memory_resource() should not go BUG on ENOMEM. That's appropriate at system boot time, but not at memory-hotplug time. Fix.

- register_memory_resource()'s caller is incorrectly replacing request_resource()'s -EBUSY with -EEXIST. Fix this by propagating errors appropriately.

Unfortunately, -EEXIST is a special case return value for both acpi_memory_enable_device() and hv_mem_hot_add(), so they would need to be modified to agree concurrently with this change.

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

Reviewed-by on v1 1/1
#5 lore raw
In reply to Nathan Zimmer
Quoted 32 lines · Nathan Zimmer

We don't need to do register_memory_resource() since it has its own lock and doesn't make any callbacks.

Also register_memory_resource return NULL on failure so we don't have anything to cleanup at this point.

The reason for this rfc is I was doing some experiments with hotplugging of memory on some of our larger systems. While it seems to work, it can be quite slow. With some preliminary digging I found that lock_memory_hotplug is clearly ripe for breakup.

It could be broken up per nid or something but it also covers the online_page_callback. The online_page_callback shouldn't be very hard to break out.

Also there is the issue of various structures(wmarks come to mind) that are only updated under the lock_memory_hotplug that would need to be dealt with.

cc Andrew Morton <[email protected]>
cc Tang Chen <[email protected]>
cc Wen Congyang <[email protected]>
cc Kamezawa Hiroyuki <[email protected]>
cc Yasuaki Ishimatsu <[email protected]>
cc "Rafael J. Wysocki" <[email protected]>
cc Mike Travis <[email protected]>
Quoted 1 line

---

The patch seems good to me.

Thanks,
Yasuaki Ishimatsu

Quoted 20 lines
  mm/memory_hotplug.c | 7 ++++---
  1 file changed, 4 insertions(+), 3 deletions(-)
mm/memory_hotplug.c +1 -3
index 1ad92b4..62a0cd1 100644
@@ -1097,17 +1097,18 @@ int __ref add_memory(int nid, u64 start, u64 size)
  	struct resource *res;
  	int ret;
 
-	lock_memory_hotplug();
-
  	res = register_memory_resource(start, size);
  	ret = -EEXIST;
  	if (!res)
-		goto out;
+		return ret;
 

mm/memory_hotplug.c int __ref add_memory(int nid, u64 start, u64 size) · line 1114

Quoted 10 lines
mm/memory_hotplug.c +3 -0
  	{	/* Stupid hack to suppress address-never-null warning */
  		void *p = NODE_DATA(nid);
  		new_pgdat = !p;
  	}
+
+	lock_memory_hotplug();
+
  	new_node = !node_online(nid);
  	if (new_node) {
  		pgdat = hotadd_new_pgdat(nid, start);

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

maintainer
#3 lore raw
In reply to David Rientjes
Quoted 8 lines · On Tue, 14 Jan 2014 17:05:42 -0800 (PST) David Rientjes <[email protected]>…
Quoted 6 lines · Andrew Morton

From: Andrew Morton <[email protected]>
Subject: mm/memory_hotplug.c: register_memory_resource() fixes

- register_memory_resource() should not go BUG on ENOMEM. That's appropriate at system boot time, but not at memory-hotplug time. Fix.

Quoted 8 lines
Quoted 4 lines

- register_memory_resource()'s caller is incorrectly replacing request_resource()'s -EBUSY with -EEXIST. Fix this by propagating errors appropriately.

Unfortunately, -EEXIST is a special case return value for both acpi_memory_enable_device() and hv_mem_hot_add(), so they would need to be modified to agree concurrently with this change.

blah, OK, thanks, I'll drop it.

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