memory.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732
  1. /*
  2. * Memory subsystem support
  3. *
  4. * Written by Matt Tolentino <matthew.e.tolentino@intel.com>
  5. * Dave Hansen <haveblue@us.ibm.com>
  6. *
  7. * This file provides the necessary infrastructure to represent
  8. * a SPARSEMEM-memory-model system's physical memory in /sysfs.
  9. * All arch-independent code that assumes MEMORY_HOTPLUG requires
  10. * SPARSEMEM should be contained here, or in mm/memory_hotplug.c.
  11. */
  12. #include <linux/module.h>
  13. #include <linux/init.h>
  14. #include <linux/topology.h>
  15. #include <linux/capability.h>
  16. #include <linux/device.h>
  17. #include <linux/memory.h>
  18. #include <linux/memory_hotplug.h>
  19. #include <linux/mm.h>
  20. #include <linux/mutex.h>
  21. #include <linux/stat.h>
  22. #include <linux/slab.h>
  23. #include <linux/atomic.h>
  24. #include <asm/uaccess.h>
  25. static DEFINE_MUTEX(mem_sysfs_mutex);
  26. #define MEMORY_CLASS_NAME "memory"
  27. #define to_memory_block(dev) container_of(dev, struct memory_block, dev)
  28. static int sections_per_block;
  29. static inline int base_memory_block_id(int section_nr)
  30. {
  31. return section_nr / sections_per_block;
  32. }
  33. static int memory_subsys_online(struct device *dev);
  34. static int memory_subsys_offline(struct device *dev);
  35. static struct bus_type memory_subsys = {
  36. .name = MEMORY_CLASS_NAME,
  37. .dev_name = MEMORY_CLASS_NAME,
  38. .online = memory_subsys_online,
  39. .offline = memory_subsys_offline,
  40. };
  41. static BLOCKING_NOTIFIER_HEAD(memory_chain);
  42. int register_memory_notifier(struct notifier_block *nb)
  43. {
  44. return blocking_notifier_chain_register(&memory_chain, nb);
  45. }
  46. EXPORT_SYMBOL(register_memory_notifier);
  47. void unregister_memory_notifier(struct notifier_block *nb)
  48. {
  49. blocking_notifier_chain_unregister(&memory_chain, nb);
  50. }
  51. EXPORT_SYMBOL(unregister_memory_notifier);
  52. static ATOMIC_NOTIFIER_HEAD(memory_isolate_chain);
  53. int register_memory_isolate_notifier(struct notifier_block *nb)
  54. {
  55. return atomic_notifier_chain_register(&memory_isolate_chain, nb);
  56. }
  57. EXPORT_SYMBOL(register_memory_isolate_notifier);
  58. void unregister_memory_isolate_notifier(struct notifier_block *nb)
  59. {
  60. atomic_notifier_chain_unregister(&memory_isolate_chain, nb);
  61. }
  62. EXPORT_SYMBOL(unregister_memory_isolate_notifier);
  63. static void memory_block_release(struct device *dev)
  64. {
  65. struct memory_block *mem = to_memory_block(dev);
  66. kfree(mem);
  67. }
  68. unsigned long __weak memory_block_size_bytes(void)
  69. {
  70. return MIN_MEMORY_BLOCK_SIZE;
  71. }
  72. static unsigned long get_memory_block_size(void)
  73. {
  74. unsigned long block_sz;
  75. block_sz = memory_block_size_bytes();
  76. /* Validate blk_sz is a power of 2 and not less than section size */
  77. if ((block_sz & (block_sz - 1)) || (block_sz < MIN_MEMORY_BLOCK_SIZE)) {
  78. WARN_ON(1);
  79. block_sz = MIN_MEMORY_BLOCK_SIZE;
  80. }
  81. return block_sz;
  82. }
  83. /*
  84. * use this as the physical section index that this memsection
  85. * uses.
  86. */
  87. static ssize_t show_mem_start_phys_index(struct device *dev,
  88. struct device_attribute *attr, char *buf)
  89. {
  90. struct memory_block *mem = to_memory_block(dev);
  91. unsigned long phys_index;
  92. phys_index = mem->start_section_nr / sections_per_block;
  93. return sprintf(buf, "%08lx\n", phys_index);
  94. }
  95. /*
  96. * Show whether the section of memory is likely to be hot-removable
  97. */
  98. static ssize_t show_mem_removable(struct device *dev,
  99. struct device_attribute *attr, char *buf)
  100. {
  101. unsigned long i, pfn;
  102. int ret = 1;
  103. struct memory_block *mem = to_memory_block(dev);
  104. for (i = 0; i < sections_per_block; i++) {
  105. if (!present_section_nr(mem->start_section_nr + i))
  106. continue;
  107. pfn = section_nr_to_pfn(mem->start_section_nr + i);
  108. ret &= is_mem_section_removable(pfn, PAGES_PER_SECTION);
  109. }
  110. return sprintf(buf, "%d\n", ret);
  111. }
  112. /*
  113. * online, offline, going offline, etc.
  114. */
  115. static ssize_t show_mem_state(struct device *dev,
  116. struct device_attribute *attr, char *buf)
  117. {
  118. struct memory_block *mem = to_memory_block(dev);
  119. ssize_t len = 0;
  120. /*
  121. * We can probably put these states in a nice little array
  122. * so that they're not open-coded
  123. */
  124. switch (mem->state) {
  125. case MEM_ONLINE:
  126. len = sprintf(buf, "online\n");
  127. break;
  128. case MEM_OFFLINE:
  129. len = sprintf(buf, "offline\n");
  130. break;
  131. case MEM_GOING_OFFLINE:
  132. len = sprintf(buf, "going-offline\n");
  133. break;
  134. default:
  135. len = sprintf(buf, "ERROR-UNKNOWN-%ld\n",
  136. mem->state);
  137. WARN_ON(1);
  138. break;
  139. }
  140. return len;
  141. }
  142. int memory_notify(unsigned long val, void *v)
  143. {
  144. return blocking_notifier_call_chain(&memory_chain, val, v);
  145. }
  146. int memory_isolate_notify(unsigned long val, void *v)
  147. {
  148. return atomic_notifier_call_chain(&memory_isolate_chain, val, v);
  149. }
  150. /*
  151. * The probe routines leave the pages reserved, just as the bootmem code does.
  152. * Make sure they're still that way.
  153. */
  154. static bool pages_correctly_reserved(unsigned long start_pfn)
  155. {
  156. int i, j;
  157. struct page *page;
  158. unsigned long pfn = start_pfn;
  159. /*
  160. * memmap between sections is not contiguous except with
  161. * SPARSEMEM_VMEMMAP. We lookup the page once per section
  162. * and assume memmap is contiguous within each section
  163. */
  164. for (i = 0; i < sections_per_block; i++, pfn += PAGES_PER_SECTION) {
  165. if (WARN_ON_ONCE(!pfn_valid(pfn)))
  166. return false;
  167. page = pfn_to_page(pfn);
  168. for (j = 0; j < PAGES_PER_SECTION; j++) {
  169. if (PageReserved(page + j))
  170. continue;
  171. printk(KERN_WARNING "section number %ld page number %d "
  172. "not reserved, was it already online?\n",
  173. pfn_to_section_nr(pfn), j);
  174. return false;
  175. }
  176. }
  177. return true;
  178. }
  179. /*
  180. * MEMORY_HOTPLUG depends on SPARSEMEM in mm/Kconfig, so it is
  181. * OK to have direct references to sparsemem variables in here.
  182. */
  183. static int
  184. memory_block_action(unsigned long phys_index, unsigned long action, int online_type)
  185. {
  186. unsigned long start_pfn;
  187. unsigned long nr_pages = PAGES_PER_SECTION * sections_per_block;
  188. struct page *first_page;
  189. int ret;
  190. first_page = pfn_to_page(phys_index << PFN_SECTION_SHIFT);
  191. start_pfn = page_to_pfn(first_page);
  192. switch (action) {
  193. case MEM_ONLINE:
  194. if (!pages_correctly_reserved(start_pfn))
  195. return -EBUSY;
  196. ret = online_pages(start_pfn, nr_pages, online_type);
  197. break;
  198. case MEM_OFFLINE:
  199. ret = offline_pages(start_pfn, nr_pages);
  200. break;
  201. default:
  202. WARN(1, KERN_WARNING "%s(%ld, %ld) unknown action: "
  203. "%ld\n", __func__, phys_index, action, action);
  204. ret = -EINVAL;
  205. }
  206. return ret;
  207. }
  208. static int memory_block_change_state(struct memory_block *mem,
  209. unsigned long to_state, unsigned long from_state_req)
  210. {
  211. int ret = 0;
  212. if (mem->state != from_state_req)
  213. return -EINVAL;
  214. if (to_state == MEM_OFFLINE)
  215. mem->state = MEM_GOING_OFFLINE;
  216. ret = memory_block_action(mem->start_section_nr, to_state,
  217. mem->online_type);
  218. mem->state = ret ? from_state_req : to_state;
  219. return ret;
  220. }
  221. /* The device lock serializes operations on memory_subsys_[online|offline] */
  222. static int memory_subsys_online(struct device *dev)
  223. {
  224. struct memory_block *mem = to_memory_block(dev);
  225. int ret;
  226. if (mem->state == MEM_ONLINE)
  227. return 0;
  228. /*
  229. * If we are called from store_mem_state(), online_type will be
  230. * set >= 0 Otherwise we were called from the device online
  231. * attribute and need to set the online_type.
  232. */
  233. if (mem->online_type < 0)
  234. mem->online_type = ONLINE_KEEP;
  235. ret = memory_block_change_state(mem, MEM_ONLINE, MEM_OFFLINE);
  236. /* clear online_type */
  237. mem->online_type = -1;
  238. return ret;
  239. }
  240. static int memory_subsys_offline(struct device *dev)
  241. {
  242. struct memory_block *mem = to_memory_block(dev);
  243. if (mem->state == MEM_OFFLINE)
  244. return 0;
  245. return memory_block_change_state(mem, MEM_OFFLINE, MEM_ONLINE);
  246. }
  247. static ssize_t
  248. store_mem_state(struct device *dev,
  249. struct device_attribute *attr, const char *buf, size_t count)
  250. {
  251. struct memory_block *mem = to_memory_block(dev);
  252. int ret, online_type;
  253. ret = lock_device_hotplug_sysfs();
  254. if (ret)
  255. return ret;
  256. if (!strncmp(buf, "online_kernel", min_t(int, count, 13)))
  257. online_type = ONLINE_KERNEL;
  258. else if (!strncmp(buf, "online_movable", min_t(int, count, 14)))
  259. online_type = ONLINE_MOVABLE;
  260. else if (!strncmp(buf, "online", min_t(int, count, 6)))
  261. online_type = ONLINE_KEEP;
  262. else if (!strncmp(buf, "offline", min_t(int, count, 7)))
  263. online_type = -1;
  264. else {
  265. ret = -EINVAL;
  266. goto err;
  267. }
  268. switch (online_type) {
  269. case ONLINE_KERNEL:
  270. case ONLINE_MOVABLE:
  271. case ONLINE_KEEP:
  272. /*
  273. * mem->online_type is not protected so there can be a
  274. * race here. However, when racing online, the first
  275. * will succeed and the second will just return as the
  276. * block will already be online. The online type
  277. * could be either one, but that is expected.
  278. */
  279. mem->online_type = online_type;
  280. ret = device_online(&mem->dev);
  281. break;
  282. case -1:
  283. ret = device_offline(&mem->dev);
  284. break;
  285. default:
  286. ret = -EINVAL; /* should never happen */
  287. }
  288. err:
  289. unlock_device_hotplug();
  290. if (ret)
  291. return ret;
  292. return count;
  293. }
  294. /*
  295. * phys_device is a bad name for this. What I really want
  296. * is a way to differentiate between memory ranges that
  297. * are part of physical devices that constitute
  298. * a complete removable unit or fru.
  299. * i.e. do these ranges belong to the same physical device,
  300. * s.t. if I offline all of these sections I can then
  301. * remove the physical device?
  302. */
  303. static ssize_t show_phys_device(struct device *dev,
  304. struct device_attribute *attr, char *buf)
  305. {
  306. struct memory_block *mem = to_memory_block(dev);
  307. return sprintf(buf, "%d\n", mem->phys_device);
  308. }
  309. static DEVICE_ATTR(phys_index, 0444, show_mem_start_phys_index, NULL);
  310. static DEVICE_ATTR(state, 0644, show_mem_state, store_mem_state);
  311. static DEVICE_ATTR(phys_device, 0444, show_phys_device, NULL);
  312. static DEVICE_ATTR(removable, 0444, show_mem_removable, NULL);
  313. /*
  314. * Block size attribute stuff
  315. */
  316. static ssize_t
  317. print_block_size(struct device *dev, struct device_attribute *attr,
  318. char *buf)
  319. {
  320. return sprintf(buf, "%lx\n", get_memory_block_size());
  321. }
  322. static DEVICE_ATTR(block_size_bytes, 0444, print_block_size, NULL);
  323. /*
  324. * Some architectures will have custom drivers to do this, and
  325. * will not need to do it from userspace. The fake hot-add code
  326. * as well as ppc64 will do all of their discovery in userspace
  327. * and will require this interface.
  328. */
  329. #ifdef CONFIG_ARCH_MEMORY_PROBE
  330. static ssize_t
  331. memory_probe_store(struct device *dev, struct device_attribute *attr,
  332. const char *buf, size_t count)
  333. {
  334. u64 phys_addr;
  335. int nid;
  336. int i, ret;
  337. unsigned long pages_per_block = PAGES_PER_SECTION * sections_per_block;
  338. phys_addr = simple_strtoull(buf, NULL, 0);
  339. if (phys_addr & ((pages_per_block << PAGE_SHIFT) - 1))
  340. return -EINVAL;
  341. for (i = 0; i < sections_per_block; i++) {
  342. nid = memory_add_physaddr_to_nid(phys_addr);
  343. ret = add_memory(nid, phys_addr,
  344. PAGES_PER_SECTION << PAGE_SHIFT);
  345. if (ret)
  346. goto out;
  347. phys_addr += MIN_MEMORY_BLOCK_SIZE;
  348. }
  349. ret = count;
  350. out:
  351. return ret;
  352. }
  353. static DEVICE_ATTR(probe, S_IWUSR, NULL, memory_probe_store);
  354. #endif
  355. #ifdef CONFIG_MEMORY_FAILURE
  356. /*
  357. * Support for offlining pages of memory
  358. */
  359. /* Soft offline a page */
  360. static ssize_t
  361. store_soft_offline_page(struct device *dev,
  362. struct device_attribute *attr,
  363. const char *buf, size_t count)
  364. {
  365. int ret;
  366. u64 pfn;
  367. if (!capable(CAP_SYS_ADMIN))
  368. return -EPERM;
  369. if (kstrtoull(buf, 0, &pfn) < 0)
  370. return -EINVAL;
  371. pfn >>= PAGE_SHIFT;
  372. if (!pfn_valid(pfn))
  373. return -ENXIO;
  374. ret = soft_offline_page(pfn_to_page(pfn), 0);
  375. return ret == 0 ? count : ret;
  376. }
  377. /* Forcibly offline a page, including killing processes. */
  378. static ssize_t
  379. store_hard_offline_page(struct device *dev,
  380. struct device_attribute *attr,
  381. const char *buf, size_t count)
  382. {
  383. int ret;
  384. u64 pfn;
  385. if (!capable(CAP_SYS_ADMIN))
  386. return -EPERM;
  387. if (kstrtoull(buf, 0, &pfn) < 0)
  388. return -EINVAL;
  389. pfn >>= PAGE_SHIFT;
  390. ret = memory_failure(pfn, 0, 0);
  391. return ret ? ret : count;
  392. }
  393. static DEVICE_ATTR(soft_offline_page, S_IWUSR, NULL, store_soft_offline_page);
  394. static DEVICE_ATTR(hard_offline_page, S_IWUSR, NULL, store_hard_offline_page);
  395. #endif
  396. /*
  397. * Note that phys_device is optional. It is here to allow for
  398. * differentiation between which *physical* devices each
  399. * section belongs to...
  400. */
  401. int __weak arch_get_memory_phys_device(unsigned long start_pfn)
  402. {
  403. return 0;
  404. }
  405. /*
  406. * A reference for the returned object is held and the reference for the
  407. * hinted object is released.
  408. */
  409. struct memory_block *find_memory_block_hinted(struct mem_section *section,
  410. struct memory_block *hint)
  411. {
  412. int block_id = base_memory_block_id(__section_nr(section));
  413. struct device *hintdev = hint ? &hint->dev : NULL;
  414. struct device *dev;
  415. dev = subsys_find_device_by_id(&memory_subsys, block_id, hintdev);
  416. if (hint)
  417. put_device(&hint->dev);
  418. if (!dev)
  419. return NULL;
  420. return to_memory_block(dev);
  421. }
  422. /*
  423. * For now, we have a linear search to go find the appropriate
  424. * memory_block corresponding to a particular phys_index. If
  425. * this gets to be a real problem, we can always use a radix
  426. * tree or something here.
  427. *
  428. * This could be made generic for all device subsystems.
  429. */
  430. struct memory_block *find_memory_block(struct mem_section *section)
  431. {
  432. return find_memory_block_hinted(section, NULL);
  433. }
  434. static struct attribute *memory_memblk_attrs[] = {
  435. &dev_attr_phys_index.attr,
  436. &dev_attr_state.attr,
  437. &dev_attr_phys_device.attr,
  438. &dev_attr_removable.attr,
  439. NULL
  440. };
  441. static struct attribute_group memory_memblk_attr_group = {
  442. .attrs = memory_memblk_attrs,
  443. };
  444. static const struct attribute_group *memory_memblk_attr_groups[] = {
  445. &memory_memblk_attr_group,
  446. NULL,
  447. };
  448. /*
  449. * register_memory - Setup a sysfs device for a memory block
  450. */
  451. static
  452. int register_memory(struct memory_block *memory)
  453. {
  454. memory->dev.bus = &memory_subsys;
  455. memory->dev.id = memory->start_section_nr / sections_per_block;
  456. memory->dev.release = memory_block_release;
  457. memory->dev.groups = memory_memblk_attr_groups;
  458. memory->dev.offline = memory->state == MEM_OFFLINE;
  459. return device_register(&memory->dev);
  460. }
  461. static int init_memory_block(struct memory_block **memory,
  462. struct mem_section *section, unsigned long state)
  463. {
  464. struct memory_block *mem;
  465. unsigned long start_pfn;
  466. int scn_nr;
  467. int ret = 0;
  468. mem = kzalloc(sizeof(*mem), GFP_KERNEL);
  469. if (!mem)
  470. return -ENOMEM;
  471. scn_nr = __section_nr(section);
  472. mem->start_section_nr =
  473. base_memory_block_id(scn_nr) * sections_per_block;
  474. mem->end_section_nr = mem->start_section_nr + sections_per_block - 1;
  475. mem->state = state;
  476. mem->section_count++;
  477. start_pfn = section_nr_to_pfn(mem->start_section_nr);
  478. mem->phys_device = arch_get_memory_phys_device(start_pfn);
  479. ret = register_memory(mem);
  480. *memory = mem;
  481. return ret;
  482. }
  483. static int add_memory_block(int base_section_nr)
  484. {
  485. struct memory_block *mem;
  486. int i, ret, section_count = 0, section_nr;
  487. for (i = base_section_nr;
  488. (i < base_section_nr + sections_per_block) && i < NR_MEM_SECTIONS;
  489. i++) {
  490. if (!present_section_nr(i))
  491. continue;
  492. if (section_count == 0)
  493. section_nr = i;
  494. section_count++;
  495. }
  496. if (section_count == 0)
  497. return 0;
  498. ret = init_memory_block(&mem, __nr_to_section(section_nr), MEM_ONLINE);
  499. if (ret)
  500. return ret;
  501. mem->section_count = section_count;
  502. return 0;
  503. }
  504. /*
  505. * need an interface for the VM to add new memory regions,
  506. * but without onlining it.
  507. */
  508. int register_new_memory(int nid, struct mem_section *section)
  509. {
  510. int ret = 0;
  511. struct memory_block *mem;
  512. mutex_lock(&mem_sysfs_mutex);
  513. mem = find_memory_block(section);
  514. if (mem) {
  515. mem->section_count++;
  516. put_device(&mem->dev);
  517. } else {
  518. ret = init_memory_block(&mem, section, MEM_OFFLINE);
  519. if (ret)
  520. goto out;
  521. }
  522. if (mem->section_count == sections_per_block)
  523. ret = register_mem_sect_under_node(mem, nid);
  524. out:
  525. mutex_unlock(&mem_sysfs_mutex);
  526. return ret;
  527. }
  528. #ifdef CONFIG_MEMORY_HOTREMOVE
  529. static void
  530. unregister_memory(struct memory_block *memory)
  531. {
  532. BUG_ON(memory->dev.bus != &memory_subsys);
  533. /* drop the ref. we got in remove_memory_block() */
  534. put_device(&memory->dev);
  535. device_unregister(&memory->dev);
  536. }
  537. static int remove_memory_block(unsigned long node_id,
  538. struct mem_section *section, int phys_device)
  539. {
  540. struct memory_block *mem;
  541. mutex_lock(&mem_sysfs_mutex);
  542. mem = find_memory_block(section);
  543. unregister_mem_sect_under_nodes(mem, __section_nr(section));
  544. mem->section_count--;
  545. if (mem->section_count == 0)
  546. unregister_memory(mem);
  547. else
  548. put_device(&mem->dev);
  549. mutex_unlock(&mem_sysfs_mutex);
  550. return 0;
  551. }
  552. int unregister_memory_section(struct mem_section *section)
  553. {
  554. if (!present_section(section))
  555. return -EINVAL;
  556. return remove_memory_block(0, section, 0);
  557. }
  558. #endif /* CONFIG_MEMORY_HOTREMOVE */
  559. /* return true if the memory block is offlined, otherwise, return false */
  560. bool is_memblock_offlined(struct memory_block *mem)
  561. {
  562. return mem->state == MEM_OFFLINE;
  563. }
  564. static struct attribute *memory_root_attrs[] = {
  565. #ifdef CONFIG_ARCH_MEMORY_PROBE
  566. &dev_attr_probe.attr,
  567. #endif
  568. #ifdef CONFIG_MEMORY_FAILURE
  569. &dev_attr_soft_offline_page.attr,
  570. &dev_attr_hard_offline_page.attr,
  571. #endif
  572. &dev_attr_block_size_bytes.attr,
  573. NULL
  574. };
  575. static struct attribute_group memory_root_attr_group = {
  576. .attrs = memory_root_attrs,
  577. };
  578. static const struct attribute_group *memory_root_attr_groups[] = {
  579. &memory_root_attr_group,
  580. NULL,
  581. };
  582. /*
  583. * Initialize the sysfs support for memory devices...
  584. */
  585. int __init memory_dev_init(void)
  586. {
  587. unsigned int i;
  588. int ret;
  589. int err;
  590. unsigned long block_sz;
  591. ret = subsys_system_register(&memory_subsys, memory_root_attr_groups);
  592. if (ret)
  593. goto out;
  594. block_sz = get_memory_block_size();
  595. sections_per_block = block_sz / MIN_MEMORY_BLOCK_SIZE;
  596. /*
  597. * Create entries for memory sections that were found
  598. * during boot and have been initialized
  599. */
  600. mutex_lock(&mem_sysfs_mutex);
  601. for (i = 0; i < NR_MEM_SECTIONS; i += sections_per_block) {
  602. err = add_memory_block(i);
  603. if (!ret)
  604. ret = err;
  605. }
  606. mutex_unlock(&mem_sysfs_mutex);
  607. out:
  608. if (ret)
  609. printk(KERN_ERR "%s() failed: %d\n", __func__, ret);
  610. return ret;
  611. }