]> git.ipfire.org Git - thirdparty/kernel/stable.git/blame - drivers/base/node.c
mm: compaction: add /proc trigger for memory compaction
[thirdparty/kernel/stable.git] / drivers / base / node.c
CommitLineData
1da177e4
LT
1/*
2 * drivers/base/node.c - basic Node class support
3 */
4
5#include <linux/sysdev.h>
6#include <linux/module.h>
7#include <linux/init.h>
8#include <linux/mm.h>
c04fc586 9#include <linux/memory.h>
1da177e4
LT
10#include <linux/node.h>
11#include <linux/hugetlb.h>
12#include <linux/cpumask.h>
13#include <linux/topology.h>
14#include <linux/nodemask.h>
76b67ed9 15#include <linux/cpu.h>
bde631a5 16#include <linux/device.h>
af936a16 17#include <linux/swap.h>
18e5b539 18#include <linux/slab.h>
1da177e4 19
3701cde6
AK
20static struct sysdev_class_attribute *node_state_attrs[];
21
1da177e4 22static struct sysdev_class node_class = {
af5ca3f4 23 .name = "node",
3701cde6 24 .attrs = node_state_attrs,
1da177e4
LT
25};
26
27
39106dcf 28static ssize_t node_read_cpumap(struct sys_device *dev, int type, char *buf)
1da177e4
LT
29{
30 struct node *node_dev = to_node(dev);
a70f7302 31 const struct cpumask *mask = cpumask_of_node(node_dev->sysdev.id);
1da177e4
LT
32 int len;
33
39106dcf
MT
34 /* 2008/04/07: buf currently PAGE_SIZE, need 9 chars per 32 bits. */
35 BUILD_BUG_ON((NR_CPUS/32 * 9) > (PAGE_SIZE-1));
1da177e4 36
39106dcf 37 len = type?
29c0177e
RR
38 cpulist_scnprintf(buf, PAGE_SIZE-2, mask) :
39 cpumask_scnprintf(buf, PAGE_SIZE-2, mask);
c5f59f08
MT
40 buf[len++] = '\n';
41 buf[len] = '\0';
1da177e4
LT
42 return len;
43}
44
4a0b2b4d
AK
45static inline ssize_t node_read_cpumask(struct sys_device *dev,
46 struct sysdev_attribute *attr, char *buf)
39106dcf
MT
47{
48 return node_read_cpumap(dev, 0, buf);
49}
4a0b2b4d
AK
50static inline ssize_t node_read_cpulist(struct sys_device *dev,
51 struct sysdev_attribute *attr, char *buf)
39106dcf
MT
52{
53 return node_read_cpumap(dev, 1, buf);
54}
55
56static SYSDEV_ATTR(cpumap, S_IRUGO, node_read_cpumask, NULL);
57static SYSDEV_ATTR(cpulist, S_IRUGO, node_read_cpulist, NULL);
1da177e4
LT
58
59#define K(x) ((x) << (PAGE_SHIFT - 10))
4a0b2b4d
AK
60static ssize_t node_read_meminfo(struct sys_device * dev,
61 struct sysdev_attribute *attr, char * buf)
1da177e4
LT
62{
63 int n;
64 int nid = dev->id;
65 struct sysinfo i;
1da177e4
LT
66
67 si_meminfo_node(&i, nid);
c07e02db 68
1da177e4 69 n = sprintf(buf, "\n"
4f98a2fe
RR
70 "Node %d MemTotal: %8lu kB\n"
71 "Node %d MemFree: %8lu kB\n"
72 "Node %d MemUsed: %8lu kB\n"
73 "Node %d Active: %8lu kB\n"
74 "Node %d Inactive: %8lu kB\n"
75 "Node %d Active(anon): %8lu kB\n"
76 "Node %d Inactive(anon): %8lu kB\n"
77 "Node %d Active(file): %8lu kB\n"
78 "Node %d Inactive(file): %8lu kB\n"
5344b7e6
NP
79 "Node %d Unevictable: %8lu kB\n"
80 "Node %d Mlocked: %8lu kB\n"
182e8e23 81#ifdef CONFIG_HIGHMEM
4f98a2fe
RR
82 "Node %d HighTotal: %8lu kB\n"
83 "Node %d HighFree: %8lu kB\n"
84 "Node %d LowTotal: %8lu kB\n"
85 "Node %d LowFree: %8lu kB\n"
182e8e23 86#endif
4f98a2fe
RR
87 "Node %d Dirty: %8lu kB\n"
88 "Node %d Writeback: %8lu kB\n"
89 "Node %d FilePages: %8lu kB\n"
90 "Node %d Mapped: %8lu kB\n"
91 "Node %d AnonPages: %8lu kB\n"
4b02108a 92 "Node %d Shmem: %8lu kB\n"
c6a7f572 93 "Node %d KernelStack: %8lu kB\n"
4f98a2fe
RR
94 "Node %d PageTables: %8lu kB\n"
95 "Node %d NFS_Unstable: %8lu kB\n"
96 "Node %d Bounce: %8lu kB\n"
97 "Node %d WritebackTmp: %8lu kB\n"
98 "Node %d Slab: %8lu kB\n"
99 "Node %d SReclaimable: %8lu kB\n"
100 "Node %d SUnreclaim: %8lu kB\n",
1da177e4
LT
101 nid, K(i.totalram),
102 nid, K(i.freeram),
103 nid, K(i.totalram - i.freeram),
4f98a2fe
RR
104 nid, K(node_page_state(nid, NR_ACTIVE_ANON) +
105 node_page_state(nid, NR_ACTIVE_FILE)),
106 nid, K(node_page_state(nid, NR_INACTIVE_ANON) +
107 node_page_state(nid, NR_INACTIVE_FILE)),
108 nid, K(node_page_state(nid, NR_ACTIVE_ANON)),
109 nid, K(node_page_state(nid, NR_INACTIVE_ANON)),
110 nid, K(node_page_state(nid, NR_ACTIVE_FILE)),
111 nid, K(node_page_state(nid, NR_INACTIVE_FILE)),
7b854121 112 nid, K(node_page_state(nid, NR_UNEVICTABLE)),
5344b7e6 113 nid, K(node_page_state(nid, NR_MLOCK)),
182e8e23 114#ifdef CONFIG_HIGHMEM
1da177e4
LT
115 nid, K(i.totalhigh),
116 nid, K(i.freehigh),
117 nid, K(i.totalram - i.totalhigh),
c07e02db 118 nid, K(i.freeram - i.freehigh),
182e8e23 119#endif
b1e7a8fd 120 nid, K(node_page_state(nid, NR_FILE_DIRTY)),
ce866b34 121 nid, K(node_page_state(nid, NR_WRITEBACK)),
347ce434 122 nid, K(node_page_state(nid, NR_FILE_PAGES)),
65ba55f5 123 nid, K(node_page_state(nid, NR_FILE_MAPPED)),
f3dbd344 124 nid, K(node_page_state(nid, NR_ANON_PAGES)),
4b02108a 125 nid, K(node_page_state(nid, NR_SHMEM)),
c6a7f572
KM
126 nid, node_page_state(nid, NR_KERNEL_STACK) *
127 THREAD_SIZE / 1024,
df849a15 128 nid, K(node_page_state(nid, NR_PAGETABLE)),
fd39fc85 129 nid, K(node_page_state(nid, NR_UNSTABLE_NFS)),
d2c5e30c 130 nid, K(node_page_state(nid, NR_BOUNCE)),
fc3ba692 131 nid, K(node_page_state(nid, NR_WRITEBACK_TEMP)),
972d1a7b
CL
132 nid, K(node_page_state(nid, NR_SLAB_RECLAIMABLE) +
133 node_page_state(nid, NR_SLAB_UNRECLAIMABLE)),
134 nid, K(node_page_state(nid, NR_SLAB_RECLAIMABLE)),
135 nid, K(node_page_state(nid, NR_SLAB_UNRECLAIMABLE)));
1da177e4
LT
136 n += hugetlb_report_node_meminfo(nid, buf + n);
137 return n;
138}
139
140#undef K
141static SYSDEV_ATTR(meminfo, S_IRUGO, node_read_meminfo, NULL);
142
4a0b2b4d
AK
143static ssize_t node_read_numastat(struct sys_device * dev,
144 struct sysdev_attribute *attr, char * buf)
1da177e4 145{
1da177e4
LT
146 return sprintf(buf,
147 "numa_hit %lu\n"
148 "numa_miss %lu\n"
149 "numa_foreign %lu\n"
150 "interleave_hit %lu\n"
151 "local_node %lu\n"
152 "other_node %lu\n",
ca889e6c
CL
153 node_page_state(dev->id, NUMA_HIT),
154 node_page_state(dev->id, NUMA_MISS),
155 node_page_state(dev->id, NUMA_FOREIGN),
156 node_page_state(dev->id, NUMA_INTERLEAVE_HIT),
157 node_page_state(dev->id, NUMA_LOCAL),
158 node_page_state(dev->id, NUMA_OTHER));
1da177e4
LT
159}
160static SYSDEV_ATTR(numastat, S_IRUGO, node_read_numastat, NULL);
161
4a0b2b4d
AK
162static ssize_t node_read_distance(struct sys_device * dev,
163 struct sysdev_attribute *attr, char * buf)
1da177e4
LT
164{
165 int nid = dev->id;
166 int len = 0;
167 int i;
168
12ee3c0a
DR
169 /*
170 * buf is currently PAGE_SIZE in length and each node needs 4 chars
171 * at the most (distance + space or newline).
172 */
173 BUILD_BUG_ON(MAX_NUMNODES * 4 > PAGE_SIZE);
1da177e4
LT
174
175 for_each_online_node(i)
176 len += sprintf(buf + len, "%s%d", i ? " " : "", node_distance(nid, i));
177
178 len += sprintf(buf + len, "\n");
179 return len;
180}
181static SYSDEV_ATTR(distance, S_IRUGO, node_read_distance, NULL);
182
9a305230
LS
183#ifdef CONFIG_HUGETLBFS
184/*
185 * hugetlbfs per node attributes registration interface:
186 * When/if hugetlb[fs] subsystem initializes [sometime after this module],
4faf8d95
LS
187 * it will register its per node attributes for all online nodes with
188 * memory. It will also call register_hugetlbfs_with_node(), below, to
9a305230
LS
189 * register its attribute registration functions with this node driver.
190 * Once these hooks have been initialized, the node driver will call into
191 * the hugetlb module to [un]register attributes for hot-plugged nodes.
192 */
193static node_registration_func_t __hugetlb_register_node;
194static node_registration_func_t __hugetlb_unregister_node;
195
39da08cb 196static inline bool hugetlb_register_node(struct node *node)
9a305230 197{
4faf8d95 198 if (__hugetlb_register_node &&
39da08cb 199 node_state(node->sysdev.id, N_HIGH_MEMORY)) {
9a305230 200 __hugetlb_register_node(node);
39da08cb
LS
201 return true;
202 }
203 return false;
9a305230
LS
204}
205
206static inline void hugetlb_unregister_node(struct node *node)
207{
208 if (__hugetlb_unregister_node)
209 __hugetlb_unregister_node(node);
210}
211
212void register_hugetlbfs_with_node(node_registration_func_t doregister,
213 node_registration_func_t unregister)
214{
215 __hugetlb_register_node = doregister;
216 __hugetlb_unregister_node = unregister;
217}
218#else
219static inline void hugetlb_register_node(struct node *node) {}
220
221static inline void hugetlb_unregister_node(struct node *node) {}
222#endif
223
1da177e4
LT
224
225/*
405ae7d3 226 * register_node - Setup a sysfs device for a node.
1da177e4
LT
227 * @num - Node number to use when creating the device.
228 *
229 * Initialize and register the node device.
230 */
4b45099b 231int register_node(struct node *node, int num, struct node *parent)
1da177e4
LT
232{
233 int error;
234
235 node->sysdev.id = num;
236 node->sysdev.cls = &node_class;
237 error = sysdev_register(&node->sysdev);
238
239 if (!error){
240 sysdev_create_file(&node->sysdev, &attr_cpumap);
39106dcf 241 sysdev_create_file(&node->sysdev, &attr_cpulist);
1da177e4
LT
242 sysdev_create_file(&node->sysdev, &attr_meminfo);
243 sysdev_create_file(&node->sysdev, &attr_numastat);
244 sysdev_create_file(&node->sysdev, &attr_distance);
af936a16
LS
245
246 scan_unevictable_register_node(node);
4faf8d95 247
9a305230 248 hugetlb_register_node(node);
1da177e4
LT
249 }
250 return error;
251}
252
4b45099b
KT
253/**
254 * unregister_node - unregister a node device
255 * @node: node going away
256 *
257 * Unregisters a node device @node. All the devices on the node must be
258 * unregistered before calling this function.
259 */
260void unregister_node(struct node *node)
261{
262 sysdev_remove_file(&node->sysdev, &attr_cpumap);
39106dcf 263 sysdev_remove_file(&node->sysdev, &attr_cpulist);
4b45099b
KT
264 sysdev_remove_file(&node->sysdev, &attr_meminfo);
265 sysdev_remove_file(&node->sysdev, &attr_numastat);
266 sysdev_remove_file(&node->sysdev, &attr_distance);
267
af936a16 268 scan_unevictable_unregister_node(node);
4faf8d95 269 hugetlb_unregister_node(node); /* no-op, if memoryless node */
af936a16 270
4b45099b
KT
271 sysdev_unregister(&node->sysdev);
272}
1da177e4 273
0fc44159
YG
274struct node node_devices[MAX_NUMNODES];
275
76b67ed9
KH
276/*
277 * register cpu under node
278 */
279int register_cpu_under_node(unsigned int cpu, unsigned int nid)
280{
1830794a 281 int ret;
f8246f31 282 struct sys_device *obj;
76b67ed9 283
f8246f31
AC
284 if (!node_online(nid))
285 return 0;
286
287 obj = get_cpu_sysdev(cpu);
288 if (!obj)
289 return 0;
290
1830794a 291 ret = sysfs_create_link(&node_devices[nid].sysdev.kobj,
f8246f31
AC
292 &obj->kobj,
293 kobject_name(&obj->kobj));
1830794a
AC
294 if (ret)
295 return ret;
296
297 return sysfs_create_link(&obj->kobj,
298 &node_devices[nid].sysdev.kobj,
299 kobject_name(&node_devices[nid].sysdev.kobj));
76b67ed9
KH
300}
301
302int unregister_cpu_under_node(unsigned int cpu, unsigned int nid)
303{
b9d52dad
AC
304 struct sys_device *obj;
305
306 if (!node_online(nid))
307 return 0;
308
309 obj = get_cpu_sysdev(cpu);
310 if (!obj)
311 return 0;
312
313 sysfs_remove_link(&node_devices[nid].sysdev.kobj,
314 kobject_name(&obj->kobj));
1830794a
AC
315 sysfs_remove_link(&obj->kobj,
316 kobject_name(&node_devices[nid].sysdev.kobj));
b9d52dad 317
76b67ed9
KH
318 return 0;
319}
320
c04fc586
GH
321#ifdef CONFIG_MEMORY_HOTPLUG_SPARSE
322#define page_initialized(page) (page->lru.next)
323
324static int get_nid_for_pfn(unsigned long pfn)
325{
326 struct page *page;
327
328 if (!pfn_valid_within(pfn))
329 return -1;
330 page = pfn_to_page(pfn);
331 if (!page_initialized(page))
332 return -1;
333 return pfn_to_nid(pfn);
334}
335
336/* register memory section under specified node if it spans that node */
337int register_mem_sect_under_node(struct memory_block *mem_blk, int nid)
338{
dee5d0d5 339 int ret;
c04fc586
GH
340 unsigned long pfn, sect_start_pfn, sect_end_pfn;
341
342 if (!mem_blk)
343 return -EFAULT;
344 if (!node_online(nid))
345 return 0;
346 sect_start_pfn = section_nr_to_pfn(mem_blk->phys_index);
347 sect_end_pfn = sect_start_pfn + PAGES_PER_SECTION - 1;
348 for (pfn = sect_start_pfn; pfn <= sect_end_pfn; pfn++) {
349 int page_nid;
350
351 page_nid = get_nid_for_pfn(pfn);
352 if (page_nid < 0)
353 continue;
354 if (page_nid != nid)
355 continue;
dee5d0d5 356 ret = sysfs_create_link_nowarn(&node_devices[nid].sysdev.kobj,
c04fc586
GH
357 &mem_blk->sysdev.kobj,
358 kobject_name(&mem_blk->sysdev.kobj));
dee5d0d5
AC
359 if (ret)
360 return ret;
361
362 return sysfs_create_link_nowarn(&mem_blk->sysdev.kobj,
363 &node_devices[nid].sysdev.kobj,
364 kobject_name(&node_devices[nid].sysdev.kobj));
c04fc586
GH
365 }
366 /* mem section does not span the specified node */
367 return 0;
368}
369
370/* unregister memory section under all nodes that it spans */
371int unregister_mem_sect_under_nodes(struct memory_block *mem_blk)
372{
9ae49fab 373 NODEMASK_ALLOC(nodemask_t, unlinked_nodes, GFP_KERNEL);
c04fc586
GH
374 unsigned long pfn, sect_start_pfn, sect_end_pfn;
375
9ae49fab
DR
376 if (!mem_blk) {
377 NODEMASK_FREE(unlinked_nodes);
c04fc586 378 return -EFAULT;
9ae49fab
DR
379 }
380 if (!unlinked_nodes)
381 return -ENOMEM;
382 nodes_clear(*unlinked_nodes);
c04fc586
GH
383 sect_start_pfn = section_nr_to_pfn(mem_blk->phys_index);
384 sect_end_pfn = sect_start_pfn + PAGES_PER_SECTION - 1;
385 for (pfn = sect_start_pfn; pfn <= sect_end_pfn; pfn++) {
47504980 386 int nid;
c04fc586
GH
387
388 nid = get_nid_for_pfn(pfn);
389 if (nid < 0)
390 continue;
391 if (!node_online(nid))
392 continue;
9ae49fab 393 if (node_test_and_set(nid, *unlinked_nodes))
c04fc586
GH
394 continue;
395 sysfs_remove_link(&node_devices[nid].sysdev.kobj,
396 kobject_name(&mem_blk->sysdev.kobj));
dee5d0d5
AC
397 sysfs_remove_link(&mem_blk->sysdev.kobj,
398 kobject_name(&node_devices[nid].sysdev.kobj));
c04fc586 399 }
9ae49fab 400 NODEMASK_FREE(unlinked_nodes);
c04fc586
GH
401 return 0;
402}
403
404static int link_mem_sections(int nid)
405{
406 unsigned long start_pfn = NODE_DATA(nid)->node_start_pfn;
407 unsigned long end_pfn = start_pfn + NODE_DATA(nid)->node_spanned_pages;
408 unsigned long pfn;
409 int err = 0;
410
411 for (pfn = start_pfn; pfn < end_pfn; pfn += PAGES_PER_SECTION) {
412 unsigned long section_nr = pfn_to_section_nr(pfn);
413 struct mem_section *mem_sect;
414 struct memory_block *mem_blk;
415 int ret;
416
417 if (!present_section_nr(section_nr))
418 continue;
419 mem_sect = __nr_to_section(section_nr);
420 mem_blk = find_memory_block(mem_sect);
421 ret = register_mem_sect_under_node(mem_blk, nid);
422 if (!err)
423 err = ret;
424
425 /* discard ref obtained in find_memory_block() */
426 kobject_put(&mem_blk->sysdev.kobj);
427 }
428 return err;
429}
4faf8d95 430
39da08cb 431#ifdef CONFIG_HUGETLBFS
4faf8d95
LS
432/*
433 * Handle per node hstate attribute [un]registration on transistions
434 * to/from memoryless state.
435 */
39da08cb
LS
436static void node_hugetlb_work(struct work_struct *work)
437{
438 struct node *node = container_of(work, struct node, node_work);
439
440 /*
441 * We only get here when a node transitions to/from memoryless state.
442 * We can detect which transition occurred by examining whether the
443 * node has memory now. hugetlb_register_node() already check this
444 * so we try to register the attributes. If that fails, then the
445 * node has transitioned to memoryless, try to unregister the
446 * attributes.
447 */
448 if (!hugetlb_register_node(node))
449 hugetlb_unregister_node(node);
450}
451
452static void init_node_hugetlb_work(int nid)
453{
454 INIT_WORK(&node_devices[nid].node_work, node_hugetlb_work);
455}
4faf8d95
LS
456
457static int node_memory_callback(struct notifier_block *self,
458 unsigned long action, void *arg)
459{
460 struct memory_notify *mnb = arg;
461 int nid = mnb->status_change_nid;
462
463 switch (action) {
39da08cb
LS
464 case MEM_ONLINE:
465 case MEM_OFFLINE:
466 /*
467 * offload per node hstate [un]registration to a work thread
468 * when transitioning to/from memoryless state.
469 */
4faf8d95 470 if (nid != NUMA_NO_NODE)
39da08cb 471 schedule_work(&node_devices[nid].node_work);
4faf8d95 472 break;
39da08cb 473
4faf8d95
LS
474 case MEM_GOING_ONLINE:
475 case MEM_GOING_OFFLINE:
476 case MEM_CANCEL_ONLINE:
477 case MEM_CANCEL_OFFLINE:
478 default:
479 break;
480 }
481
482 return NOTIFY_OK;
483}
39da08cb
LS
484#endif /* CONFIG_HUGETLBFS */
485#else /* !CONFIG_MEMORY_HOTPLUG_SPARSE */
486
c04fc586 487static int link_mem_sections(int nid) { return 0; }
39da08cb 488#endif /* CONFIG_MEMORY_HOTPLUG_SPARSE */
4faf8d95 489
39da08cb
LS
490#if !defined(CONFIG_MEMORY_HOTPLUG_SPARSE) || \
491 !defined(CONFIG_HUGETLBFS)
4faf8d95
LS
492static inline int node_memory_callback(struct notifier_block *self,
493 unsigned long action, void *arg)
494{
495 return NOTIFY_OK;
496}
39da08cb
LS
497
498static void init_node_hugetlb_work(int nid) { }
499
500#endif
c04fc586 501
0fc44159
YG
502int register_one_node(int nid)
503{
504 int error = 0;
76b67ed9 505 int cpu;
0fc44159
YG
506
507 if (node_online(nid)) {
508 int p_node = parent_node(nid);
509 struct node *parent = NULL;
510
511 if (p_node != nid)
512 parent = &node_devices[p_node];
513
514 error = register_node(&node_devices[nid], nid, parent);
76b67ed9
KH
515
516 /* link cpu under this node */
517 for_each_present_cpu(cpu) {
518 if (cpu_to_node(cpu) == nid)
519 register_cpu_under_node(cpu, nid);
520 }
c04fc586
GH
521
522 /* link memory sections under this node */
523 error = link_mem_sections(nid);
39da08cb
LS
524
525 /* initialize work queue for memory hot plug */
526 init_node_hugetlb_work(nid);
0fc44159
YG
527 }
528
529 return error;
530
531}
532
533void unregister_one_node(int nid)
534{
535 unregister_node(&node_devices[nid]);
536}
537
bde631a5
LS
538/*
539 * node states attributes
540 */
541
542static ssize_t print_nodes_state(enum node_states state, char *buf)
543{
544 int n;
545
546 n = nodelist_scnprintf(buf, PAGE_SIZE, node_states[state]);
547 if (n > 0 && PAGE_SIZE > n + 1) {
548 *(buf + n++) = '\n';
549 *(buf + n++) = '\0';
550 }
551 return n;
552}
553
b15f562f
AK
554struct node_attr {
555 struct sysdev_class_attribute attr;
556 enum node_states state;
557};
bde631a5 558
b15f562f
AK
559static ssize_t show_node_state(struct sysdev_class *class,
560 struct sysdev_class_attribute *attr, char *buf)
bde631a5 561{
b15f562f
AK
562 struct node_attr *na = container_of(attr, struct node_attr, attr);
563 return print_nodes_state(na->state, buf);
bde631a5
LS
564}
565
b15f562f
AK
566#define _NODE_ATTR(name, state) \
567 { _SYSDEV_CLASS_ATTR(name, 0444, show_node_state, NULL), state }
bde631a5 568
b15f562f
AK
569static struct node_attr node_state_attr[] = {
570 _NODE_ATTR(possible, N_POSSIBLE),
571 _NODE_ATTR(online, N_ONLINE),
572 _NODE_ATTR(has_normal_memory, N_NORMAL_MEMORY),
573 _NODE_ATTR(has_cpu, N_CPU),
bde631a5 574#ifdef CONFIG_HIGHMEM
b15f562f 575 _NODE_ATTR(has_high_memory, N_HIGH_MEMORY),
bde631a5 576#endif
bde631a5
LS
577};
578
3701cde6
AK
579static struct sysdev_class_attribute *node_state_attrs[] = {
580 &node_state_attr[0].attr,
581 &node_state_attr[1].attr,
582 &node_state_attr[2].attr,
583 &node_state_attr[3].attr,
584#ifdef CONFIG_HIGHMEM
585 &node_state_attr[4].attr,
586#endif
587 NULL
588};
bde631a5 589
4faf8d95 590#define NODE_CALLBACK_PRI 2 /* lower than SLAB */
4b45099b 591static int __init register_node_type(void)
1da177e4 592{
bde631a5
LS
593 int ret;
594
3701cde6
AK
595 BUILD_BUG_ON(ARRAY_SIZE(node_state_attr) != NR_NODE_STATES);
596 BUILD_BUG_ON(ARRAY_SIZE(node_state_attrs)-1 != NR_NODE_STATES);
597
bde631a5 598 ret = sysdev_class_register(&node_class);
4faf8d95 599 if (!ret) {
4faf8d95
LS
600 hotplug_memory_notifier(node_memory_callback,
601 NODE_CALLBACK_PRI);
602 }
bde631a5
LS
603
604 /*
605 * Note: we're not going to unregister the node class if we fail
606 * to register the node state class attribute files.
607 */
608 return ret;
1da177e4
LT
609}
610postcore_initcall(register_node_type);