mm_init.c 4.8 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. pr_cont("%d:%s ", zone->node, zone->name);
  50. #else
  51. pr_cont("0:%s ", zone->name);
  52. #endif /* CONFIG_NUMA */
  53. }
  54. pr_cont("\n");
  55. }
  56. }
  57. }
  58. void __init mminit_verify_pageflags_layout(void)
  59. {
  60. int shift, width;
  61. unsigned long or_mask, add_mask;
  62. shift = 8 * sizeof(unsigned long);
  63. width = shift - SECTIONS_WIDTH - NODES_WIDTH - ZONES_WIDTH - LAST_CPUPID_SHIFT;
  64. mminit_dprintk(MMINIT_TRACE, "pageflags_layout_widths",
  65. "Section %d Node %d Zone %d Lastcpupid %d Flags %d\n",
  66. SECTIONS_WIDTH,
  67. NODES_WIDTH,
  68. ZONES_WIDTH,
  69. LAST_CPUPID_WIDTH,
  70. NR_PAGEFLAGS);
  71. mminit_dprintk(MMINIT_TRACE, "pageflags_layout_shifts",
  72. "Section %d Node %d Zone %d Lastcpupid %d\n",
  73. SECTIONS_SHIFT,
  74. NODES_SHIFT,
  75. ZONES_SHIFT,
  76. LAST_CPUPID_SHIFT);
  77. mminit_dprintk(MMINIT_TRACE, "pageflags_layout_pgshifts",
  78. "Section %lu Node %lu Zone %lu Lastcpupid %lu\n",
  79. (unsigned long)SECTIONS_PGSHIFT,
  80. (unsigned long)NODES_PGSHIFT,
  81. (unsigned long)ZONES_PGSHIFT,
  82. (unsigned long)LAST_CPUPID_PGSHIFT);
  83. mminit_dprintk(MMINIT_TRACE, "pageflags_layout_nodezoneid",
  84. "Node/Zone ID: %lu -> %lu\n",
  85. (unsigned long)(ZONEID_PGOFF + ZONEID_SHIFT),
  86. (unsigned long)ZONEID_PGOFF);
  87. mminit_dprintk(MMINIT_TRACE, "pageflags_layout_usage",
  88. "location: %d -> %d layout %d -> %d unused %d -> %d page-flags\n",
  89. shift, width, width, NR_PAGEFLAGS, NR_PAGEFLAGS, 0);
  90. #ifdef NODE_NOT_IN_PAGE_FLAGS
  91. mminit_dprintk(MMINIT_TRACE, "pageflags_layout_nodeflags",
  92. "Node not in page flags");
  93. #endif
  94. #ifdef LAST_CPUPID_NOT_IN_PAGE_FLAGS
  95. mminit_dprintk(MMINIT_TRACE, "pageflags_layout_nodeflags",
  96. "Last cpupid not in page flags");
  97. #endif
  98. if (SECTIONS_WIDTH) {
  99. shift -= SECTIONS_WIDTH;
  100. BUG_ON(shift != SECTIONS_PGSHIFT);
  101. }
  102. if (NODES_WIDTH) {
  103. shift -= NODES_WIDTH;
  104. BUG_ON(shift != NODES_PGSHIFT);
  105. }
  106. if (ZONES_WIDTH) {
  107. shift -= ZONES_WIDTH;
  108. BUG_ON(shift != ZONES_PGSHIFT);
  109. }
  110. /* Check for bitmask overlaps */
  111. or_mask = (ZONES_MASK << ZONES_PGSHIFT) |
  112. (NODES_MASK << NODES_PGSHIFT) |
  113. (SECTIONS_MASK << SECTIONS_PGSHIFT);
  114. add_mask = (ZONES_MASK << ZONES_PGSHIFT) +
  115. (NODES_MASK << NODES_PGSHIFT) +
  116. (SECTIONS_MASK << SECTIONS_PGSHIFT);
  117. BUG_ON(or_mask != add_mask);
  118. }
  119. static __init int set_mminit_loglevel(char *str)
  120. {
  121. get_option(&str, &mminit_loglevel);
  122. return 0;
  123. }
  124. early_param("mminit_loglevel", set_mminit_loglevel);
  125. #endif /* CONFIG_DEBUG_MEMORY_INIT */
  126. struct kobject *mm_kobj;
  127. EXPORT_SYMBOL_GPL(mm_kobj);
  128. #ifdef CONFIG_SMP
  129. s32 vm_committed_as_batch = 32;
  130. static void __meminit mm_compute_batch(void)
  131. {
  132. u64 memsized_batch;
  133. s32 nr = num_present_cpus();
  134. s32 batch = max_t(s32, nr*2, 32);
  135. /* batch size set to 0.4% of (total memory/#cpus), or max int32 */
  136. memsized_batch = min_t(u64, (totalram_pages/nr)/256, 0x7fffffff);
  137. vm_committed_as_batch = max_t(s32, memsized_batch, batch);
  138. }
  139. static int __meminit mm_compute_batch_notifier(struct notifier_block *self,
  140. unsigned long action, void *arg)
  141. {
  142. switch (action) {
  143. case MEM_ONLINE:
  144. case MEM_OFFLINE:
  145. mm_compute_batch();
  146. default:
  147. break;
  148. }
  149. return NOTIFY_OK;
  150. }
  151. static struct notifier_block compute_batch_nb __meminitdata = {
  152. .notifier_call = mm_compute_batch_notifier,
  153. .priority = IPC_CALLBACK_PRI, /* use lowest priority */
  154. };
  155. static int __init mm_compute_batch_init(void)
  156. {
  157. mm_compute_batch();
  158. register_hotmemory_notifier(&compute_batch_nb);
  159. return 0;
  160. }
  161. __initcall(mm_compute_batch_init);
  162. #endif
  163. static int __init mm_sysfs_init(void)
  164. {
  165. mm_kobj = kobject_create_and_add("mm", kernel_kobj);
  166. if (!mm_kobj)
  167. return -ENOMEM;
  168. return 0;
  169. }
  170. postcore_initcall(mm_sysfs_init);