mm_init.c 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. /*
  2. * mm_init.c - Memory initialisation verification and debugging
  3. *
  4. * Copyright 2008 IBM Corporation, 2008
  5. * Author Mel Gorman <mel@csn.ul.ie>
  6. *
  7. */
  8. #include <linux/kernel.h>
  9. #include <linux/init.h>
  10. #include <linux/kobject.h>
  11. #include <linux/export.h>
  12. #include <linux/memory.h>
  13. #include <linux/notifier.h>
  14. #include <linux/sched.h>
  15. #include "internal.h"
  16. #ifdef CONFIG_DEBUG_MEMORY_INIT
  17. int __meminitdata mminit_loglevel;
  18. #ifndef SECTIONS_SHIFT
  19. #define SECTIONS_SHIFT 0
  20. #endif
  21. /* The zonelists are simply reported, validation is manual. */
  22. void __init mminit_verify_zonelist(void)
  23. {
  24. int nid;
  25. if (mminit_loglevel < MMINIT_VERIFY)
  26. return;
  27. for_each_online_node(nid) {
  28. pg_data_t *pgdat = NODE_DATA(nid);
  29. struct zone *zone;
  30. struct zoneref *z;
  31. struct zonelist *zonelist;
  32. int i, listid, zoneid;
  33. BUG_ON(MAX_ZONELISTS > 2);
  34. for (i = 0; i < MAX_ZONELISTS * MAX_NR_ZONES; i++) {
  35. /* Identify the zone and nodelist */
  36. zoneid = i % MAX_NR_ZONES;
  37. listid = i / MAX_NR_ZONES;
  38. zonelist = &pgdat->node_zonelists[listid];
  39. zone = &pgdat->node_zones[zoneid];
  40. if (!populated_zone(zone))
  41. continue;
  42. /* Print information about the zonelist */
  43. printk(KERN_DEBUG "mminit::zonelist %s %d:%s = ",
  44. listid > 0 ? "thisnode" : "general", nid,
  45. zone->name);
  46. /* Iterate the zonelist */
  47. for_each_zone_zonelist(zone, z, zonelist, zoneid) {
  48. #ifdef CONFIG_NUMA
  49. printk(KERN_CONT "%d:%s ",
  50. zone->node, zone->name);
  51. #else
  52. printk(KERN_CONT "0:%s ", zone->name);
  53. #endif /* CONFIG_NUMA */
  54. }
  55. printk(KERN_CONT "\n");
  56. }
  57. }
  58. }
  59. void __init mminit_verify_pageflags_layout(void)
  60. {
  61. int shift, width;
  62. unsigned long or_mask, add_mask;
  63. shift = 8 * sizeof(unsigned long);
  64. width = shift - SECTIONS_WIDTH - NODES_WIDTH - ZONES_WIDTH - LAST_CPUPID_SHIFT;
  65. mminit_dprintk(MMINIT_TRACE, "pageflags_layout_widths",
  66. "Section %d Node %d Zone %d Lastcpupid %d Flags %d\n",
  67. SECTIONS_WIDTH,
  68. NODES_WIDTH,
  69. ZONES_WIDTH,
  70. LAST_CPUPID_WIDTH,
  71. NR_PAGEFLAGS);
  72. mminit_dprintk(MMINIT_TRACE, "pageflags_layout_shifts",
  73. "Section %d Node %d Zone %d Lastcpupid %d\n",
  74. SECTIONS_SHIFT,
  75. NODES_SHIFT,
  76. ZONES_SHIFT,
  77. LAST_CPUPID_SHIFT);
  78. mminit_dprintk(MMINIT_TRACE, "pageflags_layout_pgshifts",
  79. "Section %lu Node %lu Zone %lu Lastcpupid %lu\n",
  80. (unsigned long)SECTIONS_PGSHIFT,
  81. (unsigned long)NODES_PGSHIFT,
  82. (unsigned long)ZONES_PGSHIFT,
  83. (unsigned long)LAST_CPUPID_PGSHIFT);
  84. mminit_dprintk(MMINIT_TRACE, "pageflags_layout_nodezoneid",
  85. "Node/Zone ID: %lu -> %lu\n",
  86. (unsigned long)(ZONEID_PGOFF + ZONEID_SHIFT),
  87. (unsigned long)ZONEID_PGOFF);
  88. mminit_dprintk(MMINIT_TRACE, "pageflags_layout_usage",
  89. "location: %d -> %d layout %d -> %d unused %d -> %d page-flags\n",
  90. shift, width, width, NR_PAGEFLAGS, NR_PAGEFLAGS, 0);
  91. #ifdef NODE_NOT_IN_PAGE_FLAGS
  92. mminit_dprintk(MMINIT_TRACE, "pageflags_layout_nodeflags",
  93. "Node not in page flags");
  94. #endif
  95. #ifdef LAST_CPUPID_NOT_IN_PAGE_FLAGS
  96. mminit_dprintk(MMINIT_TRACE, "pageflags_layout_nodeflags",
  97. "Last cpupid not in page flags");
  98. #endif
  99. if (SECTIONS_WIDTH) {
  100. shift -= SECTIONS_WIDTH;
  101. BUG_ON(shift != SECTIONS_PGSHIFT);
  102. }
  103. if (NODES_WIDTH) {
  104. shift -= NODES_WIDTH;
  105. BUG_ON(shift != NODES_PGSHIFT);
  106. }
  107. if (ZONES_WIDTH) {
  108. shift -= ZONES_WIDTH;
  109. BUG_ON(shift != ZONES_PGSHIFT);
  110. }
  111. /* Check for bitmask overlaps */
  112. or_mask = (ZONES_MASK << ZONES_PGSHIFT) |
  113. (NODES_MASK << NODES_PGSHIFT) |
  114. (SECTIONS_MASK << SECTIONS_PGSHIFT);
  115. add_mask = (ZONES_MASK << ZONES_PGSHIFT) +
  116. (NODES_MASK << NODES_PGSHIFT) +
  117. (SECTIONS_MASK << SECTIONS_PGSHIFT);
  118. BUG_ON(or_mask != add_mask);
  119. }
  120. static __init int set_mminit_loglevel(char *str)
  121. {
  122. get_option(&str, &mminit_loglevel);
  123. return 0;
  124. }
  125. early_param("mminit_loglevel", set_mminit_loglevel);
  126. #endif /* CONFIG_DEBUG_MEMORY_INIT */
  127. struct kobject *mm_kobj;
  128. EXPORT_SYMBOL_GPL(mm_kobj);
  129. #ifdef CONFIG_SMP
  130. s32 vm_committed_as_batch = 32;
  131. static void __meminit mm_compute_batch(void)
  132. {
  133. u64 memsized_batch;
  134. s32 nr = num_present_cpus();
  135. s32 batch = max_t(s32, nr*2, 32);
  136. /* batch size set to 0.4% of (total memory/#cpus), or max int32 */
  137. memsized_batch = min_t(u64, (totalram_pages/nr)/256, 0x7fffffff);
  138. vm_committed_as_batch = max_t(s32, memsized_batch, batch);
  139. }
  140. static int __meminit mm_compute_batch_notifier(struct notifier_block *self,
  141. unsigned long action, void *arg)
  142. {
  143. switch (action) {
  144. case MEM_ONLINE:
  145. case MEM_OFFLINE:
  146. mm_compute_batch();
  147. default:
  148. break;
  149. }
  150. return NOTIFY_OK;
  151. }
  152. static struct notifier_block compute_batch_nb __meminitdata = {
  153. .notifier_call = mm_compute_batch_notifier,
  154. .priority = IPC_CALLBACK_PRI, /* use lowest priority */
  155. };
  156. static int __init mm_compute_batch_init(void)
  157. {
  158. mm_compute_batch();
  159. register_hotmemory_notifier(&compute_batch_nb);
  160. return 0;
  161. }
  162. __initcall(mm_compute_batch_init);
  163. #endif
  164. static int __init mm_sysfs_init(void)
  165. {
  166. mm_kobj = kobject_create_and_add("mm", kernel_kobj);
  167. if (!mm_kobj)
  168. return -ENOMEM;
  169. return 0;
  170. }
  171. postcore_initcall(mm_sysfs_init);