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