Mel Gorman | 6b74ab9 | 2008-07-23 21:26:49 -0700 | [diff] [blame] | 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> |
Nishanth Aravamudan | ff7ea79 | 2008-07-23 21:27:39 -0700 | [diff] [blame] | 10 | #include <linux/kobject.h> |
Paul Gortmaker | b95f1b31 | 2011-10-16 02:01:52 -0400 | [diff] [blame] | 11 | #include <linux/export.h> |
Mel Gorman | 708614e | 2008-07-23 21:26:51 -0700 | [diff] [blame] | 12 | #include "internal.h" |
Mel Gorman | 6b74ab9 | 2008-07-23 21:26:49 -0700 | [diff] [blame] | 13 | |
Nishanth Aravamudan | 5e9426ab | 2008-07-23 21:27:39 -0700 | [diff] [blame] | 14 | #ifdef CONFIG_DEBUG_MEMORY_INIT |
Marcin Slusarz | 759f9a2 | 2008-08-20 14:09:06 -0700 | [diff] [blame] | 15 | int mminit_loglevel; |
Mel Gorman | 6b74ab9 | 2008-07-23 21:26:49 -0700 | [diff] [blame] | 16 | |
Andrew Morton | 5c9ffc9 | 2008-08-05 13:01:01 -0700 | [diff] [blame] | 17 | #ifndef SECTIONS_SHIFT |
| 18 | #define SECTIONS_SHIFT 0 |
| 19 | #endif |
| 20 | |
Mel Gorman | 68ad8df | 2008-07-23 21:26:52 -0700 | [diff] [blame] | 21 | /* The zonelists are simply reported, validation is manual. */ |
| 22 | void mminit_verify_zonelist(void) |
| 23 | { |
| 24 | int nid; |
| 25 | |
| 26 | if (mminit_loglevel < MMINIT_VERIFY) |
| 27 | return; |
| 28 | |
| 29 | for_each_online_node(nid) { |
| 30 | pg_data_t *pgdat = NODE_DATA(nid); |
| 31 | struct zone *zone; |
| 32 | struct zoneref *z; |
| 33 | struct zonelist *zonelist; |
| 34 | int i, listid, zoneid; |
| 35 | |
| 36 | BUG_ON(MAX_ZONELISTS > 2); |
| 37 | for (i = 0; i < MAX_ZONELISTS * MAX_NR_ZONES; i++) { |
| 38 | |
| 39 | /* Identify the zone and nodelist */ |
| 40 | zoneid = i % MAX_NR_ZONES; |
| 41 | listid = i / MAX_NR_ZONES; |
| 42 | zonelist = &pgdat->node_zonelists[listid]; |
| 43 | zone = &pgdat->node_zones[zoneid]; |
| 44 | if (!populated_zone(zone)) |
| 45 | continue; |
| 46 | |
| 47 | /* Print information about the zonelist */ |
| 48 | printk(KERN_DEBUG "mminit::zonelist %s %d:%s = ", |
| 49 | listid > 0 ? "thisnode" : "general", nid, |
| 50 | zone->name); |
| 51 | |
| 52 | /* Iterate the zonelist */ |
| 53 | for_each_zone_zonelist(zone, z, zonelist, zoneid) { |
| 54 | #ifdef CONFIG_NUMA |
| 55 | printk(KERN_CONT "%d:%s ", |
| 56 | zone->node, zone->name); |
| 57 | #else |
| 58 | printk(KERN_CONT "0:%s ", zone->name); |
| 59 | #endif /* CONFIG_NUMA */ |
| 60 | } |
| 61 | printk(KERN_CONT "\n"); |
| 62 | } |
| 63 | } |
| 64 | } |
| 65 | |
Mel Gorman | 708614e | 2008-07-23 21:26:51 -0700 | [diff] [blame] | 66 | void __init mminit_verify_pageflags_layout(void) |
| 67 | { |
| 68 | int shift, width; |
| 69 | unsigned long or_mask, add_mask; |
| 70 | |
| 71 | shift = 8 * sizeof(unsigned long); |
Mel Gorman | a4e1b4c | 2013-02-22 16:34:47 -0800 | [diff] [blame] | 72 | width = shift - SECTIONS_WIDTH - NODES_WIDTH - ZONES_WIDTH - LAST_NID_SHIFT; |
Mel Gorman | 708614e | 2008-07-23 21:26:51 -0700 | [diff] [blame] | 73 | mminit_dprintk(MMINIT_TRACE, "pageflags_layout_widths", |
Mel Gorman | a4e1b4c | 2013-02-22 16:34:47 -0800 | [diff] [blame] | 74 | "Section %d Node %d Zone %d Lastnid %d Flags %d\n", |
Mel Gorman | 708614e | 2008-07-23 21:26:51 -0700 | [diff] [blame] | 75 | SECTIONS_WIDTH, |
| 76 | NODES_WIDTH, |
| 77 | ZONES_WIDTH, |
Mel Gorman | a4e1b4c | 2013-02-22 16:34:47 -0800 | [diff] [blame] | 78 | LAST_NID_WIDTH, |
Mel Gorman | 708614e | 2008-07-23 21:26:51 -0700 | [diff] [blame] | 79 | NR_PAGEFLAGS); |
| 80 | mminit_dprintk(MMINIT_TRACE, "pageflags_layout_shifts", |
Mel Gorman | a4e1b4c | 2013-02-22 16:34:47 -0800 | [diff] [blame] | 81 | "Section %d Node %d Zone %d Lastnid %d\n", |
Mel Gorman | 708614e | 2008-07-23 21:26:51 -0700 | [diff] [blame] | 82 | SECTIONS_SHIFT, |
Mel Gorman | 708614e | 2008-07-23 21:26:51 -0700 | [diff] [blame] | 83 | NODES_SHIFT, |
Mel Gorman | a4e1b4c | 2013-02-22 16:34:47 -0800 | [diff] [blame] | 84 | ZONES_SHIFT, |
| 85 | LAST_NID_SHIFT); |
| 86 | mminit_dprintk(MMINIT_TRACE, "pageflags_layout_pgshifts", |
| 87 | "Section %lu Node %lu Zone %lu Lastnid %lu\n", |
Mel Gorman | 708614e | 2008-07-23 21:26:51 -0700 | [diff] [blame] | 88 | (unsigned long)SECTIONS_PGSHIFT, |
| 89 | (unsigned long)NODES_PGSHIFT, |
Mel Gorman | a4e1b4c | 2013-02-22 16:34:47 -0800 | [diff] [blame] | 90 | (unsigned long)ZONES_PGSHIFT, |
| 91 | (unsigned long)LAST_NID_PGSHIFT); |
| 92 | mminit_dprintk(MMINIT_TRACE, "pageflags_layout_nodezoneid", |
| 93 | "Node/Zone ID: %lu -> %lu\n", |
| 94 | (unsigned long)(ZONEID_PGOFF + ZONEID_SHIFT), |
| 95 | (unsigned long)ZONEID_PGOFF); |
Mel Gorman | 708614e | 2008-07-23 21:26:51 -0700 | [diff] [blame] | 96 | mminit_dprintk(MMINIT_TRACE, "pageflags_layout_usage", |
Mel Gorman | a4e1b4c | 2013-02-22 16:34:47 -0800 | [diff] [blame] | 97 | "location: %d -> %d layout %d -> %d unused %d -> %d page-flags\n", |
Mel Gorman | 708614e | 2008-07-23 21:26:51 -0700 | [diff] [blame] | 98 | shift, width, width, NR_PAGEFLAGS, NR_PAGEFLAGS, 0); |
| 99 | #ifdef NODE_NOT_IN_PAGE_FLAGS |
| 100 | mminit_dprintk(MMINIT_TRACE, "pageflags_layout_nodeflags", |
| 101 | "Node not in page flags"); |
| 102 | #endif |
Mel Gorman | a4e1b4c | 2013-02-22 16:34:47 -0800 | [diff] [blame] | 103 | #ifdef LAST_NID_NOT_IN_PAGE_FLAGS |
| 104 | mminit_dprintk(MMINIT_TRACE, "pageflags_layout_nodeflags", |
| 105 | "Last nid not in page flags"); |
| 106 | #endif |
Mel Gorman | 708614e | 2008-07-23 21:26:51 -0700 | [diff] [blame] | 107 | |
| 108 | if (SECTIONS_WIDTH) { |
| 109 | shift -= SECTIONS_WIDTH; |
| 110 | BUG_ON(shift != SECTIONS_PGSHIFT); |
| 111 | } |
| 112 | if (NODES_WIDTH) { |
| 113 | shift -= NODES_WIDTH; |
| 114 | BUG_ON(shift != NODES_PGSHIFT); |
| 115 | } |
| 116 | if (ZONES_WIDTH) { |
| 117 | shift -= ZONES_WIDTH; |
| 118 | BUG_ON(shift != ZONES_PGSHIFT); |
| 119 | } |
| 120 | |
| 121 | /* Check for bitmask overlaps */ |
| 122 | or_mask = (ZONES_MASK << ZONES_PGSHIFT) | |
| 123 | (NODES_MASK << NODES_PGSHIFT) | |
| 124 | (SECTIONS_MASK << SECTIONS_PGSHIFT); |
| 125 | add_mask = (ZONES_MASK << ZONES_PGSHIFT) + |
| 126 | (NODES_MASK << NODES_PGSHIFT) + |
| 127 | (SECTIONS_MASK << SECTIONS_PGSHIFT); |
| 128 | BUG_ON(or_mask != add_mask); |
| 129 | } |
| 130 | |
| 131 | void __meminit mminit_verify_page_links(struct page *page, enum zone_type zone, |
| 132 | unsigned long nid, unsigned long pfn) |
| 133 | { |
| 134 | BUG_ON(page_to_nid(page) != nid); |
| 135 | BUG_ON(page_zonenum(page) != zone); |
| 136 | BUG_ON(page_to_pfn(page) != pfn); |
| 137 | } |
| 138 | |
Mel Gorman | 6b74ab9 | 2008-07-23 21:26:49 -0700 | [diff] [blame] | 139 | static __init int set_mminit_loglevel(char *str) |
| 140 | { |
| 141 | get_option(&str, &mminit_loglevel); |
| 142 | return 0; |
| 143 | } |
| 144 | early_param("mminit_loglevel", set_mminit_loglevel); |
Nishanth Aravamudan | 5e9426ab | 2008-07-23 21:27:39 -0700 | [diff] [blame] | 145 | #endif /* CONFIG_DEBUG_MEMORY_INIT */ |
Nishanth Aravamudan | ff7ea79 | 2008-07-23 21:27:39 -0700 | [diff] [blame] | 146 | |
| 147 | struct kobject *mm_kobj; |
| 148 | EXPORT_SYMBOL_GPL(mm_kobj); |
| 149 | |
| 150 | static int __init mm_sysfs_init(void) |
| 151 | { |
| 152 | mm_kobj = kobject_create_and_add("mm", kernel_kobj); |
| 153 | if (!mm_kobj) |
| 154 | return -ENOMEM; |
| 155 | |
| 156 | return 0; |
| 157 | } |
| 158 | |
| 159 | __initcall(mm_sysfs_init); |