resource: Merge resources on a node when hot-adding memory
Subsystems (2)
PATCH RESEND 1/1 resource: Merge resources on a node when hot-adding memory
When hot-removing memory release_mem_region_adjustable() splits iomem resources if they are not the exact size of the memory being hot-deleted. Adding this memory back to the kernel adds a new resource.
Eg a node has memory 0x0 - 0xfffffffff. Offlining and hot-removing 1GB from 0xf40000000 results in the single resource 0x0-0xfffffffff being split into two resources: 0x0-0xf3fffffff and 0xf80000000-0xfffffffff.
When we hot-add the memory back we now have three resources:
0x0-0xf3fffffff, 0xf40000000-0xf7fffffff, and 0xf80000000-0xfffffffff.
Now if we try to remove a section of memory that overlaps these resources, like 2GB from 0xf40000000, release_mem_region_adjustable() fails as it expects the chunk of memory to be within the boundaries of a single resource.
This patch adds a function request_resource_and_merge(). This is called instead of request_resource_conflict() when registering a resource in add_memory(). It calls request_resource_conflict() and if there are no conflicts we attempt to merge contiguous resources on the node.
---
[Resending because there is no second patch. Don't send patches on Friday afternoons...]
include/linux/ioport.h | 2 + include/linux/memory_hotplug.h | 2 +- kernel/resource.c | 110 +++++++++++++++++++++++++++++++++++++++++ mm/memory_hotplug.c | 29 ++++------- 4 files changed, 122 insertions(+), 21 deletions(-)
include/linux/ioport.h +2 -0
@@ -189,6 +189,8 @@ extern int allocate_resource(struct resource *root, struct resource *new, resource_size_t, resource_size_t), void *alignf_data); +extern struct resource *request_resource_and_merge (struct resource *parent, +struct resource *new,int nid);struct resource *lookup_resource (struct resource *root,resource_size_t start);int adjust_resource (struct resource *res,resource_size_t start,resource_size_t size);
include/linux/memory_hotplug.h +1 -1
@@ -322,7 +322,7 @@ static inline void remove_memory(int nid, u64 start, u64 size) {}extern int walk_memory_range (unsigned long start_pfn,unsigned long end_pfn,void *arg,int (*func)(struct memory_block *,void *));extern int add_memory (int nid,u64 start,u64 size); -extern int add_memory_resource (int nid,struct resource *resource,bool online); +extern int add_memory_resource (int nid,u64 start,u64 size,bool online);extern int arch_add_memory (int nid,u64 start,u64 size,struct vmem_altmap *altmap,bool want_memblock); extern void move_pfn_range_to_zone(struct zone *zone, unsigned long start_pfn,
kernel/resource.c +110 -0
113 lines not on this page · raw message
mm/memory_hotplug.c +9 -20
@@ -97,7 +97,7 @@ void mem_hotplug_done(void) }/* add this memory to iomem resource */ -static struct resource *register_memory_resource (u64 start,u64 size) +static struct resource *register_memory_resource (int nid,u64 start,u64 size) {struct resource *res, *conflict; res =kzalloc (sizeof (struct resource ),GFP_KERNEL );
@@ -108,7 +108,7 @@ static struct resource *register_memory_resource(u64 start, u64 size) res->start = start; res->end = start + size -1 ; res->flags =IORESOURCE_SYSTEM_RAM |IORESOURCE_BUSY ; - conflict =request_resource_conflict (&iomem_resource, res); + conflict =request_resource_and_merge (&iomem_resource, res, nid);if (conflict) {if (conflict->desc ==IORES_DESC_DEVICE_PRIVATE_MEMORY ) { pr_debug("Device unaddressable memory block "
@@ -122,15 +122,6 @@ static struct resource *register_memory_resource(u64 start, u64 size)return res; } -static void release_memory_resource (struct resource *res) -{ -if (!res) -return ; -release_resource (res); -kfree (res); -return ; -} -#ifdef CONFIG_MEMORY_HOTPLUG_SPARSE void get_page_bootmem (unsigned long info,struct page *page,unsigned long type)
@@ -1096,17 +1087,13 @@ 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,bool online) +int __ref add_memory_resource (int nid,u64 start,u64 size,bool online) { -u64 start, size;pg_data_t *pgdat =NULL ;bool new_pgdat;bool new_node;int ret; - start = res->start; - size =resource_size (res); - ret =check_hotplug_memory_range (start, size);if (ret)return ret;
@@ -1195,13 +1182,15 @@ int __ref add_memory(int nid, u64 start, u64 size)struct resource *res;int ret; - res =register_memory_resource (start, size); + res =register_memory_resource (nid, start, size);if (IS_ERR (res))return PTR_ERR (res); - ret =add_memory_resource (nid, res, memhp_auto_online); -if (ret <0 ) -release_memory_resource (res); + ret =add_memory_resource (nid, start, size, memhp_auto_online); +if (ret <0 ) { +release_mem_region_adjustable (&iomem_resource, start, size); +kfree (res); + }return ret; }EXPORT_SYMBOL_GPL (add_memory);
Signature · 1 line
2.14.4
kbuild test robot
build botThank you for the patch! Yet something to improve:
Hi Rashmica,
Thank you for the patch! Yet something to improve:
[auto build test ERROR on linus/master]
[also build test ERROR on v4.18-rc7]
[cannot apply to next-20180802]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system]
url: https://github.com/0day-ci/linux/commits/Rashmica-Gupta/resource-Merge-resources-on-a-node-when-hot-adding-memory/20180803-221205
config: x86_64-randconfig-x000-201830 (attached as .config)
compiler: gcc-7 (Debian 7.3.0-16) 7.3.0
reproduce:
# save the attached .config to linux build tree
make ARCH=x86_64 All errors (new ones prefixed by >>):
mm/memory_hotplug.c: In function 'add_memory':
>> mm/memory_hotplug.c:1191:3: error: implicit declaration of function 'release_mem_region_adjustable'; did you mean 'release_mem_region'? [-Werror=implicit-function-declaration]
release_mem_region_adjustable(&iomem_resource, start, size);
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
release_mem_regioncc1: some warnings being treated as errors
vim +1191 mm/memory_hotplug.c
1179
1180 int __ref add_memory(int nid, u64 start, u64 size)
1181 {
1182 struct resource *res;
1183 int ret;
1184
1185 res = register_memory_resource(nid, start, size);
1186 if (IS_ERR(res))
1187 return PTR_ERR(res);
1188
1189 ret = add_memory_resource(nid, start, size, memhp_auto_online);
1190 if (ret < 0) {
> 1191 release_mem_region_adjustable(&iomem_resource, start, size);
1192 kfree(res);
1193 }
1194 return ret;
1195 }
1196 EXPORT_SYMBOL_GPL(add_memory);
1197
---
0-DAY kernel test infrastructure Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all Intel Corporation
kbuild test robot
build botThank you for the patch! Yet something to improve:
Hi Rashmica,
Thank you for the patch! Yet something to improve:
[auto build test ERROR on linus/master]
[also build test ERROR on v4.18-rc7]
[cannot apply to next-20180802]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system]
url: https://github.com/0day-ci/linux/commits/Rashmica-Gupta/resource-Merge-resources-on-a-node-when-hot-adding-memory/20180803-221205
config: x86_64-randconfig-s1-08032324 (attached as .config)
compiler: gcc-6 (Debian 6.4.0-9) 6.4.0 20171026 reproduce:
# save the attached .config to linux build tree
make ARCH=x86_64 All errors (new ones prefixed by >>):
mm/memory_hotplug.c: In function 'add_memory':
>> mm/memory_hotplug.c:1191:3: error: implicit declaration of function 'release_mem_region_adjustable' [-Werror=implicit-function-declaration]
release_mem_region_adjustable(&iomem_resource, start, size);
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~cc1: some warnings being treated as errors
vim +/release_mem_region_adjustable +1191 mm/memory_hotplug.c
1179
1180 int __ref add_memory(int nid, u64 start, u64 size)
1181 {
1182 struct resource *res;
1183 int ret;
1184
1185 res = register_memory_resource(nid, start, size);
1186 if (IS_ERR(res))
1187 return PTR_ERR(res);
1188
1189 ret = add_memory_resource(nid, start, size, memhp_auto_online);
1190 if (ret < 0) {
> 1191 release_mem_region_adjustable(&iomem_resource, start, size);
1192 kfree(res);
1193 }
1194 return ret;
1195 }
1196 EXPORT_SYMBOL_GPL(add_memory);
1197
---
0-DAY kernel test infrastructure Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all Intel Corporation