Skip to contentSkip to conversation

mm/memory_hotplug: selective merging of system ram resources

PATCH Superseded David Hildenbrand 6 participants 26 messages Sep 8, 2020 – Sep 15, 2020

Subsystems (16)
Memory management PowerPC ACPI s390 +12 more subsystems

v2 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

v2 cover mm/memory_hotplug: selective merging of system ram resources

Some add_memory*() users add memory in small, contiguous memory blocks. Examples include virtio-mem, hyper-v balloon, and the XEN balloon.

This can quickly result in a lot of memory resources, whereby the actual resource boundaries are not of interest (e.g., it might be relevant for DIMMs, exposed via /proc/iomem to user space). We really want to merge added resources in this scenario where possible.

Resources are effectively stored in a list-based tree. Having a lot of resources not only wastes memory, it also makes traversing that tree more expensive, and makes /proc/iomem explode in size (e.g., requiring kexec-tools to manually merge resources when creating a kdump header. The current kexec-tools resource count limit does not allow for more than ~100GB of memory with a memory block size of 128MB on x86-64).

Let's allow to selectively merge system ram resources by specifying a new flag for add_memory*(). Patch #5 contains a /proc/iomem example. Only tested with virtio-mem.

v1 -> v2:
- I had another look at v1 after vacation and didn't like it - it felt like a hack. So I want forward and added a proper flag to add_memory*(), and introduce a clean (non-racy) way to mark System RAM resources mergeable.
- "kernel/resource: move and rename IORESOURCE_MEM_DRIVER_MANAGED" -- Clean that flag up, felt wrong in the PnP section
- "mm/memory_hotplug: prepare passing flags to add_memory() and friends" -- Previously sent in other context - decided to keep Wei's ack
- "mm/memory_hotplug: MEMHP_MERGE_RESOURCE to specify merging of System RAM resources"
-- Cleaner approach to get the job done by using proper flags and only
merging the single, specified resource
- "virtio-mem: try to merge system ram resources"
"xen/balloon: try to merge system ram resources"
"hv_balloon: try to merge system ram resources"
-- Use the new flag MEMHP_MERGE_RESOURCE, much cleaner

RFC -> v1:
- Switch from rather generic "merge_child_mem_resources()" where a resource name has to be specified to "merge_system_ram_resources().
- Smaller comment/documentation/patch description changes/fixes

David Hildenbrand (7):
kernel/resource: make release_mem_region_adjustable() never fail kernel/resource: move and rename IORESOURCE_MEM_DRIVER_MANAGED mm/memory_hotplug: prepare passing flags to add_memory() and friends mm/memory_hotplug: MEMHP_MERGE_RESOURCE to specify merging of System
RAM resources
virtio-mem: try to merge system ram resources xen/balloon: try to merge system ram resources
hv_balloon: try to merge system ram resources

 arch/powerpc/platforms/powernv/memtrace.c     |   2 +-
 .../platforms/pseries/hotplug-memory.c        |   2 +-
 drivers/acpi/acpi_memhotplug.c                |   2 +-
 drivers/base/memory.c                         |   2 +-
 drivers/dax/kmem.c                            |   2 +-
 drivers/hv/hv_balloon.c                       |   2 +-
 drivers/s390/char/sclp_cmd.c                  |   2 +-
 drivers/virtio/virtio_mem.c                   |   3 +-
 drivers/xen/balloon.c                         |   2 +-
 include/linux/ioport.h                        |  12 +-
 include/linux/memory_hotplug.h                |  19 ++-
 kernel/kexec_file.c                           |   2 +-
 kernel/resource.c                             | 109 ++++++++++++++----
 mm/memory_hotplug.c                           |  48 +++-----
 14 files changed, 141 insertions(+), 68 deletions(-)
Signature · 1 line
2.26.2
#1 lore raw

PATCH v2 1/7 kernel/resource: make release_mem_region_adjustable() never fail

Let's make sure splitting a resource on memory hotunplug will never fail. This will become more relevant once we merge selected System RAM resources - then, we'll trigger that case more often on memory hotunplug.

In general, this function is already unlikely to fail. When we remove memory, we free up quite a lot of metadata (memmap, page tables, memory block device, etc.). The only reason it could really fail would be when injecting allocation errors.

All other error cases inside release_mem_region_adjustable() seem to be sanity checks if the function would be abused in different context - let's add WARN_ON_ONCE() in these cases so we can catch them.

Cc Andrew Morton <[email protected]>
Cc Michal Hocko <[email protected]>
Cc Dan Williams <[email protected]>
Cc Jason Gunthorpe <[email protected]>
Cc Kees Cook <[email protected]>
Cc Ard Biesheuvel <[email protected]>
Cc Pankaj Gupta <[email protected]>
Cc Baoquan He <[email protected]>
Cc Wei Yang <[email protected]>
---
 include/linux/ioport.h |  4 ++--
 kernel/resource.c      | 49 ++++++++++++++++++++++++------------------
 mm/memory_hotplug.c    | 22 +------------------
 3 files changed, 31 insertions(+), 44 deletions(-)
include/linux/ioport.h +2 -2
index 6c2b06fe8beb7..52a91f5fa1a36 100644
@@ -248,8 +248,8 @@ extern struct resource * __request_region(struct resource *,
 extern void __release_region(struct resource *, resource_size_t,
 				resource_size_t);
 #ifdef CONFIG_MEMORY_HOTREMOVE
-extern int release_mem_region_adjustable(struct resource *, resource_size_t,
-				resource_size_t);
+extern void release_mem_region_adjustable(struct resource *, resource_size_t,
+					  resource_size_t);
 #endif
 
 /* Wrappers for managed devices */
kernel/resource.c +28 -21

92 lines not on this page · raw message

mm/memory_hotplug.c +1 -21
index baded53b9ff92..4c47b68a9f4b5 100644
@@ -1724,26 +1724,6 @@ void try_offline_node(int nid)
 }
 EXPORT_SYMBOL(try_offline_node);
 
-static void __release_memory_resource(resource_size_t start,
-				      resource_size_t size)
-{
-	int ret;
-
-	/*
-	 * When removing memory in the same granularity as it was added,
-	 * this function never fails. It might only fail if resources
-	 * have to be adjusted or split. We'll ignore the error, as
-	 * removing of memory cannot fail.
-	 */
-	ret = release_mem_region_adjustable(&iomem_resource, start, size);
-	if (ret) {
-		resource_size_t endres = start + size - 1;
-
-		pr_warn("Unable to release resource <%pa-%pa> (%d)\n",
-			&start, &endres, ret);
-	}
-}
-
 static int __ref try_remove_memory(int nid, u64 start, u64 size)
 {
 	int rc = 0;
@@ -1777,7 +1757,7 @@ static int __ref try_remove_memory(int nid, u64 start, u64 size)
 		memblock_remove(start, size);
 	}
 
-	__release_memory_resource(start, size);
+	release_mem_region_adjustable(&iomem_resource, start, size);
 
 	try_offline_node(nid);
 
Signature · 1 line
2.26.2
#8 lore raw

PATCH v2 2/7 kernel/resource: move and rename IORESOURCE_MEM_DRIVER_MANAGED

In reply to David Hildenbrand

IORESOURCE_MEM_DRIVER_MANAGED currently uses an unused PnP bit, which is always set to 0 by hardware. This is far from beautiful (and confusing), and the bit only applies to SYSRAM. So let's move it out of the bus-specific (PnP) defined bits.

We'll add another SYSRAM specific bit soon. If we ever need more bits for other purposes, we can steal some from "desc", or reshuffle/regroup what we have.

Cc Andrew Morton <[email protected]>
Cc Michal Hocko <[email protected]>
Cc Dan Williams <[email protected]>
Cc Jason Gunthorpe <[email protected]>
Cc Kees Cook <[email protected]>
Cc Ard Biesheuvel <[email protected]>
Cc Pankaj Gupta <[email protected]>
Cc Baoquan He <[email protected]>
Cc Wei Yang <[email protected]>
Cc Eric Biederman <[email protected]>
Cc Thomas Gleixner <[email protected]>
Cc Greg Kroah-Hartman <[email protected]>
---
 include/linux/ioport.h | 4 +++-
 kernel/kexec_file.c    | 2 +-
 mm/memory_hotplug.c    | 4 ++--
 3 files changed, 6 insertions(+), 4 deletions(-)
