Skip to content

Commit 4faf8d9

Browse files
Lee Schermerhorntorvalds
authored andcommitted
hugetlb: handle memory hot-plug events
Register per node hstate attributes only for nodes with memory. As suggested by David Rientjes. With Memory Hotplug, memory can be added to a memoryless node and a node with memory can become memoryless. Therefore, add a memory on/off-line notifier callback to [un]register a node's attributes on transition to/from memoryless state. N.B., Only tested build, boot, libhugetlbfs regression. i.e., no memory hotplug testing. Signed-off-by: Lee Schermerhorn <lee.schermerhorn@hp.com> Reviewed-by: Andi Kleen <andi@firstfloor.org> Acked-by: David Rientjes <rientjes@google.com> Cc: KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com> Cc: Lee Schermerhorn <lee.schermerhorn@hp.com> Cc: Mel Gorman <mel@csn.ul.ie> Cc: Randy Dunlap <randy.dunlap@oracle.com> Cc: Nishanth Aravamudan <nacc@us.ibm.com> Cc: Adam Litke <agl@us.ibm.com> Cc: Andy Whitcroft <apw@canonical.com> Cc: Eric Whitney <eric.whitney@hp.com> Cc: Christoph Lameter <cl@linux-foundation.org> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent 8fe23e0 commit 4faf8d9

2 files changed

Lines changed: 50 additions & 6 deletions

File tree

‎Documentation/vm/hugetlbpage.txt‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,8 @@ resulting effect on persistent huge page allocation is as follows:
231231
Per Node Hugepages Attributes
232232

233233
A subset of the contents of the root huge page control directory in sysfs,
234-
described above, has been replicated under each "node" system device in:
234+
described above, will be replicated under each the system device of each
235+
NUMA node with memory in:
235236

236237
/sys/devices/system/node/node[0-9]*/hugepages/
237238

‎drivers/base/node.c‎

Lines changed: 48 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -177,8 +177,8 @@ static SYSDEV_ATTR(distance, S_IRUGO, node_read_distance, NULL);
177177
/*
178178
* hugetlbfs per node attributes registration interface:
179179
* When/if hugetlb[fs] subsystem initializes [sometime after this module],
180-
* it will register its per node attributes for all nodes online at that
181-
* time. It will also call register_hugetlbfs_with_node(), below, to
180+
* it will register its per node attributes for all online nodes with
181+
* memory. It will also call register_hugetlbfs_with_node(), below, to
182182
* register its attribute registration functions with this node driver.
183183
* Once these hooks have been initialized, the node driver will call into
184184
* the hugetlb module to [un]register attributes for hot-plugged nodes.
@@ -188,7 +188,8 @@ static node_registration_func_t __hugetlb_unregister_node;
188188

189189
static inline void hugetlb_register_node(struct node *node)
190190
{
191-
if (__hugetlb_register_node)
191+
if (__hugetlb_register_node &&
192+
node_state(node->sysdev.id, N_HIGH_MEMORY))
192193
__hugetlb_register_node(node);
193194
}
194195

@@ -233,6 +234,7 @@ int register_node(struct node *node, int num, struct node *parent)
233234
sysdev_create_file(&node->sysdev, &attr_distance);
234235

235236
scan_unevictable_register_node(node);
237+
236238
hugetlb_register_node(node);
237239
}
238240
return error;
@@ -254,7 +256,7 @@ void unregister_node(struct node *node)
254256
sysdev_remove_file(&node->sysdev, &attr_distance);
255257

256258
scan_unevictable_unregister_node(node);
257-
hugetlb_unregister_node(node);
259+
hugetlb_unregister_node(node); /* no-op, if memoryless node */
258260

259261
sysdev_unregister(&node->sysdev);
260262
}
@@ -384,8 +386,45 @@ static int link_mem_sections(int nid)
384386
}
385387
return err;
386388
}
389+
390+
/*
391+
* Handle per node hstate attribute [un]registration on transistions
392+
* to/from memoryless state.
393+
*/
394+
395+
static int node_memory_callback(struct notifier_block *self,
396+
unsigned long action, void *arg)
397+
{
398+
struct memory_notify *mnb = arg;
399+
int nid = mnb->status_change_nid;
400+
401+
switch (action) {
402+
case MEM_ONLINE: /* memory successfully brought online */
403+
if (nid != NUMA_NO_NODE)
404+
hugetlb_register_node(&node_devices[nid]);
405+
break;
406+
case MEM_OFFLINE: /* or offline */
407+
if (nid != NUMA_NO_NODE)
408+
hugetlb_unregister_node(&node_devices[nid]);
409+
break;
410+
case MEM_GOING_ONLINE:
411+
case MEM_GOING_OFFLINE:
412+
case MEM_CANCEL_ONLINE:
413+
case MEM_CANCEL_OFFLINE:
414+
default:
415+
break;
416+
}
417+
418+
return NOTIFY_OK;
419+
}
387420
#else
388421
static int link_mem_sections(int nid) { return 0; }
422+
423+
static inline int node_memory_callback(struct notifier_block *self,
424+
unsigned long action, void *arg)
425+
{
426+
return NOTIFY_OK;
427+
}
389428
#endif /* CONFIG_MEMORY_HOTPLUG_SPARSE */
390429

391430
int register_one_node(int nid)
@@ -499,13 +538,17 @@ static int node_states_init(void)
499538
return err;
500539
}
501540

541+
#define NODE_CALLBACK_PRI 2 /* lower than SLAB */
502542
static int __init register_node_type(void)
503543
{
504544
int ret;
505545

506546
ret = sysdev_class_register(&node_class);
507-
if (!ret)
547+
if (!ret) {
508548
ret = node_states_init();
549+
hotplug_memory_notifier(node_memory_callback,
550+
NODE_CALLBACK_PRI);
551+
}
509552

510553
/*
511554
* Note: we're not going to unregister the node class if we fail

0 commit comments

Comments
 (0)