Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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> |
Gary Hade | c04fc58 | 2009-01-06 14:39:14 -0800 | [diff] [blame] | 9 | #include <linux/memory.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10 | #include <linux/node.h> |
| 11 | #include <linux/hugetlb.h> |
Mel Gorman | ed4a6d7 | 2010-05-24 14:32:29 -0700 | [diff] [blame] | 12 | #include <linux/compaction.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13 | #include <linux/cpumask.h> |
| 14 | #include <linux/topology.h> |
| 15 | #include <linux/nodemask.h> |
KAMEZAWA Hiroyuki | 76b67ed | 2006-06-27 02:53:41 -0700 | [diff] [blame] | 16 | #include <linux/cpu.h> |
Lee Schermerhorn | bde631a | 2007-10-16 01:26:27 -0700 | [diff] [blame] | 17 | #include <linux/device.h> |
Lee Schermerhorn | af936a1 | 2008-10-18 20:26:53 -0700 | [diff] [blame] | 18 | #include <linux/swap.h> |
Tejun Heo | 18e5b53 | 2010-04-06 19:23:33 +0900 | [diff] [blame] | 19 | #include <linux/slab.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 20 | |
Andi Kleen | 3701cde | 2010-01-05 12:48:04 +0100 | [diff] [blame] | 21 | static struct sysdev_class_attribute *node_state_attrs[]; |
| 22 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 23 | static struct sysdev_class node_class = { |
Kay Sievers | af5ca3f | 2007-12-20 02:09:39 +0100 | [diff] [blame] | 24 | .name = "node", |
Andi Kleen | 3701cde | 2010-01-05 12:48:04 +0100 | [diff] [blame] | 25 | .attrs = node_state_attrs, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 26 | }; |
| 27 | |
| 28 | |
Mike Travis | 39106dc | 2008-04-08 11:43:03 -0700 | [diff] [blame] | 29 | static ssize_t node_read_cpumap(struct sys_device *dev, int type, char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 30 | { |
| 31 | struct node *node_dev = to_node(dev); |
Rusty Russell | a70f730 | 2009-03-13 14:49:46 +1030 | [diff] [blame] | 32 | const struct cpumask *mask = cpumask_of_node(node_dev->sysdev.id); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 33 | int len; |
| 34 | |
Mike Travis | 39106dc | 2008-04-08 11:43:03 -0700 | [diff] [blame] | 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)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 37 | |
Mike Travis | 39106dc | 2008-04-08 11:43:03 -0700 | [diff] [blame] | 38 | len = type? |
Rusty Russell | 29c0177 | 2008-12-13 21:20:25 +1030 | [diff] [blame] | 39 | cpulist_scnprintf(buf, PAGE_SIZE-2, mask) : |
| 40 | cpumask_scnprintf(buf, PAGE_SIZE-2, mask); |
Mike Travis | c5f59f0 | 2008-04-04 18:11:10 -0700 | [diff] [blame] | 41 | buf[len++] = '\n'; |
| 42 | buf[len] = '\0'; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 43 | return len; |
| 44 | } |
| 45 | |
Andi Kleen | 4a0b2b4 | 2008-07-01 18:48:41 +0200 | [diff] [blame] | 46 | static inline ssize_t node_read_cpumask(struct sys_device *dev, |
| 47 | struct sysdev_attribute *attr, char *buf) |
Mike Travis | 39106dc | 2008-04-08 11:43:03 -0700 | [diff] [blame] | 48 | { |
| 49 | return node_read_cpumap(dev, 0, buf); |
| 50 | } |
Andi Kleen | 4a0b2b4 | 2008-07-01 18:48:41 +0200 | [diff] [blame] | 51 | static inline ssize_t node_read_cpulist(struct sys_device *dev, |
| 52 | struct sysdev_attribute *attr, char *buf) |
Mike Travis | 39106dc | 2008-04-08 11:43:03 -0700 | [diff] [blame] | 53 | { |
| 54 | return node_read_cpumap(dev, 1, buf); |
| 55 | } |
| 56 | |
| 57 | static SYSDEV_ATTR(cpumap, S_IRUGO, node_read_cpumask, NULL); |
| 58 | static SYSDEV_ATTR(cpulist, S_IRUGO, node_read_cpulist, NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 59 | |
| 60 | #define K(x) ((x) << (PAGE_SHIFT - 10)) |
Andi Kleen | 4a0b2b4 | 2008-07-01 18:48:41 +0200 | [diff] [blame] | 61 | static ssize_t node_read_meminfo(struct sys_device * dev, |
| 62 | struct sysdev_attribute *attr, char * buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 63 | { |
| 64 | int n; |
| 65 | int nid = dev->id; |
| 66 | struct sysinfo i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 67 | |
| 68 | si_meminfo_node(&i, nid); |
KOSAKI Motohiro | 7ee9225 | 2010-08-09 17:19:50 -0700 | [diff] [blame] | 69 | n = sprintf(buf, |
Rik van Riel | 4f98a2f | 2008-10-18 20:26:32 -0700 | [diff] [blame] | 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" |
Nick Piggin | 5344b7e | 2008-10-18 20:26:51 -0700 | [diff] [blame] | 79 | "Node %d Unevictable: %8lu kB\n" |
KOSAKI Motohiro | 7ee9225 | 2010-08-09 17:19:50 -0700 | [diff] [blame] | 80 | "Node %d Mlocked: %8lu kB\n", |
| 81 | nid, K(i.totalram), |
| 82 | nid, K(i.freeram), |
| 83 | nid, K(i.totalram - i.freeram), |
| 84 | nid, K(node_page_state(nid, NR_ACTIVE_ANON) + |
| 85 | node_page_state(nid, NR_ACTIVE_FILE)), |
| 86 | nid, K(node_page_state(nid, NR_INACTIVE_ANON) + |
| 87 | node_page_state(nid, NR_INACTIVE_FILE)), |
| 88 | nid, K(node_page_state(nid, NR_ACTIVE_ANON)), |
| 89 | nid, K(node_page_state(nid, NR_INACTIVE_ANON)), |
| 90 | nid, K(node_page_state(nid, NR_ACTIVE_FILE)), |
| 91 | nid, K(node_page_state(nid, NR_INACTIVE_FILE)), |
| 92 | nid, K(node_page_state(nid, NR_UNEVICTABLE)), |
| 93 | nid, K(node_page_state(nid, NR_MLOCK))); |
| 94 | |
Christoph Lameter | 182e8e2 | 2006-09-25 23:31:10 -0700 | [diff] [blame] | 95 | #ifdef CONFIG_HIGHMEM |
KOSAKI Motohiro | 7ee9225 | 2010-08-09 17:19:50 -0700 | [diff] [blame] | 96 | n += sprintf(buf + n, |
Rik van Riel | 4f98a2f | 2008-10-18 20:26:32 -0700 | [diff] [blame] | 97 | "Node %d HighTotal: %8lu kB\n" |
| 98 | "Node %d HighFree: %8lu kB\n" |
| 99 | "Node %d LowTotal: %8lu kB\n" |
KOSAKI Motohiro | 7ee9225 | 2010-08-09 17:19:50 -0700 | [diff] [blame] | 100 | "Node %d LowFree: %8lu kB\n", |
| 101 | nid, K(i.totalhigh), |
| 102 | nid, K(i.freehigh), |
| 103 | nid, K(i.totalram - i.totalhigh), |
| 104 | nid, K(i.freeram - i.freehigh)); |
Christoph Lameter | 182e8e2 | 2006-09-25 23:31:10 -0700 | [diff] [blame] | 105 | #endif |
KOSAKI Motohiro | 7ee9225 | 2010-08-09 17:19:50 -0700 | [diff] [blame] | 106 | n += sprintf(buf + n, |
Rik van Riel | 4f98a2f | 2008-10-18 20:26:32 -0700 | [diff] [blame] | 107 | "Node %d Dirty: %8lu kB\n" |
| 108 | "Node %d Writeback: %8lu kB\n" |
| 109 | "Node %d FilePages: %8lu kB\n" |
| 110 | "Node %d Mapped: %8lu kB\n" |
| 111 | "Node %d AnonPages: %8lu kB\n" |
KOSAKI Motohiro | 4b02108 | 2009-09-21 17:01:33 -0700 | [diff] [blame] | 112 | "Node %d Shmem: %8lu kB\n" |
KOSAKI Motohiro | c6a7f57 | 2009-09-21 17:01:32 -0700 | [diff] [blame] | 113 | "Node %d KernelStack: %8lu kB\n" |
Rik van Riel | 4f98a2f | 2008-10-18 20:26:32 -0700 | [diff] [blame] | 114 | "Node %d PageTables: %8lu kB\n" |
| 115 | "Node %d NFS_Unstable: %8lu kB\n" |
| 116 | "Node %d Bounce: %8lu kB\n" |
| 117 | "Node %d WritebackTmp: %8lu kB\n" |
| 118 | "Node %d Slab: %8lu kB\n" |
| 119 | "Node %d SReclaimable: %8lu kB\n" |
David Rientjes | 05b258e | 2011-01-13 15:47:14 -0800 | [diff] [blame] | 120 | "Node %d SUnreclaim: %8lu kB\n" |
| 121 | #ifdef CONFIG_TRANSPARENT_HUGEPAGE |
| 122 | "Node %d AnonHugePages: %8lu kB\n" |
| 123 | #endif |
| 124 | , |
Christoph Lameter | b1e7a8f | 2006-06-30 01:55:39 -0700 | [diff] [blame] | 125 | nid, K(node_page_state(nid, NR_FILE_DIRTY)), |
Christoph Lameter | ce866b3 | 2006-06-30 01:55:40 -0700 | [diff] [blame] | 126 | nid, K(node_page_state(nid, NR_WRITEBACK)), |
Christoph Lameter | 347ce43 | 2006-06-30 01:55:35 -0700 | [diff] [blame] | 127 | nid, K(node_page_state(nid, NR_FILE_PAGES)), |
Christoph Lameter | 65ba55f | 2006-06-30 01:55:34 -0700 | [diff] [blame] | 128 | nid, K(node_page_state(nid, NR_FILE_MAPPED)), |
David Rientjes | 05b258e | 2011-01-13 15:47:14 -0800 | [diff] [blame] | 129 | nid, K(node_page_state(nid, NR_ANON_PAGES) |
| 130 | #ifdef CONFIG_TRANSPARENT_HUGEPAGE |
| 131 | + node_page_state(nid, NR_ANON_TRANSPARENT_HUGEPAGES) * |
| 132 | HPAGE_PMD_NR |
| 133 | #endif |
| 134 | ), |
KOSAKI Motohiro | 4b02108 | 2009-09-21 17:01:33 -0700 | [diff] [blame] | 135 | nid, K(node_page_state(nid, NR_SHMEM)), |
KOSAKI Motohiro | c6a7f57 | 2009-09-21 17:01:32 -0700 | [diff] [blame] | 136 | nid, node_page_state(nid, NR_KERNEL_STACK) * |
| 137 | THREAD_SIZE / 1024, |
Christoph Lameter | df849a1 | 2006-06-30 01:55:38 -0700 | [diff] [blame] | 138 | nid, K(node_page_state(nid, NR_PAGETABLE)), |
Christoph Lameter | fd39fc8 | 2006-06-30 01:55:40 -0700 | [diff] [blame] | 139 | nid, K(node_page_state(nid, NR_UNSTABLE_NFS)), |
Christoph Lameter | d2c5e30 | 2006-06-30 01:55:41 -0700 | [diff] [blame] | 140 | nid, K(node_page_state(nid, NR_BOUNCE)), |
Miklos Szeredi | fc3ba69 | 2008-04-30 00:54:38 -0700 | [diff] [blame] | 141 | nid, K(node_page_state(nid, NR_WRITEBACK_TEMP)), |
Christoph Lameter | 972d1a7 | 2006-09-25 23:31:51 -0700 | [diff] [blame] | 142 | nid, K(node_page_state(nid, NR_SLAB_RECLAIMABLE) + |
| 143 | node_page_state(nid, NR_SLAB_UNRECLAIMABLE)), |
| 144 | nid, K(node_page_state(nid, NR_SLAB_RECLAIMABLE)), |
David Rientjes | 05b258e | 2011-01-13 15:47:14 -0800 | [diff] [blame] | 145 | nid, K(node_page_state(nid, NR_SLAB_UNRECLAIMABLE)) |
| 146 | #ifdef CONFIG_TRANSPARENT_HUGEPAGE |
| 147 | , nid, |
| 148 | K(node_page_state(nid, NR_ANON_TRANSPARENT_HUGEPAGES) * |
| 149 | HPAGE_PMD_NR) |
| 150 | #endif |
| 151 | ); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 152 | n += hugetlb_report_node_meminfo(nid, buf + n); |
| 153 | return n; |
| 154 | } |
| 155 | |
| 156 | #undef K |
| 157 | static SYSDEV_ATTR(meminfo, S_IRUGO, node_read_meminfo, NULL); |
| 158 | |
Andi Kleen | 4a0b2b4 | 2008-07-01 18:48:41 +0200 | [diff] [blame] | 159 | static ssize_t node_read_numastat(struct sys_device * dev, |
| 160 | struct sysdev_attribute *attr, char * buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 161 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 162 | return sprintf(buf, |
| 163 | "numa_hit %lu\n" |
| 164 | "numa_miss %lu\n" |
| 165 | "numa_foreign %lu\n" |
| 166 | "interleave_hit %lu\n" |
| 167 | "local_node %lu\n" |
| 168 | "other_node %lu\n", |
Christoph Lameter | ca889e6 | 2006-06-30 01:55:44 -0700 | [diff] [blame] | 169 | node_page_state(dev->id, NUMA_HIT), |
| 170 | node_page_state(dev->id, NUMA_MISS), |
| 171 | node_page_state(dev->id, NUMA_FOREIGN), |
| 172 | node_page_state(dev->id, NUMA_INTERLEAVE_HIT), |
| 173 | node_page_state(dev->id, NUMA_LOCAL), |
| 174 | node_page_state(dev->id, NUMA_OTHER)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 175 | } |
| 176 | static SYSDEV_ATTR(numastat, S_IRUGO, node_read_numastat, NULL); |
| 177 | |
Michael Rubin | 2ac3903 | 2010-10-26 14:21:35 -0700 | [diff] [blame] | 178 | static ssize_t node_read_vmstat(struct sys_device *dev, |
| 179 | struct sysdev_attribute *attr, char *buf) |
| 180 | { |
| 181 | int nid = dev->id; |
| 182 | return sprintf(buf, |
| 183 | "nr_written %lu\n" |
| 184 | "nr_dirtied %lu\n", |
| 185 | node_page_state(nid, NR_WRITTEN), |
| 186 | node_page_state(nid, NR_DIRTIED)); |
| 187 | } |
| 188 | static SYSDEV_ATTR(vmstat, S_IRUGO, node_read_vmstat, NULL); |
| 189 | |
Andi Kleen | 4a0b2b4 | 2008-07-01 18:48:41 +0200 | [diff] [blame] | 190 | static ssize_t node_read_distance(struct sys_device * dev, |
| 191 | struct sysdev_attribute *attr, char * buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 192 | { |
| 193 | int nid = dev->id; |
| 194 | int len = 0; |
| 195 | int i; |
| 196 | |
David Rientjes | 12ee3c0 | 2010-03-10 14:50:21 -0800 | [diff] [blame] | 197 | /* |
| 198 | * buf is currently PAGE_SIZE in length and each node needs 4 chars |
| 199 | * at the most (distance + space or newline). |
| 200 | */ |
| 201 | BUILD_BUG_ON(MAX_NUMNODES * 4 > PAGE_SIZE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 202 | |
| 203 | for_each_online_node(i) |
| 204 | len += sprintf(buf + len, "%s%d", i ? " " : "", node_distance(nid, i)); |
| 205 | |
| 206 | len += sprintf(buf + len, "\n"); |
| 207 | return len; |
| 208 | } |
| 209 | static SYSDEV_ATTR(distance, S_IRUGO, node_read_distance, NULL); |
| 210 | |
Lee Schermerhorn | 9a30523 | 2009-12-14 17:58:25 -0800 | [diff] [blame] | 211 | #ifdef CONFIG_HUGETLBFS |
| 212 | /* |
| 213 | * hugetlbfs per node attributes registration interface: |
| 214 | * When/if hugetlb[fs] subsystem initializes [sometime after this module], |
Lee Schermerhorn | 4faf8d9 | 2009-12-14 17:58:35 -0800 | [diff] [blame] | 215 | * it will register its per node attributes for all online nodes with |
| 216 | * memory. It will also call register_hugetlbfs_with_node(), below, to |
Lee Schermerhorn | 9a30523 | 2009-12-14 17:58:25 -0800 | [diff] [blame] | 217 | * register its attribute registration functions with this node driver. |
| 218 | * Once these hooks have been initialized, the node driver will call into |
| 219 | * the hugetlb module to [un]register attributes for hot-plugged nodes. |
| 220 | */ |
| 221 | static node_registration_func_t __hugetlb_register_node; |
| 222 | static node_registration_func_t __hugetlb_unregister_node; |
| 223 | |
Lee Schermerhorn | 39da08c | 2009-12-14 17:58:36 -0800 | [diff] [blame] | 224 | static inline bool hugetlb_register_node(struct node *node) |
Lee Schermerhorn | 9a30523 | 2009-12-14 17:58:25 -0800 | [diff] [blame] | 225 | { |
Lee Schermerhorn | 4faf8d9 | 2009-12-14 17:58:35 -0800 | [diff] [blame] | 226 | if (__hugetlb_register_node && |
Lee Schermerhorn | 39da08c | 2009-12-14 17:58:36 -0800 | [diff] [blame] | 227 | node_state(node->sysdev.id, N_HIGH_MEMORY)) { |
Lee Schermerhorn | 9a30523 | 2009-12-14 17:58:25 -0800 | [diff] [blame] | 228 | __hugetlb_register_node(node); |
Lee Schermerhorn | 39da08c | 2009-12-14 17:58:36 -0800 | [diff] [blame] | 229 | return true; |
| 230 | } |
| 231 | return false; |
Lee Schermerhorn | 9a30523 | 2009-12-14 17:58:25 -0800 | [diff] [blame] | 232 | } |
| 233 | |
| 234 | static inline void hugetlb_unregister_node(struct node *node) |
| 235 | { |
| 236 | if (__hugetlb_unregister_node) |
| 237 | __hugetlb_unregister_node(node); |
| 238 | } |
| 239 | |
| 240 | void register_hugetlbfs_with_node(node_registration_func_t doregister, |
| 241 | node_registration_func_t unregister) |
| 242 | { |
| 243 | __hugetlb_register_node = doregister; |
| 244 | __hugetlb_unregister_node = unregister; |
| 245 | } |
| 246 | #else |
| 247 | static inline void hugetlb_register_node(struct node *node) {} |
| 248 | |
| 249 | static inline void hugetlb_unregister_node(struct node *node) {} |
| 250 | #endif |
| 251 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 252 | |
| 253 | /* |
Robert P. J. Day | 405ae7d | 2007-02-17 19:13:42 +0100 | [diff] [blame] | 254 | * register_node - Setup a sysfs device for a node. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 255 | * @num - Node number to use when creating the device. |
| 256 | * |
| 257 | * Initialize and register the node device. |
| 258 | */ |
Keiichiro Tokunaga | 4b45099 | 2005-05-08 21:28:53 +0900 | [diff] [blame] | 259 | int register_node(struct node *node, int num, struct node *parent) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 260 | { |
| 261 | int error; |
| 262 | |
| 263 | node->sysdev.id = num; |
| 264 | node->sysdev.cls = &node_class; |
| 265 | error = sysdev_register(&node->sysdev); |
| 266 | |
| 267 | if (!error){ |
| 268 | sysdev_create_file(&node->sysdev, &attr_cpumap); |
Mike Travis | 39106dc | 2008-04-08 11:43:03 -0700 | [diff] [blame] | 269 | sysdev_create_file(&node->sysdev, &attr_cpulist); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 270 | sysdev_create_file(&node->sysdev, &attr_meminfo); |
| 271 | sysdev_create_file(&node->sysdev, &attr_numastat); |
| 272 | sysdev_create_file(&node->sysdev, &attr_distance); |
Michael Rubin | 2ac3903 | 2010-10-26 14:21:35 -0700 | [diff] [blame] | 273 | sysdev_create_file(&node->sysdev, &attr_vmstat); |
Lee Schermerhorn | af936a1 | 2008-10-18 20:26:53 -0700 | [diff] [blame] | 274 | |
| 275 | scan_unevictable_register_node(node); |
Lee Schermerhorn | 4faf8d9 | 2009-12-14 17:58:35 -0800 | [diff] [blame] | 276 | |
Lee Schermerhorn | 9a30523 | 2009-12-14 17:58:25 -0800 | [diff] [blame] | 277 | hugetlb_register_node(node); |
Mel Gorman | ed4a6d7 | 2010-05-24 14:32:29 -0700 | [diff] [blame] | 278 | |
| 279 | compaction_register_node(node); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 280 | } |
| 281 | return error; |
| 282 | } |
| 283 | |
Keiichiro Tokunaga | 4b45099 | 2005-05-08 21:28:53 +0900 | [diff] [blame] | 284 | /** |
| 285 | * unregister_node - unregister a node device |
| 286 | * @node: node going away |
| 287 | * |
| 288 | * Unregisters a node device @node. All the devices on the node must be |
| 289 | * unregistered before calling this function. |
| 290 | */ |
| 291 | void unregister_node(struct node *node) |
| 292 | { |
| 293 | sysdev_remove_file(&node->sysdev, &attr_cpumap); |
Mike Travis | 39106dc | 2008-04-08 11:43:03 -0700 | [diff] [blame] | 294 | sysdev_remove_file(&node->sysdev, &attr_cpulist); |
Keiichiro Tokunaga | 4b45099 | 2005-05-08 21:28:53 +0900 | [diff] [blame] | 295 | sysdev_remove_file(&node->sysdev, &attr_meminfo); |
| 296 | sysdev_remove_file(&node->sysdev, &attr_numastat); |
| 297 | sysdev_remove_file(&node->sysdev, &attr_distance); |
Michael Rubin | 2ac3903 | 2010-10-26 14:21:35 -0700 | [diff] [blame] | 298 | sysdev_remove_file(&node->sysdev, &attr_vmstat); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 299 | |
Lee Schermerhorn | af936a1 | 2008-10-18 20:26:53 -0700 | [diff] [blame] | 300 | scan_unevictable_unregister_node(node); |
Lee Schermerhorn | 4faf8d9 | 2009-12-14 17:58:35 -0800 | [diff] [blame] | 301 | hugetlb_unregister_node(node); /* no-op, if memoryless node */ |
Lee Schermerhorn | af936a1 | 2008-10-18 20:26:53 -0700 | [diff] [blame] | 302 | |
Keiichiro Tokunaga | 4b45099 | 2005-05-08 21:28:53 +0900 | [diff] [blame] | 303 | sysdev_unregister(&node->sysdev); |
| 304 | } |
| 305 | |
Yasunori Goto | 0fc4415 | 2006-06-27 02:53:38 -0700 | [diff] [blame] | 306 | struct node node_devices[MAX_NUMNODES]; |
| 307 | |
KAMEZAWA Hiroyuki | 76b67ed | 2006-06-27 02:53:41 -0700 | [diff] [blame] | 308 | /* |
| 309 | * register cpu under node |
| 310 | */ |
| 311 | int register_cpu_under_node(unsigned int cpu, unsigned int nid) |
| 312 | { |
Alex Chiang | 1830794 | 2009-12-14 17:59:08 -0800 | [diff] [blame] | 313 | int ret; |
Alex Chiang | f8246f3 | 2009-12-14 17:59:06 -0800 | [diff] [blame] | 314 | struct sys_device *obj; |
KAMEZAWA Hiroyuki | 76b67ed | 2006-06-27 02:53:41 -0700 | [diff] [blame] | 315 | |
Alex Chiang | f8246f3 | 2009-12-14 17:59:06 -0800 | [diff] [blame] | 316 | if (!node_online(nid)) |
| 317 | return 0; |
| 318 | |
| 319 | obj = get_cpu_sysdev(cpu); |
| 320 | if (!obj) |
| 321 | return 0; |
| 322 | |
Alex Chiang | 1830794 | 2009-12-14 17:59:08 -0800 | [diff] [blame] | 323 | ret = sysfs_create_link(&node_devices[nid].sysdev.kobj, |
Alex Chiang | f8246f3 | 2009-12-14 17:59:06 -0800 | [diff] [blame] | 324 | &obj->kobj, |
| 325 | kobject_name(&obj->kobj)); |
Alex Chiang | 1830794 | 2009-12-14 17:59:08 -0800 | [diff] [blame] | 326 | if (ret) |
| 327 | return ret; |
| 328 | |
| 329 | return sysfs_create_link(&obj->kobj, |
| 330 | &node_devices[nid].sysdev.kobj, |
| 331 | kobject_name(&node_devices[nid].sysdev.kobj)); |
KAMEZAWA Hiroyuki | 76b67ed | 2006-06-27 02:53:41 -0700 | [diff] [blame] | 332 | } |
| 333 | |
| 334 | int unregister_cpu_under_node(unsigned int cpu, unsigned int nid) |
| 335 | { |
Alex Chiang | b9d52da | 2009-12-14 17:59:07 -0800 | [diff] [blame] | 336 | struct sys_device *obj; |
| 337 | |
| 338 | if (!node_online(nid)) |
| 339 | return 0; |
| 340 | |
| 341 | obj = get_cpu_sysdev(cpu); |
| 342 | if (!obj) |
| 343 | return 0; |
| 344 | |
| 345 | sysfs_remove_link(&node_devices[nid].sysdev.kobj, |
| 346 | kobject_name(&obj->kobj)); |
Alex Chiang | 1830794 | 2009-12-14 17:59:08 -0800 | [diff] [blame] | 347 | sysfs_remove_link(&obj->kobj, |
| 348 | kobject_name(&node_devices[nid].sysdev.kobj)); |
Alex Chiang | b9d52da | 2009-12-14 17:59:07 -0800 | [diff] [blame] | 349 | |
KAMEZAWA Hiroyuki | 76b67ed | 2006-06-27 02:53:41 -0700 | [diff] [blame] | 350 | return 0; |
| 351 | } |
| 352 | |
Gary Hade | c04fc58 | 2009-01-06 14:39:14 -0800 | [diff] [blame] | 353 | #ifdef CONFIG_MEMORY_HOTPLUG_SPARSE |
| 354 | #define page_initialized(page) (page->lru.next) |
| 355 | |
| 356 | static int get_nid_for_pfn(unsigned long pfn) |
| 357 | { |
| 358 | struct page *page; |
| 359 | |
| 360 | if (!pfn_valid_within(pfn)) |
| 361 | return -1; |
| 362 | page = pfn_to_page(pfn); |
| 363 | if (!page_initialized(page)) |
| 364 | return -1; |
| 365 | return pfn_to_nid(pfn); |
| 366 | } |
| 367 | |
| 368 | /* register memory section under specified node if it spans that node */ |
| 369 | int register_mem_sect_under_node(struct memory_block *mem_blk, int nid) |
| 370 | { |
Alex Chiang | dee5d0d | 2009-12-14 17:59:05 -0800 | [diff] [blame] | 371 | int ret; |
Gary Hade | c04fc58 | 2009-01-06 14:39:14 -0800 | [diff] [blame] | 372 | unsigned long pfn, sect_start_pfn, sect_end_pfn; |
| 373 | |
| 374 | if (!mem_blk) |
| 375 | return -EFAULT; |
| 376 | if (!node_online(nid)) |
| 377 | return 0; |
Nathan Fontenot | d336016 | 2011-01-20 10:44:29 -0600 | [diff] [blame] | 378 | |
| 379 | sect_start_pfn = section_nr_to_pfn(mem_blk->start_section_nr); |
| 380 | sect_end_pfn = section_nr_to_pfn(mem_blk->end_section_nr); |
| 381 | sect_end_pfn += PAGES_PER_SECTION - 1; |
Gary Hade | c04fc58 | 2009-01-06 14:39:14 -0800 | [diff] [blame] | 382 | for (pfn = sect_start_pfn; pfn <= sect_end_pfn; pfn++) { |
| 383 | int page_nid; |
| 384 | |
| 385 | page_nid = get_nid_for_pfn(pfn); |
| 386 | if (page_nid < 0) |
| 387 | continue; |
| 388 | if (page_nid != nid) |
| 389 | continue; |
Alex Chiang | dee5d0d | 2009-12-14 17:59:05 -0800 | [diff] [blame] | 390 | ret = sysfs_create_link_nowarn(&node_devices[nid].sysdev.kobj, |
Gary Hade | c04fc58 | 2009-01-06 14:39:14 -0800 | [diff] [blame] | 391 | &mem_blk->sysdev.kobj, |
| 392 | kobject_name(&mem_blk->sysdev.kobj)); |
Alex Chiang | dee5d0d | 2009-12-14 17:59:05 -0800 | [diff] [blame] | 393 | if (ret) |
| 394 | return ret; |
| 395 | |
| 396 | return sysfs_create_link_nowarn(&mem_blk->sysdev.kobj, |
| 397 | &node_devices[nid].sysdev.kobj, |
| 398 | kobject_name(&node_devices[nid].sysdev.kobj)); |
Gary Hade | c04fc58 | 2009-01-06 14:39:14 -0800 | [diff] [blame] | 399 | } |
| 400 | /* mem section does not span the specified node */ |
| 401 | return 0; |
| 402 | } |
| 403 | |
| 404 | /* unregister memory section under all nodes that it spans */ |
Nathan Fontenot | d336016 | 2011-01-20 10:44:29 -0600 | [diff] [blame] | 405 | int unregister_mem_sect_under_nodes(struct memory_block *mem_blk, |
| 406 | unsigned long phys_index) |
Gary Hade | c04fc58 | 2009-01-06 14:39:14 -0800 | [diff] [blame] | 407 | { |
David Rientjes | 9ae49fa | 2009-12-14 17:59:46 -0800 | [diff] [blame] | 408 | NODEMASK_ALLOC(nodemask_t, unlinked_nodes, GFP_KERNEL); |
Gary Hade | c04fc58 | 2009-01-06 14:39:14 -0800 | [diff] [blame] | 409 | unsigned long pfn, sect_start_pfn, sect_end_pfn; |
| 410 | |
David Rientjes | 9ae49fa | 2009-12-14 17:59:46 -0800 | [diff] [blame] | 411 | if (!mem_blk) { |
| 412 | NODEMASK_FREE(unlinked_nodes); |
Gary Hade | c04fc58 | 2009-01-06 14:39:14 -0800 | [diff] [blame] | 413 | return -EFAULT; |
David Rientjes | 9ae49fa | 2009-12-14 17:59:46 -0800 | [diff] [blame] | 414 | } |
| 415 | if (!unlinked_nodes) |
| 416 | return -ENOMEM; |
| 417 | nodes_clear(*unlinked_nodes); |
Nathan Fontenot | d336016 | 2011-01-20 10:44:29 -0600 | [diff] [blame] | 418 | |
| 419 | sect_start_pfn = section_nr_to_pfn(phys_index); |
Gary Hade | c04fc58 | 2009-01-06 14:39:14 -0800 | [diff] [blame] | 420 | sect_end_pfn = sect_start_pfn + PAGES_PER_SECTION - 1; |
| 421 | for (pfn = sect_start_pfn; pfn <= sect_end_pfn; pfn++) { |
Roel Kluin | 4750498 | 2009-03-10 12:55:45 -0700 | [diff] [blame] | 422 | int nid; |
Gary Hade | c04fc58 | 2009-01-06 14:39:14 -0800 | [diff] [blame] | 423 | |
| 424 | nid = get_nid_for_pfn(pfn); |
| 425 | if (nid < 0) |
| 426 | continue; |
| 427 | if (!node_online(nid)) |
| 428 | continue; |
David Rientjes | 9ae49fa | 2009-12-14 17:59:46 -0800 | [diff] [blame] | 429 | if (node_test_and_set(nid, *unlinked_nodes)) |
Gary Hade | c04fc58 | 2009-01-06 14:39:14 -0800 | [diff] [blame] | 430 | continue; |
| 431 | sysfs_remove_link(&node_devices[nid].sysdev.kobj, |
| 432 | kobject_name(&mem_blk->sysdev.kobj)); |
Alex Chiang | dee5d0d | 2009-12-14 17:59:05 -0800 | [diff] [blame] | 433 | sysfs_remove_link(&mem_blk->sysdev.kobj, |
| 434 | kobject_name(&node_devices[nid].sysdev.kobj)); |
Gary Hade | c04fc58 | 2009-01-06 14:39:14 -0800 | [diff] [blame] | 435 | } |
David Rientjes | 9ae49fa | 2009-12-14 17:59:46 -0800 | [diff] [blame] | 436 | NODEMASK_FREE(unlinked_nodes); |
Gary Hade | c04fc58 | 2009-01-06 14:39:14 -0800 | [diff] [blame] | 437 | return 0; |
| 438 | } |
| 439 | |
| 440 | static int link_mem_sections(int nid) |
| 441 | { |
| 442 | unsigned long start_pfn = NODE_DATA(nid)->node_start_pfn; |
| 443 | unsigned long end_pfn = start_pfn + NODE_DATA(nid)->node_spanned_pages; |
| 444 | unsigned long pfn; |
Robin Holt | 63d027a | 2010-09-29 14:00:56 -0500 | [diff] [blame] | 445 | struct memory_block *mem_blk = NULL; |
Gary Hade | c04fc58 | 2009-01-06 14:39:14 -0800 | [diff] [blame] | 446 | int err = 0; |
| 447 | |
| 448 | for (pfn = start_pfn; pfn < end_pfn; pfn += PAGES_PER_SECTION) { |
| 449 | unsigned long section_nr = pfn_to_section_nr(pfn); |
| 450 | struct mem_section *mem_sect; |
Gary Hade | c04fc58 | 2009-01-06 14:39:14 -0800 | [diff] [blame] | 451 | int ret; |
| 452 | |
| 453 | if (!present_section_nr(section_nr)) |
| 454 | continue; |
| 455 | mem_sect = __nr_to_section(section_nr); |
Robin Holt | 63d027a | 2010-09-29 14:00:56 -0500 | [diff] [blame] | 456 | mem_blk = find_memory_block_hinted(mem_sect, mem_blk); |
Gary Hade | c04fc58 | 2009-01-06 14:39:14 -0800 | [diff] [blame] | 457 | ret = register_mem_sect_under_node(mem_blk, nid); |
| 458 | if (!err) |
| 459 | err = ret; |
| 460 | |
| 461 | /* discard ref obtained in find_memory_block() */ |
Gary Hade | c04fc58 | 2009-01-06 14:39:14 -0800 | [diff] [blame] | 462 | } |
Robin Holt | 63d027a | 2010-09-29 14:00:56 -0500 | [diff] [blame] | 463 | |
| 464 | if (mem_blk) |
| 465 | kobject_put(&mem_blk->sysdev.kobj); |
Gary Hade | c04fc58 | 2009-01-06 14:39:14 -0800 | [diff] [blame] | 466 | return err; |
| 467 | } |
Lee Schermerhorn | 4faf8d9 | 2009-12-14 17:58:35 -0800 | [diff] [blame] | 468 | |
Lee Schermerhorn | 39da08c | 2009-12-14 17:58:36 -0800 | [diff] [blame] | 469 | #ifdef CONFIG_HUGETLBFS |
Lee Schermerhorn | 4faf8d9 | 2009-12-14 17:58:35 -0800 | [diff] [blame] | 470 | /* |
| 471 | * Handle per node hstate attribute [un]registration on transistions |
| 472 | * to/from memoryless state. |
| 473 | */ |
Lee Schermerhorn | 39da08c | 2009-12-14 17:58:36 -0800 | [diff] [blame] | 474 | static void node_hugetlb_work(struct work_struct *work) |
| 475 | { |
| 476 | struct node *node = container_of(work, struct node, node_work); |
| 477 | |
| 478 | /* |
| 479 | * We only get here when a node transitions to/from memoryless state. |
| 480 | * We can detect which transition occurred by examining whether the |
| 481 | * node has memory now. hugetlb_register_node() already check this |
| 482 | * so we try to register the attributes. If that fails, then the |
| 483 | * node has transitioned to memoryless, try to unregister the |
| 484 | * attributes. |
| 485 | */ |
| 486 | if (!hugetlb_register_node(node)) |
| 487 | hugetlb_unregister_node(node); |
| 488 | } |
| 489 | |
| 490 | static void init_node_hugetlb_work(int nid) |
| 491 | { |
| 492 | INIT_WORK(&node_devices[nid].node_work, node_hugetlb_work); |
| 493 | } |
Lee Schermerhorn | 4faf8d9 | 2009-12-14 17:58:35 -0800 | [diff] [blame] | 494 | |
| 495 | static int node_memory_callback(struct notifier_block *self, |
| 496 | unsigned long action, void *arg) |
| 497 | { |
| 498 | struct memory_notify *mnb = arg; |
| 499 | int nid = mnb->status_change_nid; |
| 500 | |
| 501 | switch (action) { |
Lee Schermerhorn | 39da08c | 2009-12-14 17:58:36 -0800 | [diff] [blame] | 502 | case MEM_ONLINE: |
| 503 | case MEM_OFFLINE: |
| 504 | /* |
| 505 | * offload per node hstate [un]registration to a work thread |
| 506 | * when transitioning to/from memoryless state. |
| 507 | */ |
Lee Schermerhorn | 4faf8d9 | 2009-12-14 17:58:35 -0800 | [diff] [blame] | 508 | if (nid != NUMA_NO_NODE) |
Lee Schermerhorn | 39da08c | 2009-12-14 17:58:36 -0800 | [diff] [blame] | 509 | schedule_work(&node_devices[nid].node_work); |
Lee Schermerhorn | 4faf8d9 | 2009-12-14 17:58:35 -0800 | [diff] [blame] | 510 | break; |
Lee Schermerhorn | 39da08c | 2009-12-14 17:58:36 -0800 | [diff] [blame] | 511 | |
Lee Schermerhorn | 4faf8d9 | 2009-12-14 17:58:35 -0800 | [diff] [blame] | 512 | case MEM_GOING_ONLINE: |
| 513 | case MEM_GOING_OFFLINE: |
| 514 | case MEM_CANCEL_ONLINE: |
| 515 | case MEM_CANCEL_OFFLINE: |
| 516 | default: |
| 517 | break; |
| 518 | } |
| 519 | |
| 520 | return NOTIFY_OK; |
| 521 | } |
Lee Schermerhorn | 39da08c | 2009-12-14 17:58:36 -0800 | [diff] [blame] | 522 | #endif /* CONFIG_HUGETLBFS */ |
| 523 | #else /* !CONFIG_MEMORY_HOTPLUG_SPARSE */ |
Lee Schermerhorn | 4faf8d9 | 2009-12-14 17:58:35 -0800 | [diff] [blame] | 524 | |
Lee Schermerhorn | 39da08c | 2009-12-14 17:58:36 -0800 | [diff] [blame] | 525 | static int link_mem_sections(int nid) { return 0; } |
| 526 | #endif /* CONFIG_MEMORY_HOTPLUG_SPARSE */ |
| 527 | |
| 528 | #if !defined(CONFIG_MEMORY_HOTPLUG_SPARSE) || \ |
| 529 | !defined(CONFIG_HUGETLBFS) |
Lee Schermerhorn | 4faf8d9 | 2009-12-14 17:58:35 -0800 | [diff] [blame] | 530 | static inline int node_memory_callback(struct notifier_block *self, |
| 531 | unsigned long action, void *arg) |
| 532 | { |
| 533 | return NOTIFY_OK; |
| 534 | } |
Lee Schermerhorn | 39da08c | 2009-12-14 17:58:36 -0800 | [diff] [blame] | 535 | |
| 536 | static void init_node_hugetlb_work(int nid) { } |
| 537 | |
| 538 | #endif |
Gary Hade | c04fc58 | 2009-01-06 14:39:14 -0800 | [diff] [blame] | 539 | |
Yasunori Goto | 0fc4415 | 2006-06-27 02:53:38 -0700 | [diff] [blame] | 540 | int register_one_node(int nid) |
| 541 | { |
| 542 | int error = 0; |
KAMEZAWA Hiroyuki | 76b67ed | 2006-06-27 02:53:41 -0700 | [diff] [blame] | 543 | int cpu; |
Yasunori Goto | 0fc4415 | 2006-06-27 02:53:38 -0700 | [diff] [blame] | 544 | |
| 545 | if (node_online(nid)) { |
| 546 | int p_node = parent_node(nid); |
| 547 | struct node *parent = NULL; |
| 548 | |
| 549 | if (p_node != nid) |
| 550 | parent = &node_devices[p_node]; |
| 551 | |
| 552 | error = register_node(&node_devices[nid], nid, parent); |
KAMEZAWA Hiroyuki | 76b67ed | 2006-06-27 02:53:41 -0700 | [diff] [blame] | 553 | |
| 554 | /* link cpu under this node */ |
| 555 | for_each_present_cpu(cpu) { |
| 556 | if (cpu_to_node(cpu) == nid) |
| 557 | register_cpu_under_node(cpu, nid); |
| 558 | } |
Gary Hade | c04fc58 | 2009-01-06 14:39:14 -0800 | [diff] [blame] | 559 | |
| 560 | /* link memory sections under this node */ |
| 561 | error = link_mem_sections(nid); |
Lee Schermerhorn | 39da08c | 2009-12-14 17:58:36 -0800 | [diff] [blame] | 562 | |
| 563 | /* initialize work queue for memory hot plug */ |
| 564 | init_node_hugetlb_work(nid); |
Yasunori Goto | 0fc4415 | 2006-06-27 02:53:38 -0700 | [diff] [blame] | 565 | } |
| 566 | |
| 567 | return error; |
| 568 | |
| 569 | } |
| 570 | |
| 571 | void unregister_one_node(int nid) |
| 572 | { |
| 573 | unregister_node(&node_devices[nid]); |
| 574 | } |
| 575 | |
Lee Schermerhorn | bde631a | 2007-10-16 01:26:27 -0700 | [diff] [blame] | 576 | /* |
| 577 | * node states attributes |
| 578 | */ |
| 579 | |
| 580 | static ssize_t print_nodes_state(enum node_states state, char *buf) |
| 581 | { |
| 582 | int n; |
| 583 | |
| 584 | n = nodelist_scnprintf(buf, PAGE_SIZE, node_states[state]); |
| 585 | if (n > 0 && PAGE_SIZE > n + 1) { |
| 586 | *(buf + n++) = '\n'; |
| 587 | *(buf + n++) = '\0'; |
| 588 | } |
| 589 | return n; |
| 590 | } |
| 591 | |
Andi Kleen | b15f562 | 2010-01-05 12:47:59 +0100 | [diff] [blame] | 592 | struct node_attr { |
| 593 | struct sysdev_class_attribute attr; |
| 594 | enum node_states state; |
| 595 | }; |
| 596 | |
| 597 | static ssize_t show_node_state(struct sysdev_class *class, |
| 598 | struct sysdev_class_attribute *attr, char *buf) |
Lee Schermerhorn | bde631a | 2007-10-16 01:26:27 -0700 | [diff] [blame] | 599 | { |
Andi Kleen | b15f562 | 2010-01-05 12:47:59 +0100 | [diff] [blame] | 600 | struct node_attr *na = container_of(attr, struct node_attr, attr); |
| 601 | return print_nodes_state(na->state, buf); |
Lee Schermerhorn | bde631a | 2007-10-16 01:26:27 -0700 | [diff] [blame] | 602 | } |
| 603 | |
Andi Kleen | b15f562 | 2010-01-05 12:47:59 +0100 | [diff] [blame] | 604 | #define _NODE_ATTR(name, state) \ |
| 605 | { _SYSDEV_CLASS_ATTR(name, 0444, show_node_state, NULL), state } |
Lee Schermerhorn | bde631a | 2007-10-16 01:26:27 -0700 | [diff] [blame] | 606 | |
Andi Kleen | b15f562 | 2010-01-05 12:47:59 +0100 | [diff] [blame] | 607 | static struct node_attr node_state_attr[] = { |
| 608 | _NODE_ATTR(possible, N_POSSIBLE), |
| 609 | _NODE_ATTR(online, N_ONLINE), |
| 610 | _NODE_ATTR(has_normal_memory, N_NORMAL_MEMORY), |
| 611 | _NODE_ATTR(has_cpu, N_CPU), |
Lee Schermerhorn | bde631a | 2007-10-16 01:26:27 -0700 | [diff] [blame] | 612 | #ifdef CONFIG_HIGHMEM |
Andi Kleen | b15f562 | 2010-01-05 12:47:59 +0100 | [diff] [blame] | 613 | _NODE_ATTR(has_high_memory, N_HIGH_MEMORY), |
Lee Schermerhorn | bde631a | 2007-10-16 01:26:27 -0700 | [diff] [blame] | 614 | #endif |
Lee Schermerhorn | bde631a | 2007-10-16 01:26:27 -0700 | [diff] [blame] | 615 | }; |
| 616 | |
Andi Kleen | 3701cde | 2010-01-05 12:48:04 +0100 | [diff] [blame] | 617 | static struct sysdev_class_attribute *node_state_attrs[] = { |
| 618 | &node_state_attr[0].attr, |
| 619 | &node_state_attr[1].attr, |
| 620 | &node_state_attr[2].attr, |
| 621 | &node_state_attr[3].attr, |
| 622 | #ifdef CONFIG_HIGHMEM |
| 623 | &node_state_attr[4].attr, |
| 624 | #endif |
| 625 | NULL |
| 626 | }; |
Lee Schermerhorn | bde631a | 2007-10-16 01:26:27 -0700 | [diff] [blame] | 627 | |
Lee Schermerhorn | 4faf8d9 | 2009-12-14 17:58:35 -0800 | [diff] [blame] | 628 | #define NODE_CALLBACK_PRI 2 /* lower than SLAB */ |
Keiichiro Tokunaga | 4b45099 | 2005-05-08 21:28:53 +0900 | [diff] [blame] | 629 | static int __init register_node_type(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 630 | { |
Lee Schermerhorn | bde631a | 2007-10-16 01:26:27 -0700 | [diff] [blame] | 631 | int ret; |
| 632 | |
Andi Kleen | 3701cde | 2010-01-05 12:48:04 +0100 | [diff] [blame] | 633 | BUILD_BUG_ON(ARRAY_SIZE(node_state_attr) != NR_NODE_STATES); |
| 634 | BUILD_BUG_ON(ARRAY_SIZE(node_state_attrs)-1 != NR_NODE_STATES); |
| 635 | |
Lee Schermerhorn | bde631a | 2007-10-16 01:26:27 -0700 | [diff] [blame] | 636 | ret = sysdev_class_register(&node_class); |
Lee Schermerhorn | 4faf8d9 | 2009-12-14 17:58:35 -0800 | [diff] [blame] | 637 | if (!ret) { |
Lee Schermerhorn | 4faf8d9 | 2009-12-14 17:58:35 -0800 | [diff] [blame] | 638 | hotplug_memory_notifier(node_memory_callback, |
| 639 | NODE_CALLBACK_PRI); |
| 640 | } |
Lee Schermerhorn | bde631a | 2007-10-16 01:26:27 -0700 | [diff] [blame] | 641 | |
| 642 | /* |
| 643 | * Note: we're not going to unregister the node class if we fail |
| 644 | * to register the node state class attribute files. |
| 645 | */ |
| 646 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 647 | } |
| 648 | postcore_initcall(register_node_type); |