blob: ce27be2d001d9a983ce3916f4a9d7e4017ad8762 [file] [log] [blame]
xjb04a4022021-11-25 15:01:52 +08001// SPDX-License-Identifier: GPL-2.0
2/*
3 * Basic Node interface support
4 */
5
6#include <linux/module.h>
7#include <linux/init.h>
8#include <linux/mm.h>
9#include <linux/memory.h>
10#include <linux/vmstat.h>
11#include <linux/notifier.h>
12#include <linux/node.h>
13#include <linux/hugetlb.h>
14#include <linux/compaction.h>
15#include <linux/cpumask.h>
16#include <linux/topology.h>
17#include <linux/nodemask.h>
18#include <linux/cpu.h>
19#include <linux/device.h>
20#include <linux/swap.h>
21#include <linux/slab.h>
22
23static struct bus_type node_subsys = {
24 .name = "node",
25 .dev_name = "node",
26};
27
28
29static ssize_t node_read_cpumap(struct device *dev, bool list, char *buf)
30{
31 ssize_t n;
32 cpumask_var_t mask;
33 struct node *node_dev = to_node(dev);
34
35 /* 2008/04/07: buf currently PAGE_SIZE, need 9 chars per 32 bits. */
36 BUILD_BUG_ON((NR_CPUS/32 * 9) > (PAGE_SIZE-1));
37
38 if (!alloc_cpumask_var(&mask, GFP_KERNEL))
39 return 0;
40
41 cpumask_and(mask, cpumask_of_node(node_dev->dev.id), cpu_online_mask);
42 n = cpumap_print_to_pagebuf(list, buf, mask);
43 free_cpumask_var(mask);
44
45 return n;
46}
47
48static inline ssize_t node_read_cpumask(struct device *dev,
49 struct device_attribute *attr, char *buf)
50{
51 return node_read_cpumap(dev, false, buf);
52}
53static inline ssize_t node_read_cpulist(struct device *dev,
54 struct device_attribute *attr, char *buf)
55{
56 return node_read_cpumap(dev, true, buf);
57}
58
59static DEVICE_ATTR(cpumap, S_IRUGO, node_read_cpumask, NULL);
60static DEVICE_ATTR(cpulist, S_IRUGO, node_read_cpulist, NULL);
61
62#define K(x) ((x) << (PAGE_SHIFT - 10))
63static ssize_t node_read_meminfo(struct device *dev,
64 struct device_attribute *attr, char *buf)
65{
66 int n;
67 int nid = dev->id;
68 struct pglist_data *pgdat = NODE_DATA(nid);
69 struct sysinfo i;
70 unsigned long sreclaimable, sunreclaimable;
71
72 si_meminfo_node(&i, nid);
73 sreclaimable = node_page_state(pgdat, NR_SLAB_RECLAIMABLE);
74 sunreclaimable = node_page_state(pgdat, NR_SLAB_UNRECLAIMABLE);
75 n = sprintf(buf,
76 "Node %d MemTotal: %8lu kB\n"
77 "Node %d MemFree: %8lu kB\n"
78 "Node %d MemUsed: %8lu kB\n"
79 "Node %d Active: %8lu kB\n"
80 "Node %d Inactive: %8lu kB\n"
81 "Node %d Active(anon): %8lu kB\n"
82 "Node %d Inactive(anon): %8lu kB\n"
83 "Node %d Active(file): %8lu kB\n"
84 "Node %d Inactive(file): %8lu kB\n"
85 "Node %d Unevictable: %8lu kB\n"
86 "Node %d Mlocked: %8lu kB\n",
87 nid, K(i.totalram),
88 nid, K(i.freeram),
89 nid, K(i.totalram - i.freeram),
90 nid, K(node_page_state(pgdat, NR_ACTIVE_ANON) +
91 node_page_state(pgdat, NR_ACTIVE_FILE)),
92 nid, K(node_page_state(pgdat, NR_INACTIVE_ANON) +
93 node_page_state(pgdat, NR_INACTIVE_FILE)),
94 nid, K(node_page_state(pgdat, NR_ACTIVE_ANON)),
95 nid, K(node_page_state(pgdat, NR_INACTIVE_ANON)),
96 nid, K(node_page_state(pgdat, NR_ACTIVE_FILE)),
97 nid, K(node_page_state(pgdat, NR_INACTIVE_FILE)),
98 nid, K(node_page_state(pgdat, NR_UNEVICTABLE)),
99 nid, K(sum_zone_node_page_state(nid, NR_MLOCK)));
100
101#ifdef CONFIG_HIGHMEM
102 n += sprintf(buf + n,
103 "Node %d HighTotal: %8lu kB\n"
104 "Node %d HighFree: %8lu kB\n"
105 "Node %d LowTotal: %8lu kB\n"
106 "Node %d LowFree: %8lu kB\n",
107 nid, K(i.totalhigh),
108 nid, K(i.freehigh),
109 nid, K(i.totalram - i.totalhigh),
110 nid, K(i.freeram - i.freehigh));
111#endif
112 n += sprintf(buf + n,
113 "Node %d Dirty: %8lu kB\n"
114 "Node %d Writeback: %8lu kB\n"
115 "Node %d FilePages: %8lu kB\n"
116 "Node %d Mapped: %8lu kB\n"
117 "Node %d AnonPages: %8lu kB\n"
118 "Node %d Shmem: %8lu kB\n"
119 "Node %d KernelStack: %8lu kB\n"
120#ifdef CONFIG_SHADOW_CALL_STACK
121 "Node %d ShadowCallStack:%8lu kB\n"
122#endif
123 "Node %d PageTables: %8lu kB\n"
124 "Node %d NFS_Unstable: %8lu kB\n"
125 "Node %d Bounce: %8lu kB\n"
126 "Node %d WritebackTmp: %8lu kB\n"
127 "Node %d KReclaimable: %8lu kB\n"
128 "Node %d Slab: %8lu kB\n"
129 "Node %d SReclaimable: %8lu kB\n"
130 "Node %d SUnreclaim: %8lu kB\n"
131#ifdef CONFIG_TRANSPARENT_HUGEPAGE
132 "Node %d AnonHugePages: %8lu kB\n"
133 "Node %d ShmemHugePages: %8lu kB\n"
134 "Node %d ShmemPmdMapped: %8lu kB\n"
135#endif
136 ,
137 nid, K(node_page_state(pgdat, NR_FILE_DIRTY)),
138 nid, K(node_page_state(pgdat, NR_WRITEBACK)),
139 nid, K(node_page_state(pgdat, NR_FILE_PAGES)),
140 nid, K(node_page_state(pgdat, NR_FILE_MAPPED)),
141 nid, K(node_page_state(pgdat, NR_ANON_MAPPED)),
142 nid, K(i.sharedram),
143 nid, sum_zone_node_page_state(nid, NR_KERNEL_STACK_KB),
144#ifdef CONFIG_SHADOW_CALL_STACK
145 nid, sum_zone_node_page_state(nid, NR_KERNEL_SCS_BYTES) / 1024,
146#endif
147 nid, K(sum_zone_node_page_state(nid, NR_PAGETABLE)),
148 nid, K(node_page_state(pgdat, NR_UNSTABLE_NFS)),
149 nid, K(sum_zone_node_page_state(nid, NR_BOUNCE)),
150 nid, K(node_page_state(pgdat, NR_WRITEBACK_TEMP)),
151 nid, K(sreclaimable +
152 node_page_state(pgdat, NR_KERNEL_MISC_RECLAIMABLE)),
153 nid, K(sreclaimable + sunreclaimable),
154 nid, K(sreclaimable),
155 nid, K(sunreclaimable)
156#ifdef CONFIG_TRANSPARENT_HUGEPAGE
157 ,
158 nid, K(node_page_state(pgdat, NR_ANON_THPS) *
159 HPAGE_PMD_NR),
160 nid, K(node_page_state(pgdat, NR_SHMEM_THPS) *
161 HPAGE_PMD_NR),
162 nid, K(node_page_state(pgdat, NR_SHMEM_PMDMAPPED) *
163 HPAGE_PMD_NR)
164#endif
165 );
166 n += hugetlb_report_node_meminfo(nid, buf + n);
167 return n;
168}
169
170#undef K
171static DEVICE_ATTR(meminfo, S_IRUGO, node_read_meminfo, NULL);
172
173static ssize_t node_read_numastat(struct device *dev,
174 struct device_attribute *attr, char *buf)
175{
176 return sprintf(buf,
177 "numa_hit %lu\n"
178 "numa_miss %lu\n"
179 "numa_foreign %lu\n"
180 "interleave_hit %lu\n"
181 "local_node %lu\n"
182 "other_node %lu\n",
183 sum_zone_numa_state(dev->id, NUMA_HIT),
184 sum_zone_numa_state(dev->id, NUMA_MISS),
185 sum_zone_numa_state(dev->id, NUMA_FOREIGN),
186 sum_zone_numa_state(dev->id, NUMA_INTERLEAVE_HIT),
187 sum_zone_numa_state(dev->id, NUMA_LOCAL),
188 sum_zone_numa_state(dev->id, NUMA_OTHER));
189}
190static DEVICE_ATTR(numastat, S_IRUGO, node_read_numastat, NULL);
191
192static ssize_t node_read_vmstat(struct device *dev,
193 struct device_attribute *attr, char *buf)
194{
195 int nid = dev->id;
196 struct pglist_data *pgdat = NODE_DATA(nid);
197 int i;
198 int n = 0;
199
200 for (i = 0; i < NR_VM_ZONE_STAT_ITEMS; i++)
201 n += sprintf(buf+n, "%s %lu\n", vmstat_text[i],
202 sum_zone_node_page_state(nid, i));
203
204#ifdef CONFIG_NUMA
205 for (i = 0; i < NR_VM_NUMA_STAT_ITEMS; i++)
206 n += sprintf(buf+n, "%s %lu\n",
207 vmstat_text[i + NR_VM_ZONE_STAT_ITEMS],
208 sum_zone_numa_state(nid, i));
209#endif
210
211 for (i = 0; i < NR_VM_NODE_STAT_ITEMS; i++) {
212 /* Skip hidden vmstat items. */
213 if (*vmstat_text[i + NR_VM_ZONE_STAT_ITEMS +
214 NR_VM_NUMA_STAT_ITEMS] == '\0')
215 continue;
216 n += sprintf(buf+n, "%s %lu\n",
217 vmstat_text[i + NR_VM_ZONE_STAT_ITEMS +
218 NR_VM_NUMA_STAT_ITEMS],
219 node_page_state(pgdat, i));
220 }
221
222 return n;
223}
224static DEVICE_ATTR(vmstat, S_IRUGO, node_read_vmstat, NULL);
225
226static ssize_t node_read_distance(struct device *dev,
227 struct device_attribute *attr, char *buf)
228{
229 int nid = dev->id;
230 int len = 0;
231 int i;
232
233 /*
234 * buf is currently PAGE_SIZE in length and each node needs 4 chars
235 * at the most (distance + space or newline).
236 */
237 BUILD_BUG_ON(MAX_NUMNODES * 4 > PAGE_SIZE);
238
239 for_each_online_node(i)
240 len += sprintf(buf + len, "%s%d", i ? " " : "", node_distance(nid, i));
241
242 len += sprintf(buf + len, "\n");
243 return len;
244}
245static DEVICE_ATTR(distance, S_IRUGO, node_read_distance, NULL);
246
247static struct attribute *node_dev_attrs[] = {
248 &dev_attr_cpumap.attr,
249 &dev_attr_cpulist.attr,
250 &dev_attr_meminfo.attr,
251 &dev_attr_numastat.attr,
252 &dev_attr_distance.attr,
253 &dev_attr_vmstat.attr,
254 NULL
255};
256ATTRIBUTE_GROUPS(node_dev);
257
258#ifdef CONFIG_HUGETLBFS
259/*
260 * hugetlbfs per node attributes registration interface:
261 * When/if hugetlb[fs] subsystem initializes [sometime after this module],
262 * it will register its per node attributes for all online nodes with
263 * memory. It will also call register_hugetlbfs_with_node(), below, to
264 * register its attribute registration functions with this node driver.
265 * Once these hooks have been initialized, the node driver will call into
266 * the hugetlb module to [un]register attributes for hot-plugged nodes.
267 */
268static node_registration_func_t __hugetlb_register_node;
269static node_registration_func_t __hugetlb_unregister_node;
270
271static inline bool hugetlb_register_node(struct node *node)
272{
273 if (__hugetlb_register_node &&
274 node_state(node->dev.id, N_MEMORY)) {
275 __hugetlb_register_node(node);
276 return true;
277 }
278 return false;
279}
280
281static inline void hugetlb_unregister_node(struct node *node)
282{
283 if (__hugetlb_unregister_node)
284 __hugetlb_unregister_node(node);
285}
286
287void register_hugetlbfs_with_node(node_registration_func_t doregister,
288 node_registration_func_t unregister)
289{
290 __hugetlb_register_node = doregister;
291 __hugetlb_unregister_node = unregister;
292}
293#else
294static inline void hugetlb_register_node(struct node *node) {}
295
296static inline void hugetlb_unregister_node(struct node *node) {}
297#endif
298
299static void node_device_release(struct device *dev)
300{
301 struct node *node = to_node(dev);
302
303#if defined(CONFIG_MEMORY_HOTPLUG_SPARSE) && defined(CONFIG_HUGETLBFS)
304 /*
305 * We schedule the work only when a memory section is
306 * onlined/offlined on this node. When we come here,
307 * all the memory on this node has been offlined,
308 * so we won't enqueue new work to this work.
309 *
310 * The work is using node->node_work, so we should
311 * flush work before freeing the memory.
312 */
313 flush_work(&node->node_work);
314#endif
315 kfree(node);
316}
317
318/*
319 * register_node - Setup a sysfs device for a node.
320 * @num - Node number to use when creating the device.
321 *
322 * Initialize and register the node device.
323 */
324static int register_node(struct node *node, int num)
325{
326 int error;
327
328 node->dev.id = num;
329 node->dev.bus = &node_subsys;
330 node->dev.release = node_device_release;
331 node->dev.groups = node_dev_groups;
332 error = device_register(&node->dev);
333
334 if (error)
335 put_device(&node->dev);
336 else {
337 hugetlb_register_node(node);
338
339 compaction_register_node(node);
340 }
341 return error;
342}
343
344/**
345 * unregister_node - unregister a node device
346 * @node: node going away
347 *
348 * Unregisters a node device @node. All the devices on the node must be
349 * unregistered before calling this function.
350 */
351void unregister_node(struct node *node)
352{
353 hugetlb_unregister_node(node); /* no-op, if memoryless node */
354
355 device_unregister(&node->dev);
356}
357
358struct node *node_devices[MAX_NUMNODES];
359
360/*
361 * register cpu under node
362 */
363int register_cpu_under_node(unsigned int cpu, unsigned int nid)
364{
365 int ret;
366 struct device *obj;
367
368 if (!node_online(nid))
369 return 0;
370
371 obj = get_cpu_device(cpu);
372 if (!obj)
373 return 0;
374
375 ret = sysfs_create_link(&node_devices[nid]->dev.kobj,
376 &obj->kobj,
377 kobject_name(&obj->kobj));
378 if (ret)
379 return ret;
380
381 return sysfs_create_link(&obj->kobj,
382 &node_devices[nid]->dev.kobj,
383 kobject_name(&node_devices[nid]->dev.kobj));
384}
385
386int unregister_cpu_under_node(unsigned int cpu, unsigned int nid)
387{
388 struct device *obj;
389
390 if (!node_online(nid))
391 return 0;
392
393 obj = get_cpu_device(cpu);
394 if (!obj)
395 return 0;
396
397 sysfs_remove_link(&node_devices[nid]->dev.kobj,
398 kobject_name(&obj->kobj));
399 sysfs_remove_link(&obj->kobj,
400 kobject_name(&node_devices[nid]->dev.kobj));
401
402 return 0;
403}
404
405#ifdef CONFIG_MEMORY_HOTPLUG_SPARSE
406static int __ref get_nid_for_pfn(unsigned long pfn)
407{
408 if (!pfn_valid_within(pfn))
409 return -1;
410#ifdef CONFIG_DEFERRED_STRUCT_PAGE_INIT
411 if (system_state < SYSTEM_RUNNING)
412 return early_pfn_to_nid(pfn);
413#endif
414 return pfn_to_nid(pfn);
415}
416
417/* register memory section under specified node if it spans that node */
418int register_mem_sect_under_node(struct memory_block *mem_blk, void *arg)
419{
420 int ret, nid = *(int *)arg;
421 unsigned long pfn, sect_start_pfn, sect_end_pfn;
422
423 mem_blk->nid = nid;
424
425 sect_start_pfn = section_nr_to_pfn(mem_blk->start_section_nr);
426 sect_end_pfn = section_nr_to_pfn(mem_blk->end_section_nr);
427 sect_end_pfn += PAGES_PER_SECTION - 1;
428 for (pfn = sect_start_pfn; pfn <= sect_end_pfn; pfn++) {
429 int page_nid;
430
431 /*
432 * memory block could have several absent sections from start.
433 * skip pfn range from absent section
434 */
435 if (!pfn_present(pfn)) {
436 pfn = round_down(pfn + PAGES_PER_SECTION,
437 PAGES_PER_SECTION) - 1;
438 continue;
439 }
440
441 /*
442 * We need to check if page belongs to nid only for the boot
443 * case, during hotplug we know that all pages in the memory
444 * block belong to the same node.
445 */
446 if (system_state == SYSTEM_BOOTING) {
447 page_nid = get_nid_for_pfn(pfn);
448 if (page_nid < 0)
449 continue;
450 if (page_nid != nid)
451 continue;
452 }
453 ret = sysfs_create_link_nowarn(&node_devices[nid]->dev.kobj,
454 &mem_blk->dev.kobj,
455 kobject_name(&mem_blk->dev.kobj));
456 if (ret)
457 return ret;
458
459 return sysfs_create_link_nowarn(&mem_blk->dev.kobj,
460 &node_devices[nid]->dev.kobj,
461 kobject_name(&node_devices[nid]->dev.kobj));
462 }
463 /* mem section does not span the specified node */
464 return 0;
465}
466
467/* unregister memory section under all nodes that it spans */
468int unregister_mem_sect_under_nodes(struct memory_block *mem_blk,
469 unsigned long phys_index)
470{
471 NODEMASK_ALLOC(nodemask_t, unlinked_nodes, GFP_KERNEL);
472 unsigned long pfn, sect_start_pfn, sect_end_pfn;
473
474 if (!mem_blk) {
475 NODEMASK_FREE(unlinked_nodes);
476 return -EFAULT;
477 }
478 if (!unlinked_nodes)
479 return -ENOMEM;
480 nodes_clear(*unlinked_nodes);
481
482 sect_start_pfn = section_nr_to_pfn(phys_index);
483 sect_end_pfn = sect_start_pfn + PAGES_PER_SECTION - 1;
484 for (pfn = sect_start_pfn; pfn <= sect_end_pfn; pfn++) {
485 int nid;
486
487 nid = get_nid_for_pfn(pfn);
488 if (nid < 0)
489 continue;
490 if (!node_online(nid))
491 continue;
492 if (node_test_and_set(nid, *unlinked_nodes))
493 continue;
494 sysfs_remove_link(&node_devices[nid]->dev.kobj,
495 kobject_name(&mem_blk->dev.kobj));
496 sysfs_remove_link(&mem_blk->dev.kobj,
497 kobject_name(&node_devices[nid]->dev.kobj));
498 }
499 NODEMASK_FREE(unlinked_nodes);
500 return 0;
501}
502
503int link_mem_sections(int nid, unsigned long start_pfn, unsigned long end_pfn)
504{
505 return walk_memory_range(start_pfn, end_pfn, (void *)&nid,
506 register_mem_sect_under_node);
507}
508
509#ifdef CONFIG_HUGETLBFS
510/*
511 * Handle per node hstate attribute [un]registration on transistions
512 * to/from memoryless state.
513 */
514static void node_hugetlb_work(struct work_struct *work)
515{
516 struct node *node = container_of(work, struct node, node_work);
517
518 /*
519 * We only get here when a node transitions to/from memoryless state.
520 * We can detect which transition occurred by examining whether the
521 * node has memory now. hugetlb_register_node() already check this
522 * so we try to register the attributes. If that fails, then the
523 * node has transitioned to memoryless, try to unregister the
524 * attributes.
525 */
526 if (!hugetlb_register_node(node))
527 hugetlb_unregister_node(node);
528}
529
530static void init_node_hugetlb_work(int nid)
531{
532 INIT_WORK(&node_devices[nid]->node_work, node_hugetlb_work);
533}
534
535static int node_memory_callback(struct notifier_block *self,
536 unsigned long action, void *arg)
537{
538 struct memory_notify *mnb = arg;
539 int nid = mnb->status_change_nid;
540
541 switch (action) {
542 case MEM_ONLINE:
543 case MEM_OFFLINE:
544 /*
545 * offload per node hstate [un]registration to a work thread
546 * when transitioning to/from memoryless state.
547 */
548 if (nid != NUMA_NO_NODE)
549 schedule_work(&node_devices[nid]->node_work);
550 break;
551
552 case MEM_GOING_ONLINE:
553 case MEM_GOING_OFFLINE:
554 case MEM_CANCEL_ONLINE:
555 case MEM_CANCEL_OFFLINE:
556 default:
557 break;
558 }
559
560 return NOTIFY_OK;
561}
562#endif /* CONFIG_HUGETLBFS */
563#endif /* CONFIG_MEMORY_HOTPLUG_SPARSE */
564
565#if !defined(CONFIG_MEMORY_HOTPLUG_SPARSE) || \
566 !defined(CONFIG_HUGETLBFS)
567static inline int node_memory_callback(struct notifier_block *self,
568 unsigned long action, void *arg)
569{
570 return NOTIFY_OK;
571}
572
573static void init_node_hugetlb_work(int nid) { }
574
575#endif
576
577int __register_one_node(int nid)
578{
579 int error;
580 int cpu;
581
582 node_devices[nid] = kzalloc(sizeof(struct node), GFP_KERNEL);
583 if (!node_devices[nid])
584 return -ENOMEM;
585
586 error = register_node(node_devices[nid], nid);
587
588 /* link cpu under this node */
589 for_each_present_cpu(cpu) {
590 if (cpu_to_node(cpu) == nid)
591 register_cpu_under_node(cpu, nid);
592 }
593
594 /* initialize work queue for memory hot plug */
595 init_node_hugetlb_work(nid);
596
597 return error;
598}
599
600void unregister_one_node(int nid)
601{
602 if (!node_devices[nid])
603 return;
604
605 unregister_node(node_devices[nid]);
606 node_devices[nid] = NULL;
607}
608
609/*
610 * node states attributes
611 */
612
613static ssize_t print_nodes_state(enum node_states state, char *buf)
614{
615 int n;
616
617 n = scnprintf(buf, PAGE_SIZE - 1, "%*pbl",
618 nodemask_pr_args(&node_states[state]));
619 buf[n++] = '\n';
620 buf[n] = '\0';
621 return n;
622}
623
624struct node_attr {
625 struct device_attribute attr;
626 enum node_states state;
627};
628
629static ssize_t show_node_state(struct device *dev,
630 struct device_attribute *attr, char *buf)
631{
632 struct node_attr *na = container_of(attr, struct node_attr, attr);
633 return print_nodes_state(na->state, buf);
634}
635
636#define _NODE_ATTR(name, state) \
637 { __ATTR(name, 0444, show_node_state, NULL), state }
638
639static struct node_attr node_state_attr[] = {
640 [N_POSSIBLE] = _NODE_ATTR(possible, N_POSSIBLE),
641 [N_ONLINE] = _NODE_ATTR(online, N_ONLINE),
642 [N_NORMAL_MEMORY] = _NODE_ATTR(has_normal_memory, N_NORMAL_MEMORY),
643#ifdef CONFIG_HIGHMEM
644 [N_HIGH_MEMORY] = _NODE_ATTR(has_high_memory, N_HIGH_MEMORY),
645#endif
646 [N_MEMORY] = _NODE_ATTR(has_memory, N_MEMORY),
647 [N_CPU] = _NODE_ATTR(has_cpu, N_CPU),
648};
649
650static struct attribute *node_state_attrs[] = {
651 &node_state_attr[N_POSSIBLE].attr.attr,
652 &node_state_attr[N_ONLINE].attr.attr,
653 &node_state_attr[N_NORMAL_MEMORY].attr.attr,
654#ifdef CONFIG_HIGHMEM
655 &node_state_attr[N_HIGH_MEMORY].attr.attr,
656#endif
657 &node_state_attr[N_MEMORY].attr.attr,
658 &node_state_attr[N_CPU].attr.attr,
659 NULL
660};
661
662static struct attribute_group memory_root_attr_group = {
663 .attrs = node_state_attrs,
664};
665
666static const struct attribute_group *cpu_root_attr_groups[] = {
667 &memory_root_attr_group,
668 NULL,
669};
670
671#define NODE_CALLBACK_PRI 2 /* lower than SLAB */
672static int __init register_node_type(void)
673{
674 int ret;
675
676 BUILD_BUG_ON(ARRAY_SIZE(node_state_attr) != NR_NODE_STATES);
677 BUILD_BUG_ON(ARRAY_SIZE(node_state_attrs)-1 != NR_NODE_STATES);
678
679 ret = subsys_system_register(&node_subsys, cpu_root_attr_groups);
680 if (!ret) {
681 static struct notifier_block node_memory_callback_nb = {
682 .notifier_call = node_memory_callback,
683 .priority = NODE_CALLBACK_PRI,
684 };
685 register_hotmemory_notifier(&node_memory_callback_nb);
686 }
687
688 /*
689 * Note: we're not going to unregister the node class if we fail
690 * to register the node state class attribute files.
691 */
692 return ret;
693}
694postcore_initcall(register_node_type);