include/linux/ioport.h +3 -1
index 52a91f5fa1a36..d7620d7c941a0 100644
@@ -58,6 +58,9 @@ struct resource {
 #define IORESOURCE_EXT_TYPE_BITS 0x01000000	/* Resource extended types */
 #define IORESOURCE_SYSRAM	0x01000000	/* System RAM (modifier) */
 
+/* IORESOURCE_SYSRAM specific bits. */
+#define IORESOURCE_SYSRAM_DRIVER_MANAGED	0x02000000 /* Always detected via a driver. */
+
 #define IORESOURCE_EXCLUSIVE	0x08000000	/* Userland may not map this resource */
 
 #define IORESOURCE_DISABLED	0x10000000
@@ -103,7 +106,6 @@ struct resource {
 #define IORESOURCE_MEM_32BIT		(3<<3)
 #define IORESOURCE_MEM_SHADOWABLE	(1<<5)	/* dup: IORESOURCE_SHADOWABLE */
 #define IORESOURCE_MEM_EXPANSIONROM	(1<<6)
-#define IORESOURCE_MEM_DRIVER_MANAGED	(1<<7)
 
 /* PnP I/O specific bits (IORESOURCE_BITS) */
 #define IORESOURCE_IO_16BIT_ADDR	(1<<0)
kernel/kexec_file.c +1 -1
index ca40bef75a616..dfeeed1aed084 100644
@@ -520,7 +520,7 @@ static int locate_mem_hole_callback(struct resource *res, void *arg)
 	/* Returning 0 will take to next memory range */
 
 	/* Don't use memory that will be detected and handled by a driver. */
-	if (res->flags & IORESOURCE_MEM_DRIVER_MANAGED)
+	if (res->flags & IORESOURCE_SYSRAM_DRIVER_MANAGED)
 		return 0;
 
 	if (sz < kbuf->memsz)
mm/memory_hotplug.c +2 -2
index 4c47b68a9f4b5..8e1cd18b5cf14 100644
@@ -105,7 +105,7 @@ static struct resource *register_memory_resource(u64 start, u64 size,
 	unsigned long flags =  IORESOURCE_SYSTEM_RAM | IORESOURCE_BUSY;
 
 	if (strcmp(resource_name, "System RAM"))
-		flags |= IORESOURCE_MEM_DRIVER_MANAGED;
+		flags |= IORESOURCE_SYSRAM_DRIVER_MANAGED;
 
 	/*
 	 * Make sure value parsed from 'mem=' only restricts memory adding
@@ -1160,7 +1160,7 @@ EXPORT_SYMBOL_GPL(add_memory);
  *
  * For this memory, no entries in /sys/firmware/memmap ("raw firmware-provided
  * memory map") are created. Also, the created memory resource is flagged
- * with IORESOURCE_MEM_DRIVER_MANAGED, so in-kernel users can special-case
+ * with IORESOURCE_SYSRAM_DRIVER_MANAGED, so in-kernel users can special-case
  * this memory as well (esp., not place kexec images onto it).
  *
  * The resource_name (visible via /proc/iomem) has to have the format
Signature · 1 line
2.26.2
#13 lore raw

PATCH v2 3/7 mm/memory_hotplug: prepare passing flags to add_memory() and friends

In reply to David Hildenbrand

We soon want to pass flags, e.g., to mark added System RAM resources. mergeable. Prepare for that.

This patch is based on a similar patch by Oscar Salvador:

https://lkml.kernel.org/r/[email protected]

Cc Andrew Morton <[email protected]>
Cc Michal Hocko <[email protected]>
Cc Dan Williams <[email protected]>
Cc Jason Gunthorpe <[email protected]>
Cc Pankaj Gupta <[email protected]>
Cc Baoquan He <[email protected]>
Cc Wei Yang <[email protected]>
Cc Michael Ellerman <[email protected]>
Cc Benjamin Herrenschmidt <[email protected]>
Cc Paul Mackerras <[email protected]>
Cc "Rafael J. Wysocki" <[email protected]>
Cc Len Brown <[email protected]>
Cc Greg Kroah-Hartman <[email protected]>
Cc Vishal Verma <[email protected]>
Cc Dave Jiang <[email protected]>
Cc "K. Y. Srinivasan" <[email protected]>
Cc Haiyang Zhang <[email protected]>
Cc Stephen Hemminger <[email protected]>
Cc Wei Liu <[email protected]>
Cc Heiko Carstens <[email protected]>
Cc Vasily Gorbik <[email protected]>
Cc Christian Borntraeger <[email protected]>
Cc David Hildenbrand <[email protected]>
Cc "Michael S. Tsirkin" <[email protected]>
Cc Jason Wang <[email protected]>
Cc Boris Ostrovsky <[email protected]>
Cc Juergen Gross <[email protected]>
Cc Stefano Stabellini <[email protected]>
Cc "Oliver O'Halloran" <[email protected]>
Cc Pingfan Liu <[email protected]>
Cc Nathan Lynch <[email protected]>
Cc Libor Pechacek <[email protected]>
Cc Anton Blanchard <[email protected]>
Cc Leonardo Bras <[email protected]>
---
 arch/powerpc/platforms/powernv/memtrace.c       |  2 +-
 arch/powerpc/platforms/pseries/hotplug-memory.c |  2 +-
 drivers/acpi/acpi_memhotplug.c                  |  2 +-
 drivers/base/memory.c                           |  2 +-
 drivers/dax/kmem.c                              |  2 +-
 drivers/hv/hv_balloon.c                         |  2 +-
 drivers/s390/char/sclp_cmd.c                    |  2 +-
 drivers/virtio/virtio_mem.c                     |  2 +-
 drivers/xen/balloon.c                           |  2 +-
 include/linux/memory_hotplug.h                  | 10 ++++++----
 mm/memory_hotplug.c                             | 15 ++++++++-------
 11 files changed, 23 insertions(+), 20 deletions(-)
arch/powerpc/platforms/powernv/memtrace.c +1 -1
index 13b369d2cc454..a7475d18c671c 100644
@@ -224,7 +224,7 @@ static int memtrace_online(void)
 			ent->mem = 0;
 		}
 
-		if (add_memory(ent->nid, ent->start, ent->size)) {
+		if (add_memory(ent->nid, ent->start, ent->size, 0)) {
 			pr_err("Failed to add trace memory to node %d\n",
 				ent->nid);
 			ret += 1;
arch/powerpc/platforms/pseries/hotplug-memory.c +1 -1
index 5d545b78111f9..54a888ea7f751 100644
@@ -606,7 +606,7 @@ static int dlpar_add_lmb(struct drmem_lmb *lmb)
 	block_sz = memory_block_size_bytes();
 
 	/* Add the memory */
-	rc = __add_memory(lmb->nid, lmb->base_addr, block_sz);
+	rc = __add_memory(lmb->nid, lmb->base_addr, block_sz, 0);
 	if (rc) {
 		invalidate_lmb_associativity_index(lmb);
 		return rc;
drivers/acpi/acpi_memhotplug.c +1 -1
index e294f44a78504..d91b3584d4b2b 100644
@@ -207,7 +207,7 @@ static int acpi_memory_enable_device(struct acpi_memory_device *mem_device)
 		if (node < 0)
 			node = memory_add_physaddr_to_nid(info->start_addr);
 
-		result = __add_memory(node, info->start_addr, info->length);
+		result = __add_memory(node, info->start_addr, info->length, 0);
 
 		/*
 		 * If the memory block has been used by the kernel, add_memory()
drivers/base/memory.c +1 -1
index 4db3c660de831..2287bcf86480e 100644
@@ -432,7 +432,7 @@ static ssize_t probe_store(struct device *dev, struct device_attribute *attr,
 
 	nid = memory_add_physaddr_to_nid(phys_addr);
 	ret = __add_memory(nid, phys_addr,
-			   MIN_MEMORY_BLOCK_SIZE * sections_per_block);
+			   MIN_MEMORY_BLOCK_SIZE * sections_per_block, 0);
 
 	if (ret)
 		goto out;
drivers/dax/kmem.c +1 -1
index 7dcb2902e9b1b..8e66b28ef5bc6 100644
@@ -95,7 +95,7 @@ int dev_dax_kmem_probe(struct dev_dax *dev_dax)
 		 * this as RAM automatically.
 		 */
 		rc = add_memory_driver_managed(numa_node, range.start,
-				range_len(&range), kmem_name);
+				range_len(&range), kmem_name, 0);
 
 		res->flags |= IORESOURCE_BUSY;
 		if (rc) {
drivers/hv/hv_balloon.c +1 -1
index 32e3bc0aa665a..0194bed1a5736 100644
@@ -726,7 +726,7 @@ static void hv_mem_hot_add(unsigned long start, unsigned long size,
 
 		nid = memory_add_physaddr_to_nid(PFN_PHYS(start_pfn));
 		ret = add_memory(nid, PFN_PHYS((start_pfn)),
-				(HA_CHUNK << PAGE_SHIFT));
+				(HA_CHUNK << PAGE_SHIFT), 0);
 
 		if (ret) {
 			pr_err("hot_add memory failed error is %d\n", ret);
drivers/s390/char/sclp_cmd.c +1 -1
index a864b21af602a..a6a908244c742 100644
@@ -406,7 +406,7 @@ static void __init add_memory_merged(u16 rn)
 	if (!size)
 		goto skip_add;
 	for (addr = start; addr < start + size; addr += block_size)
-		add_memory(0, addr, block_size);
+		add_memory(0, addr, block_size, 0);
 skip_add:
 	first_rn = rn;
 	num = 1;
drivers/virtio/virtio_mem.c +1 -1
index 834b7c13ef3dc..314ab753139d1 100644
@@ -424,7 +424,7 @@ static int virtio_mem_mb_add(struct virtio_mem *vm, unsigned long mb_id)
 
 	dev_dbg(&vm->vdev->dev, "adding memory block: %lu\n", mb_id);
 	return add_memory_driver_managed(nid, addr, memory_block_size_bytes(),
-					 vm->resource_name);
+					 vm->resource_name, 0);
 }
 
 /*
drivers/xen/balloon.c +1 -1
index 51427c752b37b..7bac38764513d 100644
@@ -331,7 +331,7 @@ static enum bp_state reserve_additional_memory(void)
 	mutex_unlock(&balloon_mutex);
 	/* add_memory_resource() requires the device_hotplug lock */
 	lock_device_hotplug();
-	rc = add_memory_resource(nid, resource);
+	rc = add_memory_resource(nid, resource, 0);
 	unlock_device_hotplug();
 	mutex_lock(&balloon_mutex);
 
include/linux/memory_hotplug.h +6 -4
index 51a877fec8da8..5cd48332ce119 100644
@@ -345,11 +345,13 @@ extern void set_zone_contiguous(struct zone *zone);
 extern void clear_zone_contiguous(struct zone *zone);
 
 extern void __ref free_area_init_core_hotplug(int nid);
-extern int __add_memory(int nid, u64 start, u64 size);
-extern int add_memory(int nid, u64 start, u64 size);
-extern int add_memory_resource(int nid, struct resource *resource);
+extern int __add_memory(int nid, u64 start, u64 size, unsigned long flags);
+extern int add_memory(int nid, u64 start, u64 size, unsigned long flags);
+extern int add_memory_resource(int nid, struct resource *resource,
+			       unsigned long flags);
 extern int add_memory_driver_managed(int nid, u64 start, u64 size,
-				     const char *resource_name);
+				     const char *resource_name,
+				     unsigned long flags);
 extern void move_pfn_range_to_zone(struct zone *zone, unsigned long start_pfn,
 				   unsigned long nr_pages,
 				   struct vmem_altmap *altmap, int migratetype);
mm/memory_hotplug.c +8 -7
index 8e1cd18b5cf14..64b07f006bc10 100644
@@ -1039,7 +1039,8 @@ static int online_memory_block(struct memory_block *mem, void *arg)
  *
  * we are OK calling __meminit stuff here - we have CONFIG_MEMORY_HOTPLUG
  */
-int __ref add_memory_resource(int nid, struct resource *res)
+int __ref add_memory_resource(int nid, struct resource *res,
+			      unsigned long flags)
 {
 	struct mhp_params params = { .pgprot = PAGE_KERNEL };
 	u64 start, size;
@@ -1118,7 +1119,7 @@ int __ref add_memory_resource(int nid, struct resource *res)
 }
 
 /* requires device_hotplug_lock, see add_memory_resource() */
-int __ref __add_memory(int nid, u64 start, u64 size)
+int __ref __add_memory(int nid, u64 start, u64 size, unsigned long flags)
 {
 	struct resource *res;
 	int ret;
@@ -1127,18 +1128,18 @@ int __ref __add_memory(int nid, u64 start, u64 size)
 	if (IS_ERR(res))
 		return PTR_ERR(res);
 
-	ret = add_memory_resource(nid, res);
+	ret = add_memory_resource(nid, res, flags);
 	if (ret < 0)
 		release_memory_resource(res);
 	return ret;
 }
 
-int add_memory(int nid, u64 start, u64 size)
+int add_memory(int nid, u64 start, u64 size, unsigned long flags)
 {
 	int rc;
 
 	lock_device_hotplug();
-	rc = __add_memory(nid, start, size);
+	rc = __add_memory(nid, start, size, flags);
 	unlock_device_hotplug();
 
 	return rc;
@@ -1167,7 +1168,7 @@ EXPORT_SYMBOL_GPL(add_memory);
  * "System RAM ($DRIVER)".
  */
 int add_memory_driver_managed(int nid, u64 start, u64 size,
-			      const char *resource_name)
+			      const char *resource_name, unsigned long flags)
 {
 	struct resource *res;
 	int rc;
@@ -1185,7 +1186,7 @@ int add_memory_driver_managed(int nid, u64 start, u64 size,
 		goto out_unlock;
 	}
 
-	rc = add_memory_resource(nid, res);
+	rc = add_memory_resource(nid, res, flags);
 	if (rc < 0)
 		release_memory_resource(res);
 
Signature · 1 line
2.26.2
#20 lore raw

PATCH v2 4/7 mm/memory_hotplug: MEMHP_MERGE_RESOURCE to specify merging of System RAM resources

In reply to David Hildenbrand

Some add_memory*() users add memory in small, contiguous memory blocks. Examples include virtio-mem, hyper-v balloon, and the XEN balloon.

This can quickly result in a lot of memory resources, whereby the actual resource boundaries are not of interest (e.g., it might be relevant for DIMMs, exposed via /proc/iomem to user space). We really want to merge added resources in this scenario where possible.

Let's provide a flag (MEMHP_MERGE_RESOURCE) to specify that a resource either created within add_memory*() or passed via add_memory_resource() shall be marked mergeable and merged with applicable siblings.

To implement that, we need a kernel/resource interface to mark selected System RAM resources mergeable (IORESOURCE_SYSRAM_MERGEABLE) and trigger merging.

Note: We really want to merge after the whole operation succeeded, not directly when adding a resource to the resource tree (it would break add_memory_resource() and require splitting resources again when the operation failed - e.g., due to -ENOMEM).

Cc Andrew Morton <[email protected]>
Cc Michal Hocko <[email protected]>
Cc Dan Williams <[email protected]>
Cc Jason Gunthorpe <[email protected]>
Cc Kees Cook <[email protected]>
Cc Ard Biesheuvel <[email protected]>
Cc Thomas Gleixner <[email protected]>
Cc "K. Y. Srinivasan" <[email protected]>
Cc Haiyang Zhang <[email protected]>
Cc Stephen Hemminger <[email protected]>
Cc Wei Liu <[email protected]>
Cc Boris Ostrovsky <[email protected]>
Cc Juergen Gross <[email protected]>
Cc Stefano Stabellini <[email protected]>
Cc Roger Pau Monné <[email protected]>
Cc Julien Grall <[email protected]>
Cc Pankaj Gupta <[email protected]>
Cc Baoquan He <[email protected]>
Cc Wei Yang <[email protected]>
---
 include/linux/ioport.h         |  4 +++
 include/linux/memory_hotplug.h |  9 +++++
 kernel/resource.c              | 60 ++++++++++++++++++++++++++++++++++
 mm/memory_hotplug.c            |  7 ++++
 4 files changed, 80 insertions(+)
include/linux/ioport.h +4 -0
index d7620d7c941a0..7e61389dcb017 100644
@@ -60,6 +60,7 @@ struct resource {
 
 /* IORESOURCE_SYSRAM specific bits. */
 #define IORESOURCE_SYSRAM_DRIVER_MANAGED	0x02000000 /* Always detected via a driver. */
+#define IORESOURCE_SYSRAM_MERGEABLE		0x04000000 /* Resource can be merged. */
 
 #define IORESOURCE_EXCLUSIVE	0x08000000	/* Userland may not map this resource */
 
@@ -253,6 +254,9 @@ extern void __release_region(struct resource *, resource_size_t,
 extern void release_mem_region_adjustable(struct resource *, resource_size_t,
 					  resource_size_t);
 #endif
+#ifdef CONFIG_MEMORY_HOTPLUG
+extern void merge_system_ram_resource(struct resource *res);
+#endif
 
 /* Wrappers for managed devices */
 struct device;
include/linux/memory_hotplug.h +9 -0
index 5cd48332ce119..feb4aac03f2eb 100644
@@ -68,6 +68,15 @@ struct mhp_params {
 	pgprot_t pgprot;
 };
 
+/* Flags used for add_memory() and friends. */
+
+/*
+ * Allow merging of the added System RAM resource with adjacent, mergeable
+ * resources. After a successful call to add_memory_resource() with this flag
+ * set, the resource pointer must no longer be used as it might be stale.
+ */
+#define MEMHP_MERGE_RESOURCE		1
+
 /*
  * Zone resizing functions
  *
kernel/resource.c +60 -0

66 lines not on this page · raw message

mm/memory_hotplug.c +7 -0
index 64b07f006bc10..f62c2a46df8b1 100644
@@ -1103,6 +1103,13 @@ int __ref add_memory_resource(int nid, struct resource *res,
 	/* device_online() will take the lock when calling online_pages() */
 	mem_hotplug_done();
 
+	/*
+	 * In case we're allowed to merge the resource, flag it and trigger
+	 * merging now that adding succeeded.
+	 */
+	if (flags & MEMHP_MERGE_RESOURCE)
+		merge_system_ram_resource(res);
+
 	/* online pages if requested */
 	if (memhp_default_online_type != MMOP_OFFLINE)
 		walk_memory_blocks(start, size, NULL, online_memory_block);
Signature · 1 line
2.26.2
#21 lore raw

PATCH v2 5/7 virtio-mem: try to merge system ram resources

In reply to David Hildenbrand

virtio-mem adds memory in memory block granularity, to be able to remove it in the same granularity again later, and to grow slowly on demand. This, however, results in quite a lot of resources when adding a lot of memory. Resources are effectively stored in a list-based tree. Having a lot of resources not only wastes memory, it also makes traversing that tree more expensive, and makes /proc/iomem explode in size (e.g., requiring kexec-tools to manually merge resources later when e.g., trying to create a kdump header).

Before this patch, we get (/proc/iomem) when hotplugging 2G via virtio-mem on x86-64:

        [...]
        100000000-13fffffff : System RAM
        140000000-33fffffff : virtio0
          140000000-147ffffff : System RAM (virtio_mem)
          148000000-14fffffff : System RAM (virtio_mem)
          150000000-157ffffff : System RAM (virtio_mem)
          158000000-15fffffff : System RAM (virtio_mem)
          160000000-167ffffff : System RAM (virtio_mem)
          168000000-16fffffff : System RAM (virtio_mem)
          170000000-177ffffff : System RAM (virtio_mem)
          178000000-17fffffff : System RAM (virtio_mem)
          180000000-187ffffff : System RAM (virtio_mem)
          188000000-18fffffff : System RAM (virtio_mem)
          190000000-197ffffff : System RAM (virtio_mem)
          198000000-19fffffff : System RAM (virtio_mem)
          1a0000000-1a7ffffff : System RAM (virtio_mem)
          1a8000000-1afffffff : System RAM (virtio_mem)
          1b0000000-1b7ffffff : System RAM (virtio_mem)
          1b8000000-1bfffffff : System RAM (virtio_mem)
        3280000000-32ffffffff : PCI Bus 0000:00

With this patch, we get (/proc/iomem):

        [...]
        fffc0000-ffffffff : Reserved
        100000000-13fffffff : System RAM
        140000000-33fffffff : virtio0
          140000000-1bfffffff : System RAM (virtio_mem)
        3280000000-32ffffffff : PCI Bus 0000:00

Of course, with more hotplugged memory, it gets worse. When unplugging memory blocks again, try_remove_memory() (via offline_and_remove_memory()) will properly split the resource up again.

Cc Andrew Morton <[email protected]>
Cc Michal Hocko <[email protected]>
Cc Dan Williams <[email protected]>
Cc Michael S. Tsirkin <[email protected]>
Cc Jason Wang <[email protected]>
Cc Pankaj Gupta <[email protected]>
Cc Baoquan He <[email protected]>
Cc Wei Yang <[email protected]>
---
 drivers/virtio/virtio_mem.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/virtio/virtio_mem.c +2 -1
index 314ab753139d1..ba4de598f6636 100644
@@ -424,7 +424,8 @@ static int virtio_mem_mb_add(struct virtio_mem *vm, unsigned long mb_id)
 
 	dev_dbg(&vm->vdev->dev, "adding memory block: %lu\n", mb_id);
 	return add_memory_driver_managed(nid, addr, memory_block_size_bytes(),
-					 vm->resource_name, 0);
+					 vm->resource_name,
+					 MEMHP_MERGE_RESOURCE);
 }
 
 /*
Signature · 1 line
2.26.2
#22 lore raw

PATCH v2 6/7 xen/balloon: try to merge system ram resources

In reply to David Hildenbrand

Let's try to merge system ram resources we add, to minimize the number of resources in /proc/iomem. We don't care about the boundaries of individual chunks we added.

Cc Andrew Morton <[email protected]>
Cc Michal Hocko <[email protected]>
Cc Boris Ostrovsky <[email protected]>
Cc Juergen Gross <[email protected]>
Cc Stefano Stabellini <[email protected]>
Cc Roger Pau Monné <[email protected]>
Cc Julien Grall <[email protected]>
Cc Pankaj Gupta <[email protected]>
Cc Baoquan He <[email protected]>
Cc Wei Yang <[email protected]>
---
 drivers/xen/balloon.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/xen/balloon.c +1 -1
index 7bac38764513d..b57b2067ecbfb 100644
@@ -331,7 +331,7 @@ static enum bp_state reserve_additional_memory(void)
 	mutex_unlock(&balloon_mutex);
 	/* add_memory_resource() requires the device_hotplug lock */
 	lock_device_hotplug();
-	rc = add_memory_resource(nid, resource, 0);
+	rc = add_memory_resource(nid, resource, MEMHP_MERGE_RESOURCE);
 	unlock_device_hotplug();
 	mutex_lock(&balloon_mutex);
 
Signature · 1 line
2.26.2
#24 lore raw

PATCH v2 7/7 hv_balloon: try to merge system ram resources

In reply to David Hildenbrand

Let's try to merge system ram resources we add, to minimize the number of resources in /proc/iomem. We don't care about the boundaries of individual chunks we added.

Cc Andrew Morton <[email protected]>
Cc Michal Hocko <[email protected]>
Cc "K. Y. Srinivasan" <[email protected]>
Cc Haiyang Zhang <[email protected]>
Cc Stephen Hemminger <[email protected]>
Cc Wei Liu <[email protected]>
Cc Pankaj Gupta <[email protected]>
Cc Baoquan He <[email protected]>
Cc Wei Yang <[email protected]>
---
 drivers/hv/hv_balloon.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/hv/hv_balloon.c +1 -1
index 0194bed1a5736..b64d2efbefe71 100644
@@ -726,7 +726,7 @@ static void hv_mem_hot_add(unsigned long start, unsigned long size,
 
 		nid = memory_add_physaddr_to_nid(PFN_PHYS(start_pfn));
 		ret = add_memory(nid, PFN_PHYS((start_pfn)),
-				(HA_CHUNK << PAGE_SHIFT), 0);
+				(HA_CHUNK << PAGE_SHIFT), MEMHP_MERGE_RESOURCE);
 
 		if (ret) {
 			pr_err("hot_add memory failed error is %d\n", ret);
Signature · 1 line
2.26.2
maintainer Reviewed-by on v2 3/7
#14 lore raw

Re: [PATCH v2 3/7] mm/memory_hotplug: prepare passing flags to add_memory() and friends

In reply to David Hildenbrand
Quoted 42 lines · David Hildenbrand

We soon want to pass flags, e.g., to mark added System RAM resources. mergeable. Prepare for that.

This patch is based on a similar patch by Oscar Salvador:

https://lkml.kernel.org/r/[email protected]

Cc Andrew Morton <[email protected]>
Cc Michal Hocko <[email protected]>
Cc Dan Williams <[email protected]>
Cc Jason Gunthorpe <[email protected]>
Cc Pankaj Gupta <[email protected]>
Cc Baoquan He <[email protected]>
Cc Wei Yang <[email protected]>
Cc Michael Ellerman <[email protected]>
Cc Benjamin Herrenschmidt <[email protected]>
Cc Paul Mackerras <[email protected]>
Cc "Rafael J. Wysocki" <[email protected]>
Cc Len Brown <[email protected]>
Cc Greg Kroah-Hartman <[email protected]>
Cc Vishal Verma <[email protected]>
Cc Dave Jiang <[email protected]>
Cc "K. Y. Srinivasan" <[email protected]>
Cc Haiyang Zhang <[email protected]>
Cc Stephen Hemminger <[email protected]>
Cc Wei Liu <[email protected]>
Cc Heiko Carstens <[email protected]>
Cc Vasily Gorbik <[email protected]>
Cc Christian Borntraeger <[email protected]>
Cc David Hildenbrand <[email protected]>
Cc "Michael S. Tsirkin" <[email protected]>
Cc Jason Wang <[email protected]>
Cc Boris Ostrovsky <[email protected]>
Cc Juergen Gross <[email protected]>
Cc Stefano Stabellini <[email protected]>
Cc "Oliver O'Halloran" <[email protected]>
Cc Pingfan Liu <[email protected]>
Cc Nathan Lynch <[email protected]>
Cc Libor Pechacek <[email protected]>
Cc Anton Blanchard <[email protected]>
Cc Leonardo Bras <[email protected]>
Quoted 8 lines

Juergen

Quoted 217 lines
---
  arch/powerpc/platforms/powernv/memtrace.c       |  2 +-
  arch/powerpc/platforms/pseries/hotplug-memory.c |  2 +-
  drivers/acpi/acpi_memhotplug.c                  |  2 +-
  drivers/base/memory.c                           |  2 +-
  drivers/dax/kmem.c                              |  2 +-
  drivers/hv/hv_balloon.c                         |  2 +-
  drivers/s390/char/sclp_cmd.c                    |  2 +-
  drivers/virtio/virtio_mem.c                     |  2 +-
  drivers/xen/balloon.c                           |  2 +-
  include/linux/memory_hotplug.h                  | 10 ++++++----
  mm/memory_hotplug.c                             | 15 ++++++++-------
  11 files changed, 23 insertions(+), 20 deletions(-)
arch/powerpc/platforms/powernv/memtrace.c +1 -1
index 13b369d2cc454..a7475d18c671c 100644
@@ -224,7 +224,7 @@ static int memtrace_online(void)
  			ent->mem = 0;
  		}
 
-		if (add_memory(ent->nid, ent->start, ent->size)) {
+		if (add_memory(ent->nid, ent->start, ent->size, 0)) {
  			pr_err("Failed to add trace memory to node %d\n",
  				ent->nid);
  			ret += 1;
arch/powerpc/platforms/pseries/hotplug-memory.c +1 -1
index 5d545b78111f9..54a888ea7f751 100644
@@ -606,7 +606,7 @@ static int dlpar_add_lmb(struct drmem_lmb *lmb)
  	block_sz = memory_block_size_bytes();
 
  	/* Add the memory */
-	rc = __add_memory(lmb->nid, lmb->base_addr, block_sz);
+	rc = __add_memory(lmb->nid, lmb->base_addr, block_sz, 0);
  	if (rc) {
  		invalidate_lmb_associativity_index(lmb);
  		return rc;
drivers/acpi/acpi_memhotplug.c +1 -1
index e294f44a78504..d91b3584d4b2b 100644
@@ -207,7 +207,7 @@ static int acpi_memory_enable_device(struct acpi_memory_device *mem_device)
  		if (node < 0)
  			node = memory_add_physaddr_to_nid(info->start_addr);
 
-		result = __add_memory(node, info->start_addr, info->length);
+		result = __add_memory(node, info->start_addr, info->length, 0);
 
  		/*
  		 * If the memory block has been used by the kernel, add_memory()
drivers/base/memory.c +1 -1
index 4db3c660de831..2287bcf86480e 100644
@@ -432,7 +432,7 @@ static ssize_t probe_store(struct device *dev, struct device_attribute *attr,
 
  	nid = memory_add_physaddr_to_nid(phys_addr);
  	ret = __add_memory(nid, phys_addr,
-			   MIN_MEMORY_BLOCK_SIZE * sections_per_block);
+			   MIN_MEMORY_BLOCK_SIZE * sections_per_block, 0);
 
  	if (ret)
  		goto out;
drivers/dax/kmem.c +1 -1
index 7dcb2902e9b1b..8e66b28ef5bc6 100644
@@ -95,7 +95,7 @@ int dev_dax_kmem_probe(struct dev_dax *dev_dax)
  		 * this as RAM automatically.
  		 */
  		rc = add_memory_driver_managed(numa_node, range.start,
-				range_len(&range), kmem_name);
+				range_len(&range), kmem_name, 0);
 
  		res->flags |= IORESOURCE_BUSY;
  		if (rc) {
drivers/hv/hv_balloon.c +1 -1
index 32e3bc0aa665a..0194bed1a5736 100644
@@ -726,7 +726,7 @@ static void hv_mem_hot_add(unsigned long start, unsigned long size,
 
  		nid = memory_add_physaddr_to_nid(PFN_PHYS(start_pfn));
  		ret = add_memory(nid, PFN_PHYS((start_pfn)),
-				(HA_CHUNK << PAGE_SHIFT));
+				(HA_CHUNK << PAGE_SHIFT), 0);
 
  		if (ret) {
  			pr_err("hot_add memory failed error is %d\n", ret);
drivers/s390/char/sclp_cmd.c +1 -1
index a864b21af602a..a6a908244c742 100644
@@ -406,7 +406,7 @@ static void __init add_memory_merged(u16 rn)
  	if (!size)
  		goto skip_add;
  	for (addr = start; addr < start + size; addr += block_size)
-		add_memory(0, addr, block_size);
+		add_memory(0, addr, block_size, 0);
  skip_add:
  	first_rn = rn;
  	num = 1;
drivers/virtio/virtio_mem.c +1 -1
index 834b7c13ef3dc..314ab753139d1 100644
@@ -424,7 +424,7 @@ static int virtio_mem_mb_add(struct virtio_mem *vm, unsigned long mb_id)
 
  	dev_dbg(&vm->vdev->dev, "adding memory block: %lu\n", mb_id);
  	return add_memory_driver_managed(nid, addr, memory_block_size_bytes(),
-					 vm->resource_name);
+					 vm->resource_name, 0);
  }
 
  /*
drivers/xen/balloon.c +1 -1
index 51427c752b37b..7bac38764513d 100644
@@ -331,7 +331,7 @@ static enum bp_state reserve_additional_memory(void)
  	mutex_unlock(&balloon_mutex);
  	/* add_memory_resource() requires the device_hotplug lock */
  	lock_device_hotplug();
-	rc = add_memory_resource(nid, resource);
+	rc = add_memory_resource(nid, resource, 0);
  	unlock_device_hotplug();
  	mutex_lock(&balloon_mutex);
 
include/linux/memory_hotplug.h +6 -4
index 51a877fec8da8..5cd48332ce119 100644
@@ -345,11 +345,13 @@ extern void set_zone_contiguous(struct zone *zone);
  extern void clear_zone_contiguous(struct zone *zone);
 
  extern void __ref free_area_init_core_hotplug(int nid);
-extern int __add_memory(int nid, u64 start, u64 size);
-extern int add_memory(int nid, u64 start, u64 size);
-extern int add_memory_resource(int nid, struct resource *resource);
+extern int __add_memory(int nid, u64 start, u64 size, unsigned long flags);
+extern int add_memory(int nid, u64 start, u64 size, unsigned long flags);
+extern int add_memory_resource(int nid, struct resource *resource,
+			       unsigned long flags);
  extern int add_memory_driver_managed(int nid, u64 start, u64 size,
-				     const char *resource_name);
+				     const char *resource_name,
+				     unsigned long flags);
  extern void move_pfn_range_to_zone(struct zone *zone, unsigned long start_pfn,
  				   unsigned long nr_pages,
  				   struct vmem_altmap *altmap, int migratetype);
mm/memory_hotplug.c +8 -7
index 8e1cd18b5cf14..64b07f006bc10 100644
@@ -1039,7 +1039,8 @@ static int online_memory_block(struct memory_block *mem, void *arg)
   *
   * we are OK calling __meminit stuff here - we have CONFIG_MEMORY_HOTPLUG
   */
-int __ref add_memory_resource(int nid, struct resource *res)
+int __ref add_memory_resource(int nid, struct resource *res,
+			      unsigned long flags)
  {
  	struct mhp_params params = { .pgprot = PAGE_KERNEL };
  	u64 start, size;
@@ -1118,7 +1119,7 @@ int __ref add_memory_resource(int nid, struct resource *res)
  }
 
  /* requires device_hotplug_lock, see add_memory_resource() */
-int __ref __add_memory(int nid, u64 start, u64 size)
+int __ref __add_memory(int nid, u64 start, u64 size, unsigned long flags)
  {
  	struct resource *res;
  	int ret;
@@ -1127,18 +1128,18 @@ int __ref __add_memory(int nid, u64 start, u64 size)
  	if (IS_ERR(res))
  		return PTR_ERR(res);
 
-	ret = add_memory_resource(nid, res);
+	ret = add_memory_resource(nid, res, flags);
  	if (ret < 0)
  		release_memory_resource(res);
  	return ret;
  }
 
-int add_memory(int nid, u64 start, u64 size)
+int add_memory(int nid, u64 start, u64 size, unsigned long flags)
  {
  	int rc;
 
  	lock_device_hotplug();
-	rc = __add_memory(nid, start, size);
+	rc = __add_memory(nid, start, size, flags);
  	unlock_device_hotplug();
 
  	return rc;
@@ -1167,7 +1168,7 @@ EXPORT_SYMBOL_GPL(add_memory);
   * "System RAM ($DRIVER)".
   */
  int add_memory_driver_managed(int nid, u64 start, u64 size,
-			      const char *resource_name)
+			      const char *resource_name, unsigned long flags)
  {
  	struct resource *res;
  	int rc;
@@ -1185,7 +1186,7 @@ int add_memory_driver_managed(int nid, u64 start, u64 size,
  		goto out_unlock;
  	}
 
-	rc = add_memory_resource(nid, res);
+	rc = add_memory_resource(nid, res, flags);
  	if (rc < 0)
  		release_memory_resource(res);
 
maintainer Reviewed-by on v2 6/7
#23 lore raw

Re: [PATCH v2 6/7] xen/balloon: try to merge system ram resources

In reply to David Hildenbrand
Quoted 4 lines · David Hildenbrand

Let's try to merge system ram resources we add, to minimize the number of resources in /proc/iomem. We don't care about the boundaries of individual chunks we added.

Quoted 11 lines
Cc Andrew Morton <[email protected]>
Cc Michal Hocko <[email protected]>
Cc Boris Ostrovsky <[email protected]>
Cc Juergen Gross <[email protected]>
Cc Stefano Stabellini <[email protected]>
Cc Roger Pau Monné <[email protected]>
Cc Julien Grall <[email protected]>
Cc Pankaj Gupta <[email protected]>
Cc Baoquan He <[email protected]>
Cc Wei Yang <[email protected]>

Juergen

Quoted 18 lines
---
  drivers/xen/balloon.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
drivers/xen/balloon.c +1 -1
index 7bac38764513d..b57b2067ecbfb 100644
@@ -331,7 +331,7 @@ static enum bp_state reserve_additional_memory(void)
  	mutex_unlock(&balloon_mutex);
  	/* add_memory_resource() requires the device_hotplug lock */
  	lock_device_hotplug();
-	rc = add_memory_resource(nid, resource, 0);
+	rc = add_memory_resource(nid, resource, MEMHP_MERGE_RESOURCE);
  	unlock_device_hotplug();
  	mutex_lock(&balloon_mutex);
 
#9 lore raw

Re: [PATCH v2 2/7] kernel/resource: move and rename IORESOURCE_MEM_DRIVER_MANAGED

In reply to David Hildenbrand
Quoted 34 lines · David Hildenbrand

IORESOURCE_MEM_DRIVER_MANAGED currently uses an unused PnP bit, which is always set to 0 by hardware. This is far from beautiful (and confusing), and the bit only applies to SYSRAM. So let's move it out of the bus-specific (PnP) defined bits.

We'll add another SYSRAM specific bit soon. If we ever need more bits for other purposes, we can steal some from "desc", or reshuffle/regroup what we have.

Cc Andrew Morton <[email protected]>
Cc Michal Hocko <[email protected]>
Cc Dan Williams <[email protected]>
Cc Jason Gunthorpe <[email protected]>
Cc Kees Cook <[email protected]>
Cc Ard Biesheuvel <[email protected]>
Cc Pankaj Gupta <[email protected]>
Cc Baoquan He <[email protected]>
Cc Wei Yang <[email protected]>
Cc Eric Biederman <[email protected]>
Cc Thomas Gleixner <[email protected]>
Cc Greg Kroah-Hartman <[email protected]>
---
 include/linux/ioport.h | 4 +++-
 kernel/kexec_file.c    | 2 +-
 mm/memory_hotplug.c    | 4 ++--
 3 files changed, 6 insertions(+), 4 deletions(-)
include/linux/ioport.h +0 -0
index 52a91f5fa1a36..d7620d7c941a0 100644

include/linux/ioport.h struct resource { · line 63

Quoted 6 lines
include/linux/ioport.h +3 -0
@@ -58,6 +58,9 @@ struct resource {
 #define IORESOURCE_EXT_TYPE_BITS 0x01000000	/* Resource extended types */
 #define IORESOURCE_SYSRAM	0x01000000	/* System RAM (modifier) */
 
+/* IORESOURCE_SYSRAM specific bits. */
+#define IORESOURCE_SYSRAM_DRIVER_MANAGED	0x02000000 /* Always detected via a driver. */
+

Can't you use BIT() here?

thanks,

greg k-h

#15 lore raw

Re: [PATCH v2 3/7] mm/memory_hotplug: prepare passing flags to add_memory() and friends

In reply to David Hildenbrand
Quoted 2 lines · David Hildenbrand

We soon want to pass flags, e.g., to mark added System RAM resources. mergeable. Prepare for that.

What are these random "flags", and how do we know what should be passed to them?

Why not make this an enumerated type so that we know it all works properly, like the GPF_* flags are? Passing around a random unsigned long feels very odd/broken...

thanks,

greg k-h

#10 lore raw

Re: [PATCH v2 2/7] kernel/resource: move and rename IORESOURCE_MEM_DRIVER_MANAGED

In reply to Greg Kroah-Hartman
Quoted 38 lines · Greg Kroah-Hartman
Quoted 37 lines · David Hildenbrand

IORESOURCE_MEM_DRIVER_MANAGED currently uses an unused PnP bit, which is always set to 0 by hardware. This is far from beautiful (and confusing), and the bit only applies to SYSRAM. So let's move it out of the bus-specific (PnP) defined bits.

We'll add another SYSRAM specific bit soon. If we ever need more bits for other purposes, we can steal some from "desc", or reshuffle/regroup what we have.

Cc Andrew Morton <[email protected]>
Cc Michal Hocko <[email protected]>
Cc Dan Williams <[email protected]>
Cc Jason Gunthorpe <[email protected]>
Cc Kees Cook <[email protected]>
Cc Ard Biesheuvel <[email protected]>
Cc Pankaj Gupta <[email protected]>
Cc Baoquan He <[email protected]>
Cc Wei Yang <[email protected]>
Cc Eric Biederman <[email protected]>
Cc Thomas Gleixner <[email protected]>
Cc Greg Kroah-Hartman <[email protected]>
---
 include/linux/ioport.h | 4 +++-
 kernel/kexec_file.c    | 2 +-
 mm/memory_hotplug.c    | 4 ++--
 3 files changed, 6 insertions(+), 4 deletions(-)
include/linux/ioport.h +0 -0
index 52a91f5fa1a36..d7620d7c941a0 100644
@@ -58,6 +58,9 @@ struct resource {
 #define IORESOURCE_EXT_TYPE_BITS 0x01000000	/* Resource extended types */
 #define IORESOURCE_SYSRAM	0x01000000	/* System RAM (modifier) */
 
Quoted 5 lines

include/linux/ioport.h struct resource { · line 63

Quoted 3 lines
include/linux/ioport.h +3 -0
+/* IORESOURCE_SYSRAM specific bits. */
+#define IORESOURCE_SYSRAM_DRIVER_MANAGED	0x02000000 /* Always detected via a driver. */
+

Can't you use BIT() here?

I could, but this will make it look different to all other IORESOURCE_* definitions?

If so, we should change all existing definitions - however the ones spanning multiple bits might turn out rather ugly, like

#define IORESOURCE_TYPE_BITS 0x00001f00

Thoughts? Thanks

Quoted 5 lines

thanks,

greg k-h

Signature · 3 lines
Thanks,

David / dhildenb
#16 lore raw

Re: [PATCH v2 3/7] mm/memory_hotplug: prepare passing flags to add_memory() and friends

In reply to Greg Kroah-Hartman
Quoted 10 lines · Greg Kroah-Hartman
Quoted 2 lines · David Hildenbrand

We soon want to pass flags, e.g., to mark added System RAM resources. mergeable. Prepare for that.

What are these random "flags", and how do we know what should be passed to them?

Why not make this an enumerated type so that we know it all works properly, like the GPF_* flags are? Passing around a random unsigned long feels very odd/broken...

Agreed, an enum (mhp_flags) seems to give a better hint what can actually be passed. Thanks!

Signature · 3 lines
Thanks,

David / dhildenb
maintainer Reviewed-by on v2 7/7
#25 lore raw

Re: [PATCH v2 7/7] hv_balloon: try to merge system ram resources

In reply to David Hildenbrand
Quoted 4 lines · David Hildenbrand

Let's try to merge system ram resources we add, to minimize the number of resources in /proc/iomem. We don't care about the boundaries of individual chunks we added.

Quoted 10 lines
Cc Andrew Morton <[email protected]>
Cc Michal Hocko <[email protected]>
Cc "K. Y. Srinivasan" <[email protected]>
Cc Haiyang Zhang <[email protected]>
Cc Stephen Hemminger <[email protected]>
Cc Wei Liu <[email protected]>
Cc Pankaj Gupta <[email protected]>
Cc Baoquan He <[email protected]>
Cc Wei Yang <[email protected]>
#17 lore raw

Re: [PATCH v2 3/7] mm/memory_hotplug: prepare passing flags to add_memory() and friends

In reply to David Hildenbrand
Quoted 8 lines · David Hildenbrand
Quoted 7 lines · Greg Kroah-Hartman
Quoted 2 lines · David Hildenbrand

We soon want to pass flags, e.g., to mark added System RAM resources. mergeable. Prepare for that.

What are these random "flags", and how do we know what should be passed to them?

Quoted 6 lines
Quoted 3 lines

Why not make this an enumerated type so that we know it all works properly, like the GPF_* flags are? Passing around a random unsigned long feels very odd/broken...

Agreed, an enum (mhp_flags) seems to give a better hint what can actually be passed. Thanks!

You probably know this but ...

Just using a C enum doesn't get you any type safety.

You can get some checking via sparse by using __bitwise, which is what gfp_t does. You don't actually have to use an enum for that, it works with #defines also.

Or you can wrap the flag in a struct, the way atomic_t does, and then the compiler will prevent passing plain integers in place of your custom type.

cheers

#18 lore raw

Re: [PATCH v2 3/7] mm/memory_hotplug: prepare passing flags to add_memory() and friends

Quoted 16 lines · Michael Ellerman
Quoted 8 lines · David Hildenbrand
Quoted 7 lines · Greg Kroah-Hartman
Quoted 2 lines · David Hildenbrand

We soon want to pass flags, e.g., to mark added System RAM resources. mergeable. Prepare for that.

What are these random "flags", and how do we know what should be passed to them?

Quoted 6 lines
Quoted 3 lines

Why not make this an enumerated type so that we know it all works properly, like the GPF_* flags are? Passing around a random unsigned long feels very odd/broken...

Agreed, an enum (mhp_flags) seems to give a better hint what can actually be passed. Thanks!

Quoted 7 lines

You probably know this but ...

Just using a C enum doesn't get you any type safety.

You can get some checking via sparse by using __bitwise, which is what gfp_t does. You don't actually have to use an enum for that, it works with #defines also.

Yeah, we seem to be using different approaches. And there is always a way to mess things up :)

gfp_t is one (extreme) example, enum memblock_flags is another example. I tend to prefer an enum in this particular case, because it's simple and at least tells the user which values are expected.

Thoughts?

Quoted 4 lines

Or you can wrap the flag in a struct, the way atomic_t does, and then the compiler will prevent passing plain integers in place of your custom type.

Signature · 3 lines
Thanks,

David / dhildenb
#19 lore raw

Re: [PATCH v2 3/7] mm/memory_hotplug: prepare passing flags to add_memory() and friends

Quoted 25 lines · David Hildenbrand
Quoted 16 lines · Michael Ellerman
Quoted 8 lines · David Hildenbrand
Quoted 7 lines · Greg Kroah-Hartman
Quoted 2 lines · David Hildenbrand

We soon want to pass flags, e.g., to mark added System RAM resources. mergeable. Prepare for that.

What are these random "flags", and how do we know what should be passed to them?

Quoted 6 lines
Quoted 3 lines

Why not make this an enumerated type so that we know it all works properly, like the GPF_* flags are? Passing around a random unsigned long feels very odd/broken...

Agreed, an enum (mhp_flags) seems to give a better hint what can actually be passed. Thanks!

Quoted 7 lines

You probably know this but ...

Just using a C enum doesn't get you any type safety.

You can get some checking via sparse by using __bitwise, which is what gfp_t does. You don't actually have to use an enum for that, it works with #defines also.

Quoted 7 lines

Yeah, we seem to be using different approaches. And there is always a way to mess things up :)

gfp_t is one (extreme) example, enum memblock_flags is another example. I tend to prefer an enum in this particular case, because it's simple and at least tells the user which values are expected.

Gave it another try, looks like mhp_t (like gfp_t) is actually nicer.

Signature · 6 lines
Thanks,

David / dhildenb
_______________________________________________
Linux-nvdimm mailing list -- [email protected]
To unsubscribe send an email to [email protected]
#2 lore raw

Re: [PATCH v2 1/7] kernel/resource: make release_mem_region_adjustable() never fail

In reply to David Hildenbrand
Quoted 73 lines · David Hildenbrand

Let's make sure splitting a resource on memory hotunplug will never fail. This will become more relevant once we merge selected System RAM resources - then, we'll trigger that case more often on memory hotunplug.

In general, this function is already unlikely to fail. When we remove memory, we free up quite a lot of metadata (memmap, page tables, memory block device, etc.). The only reason it could really fail would be when injecting allocation errors.

All other error cases inside release_mem_region_adjustable() seem to be sanity checks if the function would be abused in different context - let's add WARN_ON_ONCE() in these cases so we can catch them.

Cc Andrew Morton <[email protected]>
Cc Michal Hocko <[email protected]>
Cc Dan Williams <[email protected]>
Cc Jason Gunthorpe <[email protected]>
Cc Kees Cook <[email protected]>
Cc Ard Biesheuvel <[email protected]>
Cc Pankaj Gupta <[email protected]>
Cc Baoquan He <[email protected]>
Cc Wei Yang <[email protected]>

---

include/linux/ioport.h |  4 ++--
kernel/resource.c      | 49 ++++++++++++++++++++++++------------------
mm/memory_hotplug.c    | 22 +------------------
3 files changed, 31 insertions(+), 44 deletions(-)
include/linux/ioport.h +2 -2
index 6c2b06fe8beb7..52a91f5fa1a36 100644
@@ -248,8 +248,8 @@ extern struct resource * __request_region(struct resource *,
 extern void __release_region(struct resource *, resource_size_t,
 				resource_size_t);
 #ifdef CONFIG_MEMORY_HOTREMOVE
-extern int release_mem_region_adjustable(struct resource *, resource_size_t,
-				resource_size_t);
+extern void release_mem_region_adjustable(struct resource *, resource_size_t,
+					  resource_size_t);
 #endif
 
 /* Wrappers for managed devices */
kernel/resource.c +6 -8
index f1175ce93a1d5..36b3552210120 100644
@@ -1258,21 +1258,28 @@ EXPORT_SYMBOL(__release_region);
 *   assumes that all children remain in the lower address entry for
 *   simplicity.  Enhance this logic when necessary.
 */
-int release_mem_region_adjustable(struct resource *parent,
-				  resource_size_t start, resource_size_t size)
+void release_mem_region_adjustable(struct resource *parent,
+				   resource_size_t start, resource_size_t size)
 {
+	struct resource *new_res = NULL;
+	bool alloc_nofail = false;
 	struct resource **p;
 	struct resource *res;
-	struct resource *new_res;
 	resource_size_t end;
-	int ret = -EINVAL;
 
 	end = start + size - 1;
-	if ((start < parent->start) || (end > parent->end))
-		return ret;
+	if (WARN_ON_ONCE((start < parent->start) || (end > parent->end)))
+		return;
 
-	/* The alloc_resource() result gets checked later */
-	new_res = alloc_resource(GFP_KERNEL);

kernel/resource.c EXPORT_SYMBOL(__release_region); · line 1283

Quoted 10 lines
kernel/resource.c +9 -0
+	/*
+	 * We free up quite a lot of memory on memory hotunplug (esp., memap),
+	 * just before releasing the region. This is highly unlikely to
+	 * fail - let's play save and make it never fail as the caller cannot
+	 * perform any error handling (e.g., trying to re-add memory will fail
+	 * similarly).
+	 */
+retry:
+	new_res = alloc_resource(GFP_KERNEL | alloc_nofail ? __GFP_NOFAIL : 0);
 

It looks like a bold change, while I don't find a reason to object it.

Quoted 104 lines
kernel/resource.c +13 -13
 	p = &parent->child;
 	write_lock(&resource_lock);
@@ -1298,7 +1305,6 @@ int release_mem_region_adjustable(struct resource *parent,
 		 * so if we are dealing with them, let us just back off here.
 		 */
 		if (!(res->flags & IORESOURCE_SYSRAM)) {
-			ret = 0;
 			break;
 		}
 
@@ -1315,20 +1321,23 @@ int release_mem_region_adjustable(struct resource *parent,
 			/* free the whole entry */
 			*p = res->sibling;
 			free_resource(res);
-			ret = 0;
 		} else if (res->start == start && res->end != end) {
 			/* adjust the start */
-			ret = __adjust_resource(res, end + 1,
-						res->end - end);
+			WARN_ON_ONCE(__adjust_resource(res, end + 1,
+						       res->end - end));
 		} else if (res->start != start && res->end == end) {
 			/* adjust the end */
-			ret = __adjust_resource(res, res->start,
-						start - res->start);
+			WARN_ON_ONCE(__adjust_resource(res, res->start,
+						       start - res->start));
 		} else {
-			/* split into two entries */
+			/* split into two entries - we need a new resource */
 			if (!new_res) {
-				ret = -ENOMEM;
-				break;
+				new_res = alloc_resource(GFP_ATOMIC);
+				if (!new_res) {
+					alloc_nofail = true;
+					write_unlock(&resource_lock);
+					goto retry;
+				}
 			}
 			new_res->name = res->name;
 			new_res->start = end + 1;
@@ -1339,9 +1348,8 @@ int release_mem_region_adjustable(struct resource *parent,
 			new_res->sibling = res->sibling;
 			new_res->child = NULL;
 
-			ret = __adjust_resource(res, res->start,
-						start - res->start);
-			if (ret)
+			if (WARN_ON_ONCE(__adjust_resource(res, res->start,
+							   start - res->start)))
 				break;
 			res->sibling = new_res;
 			new_res = NULL;
@@ -1352,7 +1360,6 @@ int release_mem_region_adjustable(struct resource *parent,
 
 	write_unlock(&resource_lock);
 	free_resource(new_res);
-	return ret;
 }
 #endif	/* CONFIG_MEMORY_HOTREMOVE */
 
mm/memory_hotplug.c +1 -21
index baded53b9ff92..4c47b68a9f4b5 100644
@@ -1724,26 +1724,6 @@ void try_offline_node(int nid)
 }
 EXPORT_SYMBOL(try_offline_node);
 
-static void __release_memory_resource(resource_size_t start,
-				      resource_size_t size)
-{
-	int ret;
-
-	/*
-	 * When removing memory in the same granularity as it was added,
-	 * this function never fails. It might only fail if resources
-	 * have to be adjusted or split. We'll ignore the error, as
-	 * removing of memory cannot fail.
-	 */
-	ret = release_mem_region_adjustable(&iomem_resource, start, size);
-	if (ret) {
-		resource_size_t endres = start + size - 1;
-
-		pr_warn("Unable to release resource <%pa-%pa> (%d)\n",
-			&start, &endres, ret);
-	}
-}
-
 static int __ref try_remove_memory(int nid, u64 start, u64 size)
 {
 	int rc = 0;
@@ -1777,7 +1757,7 @@ static int __ref try_remove_memory(int nid, u64 start, u64 size)
 		memblock_remove(start, size);
 	}
 
-	__release_memory_resource(start, size);
+	release_mem_region_adjustable(&iomem_resource, start, size);
 
 	try_offline_node(nid);
 
Signature · 1 line
2.26.2
Signature · 2 lines
Wei Yang
Help you, Help me
#3 lore raw

Re: [PATCH v2 1/7] kernel/resource: make release_mem_region_adjustable() never fail

In reply to David Hildenbrand
Quoted 177 lines · David Hildenbrand

Let's make sure splitting a resource on memory hotunplug will never fail. This will become more relevant once we merge selected System RAM resources - then, we'll trigger that case more often on memory hotunplug.

In general, this function is already unlikely to fail. When we remove memory, we free up quite a lot of metadata (memmap, page tables, memory block device, etc.). The only reason it could really fail would be when injecting allocation errors.

All other error cases inside release_mem_region_adjustable() seem to be sanity checks if the function would be abused in different context - let's add WARN_ON_ONCE() in these cases so we can catch them.

Cc Andrew Morton <[email protected]>
Cc Michal Hocko <[email protected]>
Cc Dan Williams <[email protected]>
Cc Jason Gunthorpe <[email protected]>
Cc Kees Cook <[email protected]>
Cc Ard Biesheuvel <[email protected]>
Cc Pankaj Gupta <[email protected]>
Cc Baoquan He <[email protected]>
Cc Wei Yang <[email protected]>

---

include/linux/ioport.h |  4 ++--
kernel/resource.c      | 49 ++++++++++++++++++++++++------------------
mm/memory_hotplug.c    | 22 +------------------
3 files changed, 31 insertions(+), 44 deletions(-)
include/linux/ioport.h +2 -2
index 6c2b06fe8beb7..52a91f5fa1a36 100644
@@ -248,8 +248,8 @@ extern struct resource * __request_region(struct resource *,
 extern void __release_region(struct resource *, resource_size_t,
 				resource_size_t);
 #ifdef CONFIG_MEMORY_HOTREMOVE
-extern int release_mem_region_adjustable(struct resource *, resource_size_t,
-				resource_size_t);
+extern void release_mem_region_adjustable(struct resource *, resource_size_t,
+					  resource_size_t);
 #endif
 
 /* Wrappers for managed devices */
kernel/resource.c +28 -21
index f1175ce93a1d5..36b3552210120 100644
@@ -1258,21 +1258,28 @@ EXPORT_SYMBOL(__release_region);
 *   assumes that all children remain in the lower address entry for
 *   simplicity.  Enhance this logic when necessary.
 */
-int release_mem_region_adjustable(struct resource *parent,
-				  resource_size_t start, resource_size_t size)
+void release_mem_region_adjustable(struct resource *parent,
+				   resource_size_t start, resource_size_t size)
 {
+	struct resource *new_res = NULL;
+	bool alloc_nofail = false;
 	struct resource **p;
 	struct resource *res;
-	struct resource *new_res;
 	resource_size_t end;
-	int ret = -EINVAL;
 
 	end = start + size - 1;
-	if ((start < parent->start) || (end > parent->end))
-		return ret;
+	if (WARN_ON_ONCE((start < parent->start) || (end > parent->end)))
+		return;
 
-	/* The alloc_resource() result gets checked later */
-	new_res = alloc_resource(GFP_KERNEL);
+	/*
+	 * We free up quite a lot of memory on memory hotunplug (esp., memap),
+	 * just before releasing the region. This is highly unlikely to
+	 * fail - let's play save and make it never fail as the caller cannot
+	 * perform any error handling (e.g., trying to re-add memory will fail
+	 * similarly).
+	 */
+retry:
+	new_res = alloc_resource(GFP_KERNEL | alloc_nofail ? __GFP_NOFAIL : 0);
 
 	p = &parent->child;
 	write_lock(&resource_lock);
@@ -1298,7 +1305,6 @@ int release_mem_region_adjustable(struct resource *parent,
 		 * so if we are dealing with them, let us just back off here.
 		 */
 		if (!(res->flags & IORESOURCE_SYSRAM)) {
-			ret = 0;
 			break;
 		}
 
@@ -1315,20 +1321,23 @@ int release_mem_region_adjustable(struct resource *parent,
 			/* free the whole entry */
 			*p = res->sibling;
 			free_resource(res);
-			ret = 0;
 		} else if (res->start == start && res->end != end) {
 			/* adjust the start */
-			ret = __adjust_resource(res, end + 1,
-						res->end - end);
+			WARN_ON_ONCE(__adjust_resource(res, end + 1,
+						       res->end - end));
 		} else if (res->start != start && res->end == end) {
 			/* adjust the end */
-			ret = __adjust_resource(res, res->start,
-						start - res->start);
+			WARN_ON_ONCE(__adjust_resource(res, res->start,
+						       start - res->start));
 		} else {
-			/* split into two entries */
+			/* split into two entries - we need a new resource */
 			if (!new_res) {
-				ret = -ENOMEM;
-				break;
+				new_res = alloc_resource(GFP_ATOMIC);
+				if (!new_res) {
+					alloc_nofail = true;
+					write_unlock(&resource_lock);
+					goto retry;
+				}
 			}
 			new_res->name = res->name;
 			new_res->start = end + 1;
@@ -1339,9 +1348,8 @@ int release_mem_region_adjustable(struct resource *parent,
 			new_res->sibling = res->sibling;
 			new_res->child = NULL;
 
-			ret = __adjust_resource(res, res->start,
-						start - res->start);
-			if (ret)
+			if (WARN_ON_ONCE(__adjust_resource(res, res->start,
+							   start - res->start)))
 				break;
 			res->sibling = new_res;
 			new_res = NULL;
@@ -1352,7 +1360,6 @@ int release_mem_region_adjustable(struct resource *parent,
 
 	write_unlock(&resource_lock);
 	free_resource(new_res);
-	return ret;
 }
 #endif	/* CONFIG_MEMORY_HOTREMOVE */
 
mm/memory_hotplug.c +0 -20
index baded53b9ff92..4c47b68a9f4b5 100644
@@ -1724,26 +1724,6 @@ void try_offline_node(int nid)
 }
 EXPORT_SYMBOL(try_offline_node);
 
-static void __release_memory_resource(resource_size_t start,
-				      resource_size_t size)
-{
-	int ret;
-
-	/*
-	 * When removing memory in the same granularity as it was added,
-	 * this function never fails. It might only fail if resources
-	 * have to be adjusted or split. We'll ignore the error, as
-	 * removing of memory cannot fail.
-	 */
-	ret = release_mem_region_adjustable(&iomem_resource, start, size);
-	if (ret) {
-		resource_size_t endres = start + size - 1;
-
-		pr_warn("Unable to release resource <%pa-%pa> (%d)\n",
-			&start, &endres, ret);
-	}
-}
-
 static int __ref try_remove_memory(int nid, u64 start, u64 size)
 {
 	int rc = 0;

mm/memory_hotplug.c static int __ref try_remove_memory(int nid, u64 start, u64 size) · line 1761

Quoted 6 lines
mm/memory_hotplug.c +1 -1
@@ -1777,7 +1757,7 @@ static int __ref try_remove_memory(int nid, u64 start, u64 size)
 		memblock_remove(start, size);
 	}
 
-	__release_memory_resource(start, size);
+	release_mem_region_adjustable(&iomem_resource, start, size);
 

Seems the only user of release_mem_region_adjustable() is here, can we move iomem_resource into the function body? Actually, we don't iterate the resource tree from any level. We always start from the root.

Quoted 4 lines
mm/memory_hotplug.c +0 -0
 	try_offline_node(nid);
 
Signature · 1 line
2.26.2
Signature · 2 lines
Wei Yang
Help you, Help me
#11 lore raw

Re: [PATCH v2 2/7] kernel/resource: move and rename IORESOURCE_MEM_DRIVER_MANAGED

In reply to David Hildenbrand
Quoted 8 lines · David Hildenbrand

IORESOURCE_MEM_DRIVER_MANAGED currently uses an unused PnP bit, which is always set to 0 by hardware. This is far from beautiful (and confusing), and the bit only applies to SYSRAM. So let's move it out of the bus-specific (PnP) defined bits.

We'll add another SYSRAM specific bit soon. If we ever need more bits for other purposes, we can steal some from "desc", or reshuffle/regroup what we have.

I think you make this definition because we use IORESOURCE_SYSRAM_RAM for hotpluged memory? So we make them all in IORESOURCE_SYSRAM_XXX family?

Quoted 80 lines
Cc Andrew Morton <[email protected]>
Cc Michal Hocko <[email protected]>
Cc Dan Williams <[email protected]>
Cc Jason Gunthorpe <[email protected]>
Cc Kees Cook <[email protected]>
Cc Ard Biesheuvel <[email protected]>
Cc Pankaj Gupta <[email protected]>
Cc Baoquan He <[email protected]>
Cc Wei Yang <[email protected]>
Cc Eric Biederman <[email protected]>
Cc Thomas Gleixner <[email protected]>
Cc Greg Kroah-Hartman <[email protected]>

---

include/linux/ioport.h | 4 +++-
kernel/kexec_file.c    | 2 +-
mm/memory_hotplug.c    | 4 ++--
3 files changed, 6 insertions(+), 4 deletions(-)
include/linux/ioport.h +3 -1
index 52a91f5fa1a36..d7620d7c941a0 100644
@@ -58,6 +58,9 @@ struct resource {
 #define IORESOURCE_EXT_TYPE_BITS 0x01000000	/* Resource extended types */
 #define IORESOURCE_SYSRAM	0x01000000	/* System RAM (modifier) */
 
+/* IORESOURCE_SYSRAM specific bits. */
+#define IORESOURCE_SYSRAM_DRIVER_MANAGED	0x02000000 /* Always detected via a driver. */
+
 #define IORESOURCE_EXCLUSIVE	0x08000000	/* Userland may not map this resource */
 
 #define IORESOURCE_DISABLED	0x10000000
@@ -103,7 +106,6 @@ struct resource {
 #define IORESOURCE_MEM_32BIT		(3<<3)
 #define IORESOURCE_MEM_SHADOWABLE	(1<<5)	/* dup: IORESOURCE_SHADOWABLE */
 #define IORESOURCE_MEM_EXPANSIONROM	(1<<6)
-#define IORESOURCE_MEM_DRIVER_MANAGED	(1<<7)
 
 /* PnP I/O specific bits (IORESOURCE_BITS) */
 #define IORESOURCE_IO_16BIT_ADDR	(1<<0)
kernel/kexec_file.c +1 -1
index ca40bef75a616..dfeeed1aed084 100644
@@ -520,7 +520,7 @@ static int locate_mem_hole_callback(struct resource *res, void *arg)
 	/* Returning 0 will take to next memory range */
 
 	/* Don't use memory that will be detected and handled by a driver. */
-	if (res->flags & IORESOURCE_MEM_DRIVER_MANAGED)
+	if (res->flags & IORESOURCE_SYSRAM_DRIVER_MANAGED)
 		return 0;
 
 	if (sz < kbuf->memsz)
mm/memory_hotplug.c +2 -2
index 4c47b68a9f4b5..8e1cd18b5cf14 100644
@@ -105,7 +105,7 @@ static struct resource *register_memory_resource(u64 start, u64 size,
 	unsigned long flags =  IORESOURCE_SYSTEM_RAM | IORESOURCE_BUSY;
 
 	if (strcmp(resource_name, "System RAM"))
-		flags |= IORESOURCE_MEM_DRIVER_MANAGED;
+		flags |= IORESOURCE_SYSRAM_DRIVER_MANAGED;
 
 	/*
 	 * Make sure value parsed from 'mem=' only restricts memory adding
@@ -1160,7 +1160,7 @@ EXPORT_SYMBOL_GPL(add_memory);
 *
 * For this memory, no entries in /sys/firmware/memmap ("raw firmware-provided
 * memory map") are created. Also, the created memory resource is flagged
- * with IORESOURCE_MEM_DRIVER_MANAGED, so in-kernel users can special-case
+ * with IORESOURCE_SYSRAM_DRIVER_MANAGED, so in-kernel users can special-case
 * this memory as well (esp., not place kexec images onto it).
 *
 * The resource_name (visible via /proc/iomem) has to have the format
Signature · 1 line
2.26.2
Signature · 2 lines
Wei Yang
Help you, Help me
#4 lore raw

Re: [PATCH v2 1/7] kernel/resource: make release_mem_region_adjustable() never fail

In reply to Wei Yang
Quoted 8 lines
Quoted 8 lines

static int __ref try_remove_memory(int nid, u64 start, u64 size)

{
	int rc = 0;
mm/memory_hotplug.c +0 -0
@@ -1777,7 +1757,7 @@ static int __ref try_remove_memory(int nid, u64 start, u64 size)
 		memblock_remove(start, size);
 	}
 
Quoted 7 lines

mm/memory_hotplug.c static int __ref try_remove_memory(int nid, u64 start, u64 size) · line 1761

Quoted 3 lines
mm/memory_hotplug.c +1 -1
-	__release_memory_resource(start, size);
+	release_mem_region_adjustable(&iomem_resource, start, size);
 

Seems the only user of release_mem_region_adjustable() is here, can we move iomem_resource into the function body? Actually, we don't iterate the resource tree from any level. We always start from the root.

You mean, making iomem_resource implicit? I can spot that something similar was done for

#define devm_release_mem_region(dev, start, n) \
	__devm_release_region(dev, &iomem_resource, (start), (n))

I'll send an addon patch for that, ok? - thanks.

Signature · 3 lines
Thanks,

David / dhildenb
#12 lore raw

Re: [PATCH v2 2/7] kernel/resource: move and rename IORESOURCE_MEM_DRIVER_MANAGED

In reply to Wei Yang
Quoted 6 lines · Wei Yang
Quoted 5 lines · David Hildenbrand

IORESOURCE_MEM_DRIVER_MANAGED currently uses an unused PnP bit, which is always set to 0 by hardware. This is far from beautiful (and confusing), and the bit only applies to SYSRAM. So let's move it out of the bus-specific (PnP) defined bits.

Quoted 6 lines
Quoted 3 lines

We'll add another SYSRAM specific bit soon. If we ever need more bits for other purposes, we can steal some from "desc", or reshuffle/regroup what we have.

I think you make this definition because we use IORESOURCE_SYSRAM_RAM for hotpluged memory? So we make them all in IORESOURCE_SYSRAM_XXX family?

Yeah, to specify based on the extended MEM type SYSRAM. Because it really only applies to that.

Signature · 3 lines
Thanks,

David / dhildenb
#5 lore raw

Re: [PATCH v2 1/7] kernel/resource: make release_mem_region_adjustable() never fail

In reply to David Hildenbrand
Quoted 16 lines · David Hildenbrand
Quoted 8 lines
Quoted 8 lines

static int __ref try_remove_memory(int nid, u64 start, u64 size)

{
	int rc = 0;
mm/memory_hotplug.c +0 -0
@@ -1777,7 +1757,7 @@ static int __ref try_remove_memory(int nid, u64 start, u64 size)
 		memblock_remove(start, size);
 	}
 
Quoted 7 lines

mm/memory_hotplug.c static int __ref try_remove_memory(int nid, u64 start, u64 size) · line 1761

Quoted 3 lines
mm/memory_hotplug.c +1 -1
-	__release_memory_resource(start, size);
+	release_mem_region_adjustable(&iomem_resource, start, size);
 

Seems the only user of release_mem_region_adjustable() is here, can we move iomem_resource into the function body? Actually, we don't iterate the resource tree from any level. We always start from the root.

Quoted 6 lines

You mean, making iomem_resource implicit? I can spot that something similar was done for

#define devm_release_mem_region(dev, start, n) \
	__devm_release_region(dev, &iomem_resource, (start), (n))

What I prefer is remove iomem_resource from the parameter list. Just use is in the function body.

For the example you listed, __release_region() would have varies of *parent*, which looks reasonable to keep it here.

Quoted 6 lines

I'll send an addon patch for that, ok? - thanks.

Signature · 3 lines
Thanks,

David / dhildenb
Signature · 2 lines
Wei Yang
Help you, Help me
#6 lore raw

Re: [PATCH v2 1/7] kernel/resource: make release_mem_region_adjustable() never fail

Quoted 29 lines · Wei Yang
Quoted 16 lines · David Hildenbrand
Quoted 8 lines
Quoted 8 lines

static int __ref try_remove_memory(int nid, u64 start, u64 size)

{
	int rc = 0;
mm/memory_hotplug.c +0 -0
@@ -1777,7 +1757,7 @@ static int __ref try_remove_memory(int nid, u64 start, u64 size)
 		memblock_remove(start, size);
 	}
 
Quoted 7 lines

mm/memory_hotplug.c static int __ref try_remove_memory(int nid, u64 start, u64 size) · line 1761

Quoted 3 lines
mm/memory_hotplug.c +1 -1
-	__release_memory_resource(start, size);
+	release_mem_region_adjustable(&iomem_resource, start, size);
 

Seems the only user of release_mem_region_adjustable() is here, can we move iomem_resource into the function body? Actually, we don't iterate the resource tree from any level. We always start from the root.

Quoted 6 lines

You mean, making iomem_resource implicit? I can spot that something similar was done for

#define devm_release_mem_region(dev, start, n) \
	__devm_release_region(dev, &iomem_resource, (start), (n))

What I prefer is remove iomem_resource from the parameter list. Just use is in the function body.

For the example you listed, __release_region() would have varies of *parent*, which looks reasonable to keep it here.

Quoted 1 line · as I
Quoted 1 line

I'll send an addon patch for that, ok? - thanks.

Signature · 3 lines
Thanks,

David / dhildenb
#7 lore raw

Re: [PATCH v2 1/7] kernel/resource: make release_mem_region_adjustable() never fail

Quoted 25 lines · David Hildenbrand
Quoted 24 lines · Wei Yang
Quoted 22 lines · David Hildenbrand
Quoted 8 lines
Quoted 8 lines

static int __ref try_remove_memory(int nid, u64 start, u64 size)

{
	int rc = 0;
mm/memory_hotplug.c +0 -0
@@ -1777,7 +1757,7 @@ static int __ref try_remove_memory(int nid, u64 start, u64 size)
 		memblock_remove(start, size);
 	}
 
Quoted 7 lines

mm/memory_hotplug.c static int __ref try_remove_memory(int nid, u64 start, u64 size) · line 1761

Quoted 3 lines
mm/memory_hotplug.c +1 -1
-	__release_memory_resource(start, size);
+	release_mem_region_adjustable(&iomem_resource, start, size);
 

Seems the only user of release_mem_region_adjustable() is here, can we move iomem_resource into the function body? Actually, we don't iterate the resource tree from any level. We always start from the root.

You mean, making iomem_resource implicit? I can spot that something similar was done for

#define devm_release_mem_region(dev, start, n) \
	__devm_release_region(dev, &iomem_resource, (start), (n))
Quoted 8 lines
Quoted 5 lines

What I prefer is remove iomem_resource from the parameter list. Just use is in the function body.

For the example you listed, __release_region() would have varies of *parent*, which looks reasonable to keep it here.

Yeah I got that ("making iomem_resource implicit"), as I said:

Thanks

Quoted 6 lines
Quoted 1 line
Quoted 1 line

I'll send an addon patch for that, ok? - thanks.

Signature · 3 lines
Thanks,

David / dhildenb
Signature · 2 lines
Wei Yang
Help you, Help me