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> |
Mel Gorman | 708614e | 2008-07-23 21:26:51 -0700 | [diff] [blame] | 10 | #include "internal.h" |
Mel Gorman | 6b74ab9 | 2008-07-23 21:26:49 -0700 | [diff] [blame] | 11 | |
Nishanth Aravamudan | 5e9426ab | 2008-07-23 21:27:39 -0700 | [diff] [blame^] | 12 | #ifdef CONFIG_DEBUG_MEMORY_INIT |
Mel Gorman | 6b74ab9 | 2008-07-23 21:26:49 -0700 | [diff] [blame] | 13 | int __meminitdata mminit_loglevel; |
| 14 | |
Mel Gorman | 68ad8df | 2008-07-23 21:26:52 -0700 | [diff] [blame] | 15 | /* The zonelists are simply reported, validation is manual. */ |
| 16 | void mminit_verify_zonelist(void) |
| 17 | { |
| 18 | int nid; |
| 19 | |
| 20 | if (mminit_loglevel < MMINIT_VERIFY) |
| 21 | return; |
| 22 | |
| 23 | for_each_online_node(nid) { |
| 24 | pg_data_t *pgdat = NODE_DATA(nid); |
| 25 | struct zone *zone; |
| 26 | struct zoneref *z; |
| 27 | struct zonelist *zonelist; |
| 28 | int i, listid, zoneid; |
| 29 | |
| 30 | BUG_ON(MAX_ZONELISTS > 2); |
| 31 | for (i = 0; i < MAX_ZONELISTS * MAX_NR_ZONES; i++) { |
| 32 | |
| 33 | /* Identify the zone and nodelist */ |
| 34 | zoneid = i % MAX_NR_ZONES; |
| 35 | listid = i / MAX_NR_ZONES; |
| 36 | zonelist = &pgdat->node_zonelists[listid]; |
| 37 | zone = &pgdat->node_zones[zoneid]; |
| 38 | if (!populated_zone(zone)) |
| 39 | continue; |
| 40 | |
| 41 | /* Print information about the zonelist */ |
| 42 | printk(KERN_DEBUG "mminit::zonelist %s %d:%s = ", |
| 43 | listid > 0 ? "thisnode" : "general", nid, |
| 44 | zone->name); |
| 45 | |
| 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 | |
Mel Gorman | 708614e | 2008-07-23 21:26:51 -0700 | [diff] [blame] | 60 | void __init mminit_verify_pageflags_layout(void) |
| 61 | { |
| 62 | int shift, width; |
| 63 | unsigned long or_mask, add_mask; |
| 64 | |
| 65 | shift = 8 * sizeof(unsigned long); |
| 66 | width = shift - SECTIONS_WIDTH - NODES_WIDTH - ZONES_WIDTH; |
| 67 | mminit_dprintk(MMINIT_TRACE, "pageflags_layout_widths", |
| 68 | "Section %d Node %d Zone %d Flags %d\n", |
| 69 | SECTIONS_WIDTH, |
| 70 | NODES_WIDTH, |
| 71 | ZONES_WIDTH, |
| 72 | NR_PAGEFLAGS); |
| 73 | mminit_dprintk(MMINIT_TRACE, "pageflags_layout_shifts", |
| 74 | "Section %d Node %d Zone %d\n", |
| 75 | #ifdef SECTIONS_SHIFT |
| 76 | SECTIONS_SHIFT, |
| 77 | #else |
| 78 | 0, |
| 79 | #endif |
| 80 | NODES_SHIFT, |
| 81 | ZONES_SHIFT); |
| 82 | mminit_dprintk(MMINIT_TRACE, "pageflags_layout_offsets", |
| 83 | "Section %lu Node %lu Zone %lu\n", |
| 84 | (unsigned long)SECTIONS_PGSHIFT, |
| 85 | (unsigned long)NODES_PGSHIFT, |
| 86 | (unsigned long)ZONES_PGSHIFT); |
| 87 | mminit_dprintk(MMINIT_TRACE, "pageflags_layout_zoneid", |
| 88 | "Zone ID: %lu -> %lu\n", |
| 89 | (unsigned long)ZONEID_PGOFF, |
| 90 | (unsigned long)(ZONEID_PGOFF + ZONEID_SHIFT)); |
| 91 | mminit_dprintk(MMINIT_TRACE, "pageflags_layout_usage", |
| 92 | "location: %d -> %d unused %d -> %d flags %d -> %d\n", |
| 93 | shift, width, width, NR_PAGEFLAGS, NR_PAGEFLAGS, 0); |
| 94 | #ifdef NODE_NOT_IN_PAGE_FLAGS |
| 95 | mminit_dprintk(MMINIT_TRACE, "pageflags_layout_nodeflags", |
| 96 | "Node not in page flags"); |
| 97 | #endif |
| 98 | |
| 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 | |
| 112 | /* Check for bitmask overlaps */ |
| 113 | or_mask = (ZONES_MASK << ZONES_PGSHIFT) | |
| 114 | (NODES_MASK << NODES_PGSHIFT) | |
| 115 | (SECTIONS_MASK << SECTIONS_PGSHIFT); |
| 116 | add_mask = (ZONES_MASK << ZONES_PGSHIFT) + |
| 117 | (NODES_MASK << NODES_PGSHIFT) + |
| 118 | (SECTIONS_MASK << SECTIONS_PGSHIFT); |
| 119 | BUG_ON(or_mask != add_mask); |
| 120 | } |
| 121 | |
| 122 | void __meminit mminit_verify_page_links(struct page *page, enum zone_type zone, |
| 123 | unsigned long nid, unsigned long pfn) |
| 124 | { |
| 125 | BUG_ON(page_to_nid(page) != nid); |
| 126 | BUG_ON(page_zonenum(page) != zone); |
| 127 | BUG_ON(page_to_pfn(page) != pfn); |
| 128 | } |
| 129 | |
Mel Gorman | 6b74ab9 | 2008-07-23 21:26:49 -0700 | [diff] [blame] | 130 | static __init int set_mminit_loglevel(char *str) |
| 131 | { |
| 132 | get_option(&str, &mminit_loglevel); |
| 133 | return 0; |
| 134 | } |
| 135 | early_param("mminit_loglevel", set_mminit_loglevel); |
Nishanth Aravamudan | 5e9426ab | 2008-07-23 21:27:39 -0700 | [diff] [blame^] | 136 | #endif /* CONFIG_DEBUG_MEMORY_INIT */ |