node.c 18 KB

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