Skip to content

Commit 39da08c

Browse files
Lee Schermerhorntorvalds
authored andcommitted
hugetlb: offload per node attribute registrations
Offload the registration and unregistration of per node hstate sysfs attributes to a worker thread rather than attempt the allocation/attachment or detachment/freeing of the attributes in the context of the memory hotplug handler. I don't know that this is absolutely required, but the registration can sleep in allocations and other mem hot plug handlers do it this way. If it turns out this is NOT required, we can drop this patch. 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> 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: David Rientjes <rientjes@google.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 4faf8d9 commit 39da08c

2 files changed

Lines changed: 52 additions & 10 deletions

File tree

‎drivers/base/node.c‎

Lines changed: 47 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -186,11 +186,14 @@ static SYSDEV_ATTR(distance, S_IRUGO, node_read_distance, NULL);
186186
static node_registration_func_t __hugetlb_register_node;
187187
static node_registration_func_t __hugetlb_unregister_node;
188188

189-
static inline void hugetlb_register_node(struct node *node)
189+
static inline bool hugetlb_register_node(struct node *node)
190190
{
191191
if (__hugetlb_register_node &&
192-
node_state(node->sysdev.id, N_HIGH_MEMORY))
192+
node_state(node->sysdev.id, N_HIGH_MEMORY)) {
193193
__hugetlb_register_node(node);
194+
return true;
195+
}
196+
return false;
194197
}
195198

196199
static inline void hugetlb_unregister_node(struct node *node)
@@ -387,10 +390,31 @@ static int link_mem_sections(int nid)
387390
return err;
388391
}
389392

393+
#ifdef CONFIG_HUGETLBFS
390394
/*
391395
* Handle per node hstate attribute [un]registration on transistions
392396
* to/from memoryless state.
393397
*/
398+
static void node_hugetlb_work(struct work_struct *work)
399+
{
400+
struct node *node = container_of(work, struct node, node_work);
401+
402+
/*
403+
* We only get here when a node transitions to/from memoryless state.
404+
* We can detect which transition occurred by examining whether the
405+
* node has memory now. hugetlb_register_node() already check this
406+
* so we try to register the attributes. If that fails, then the
407+
* node has transitioned to memoryless, try to unregister the
408+
* attributes.
409+
*/
410+
if (!hugetlb_register_node(node))
411+
hugetlb_unregister_node(node);
412+
}
413+
414+
static void init_node_hugetlb_work(int nid)
415+
{
416+
INIT_WORK(&node_devices[nid].node_work, node_hugetlb_work);
417+
}
394418

395419
static int node_memory_callback(struct notifier_block *self,
396420
unsigned long action, void *arg)
@@ -399,14 +423,16 @@ static int node_memory_callback(struct notifier_block *self,
399423
int nid = mnb->status_change_nid;
400424

401425
switch (action) {
402-
case MEM_ONLINE: /* memory successfully brought online */
426+
case MEM_ONLINE:
427+
case MEM_OFFLINE:
428+
/*
429+
* offload per node hstate [un]registration to a work thread
430+
* when transitioning to/from memoryless state.
431+
*/
403432
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]);
433+
schedule_work(&node_devices[nid].node_work);
409434
break;
435+
410436
case MEM_GOING_ONLINE:
411437
case MEM_GOING_OFFLINE:
412438
case MEM_CANCEL_ONLINE:
@@ -417,15 +443,23 @@ static int node_memory_callback(struct notifier_block *self,
417443

418444
return NOTIFY_OK;
419445
}
420-
#else
446+
#endif /* CONFIG_HUGETLBFS */
447+
#else /* !CONFIG_MEMORY_HOTPLUG_SPARSE */
448+
421449
static int link_mem_sections(int nid) { return 0; }
450+
#endif /* CONFIG_MEMORY_HOTPLUG_SPARSE */
422451

452+
#if !defined(CONFIG_MEMORY_HOTPLUG_SPARSE) || \
453+
!defined(CONFIG_HUGETLBFS)
423454
static inline int node_memory_callback(struct notifier_block *self,
424455
unsigned long action, void *arg)
425456
{
426457
return NOTIFY_OK;
427458
}
428-
#endif /* CONFIG_MEMORY_HOTPLUG_SPARSE */
459+
460+
static void init_node_hugetlb_work(int nid) { }
461+
462+
#endif
429463

430464
int register_one_node(int nid)
431465
{
@@ -449,6 +483,9 @@ int register_one_node(int nid)
449483

450484
/* link memory sections under this node */
451485
error = link_mem_sections(nid);
486+
487+
/* initialize work queue for memory hot plug */
488+
init_node_hugetlb_work(nid);
452489
}
453490

454491
return error;

‎include/linux/node.h‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,14 @@
2121

2222
#include <linux/sysdev.h>
2323
#include <linux/cpumask.h>
24+
#include <linux/workqueue.h>
2425

2526
struct node {
2627
struct sys_device sysdev;
28+
29+
#if defined(CONFIG_MEMORY_HOTPLUG_SPARSE) && defined(CONFIG_HUGETLBFS)
30+
struct work_struct node_work;
31+
#endif
2732
};
2833

2934
struct memory_block;

0 commit comments

Comments
 (0)