mm_init.c 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  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/module.h>
  12. #include "internal.h"
  13. #ifdef CONFIG_DEBUG_MEMORY_INIT
  14. int mminit_loglevel;
  15. #ifndef SECTIONS_SHIFT
  16. #define SECTIONS_SHIFT 0
  17. #endif
  18. /* The zonelists are simply reported, validation is manual. */
  19. void mminit_verify_zonelist(void)
  20. {
  21. int nid;
  22. if (mminit_loglevel < MMINIT_VERIFY)
  23. return;
  24. for_each_online_node(nid) {
  25. pg_data_t *pgdat = NODE_DATA(nid);
  26. struct zone *zone;
  27. struct zoneref *z;
  28. struct zonelist *zonelist;
  29. int i, listid, zoneid;
  30. BUG_ON(MAX_ZONELISTS > 2);
  31. for (i = 0; i < MAX_ZONELISTS * MAX_NR_ZONES; i++) {
  32. /* Identify the zone and nodelist */
  33. zoneid = i % MAX_NR_ZONES;
  34. listid = i / MAX_NR_ZONES;
  35. zonelist = &pgdat->node_zonelists[listid];
  36. zone = &pgdat->node_zones[zoneid];
  37. if (!populated_zone(zone))
  38. continue;
  39. /* Print information about the zonelist */
  40. printk(KERN_DEBUG "mminit::zonelist %s %d:%s = ",
  41. listid > 0 ? "thisnode" : "general", nid,
  42. zone->name);
  43. /* Iterate the zonelist */
  44. for_each_zone_zonelist(zone, z, zonelist, zoneid) {
  45. #ifdef CONFIG_NUMA
  46. printk(KERN_CONT "%d:%s ",
  47. zone->node, zone->name);
  48. #else
  49. printk(KERN_CONT "0:%s ", zone->name);
  50. #endif /* CONFIG_NUMA */
  51. }
  52. printk(KERN_CONT "\n");
  53. }
  54. }
  55. }
  56. void __init mminit_verify_pageflags_layout(void)
  57. {
  58. int shift, width;
  59. unsigned long or_mask, add_mask;
  60. shift = 8 * sizeof(unsigned long);
  61. width = shift - SECTIONS_WIDTH - NODES_WIDTH - ZONES_WIDTH;
  62. mminit_dprintk(MMINIT_TRACE, "pageflags_layout_widths",
  63. "Section %d Node %d Zone %d Flags %d\n",
  64. SECTIONS_WIDTH,
  65. NODES_WIDTH,
  66. ZONES_WIDTH,
  67. NR_PAGEFLAGS);
  68. mminit_dprintk(MMINIT_TRACE, "pageflags_layout_shifts",
  69. "Section %d Node %d Zone %d\n",
  70. SECTIONS_SHIFT,
  71. NODES_SHIFT,
  72. ZONES_SHIFT);
  73. mminit_dprintk(MMINIT_TRACE, "pageflags_layout_offsets",
  74. "Section %lu Node %lu Zone %lu\n",
  75. (unsigned long)SECTIONS_PGSHIFT,
  76. (unsigned long)NODES_PGSHIFT,
  77. (unsigned long)ZONES_PGSHIFT);
  78. mminit_dprintk(MMINIT_TRACE, "pageflags_layout_zoneid",
  79. "Zone ID: %lu -> %lu\n",
  80. (unsigned long)ZONEID_PGOFF,
  81. (unsigned long)(ZONEID_PGOFF + ZONEID_SHIFT));
  82. mminit_dprintk(MMINIT_TRACE, "pageflags_layout_usage",
  83. "location: %d -> %d unused %d -> %d flags %d -> %d\n",
  84. shift, width, width, NR_PAGEFLAGS, NR_PAGEFLAGS, 0);
  85. #ifdef NODE_NOT_IN_PAGE_FLAGS
  86. mminit_dprintk(MMINIT_TRACE, "pageflags_layout_nodeflags",
  87. "Node not in page flags");
  88. #endif
  89. if (SECTIONS_WIDTH) {
  90. shift -= SECTIONS_WIDTH;
  91. BUG_ON(shift != SECTIONS_PGSHIFT);
  92. }
  93. if (NODES_WIDTH) {
  94. shift -= NODES_WIDTH;
  95. BUG_ON(shift != NODES_PGSHIFT);
  96. }
  97. if (ZONES_WIDTH) {
  98. shift -= ZONES_WIDTH;
  99. BUG_ON(shift != ZONES_PGSHIFT);
  100. }
  101. /* Check for bitmask overlaps */
  102. or_mask = (ZONES_MASK << ZONES_PGSHIFT) |
  103. (NODES_MASK << NODES_PGSHIFT) |
  104. (SECTIONS_MASK << SECTIONS_PGSHIFT);
  105. add_mask = (ZONES_MASK << ZONES_PGSHIFT) +
  106. (NODES_MASK << NODES_PGSHIFT) +
  107. (SECTIONS_MASK << SECTIONS_PGSHIFT);
  108. BUG_ON(or_mask != add_mask);
  109. }
  110. void __meminit mminit_verify_page_links(struct page *page, enum zone_type zone,
  111. unsigned long nid, unsigned long pfn)
  112. {
  113. BUG_ON(page_to_nid(page) != nid);
  114. BUG_ON(page_zonenum(page) != zone);
  115. BUG_ON(page_to_pfn(page) != pfn);
  116. }
  117. static __init int set_mminit_loglevel(char *str)
  118. {
  119. get_option(&str, &mminit_loglevel);
  120. return 0;
  121. }
  122. early_param("mminit_loglevel", set_mminit_loglevel);
  123. #endif /* CONFIG_DEBUG_MEMORY_INIT */
  124. struct kobject *mm_kobj;
  125. EXPORT_SYMBOL_GPL(mm_kobj);
  126. static int __init mm_sysfs_init(void)
  127. {
  128. mm_kobj = kobject_create_and_add("mm", kernel_kobj);
  129. if (!mm_kobj)
  130. return -ENOMEM;
  131. return 0;
  132. }
  133. __initcall(mm_sysfs_init);