2 * linux/arch/alpha/mm/numa.c
4 * DISCONTIGMEM NUMA alpha support.
6 * Copyright (C) 2001 Andrea Arcangeli <andrea@suse.de> SuSE
9 #include <linux/types.h>
10 #include <linux/kernel.h>
12 #include <linux/bootmem.h>
13 #include <linux/swap.h>
14 #include <linux/initrd.h>
15 #include <linux/pfn.h>
17 #include <asm/hwrpb.h>
18 #include <asm/pgalloc.h>
20 pg_data_t node_data[MAX_NUMNODES];
21 bootmem_data_t node_bdata[MAX_NUMNODES];
23 #undef DEBUG_DISCONTIG
24 #ifdef DEBUG_DISCONTIG
25 #define DBGDCONT(args...) printk(args)
27 #define DBGDCONT(args...)
30 #define for_each_mem_cluster(memdesc, cluster, i) \
31 for ((cluster) = (memdesc)->cluster, (i) = 0; \
32 (i) < (memdesc)->numclusters; (i)++, (cluster)++)
34 static void __init show_mem_layout(void)
36 struct memclust_struct * cluster;
37 struct memdesc_struct * memdesc;
40 /* Find free clusters, and init and free the bootmem accordingly. */
41 memdesc = (struct memdesc_struct *)
42 (hwrpb->mddt_offset + (unsigned long) hwrpb);
44 printk("Raw memory layout:\n");
45 for_each_mem_cluster(memdesc, cluster, i) {
46 printk(" memcluster %2d, usage %1lx, start %8lu, end %8lu\n",
47 i, cluster->usage, cluster->start_pfn,
48 cluster->start_pfn + cluster->numpages);
53 setup_memory_node(int nid, void *kernel_end)
55 extern unsigned long mem_size_limit;
56 struct memclust_struct * cluster;
57 struct memdesc_struct * memdesc;
58 unsigned long start_kernel_pfn, end_kernel_pfn;
59 unsigned long bootmap_size, bootmap_pages, bootmap_start;
60 unsigned long start, end;
61 unsigned long node_pfn_start, node_pfn_end;
62 unsigned long node_min_pfn, node_max_pfn;
64 unsigned long node_datasz = PFN_UP(sizeof(pg_data_t));
67 /* Find the bounds of current node */
68 node_pfn_start = (node_mem_start(nid)) >> PAGE_SHIFT;
69 node_pfn_end = node_pfn_start + (node_mem_size(nid) >> PAGE_SHIFT);
71 /* Find free clusters, and init and free the bootmem accordingly. */
72 memdesc = (struct memdesc_struct *)
73 (hwrpb->mddt_offset + (unsigned long) hwrpb);
75 /* find the bounds of this node (node_min_pfn/node_max_pfn) */
78 for_each_mem_cluster(memdesc, cluster, i) {
79 /* Bit 0 is console/PALcode reserved. Bit 1 is
80 non-volatile memory -- we might want to mark
82 if (cluster->usage & 3)
85 start = cluster->start_pfn;
86 end = start + cluster->numpages;
88 if (start >= node_pfn_end || end <= node_pfn_start)
93 printk("Initializing bootmem allocator on Node ID %d\n", nid);
95 printk(" memcluster %2d, usage %1lx, start %8lu, end %8lu\n",
96 i, cluster->usage, cluster->start_pfn,
97 cluster->start_pfn + cluster->numpages);
99 if (start < node_pfn_start)
100 start = node_pfn_start;
101 if (end > node_pfn_end)
104 if (start < node_min_pfn)
105 node_min_pfn = start;
106 if (end > node_max_pfn)
110 if (mem_size_limit && node_max_pfn > mem_size_limit) {
111 static int msg_shown = 0;
114 printk("setup: forcing memory size to %ldK (from %ldK).\n",
115 mem_size_limit << (PAGE_SHIFT - 10),
116 node_max_pfn << (PAGE_SHIFT - 10));
118 node_max_pfn = mem_size_limit;
121 if (node_min_pfn >= node_max_pfn)
124 /* Update global {min,max}_low_pfn from node information. */
125 if (node_min_pfn < min_low_pfn)
126 min_low_pfn = node_min_pfn;
127 if (node_max_pfn > max_low_pfn)
128 max_pfn = max_low_pfn = node_max_pfn;
130 num_physpages += node_max_pfn - node_min_pfn;
132 #if 0 /* we'll try this one again in a little while */
133 /* Cute trick to make sure our local node data is on local memory */
134 node_data[nid] = (pg_data_t *)(__va(node_min_pfn << PAGE_SHIFT));
136 /* Quasi-mark the pg_data_t as in-use */
137 node_min_pfn += node_datasz;
138 if (node_min_pfn >= node_max_pfn) {
139 printk(" not enough mem to reserve NODE_DATA");
142 NODE_DATA(nid)->bdata = &node_bdata[nid];
144 printk(" Detected node memory: start %8lu, end %8lu\n",
145 node_min_pfn, node_max_pfn);
147 DBGDCONT(" DISCONTIG: node_data[%d] is at 0x%p\n", nid, NODE_DATA(nid));
148 DBGDCONT(" DISCONTIG: NODE_DATA(%d)->bdata is at 0x%p\n", nid, NODE_DATA(nid)->bdata);
150 /* Find the bounds of kernel memory. */
151 start_kernel_pfn = PFN_DOWN(KERNEL_START_PHYS);
152 end_kernel_pfn = PFN_UP(virt_to_phys(kernel_end));
155 if (!nid && (node_max_pfn < end_kernel_pfn || node_min_pfn > start_kernel_pfn))
156 panic("kernel loaded out of ram");
158 /* Zone start phys-addr must be 2^(MAX_ORDER-1) aligned.
159 Note that we round this down, not up - node memory
160 has much larger alignment than 8Mb, so it's safe. */
161 node_min_pfn &= ~((1UL << (MAX_ORDER-1))-1);
163 /* We need to know how many physically contiguous pages
164 we'll need for the bootmap. */
165 bootmap_pages = bootmem_bootmap_pages(node_max_pfn-node_min_pfn);
167 /* Now find a good region where to allocate the bootmap. */
168 for_each_mem_cluster(memdesc, cluster, i) {
169 if (cluster->usage & 3)
172 start = cluster->start_pfn;
173 end = start + cluster->numpages;
175 if (start >= node_max_pfn || end <= node_min_pfn)
178 if (end > node_max_pfn)
180 if (start < node_min_pfn)
181 start = node_min_pfn;
183 if (start < start_kernel_pfn) {
184 if (end > end_kernel_pfn
185 && end - end_kernel_pfn >= bootmap_pages) {
186 bootmap_start = end_kernel_pfn;
188 } else if (end > start_kernel_pfn)
189 end = start_kernel_pfn;
190 } else if (start < end_kernel_pfn)
191 start = end_kernel_pfn;
192 if (end - start >= bootmap_pages) {
193 bootmap_start = start;
198 if (bootmap_start == -1)
199 panic("couldn't find a contigous place for the bootmap");
201 /* Allocate the bootmap and mark the whole MM as reserved. */
202 bootmap_size = init_bootmem_node(NODE_DATA(nid), bootmap_start,
203 node_min_pfn, node_max_pfn);
204 DBGDCONT(" bootmap_start %lu, bootmap_size %lu, bootmap_pages %lu\n",
205 bootmap_start, bootmap_size, bootmap_pages);
207 /* Mark the free regions. */
208 for_each_mem_cluster(memdesc, cluster, i) {
209 if (cluster->usage & 3)
212 start = cluster->start_pfn;
213 end = cluster->start_pfn + cluster->numpages;
215 if (start >= node_max_pfn || end <= node_min_pfn)
218 if (end > node_max_pfn)
220 if (start < node_min_pfn)
221 start = node_min_pfn;
223 if (start < start_kernel_pfn) {
224 if (end > end_kernel_pfn) {
225 free_bootmem_node(NODE_DATA(nid), PFN_PHYS(start),
226 (PFN_PHYS(start_kernel_pfn)
228 printk(" freeing pages %ld:%ld\n",
229 start, start_kernel_pfn);
230 start = end_kernel_pfn;
231 } else if (end > start_kernel_pfn)
232 end = start_kernel_pfn;
233 } else if (start < end_kernel_pfn)
234 start = end_kernel_pfn;
238 free_bootmem_node(NODE_DATA(nid), PFN_PHYS(start), PFN_PHYS(end) - PFN_PHYS(start));
239 printk(" freeing pages %ld:%ld\n", start, end);
242 /* Reserve the bootmap memory. */
243 reserve_bootmem_node(NODE_DATA(nid), PFN_PHYS(bootmap_start), bootmap_size);
244 printk(" reserving pages %ld:%ld\n", bootmap_start, bootmap_start+PFN_UP(bootmap_size));
246 node_set_online(nid);
250 setup_memory(void *kernel_end)
256 nodes_clear(node_online_map);
260 for (nid = 0; nid < MAX_NUMNODES; nid++)
261 setup_memory_node(nid, kernel_end);
263 #ifdef CONFIG_BLK_DEV_INITRD
264 initrd_start = INITRD_START;
266 extern void *move_initrd(unsigned long);
268 initrd_end = initrd_start+INITRD_SIZE;
269 printk("Initial ramdisk at: 0x%p (%lu bytes)\n",
270 (void *) initrd_start, INITRD_SIZE);
272 if ((void *)initrd_end > phys_to_virt(PFN_PHYS(max_low_pfn))) {
273 if (!move_initrd(PFN_PHYS(max_low_pfn)))
274 printk("initrd extends beyond end of memory "
275 "(0x%08lx > 0x%p)\ndisabling initrd\n",
277 phys_to_virt(PFN_PHYS(max_low_pfn)));
279 nid = kvaddr_to_nid(initrd_start);
280 reserve_bootmem_node(NODE_DATA(nid),
281 virt_to_phys((void *)initrd_start),
285 #endif /* CONFIG_BLK_DEV_INITRD */
288 void __init paging_init(void)
291 unsigned long zones_size[MAX_NR_ZONES] = {0, };
292 unsigned long dma_local_pfn;
295 * The old global MAX_DMA_ADDRESS per-arch API doesn't fit
296 * in the NUMA model, for now we convert it to a pfn and
297 * we interpret this pfn as a local per-node information.
298 * This issue isn't very important since none of these machines
299 * have legacy ISA slots anyways.
301 dma_local_pfn = virt_to_phys((char *)MAX_DMA_ADDRESS) >> PAGE_SHIFT;
303 for_each_online_node(nid) {
304 unsigned long start_pfn = node_bdata[nid].node_boot_start >> PAGE_SHIFT;
305 unsigned long end_pfn = node_bdata[nid].node_low_pfn;
307 if (dma_local_pfn >= end_pfn - start_pfn)
308 zones_size[ZONE_DMA] = end_pfn - start_pfn;
310 zones_size[ZONE_DMA] = dma_local_pfn;
311 zones_size[ZONE_NORMAL] = (end_pfn - start_pfn) - dma_local_pfn;
313 free_area_init_node(nid, NODE_DATA(nid), zones_size, start_pfn, NULL);
316 /* Initialize the kernel's ZERO_PGE. */
317 memset((void *)ZERO_PGE, 0, PAGE_SIZE);
320 void __init mem_init(void)
322 unsigned long codesize, reservedpages, datasize, initsize, pfn;
323 extern int page_is_ram(unsigned long) __init;
324 extern char _text, _etext, _data, _edata;
325 extern char __init_begin, __init_end;
326 unsigned long nid, i;
327 high_memory = (void *) __va(max_low_pfn << PAGE_SHIFT);
330 for_each_online_node(nid) {
332 * This will free up the bootmem, ie, slot 0 memory
334 totalram_pages += free_all_bootmem_node(NODE_DATA(nid));
336 pfn = NODE_DATA(nid)->node_start_pfn;
337 for (i = 0; i < node_spanned_pages(nid); i++, pfn++)
338 if (page_is_ram(pfn) &&
339 PageReserved(nid_page_nr(nid, i)))
343 codesize = (unsigned long) &_etext - (unsigned long) &_text;
344 datasize = (unsigned long) &_edata - (unsigned long) &_data;
345 initsize = (unsigned long) &__init_end - (unsigned long) &__init_begin;
347 printk("Memory: %luk/%luk available (%luk kernel code, %luk reserved, "
348 "%luk data, %luk init)\n",
349 (unsigned long)nr_free_pages() << (PAGE_SHIFT-10),
350 num_physpages << (PAGE_SHIFT-10),
352 reservedpages << (PAGE_SHIFT-10),
363 long i,free = 0,total = 0,reserved = 0;
364 long shared = 0, cached = 0;
367 printk("\nMem-info:\n");
369 printk("Free swap: %6ldkB\n", nr_swap_pages<<(PAGE_SHIFT-10));
370 for_each_online_node(nid) {
372 pgdat_resize_lock(NODE_DATA(nid), &flags);
373 i = node_spanned_pages(nid);
375 struct page *page = nid_page_nr(nid, i);
377 if (PageReserved(page))
379 else if (PageSwapCache(page))
381 else if (!page_count(page))
384 shared += page_count(page) - 1;
386 pgdat_resize_unlock(NODE_DATA(nid), &flags);
388 printk("%ld pages of RAM\n",total);
389 printk("%ld free pages\n",free);
390 printk("%ld reserved pages\n",reserved);
391 printk("%ld pages shared\n",shared);
392 printk("%ld pages swap cached\n",cached);