Revert to pre E17 ckrm memory controller back port code, which apparently
[linux-2.6.git] / mm / page_alloc.c
1 /*
2  *  linux/mm/page_alloc.c
3  *
4  *  Manages the free list, the system allocates free pages here.
5  *  Note that kmalloc() lives in slab.c
6  *
7  *  Copyright (C) 1991, 1992, 1993, 1994  Linus Torvalds
8  *  Swap reorganised 29.12.95, Stephen Tweedie
9  *  Support of BIGMEM added by Gerhard Wichert, Siemens AG, July 1999
10  *  Reshaped it to be a zoned allocator, Ingo Molnar, Red Hat, 1999
11  *  Discontiguous memory support, Kanoj Sarcar, SGI, Nov 1999
12  *  Zone balancing, Kanoj Sarcar, SGI, Jan 2000
13  *  Per cpu hot/cold page lists, bulk allocation, Martin J. Bligh, Sept 2002
14  *          (lots of bits borrowed from Ingo Molnar & Andrew Morton)
15  */
16
17 #include <linux/config.h>
18 #include <linux/stddef.h>
19 #include <linux/mm.h>
20 #include <linux/swap.h>
21 #include <linux/interrupt.h>
22 #include <linux/pagemap.h>
23 #include <linux/bootmem.h>
24 #include <linux/compiler.h>
25 #include <linux/module.h>
26 #include <linux/suspend.h>
27 #include <linux/pagevec.h>
28 #include <linux/blkdev.h>
29 #include <linux/slab.h>
30 #include <linux/notifier.h>
31 #include <linux/topology.h>
32 #include <linux/sysctl.h>
33 #include <linux/cpu.h>
34 #include <linux/ckrm_mem_inline.h>
35 #include <linux/vs_base.h>
36 #include <linux/vs_limit.h>
37 #include <linux/nodemask.h>
38
39 #include <asm/tlbflush.h>
40
41 nodemask_t node_online_map = NODE_MASK_NONE;
42 nodemask_t node_possible_map = NODE_MASK_ALL;
43 struct pglist_data *pgdat_list;
44 unsigned long totalram_pages;
45 unsigned long totalhigh_pages;
46 long nr_swap_pages;
47 int numnodes = 1;
48 int sysctl_lower_zone_protection = 0;
49
50 EXPORT_SYMBOL(totalram_pages);
51 EXPORT_SYMBOL(nr_swap_pages);
52
53 #ifdef CONFIG_CRASH_DUMP
54 /* This symbol has to be exported to use 'for_each_pgdat' macro by modules. */
55 EXPORT_SYMBOL(pgdat_list);
56 #endif
57
58 /*
59  * Used by page_zone() to look up the address of the struct zone whose
60  * id is encoded in the upper bits of page->flags
61  */
62 struct zone *zone_table[1 << (ZONES_SHIFT + NODES_SHIFT)];
63 EXPORT_SYMBOL(zone_table);
64
65 static char *zone_names[MAX_NR_ZONES] = { "DMA", "Normal", "HighMem" };
66 int min_free_kbytes = 1024;
67
68 unsigned long __initdata nr_kernel_pages;
69 unsigned long __initdata nr_all_pages;
70
71 /*
72  * Temporary debugging check for pages not lying within a given zone.
73  */
74 static int bad_range(struct zone *zone, struct page *page)
75 {
76         if (page_to_pfn(page) >= zone->zone_start_pfn + zone->spanned_pages)
77                 return 1;
78         if (page_to_pfn(page) < zone->zone_start_pfn)
79                 return 1;
80         if (zone != page_zone(page))
81                 return 1;
82         return 0;
83 }
84
85 static void bad_page(const char *function, struct page *page)
86 {
87         printk(KERN_EMERG "Bad page state at %s (in process '%s', page %p)\n",
88                 function, current->comm, page);
89         printk(KERN_EMERG "flags:0x%0*lx mapping:%p mapcount:%d count:%d (%s)\n",
90                 (int)(2*sizeof(page_flags_t)), (unsigned long)page->flags,
91                 page->mapping, page_mapcount(page), page_count(page), print_tainted());
92         printk(KERN_EMERG "Backtrace:\n");
93         dump_stack();
94         printk(KERN_EMERG "Trying to fix it up, but a reboot is needed\n");
95         page->flags &= ~(1 << PG_private        |
96                         1 << PG_locked  |
97                         1 << PG_lru     |
98                         1 << PG_active  |
99                         1 << PG_dirty   |
100                         1 << PG_swapcache |
101                         1 << PG_writeback);
102         set_page_count(page, 0);
103         reset_page_mapcount(page);
104         page->mapping = NULL;
105         tainted |= TAINT_BAD_PAGE;
106 }
107
108 #if !defined(CONFIG_HUGETLB_PAGE) && !defined(CONFIG_CRASH_DUMP)
109 #define prep_compound_page(page, order) do { } while (0)
110 #define destroy_compound_page(page, order) do { } while (0)
111 #else
112 /*
113  * Higher-order pages are called "compound pages".  They are structured thusly:
114  *
115  * The first PAGE_SIZE page is called the "head page".
116  *
117  * The remaining PAGE_SIZE pages are called "tail pages".
118  *
119  * All pages have PG_compound set.  All pages have their ->private pointing at
120  * the head page (even the head page has this).
121  *
122  * The first tail page's ->mapping, if non-zero, holds the address of the
123  * compound page's put_page() function.
124  *
125  * The order of the allocation is stored in the first tail page's ->index
126  * This is only for debug at present.  This usage means that zero-order pages
127  * may not be compound.
128  */
129 static void prep_compound_page(struct page *page, unsigned long order)
130 {
131         int i;
132         int nr_pages = 1 << order;
133
134         page[1].mapping = NULL;
135         page[1].index = order;
136         for (i = 0; i < nr_pages; i++) {
137                 struct page *p = page + i;
138
139                 SetPageCompound(p);
140                 p->private = (unsigned long)page;
141         }
142 }
143
144 static void destroy_compound_page(struct page *page, unsigned long order)
145 {
146         int i;
147         int nr_pages = 1 << order;
148
149         if (!PageCompound(page))
150                 return;
151
152         if (page[1].index != order)
153                 bad_page(__FUNCTION__, page);
154
155         for (i = 0; i < nr_pages; i++) {
156                 struct page *p = page + i;
157
158                 if (!PageCompound(p))
159                         bad_page(__FUNCTION__, page);
160                 if (p->private != (unsigned long)page)
161                         bad_page(__FUNCTION__, page);
162                 ClearPageCompound(p);
163         }
164 }
165 #endif          /* CONFIG_HUGETLB_PAGE */
166
167 /*
168  * Freeing function for a buddy system allocator.
169  *
170  * The concept of a buddy system is to maintain direct-mapped table
171  * (containing bit values) for memory blocks of various "orders".
172  * The bottom level table contains the map for the smallest allocatable
173  * units of memory (here, pages), and each level above it describes
174  * pairs of units from the levels below, hence, "buddies".
175  * At a high level, all that happens here is marking the table entry
176  * at the bottom level available, and propagating the changes upward
177  * as necessary, plus some accounting needed to play nicely with other
178  * parts of the VM system.
179  * At each level, we keep one bit for each pair of blocks, which
180  * is set to 1 iff only one of the pair is allocated.  So when we
181  * are allocating or freeing one, we can derive the state of the
182  * other.  That is, if we allocate a small block, and both were   
183  * free, the remainder of the region must be split into blocks.   
184  * If a block is freed, and its buddy is also free, then this
185  * triggers coalescing into a block of larger size.            
186  *
187  * -- wli
188  */
189
190 static inline void __free_pages_bulk (struct page *page, struct page *base,
191                 struct zone *zone, struct free_area *area, unsigned int order)
192 {
193         unsigned long page_idx, index, mask;
194
195         if (order)
196                 destroy_compound_page(page, order);
197         mask = (~0UL) << order;
198         page_idx = page - base;
199         if (page_idx & ~mask)
200                 BUG();
201         index = page_idx >> (1 + order);
202
203         zone->free_pages += 1 << order;
204         while (order < MAX_ORDER-1) {
205                 struct page *buddy1, *buddy2;
206
207                 BUG_ON(area >= zone->free_area + MAX_ORDER);
208                 if (!__test_and_change_bit(index, area->map))
209                         /*
210                          * the buddy page is still allocated.
211                          */
212                         break;
213
214                 /* Move the buddy up one level. */
215                 buddy1 = base + (page_idx ^ (1 << order));
216                 buddy2 = base + page_idx;
217                 BUG_ON(bad_range(zone, buddy1));
218                 BUG_ON(bad_range(zone, buddy2));
219                 list_del(&buddy1->lru);
220                 mask <<= 1;
221                 order++;
222                 area++;
223                 index >>= 1;
224                 page_idx &= mask;
225         }
226         list_add(&(base + page_idx)->lru, &area->free_list);
227 }
228
229 static inline void free_pages_check(const char *function, struct page *page)
230 {
231         if (    page_mapped(page) ||
232                 page->mapping != NULL ||
233                 page_count(page) != 0 ||
234                 (page->flags & (
235                         1 << PG_lru     |
236                         1 << PG_private |
237                         1 << PG_locked  |
238                         1 << PG_active  |
239                         1 << PG_reclaim |
240                         1 << PG_slab    |
241                         1 << PG_swapcache |
242                         1 << PG_writeback )))
243                 bad_page(function, page);
244         if (PageDirty(page))
245                 ClearPageDirty(page);
246 }
247
248 /*
249  * Frees a list of pages. 
250  * Assumes all pages on list are in same zone, and of same order.
251  * count is the number of pages to free, or 0 for all on the list.
252  *
253  * If the zone was previously in an "all pages pinned" state then look to
254  * see if this freeing clears that state.
255  *
256  * And clear the zone's pages_scanned counter, to hold off the "all pages are
257  * pinned" detection logic.
258  */
259 static int
260 free_pages_bulk(struct zone *zone, int count,
261                 struct list_head *list, unsigned int order)
262 {
263         unsigned long flags;
264         struct free_area *area;
265         struct page *base, *page = NULL;
266         int ret = 0;
267
268         base = zone->zone_mem_map;
269         area = zone->free_area + order;
270         spin_lock_irqsave(&zone->lock, flags);
271         zone->all_unreclaimable = 0;
272         zone->pages_scanned = 0;
273         while (!list_empty(list) && count--) {
274                 page = list_entry(list->prev, struct page, lru);
275                 /* have to delete it as __free_pages_bulk list manipulates */
276                 list_del(&page->lru);
277                 __free_pages_bulk(page, base, zone, area, order);
278                 ckrm_clear_page_class(page);
279                 ret++;
280         }
281         spin_unlock_irqrestore(&zone->lock, flags);
282         return ret;
283 }
284
285 void __free_pages_ok(struct page *page, unsigned int order)
286 {
287         LIST_HEAD(list);
288         int i;
289
290         arch_free_page(page, order);
291
292         mod_page_state(pgfree, 1 << order);
293         for (i = 0 ; i < (1 << order) ; ++i)
294                 free_pages_check(__FUNCTION__, page + i);
295         list_add(&page->lru, &list);
296         kernel_map_pages(page, 1<<order, 0);
297         free_pages_bulk(page_zone(page), 1, &list, order);
298 }
299
300 #define MARK_USED(index, order, area) \
301         __change_bit((index) >> (1+(order)), (area)->map)
302
303 /*
304  * The order of subdivision here is critical for the IO subsystem.
305  * Please do not alter this order without good reasons and regression
306  * testing. Specifically, as large blocks of memory are subdivided,
307  * the order in which smaller blocks are delivered depends on the order
308  * they're subdivided in this function. This is the primary factor
309  * influencing the order in which pages are delivered to the IO
310  * subsystem according to empirical testing, and this is also justified
311  * by considering the behavior of a buddy system containing a single
312  * large block of memory acted on by a series of small allocations.
313  * This behavior is a critical factor in sglist merging's success.
314  *
315  * -- wli
316  */
317 static inline struct page *
318 expand(struct zone *zone, struct page *page,
319          unsigned long index, int low, int high, struct free_area *area)
320 {
321         unsigned long size = 1 << high;
322
323         while (high > low) {
324                 area--;
325                 high--;
326                 size >>= 1;
327                 BUG_ON(bad_range(zone, &page[size]));
328                 list_add(&page[size].lru, &area->free_list);
329                 MARK_USED(index + size, high, area);
330         }
331         return page;
332 }
333
334 static inline void set_page_refs(struct page *page, int order)
335 {
336 #ifdef CONFIG_MMU
337         set_page_count(page, 1);
338 #else
339         int i;
340
341         /*
342          * We need to reference all the pages for this order, otherwise if
343          * anyone accesses one of the pages with (get/put) it will be freed.
344          */
345         for (i = 0; i < (1 << order); i++)
346                 set_page_count(page+i, 1);
347 #endif /* CONFIG_MMU */
348 }
349
350 /*
351  * This page is about to be returned from the page allocator
352  */
353 static void prep_new_page(struct page *page, int order)
354 {
355         if (page->mapping || page_mapped(page) ||
356             (page->flags & (
357                         1 << PG_private |
358                         1 << PG_locked  |
359                         1 << PG_lru     |
360                         1 << PG_active  |
361                         1 << PG_dirty   |
362                         1 << PG_reclaim |
363                         1 << PG_swapcache |
364                         1 << PG_writeback )))
365                 bad_page(__FUNCTION__, page);
366
367         page->flags &= ~(1 << PG_uptodate | 1 << PG_error |
368                         1 << PG_referenced | 1 << PG_arch_1 |
369 #ifdef CONFIG_CKRM_RES_MEM
370                         1 << PG_ckrm_account |
371 #endif
372                         1 << PG_checked | 1 << PG_mappedtodisk);
373         page->private = 0;
374 #ifdef CONFIG_CKRM_RES_MEM
375         page->ckrm_zone = NULL;
376 #endif
377         set_page_refs(page, order);
378 }
379
380 /* 
381  * Do the hard work of removing an element from the buddy allocator.
382  * Call me with the zone->lock already held.
383  */
384 static struct page *__rmqueue(struct zone *zone, unsigned int order)
385 {
386         struct free_area * area;
387         unsigned int current_order;
388         struct page *page;
389         unsigned int index;
390
391         for (current_order = order; current_order < MAX_ORDER; ++current_order) {
392                 area = zone->free_area + current_order;
393                 if (list_empty(&area->free_list))
394                         continue;
395
396                 page = list_entry(area->free_list.next, struct page, lru);
397                 list_del(&page->lru);
398                 index = page - zone->zone_mem_map;
399                 if (current_order != MAX_ORDER-1)
400                         MARK_USED(index, current_order, area);
401                 zone->free_pages -= 1UL << order;
402                 return expand(zone, page, index, order, current_order, area);
403         }
404
405         return NULL;
406 }
407
408 /* 
409  * Obtain a specified number of elements from the buddy allocator, all under
410  * a single hold of the lock, for efficiency.  Add them to the supplied list.
411  * Returns the number of new pages which were placed at *list.
412  */
413 static int rmqueue_bulk(struct zone *zone, unsigned int order, 
414                         unsigned long count, struct list_head *list)
415 {
416         unsigned long flags;
417         int i;
418         int allocated = 0;
419         struct page *page;
420         
421         spin_lock_irqsave(&zone->lock, flags);
422         for (i = 0; i < count; ++i) {
423                 page = __rmqueue(zone, order);
424                 if (page == NULL)
425                         break;
426                 allocated++;
427                 list_add_tail(&page->lru, list);
428         }
429         spin_unlock_irqrestore(&zone->lock, flags);
430         return allocated;
431 }
432
433 #if defined(CONFIG_PM) || defined(CONFIG_HOTPLUG_CPU)
434 static void __drain_pages(unsigned int cpu)
435 {
436         struct zone *zone;
437         int i;
438
439         for_each_zone(zone) {
440                 struct per_cpu_pageset *pset;
441
442                 pset = &zone->pageset[cpu];
443                 for (i = 0; i < ARRAY_SIZE(pset->pcp); i++) {
444                         struct per_cpu_pages *pcp;
445
446                         pcp = &pset->pcp[i];
447                         pcp->count -= free_pages_bulk(zone, pcp->count,
448                                                 &pcp->list, 0);
449                 }
450         }
451 }
452 #endif /* CONFIG_PM || CONFIG_HOTPLUG_CPU */
453
454 #ifdef CONFIG_PM
455 int is_head_of_free_region(struct page *page)
456 {
457         struct zone *zone = page_zone(page);
458         unsigned long flags;
459         int order;
460         struct list_head *curr;
461
462         /*
463          * Should not matter as we need quiescent system for
464          * suspend anyway, but...
465          */
466         spin_lock_irqsave(&zone->lock, flags);
467         for (order = MAX_ORDER - 1; order >= 0; --order)
468                 list_for_each(curr, &zone->free_area[order].free_list)
469                         if (page == list_entry(curr, struct page, lru)) {
470                                 spin_unlock_irqrestore(&zone->lock, flags);
471                                 return 1 << order;
472                         }
473         spin_unlock_irqrestore(&zone->lock, flags);
474         return 0;
475 }
476
477 /*
478  * Spill all of this CPU's per-cpu pages back into the buddy allocator.
479  */
480 void drain_local_pages(void)
481 {
482         unsigned long flags;
483
484         local_irq_save(flags);  
485         __drain_pages(smp_processor_id());
486         local_irq_restore(flags);       
487 }
488 #endif /* CONFIG_PM */
489
490 static void zone_statistics(struct zonelist *zonelist, struct zone *z)
491 {
492 #ifdef CONFIG_NUMA
493         unsigned long flags;
494         int cpu;
495         pg_data_t *pg = z->zone_pgdat;
496         pg_data_t *orig = zonelist->zones[0]->zone_pgdat;
497         struct per_cpu_pageset *p;
498
499         local_irq_save(flags);
500         cpu = smp_processor_id();
501         p = &z->pageset[cpu];
502         if (pg == orig) {
503                 z->pageset[cpu].numa_hit++;
504         } else {
505                 p->numa_miss++;
506                 zonelist->zones[0]->pageset[cpu].numa_foreign++;
507         }
508         if (pg == NODE_DATA(numa_node_id()))
509                 p->local_node++;
510         else
511                 p->other_node++;
512         local_irq_restore(flags);
513 #endif
514 }
515
516 /*
517  * Free a 0-order page
518  */
519 static void FASTCALL(free_hot_cold_page(struct page *page, int cold));
520 static void fastcall free_hot_cold_page(struct page *page, int cold)
521 {
522         struct zone *zone = page_zone(page);
523         struct per_cpu_pages *pcp;
524         unsigned long flags;
525
526         arch_free_page(page, 0);
527
528         kernel_map_pages(page, 1, 0);
529         inc_page_state(pgfree);
530         if (PageAnon(page))
531                 page->mapping = NULL;
532         free_pages_check(__FUNCTION__, page);
533         pcp = &zone->pageset[get_cpu()].pcp[cold];
534         local_irq_save(flags);
535         if (pcp->count >= pcp->high)
536                 pcp->count -= free_pages_bulk(zone, pcp->batch, &pcp->list, 0);
537         list_add(&page->lru, &pcp->list);
538         pcp->count++;
539         local_irq_restore(flags);
540         put_cpu();
541 }
542
543 void fastcall free_hot_page(struct page *page)
544 {
545         free_hot_cold_page(page, 0);
546 }
547         
548 void fastcall free_cold_page(struct page *page)
549 {
550         free_hot_cold_page(page, 1);
551 }
552
553 /*
554  * Really, prep_compound_page() should be called from __rmqueue_bulk().  But
555  * we cheat by calling it from here, in the order > 0 path.  Saves a branch
556  * or two.
557  */
558
559 static struct page *
560 buffered_rmqueue(struct zone *zone, int order, int gfp_flags)
561 {
562         unsigned long flags;
563         struct page *page = NULL;
564         int cold = !!(gfp_flags & __GFP_COLD);
565
566         if (order == 0) {
567                 struct per_cpu_pages *pcp;
568
569                 pcp = &zone->pageset[get_cpu()].pcp[cold];
570                 local_irq_save(flags);
571                 if (pcp->count <= pcp->low)
572                         pcp->count += rmqueue_bulk(zone, 0,
573                                                 pcp->batch, &pcp->list);
574                 if (pcp->count) {
575                         page = list_entry(pcp->list.next, struct page, lru);
576                         list_del(&page->lru);
577                         pcp->count--;
578                 }
579                 local_irq_restore(flags);
580                 put_cpu();
581         }
582
583         if (page == NULL) {
584                 spin_lock_irqsave(&zone->lock, flags);
585                 page = __rmqueue(zone, order);
586                 spin_unlock_irqrestore(&zone->lock, flags);
587         }
588
589         if (page != NULL) {
590                 BUG_ON(bad_range(zone, page));
591                 mod_page_state_zone(zone, pgalloc, 1 << order);
592                 prep_new_page(page, order);
593                 if (order && (gfp_flags & __GFP_COMP))
594                         prep_compound_page(page, order);
595         }
596         return page;
597 }
598
599 /*
600  * This is the 'heart' of the zoned buddy allocator.
601  *
602  * Herein lies the mysterious "incremental min".  That's the
603  *
604  *      local_low = z->pages_low;
605  *      min += local_low;
606  *
607  * thing.  The intent here is to provide additional protection to low zones for
608  * allocation requests which _could_ use higher zones.  So a GFP_HIGHMEM
609  * request is not allowed to dip as deeply into the normal zone as a GFP_KERNEL
610  * request.  This preserves additional space in those lower zones for requests
611  * which really do need memory from those zones.  It means that on a decent
612  * sized machine, GFP_HIGHMEM and GFP_KERNEL requests basically leave the DMA
613  * zone untouched.
614  */
615 struct page * fastcall
616 __alloc_pages(unsigned int gfp_mask, unsigned int order,
617                 struct zonelist *zonelist)
618 {
619         const int wait = gfp_mask & __GFP_WAIT;
620         unsigned long min;
621         struct zone **zones, *z;
622         struct page *page;
623         struct reclaim_state reclaim_state;
624         struct task_struct *p = current;
625         int i;
626         int alloc_type;
627         int do_retry;
628         int can_try_harder;
629
630         might_sleep_if(wait);
631
632         /*
633          * The caller may dip into page reserves a bit more if the caller
634          * cannot run direct reclaim, or is the caller has realtime scheduling
635          * policy
636          */
637         can_try_harder = (unlikely(rt_task(p)) && !in_interrupt()) || !wait;
638
639         if (!ckrm_class_limit_ok((ckrm_get_mem_class(current)))) {
640                 return NULL;
641         }
642
643         zones = zonelist->zones;  /* the list of zones suitable for gfp_mask */
644
645         if (unlikely(zones[0] == NULL)) {
646                 /* Should this ever happen?? */
647                 return NULL;
648         }
649
650         alloc_type = zone_idx(zones[0]);
651
652         /* Go through the zonelist once, looking for a zone with enough free */
653         for (i = 0; (z = zones[i]) != NULL; i++) {
654                 min = z->pages_low + (1<<order) + z->protection[alloc_type];
655
656                 if (z->free_pages < min)
657                         continue;
658
659                 page = buffered_rmqueue(z, order, gfp_mask);
660                 if (page)
661                         goto got_pg;
662         }
663
664         for (i = 0; (z = zones[i]) != NULL; i++)
665                 wakeup_kswapd(z);
666
667         /*
668          * Go through the zonelist again. Let __GFP_HIGH and allocations
669          * coming from realtime tasks to go deeper into reserves
670          */
671         for (i = 0; (z = zones[i]) != NULL; i++) {
672                 min = z->pages_min;
673                 if (gfp_mask & __GFP_HIGH)
674                         min /= 2;
675                 if (can_try_harder)
676                         min -= min / 4;
677                 min += (1<<order) + z->protection[alloc_type];
678
679                 if (z->free_pages < min)
680                         continue;
681
682                 page = buffered_rmqueue(z, order, gfp_mask);
683                 if (page)
684                         goto got_pg;
685         }
686
687         /* This allocation should allow future memory freeing. */
688         if ((p->flags & (PF_MEMALLOC | PF_MEMDIE)) && !in_interrupt()) {
689                 /* go through the zonelist yet again, ignoring mins */
690                 for (i = 0; (z = zones[i]) != NULL; i++) {
691                         page = buffered_rmqueue(z, order, gfp_mask);
692                         if (page)
693                                 goto got_pg;
694                 }
695                 goto nopage;
696         }
697
698         /* Atomic allocations - we can't balance anything */
699         if (!wait)
700                 goto nopage;
701
702 rebalance:
703         /* We now go into synchronous reclaim */
704         p->flags |= PF_MEMALLOC;
705         reclaim_state.reclaimed_slab = 0;
706         p->reclaim_state = &reclaim_state;
707
708         try_to_free_pages(zones, gfp_mask, order);
709
710         p->reclaim_state = NULL;
711         p->flags &= ~PF_MEMALLOC;
712
713         /* go through the zonelist yet one more time */
714         for (i = 0; (z = zones[i]) != NULL; i++) {
715                 min = z->pages_min;
716                 if (gfp_mask & __GFP_HIGH)
717                         min /= 2;
718                 if (can_try_harder)
719                         min -= min / 4;
720                 min += (1<<order) + z->protection[alloc_type];
721
722                 if (z->free_pages < min)
723                         continue;
724
725                 page = buffered_rmqueue(z, order, gfp_mask);
726                 if (page)
727                         goto got_pg;
728         }
729
730         /*
731          * Don't let big-order allocations loop unless the caller explicitly
732          * requests that.  Wait for some write requests to complete then retry.
733          *
734          * In this implementation, __GFP_REPEAT means __GFP_NOFAIL for order
735          * <= 3, but that may not be true in other implementations.
736          */
737         do_retry = 0;
738         if (!(gfp_mask & __GFP_NORETRY)) {
739                 if ((order <= 3) || (gfp_mask & __GFP_REPEAT))
740                         do_retry = 1;
741                 if (gfp_mask & __GFP_NOFAIL)
742                         do_retry = 1;
743         }
744         if (do_retry) {
745                 blk_congestion_wait(WRITE, HZ/50);
746                 goto rebalance;
747         }
748
749 nopage:
750         if (!(gfp_mask & __GFP_NOWARN) && printk_ratelimit()) {
751                 printk(KERN_WARNING "%s: page allocation failure."
752                         " order:%d, mode:0x%x\n",
753                         p->comm, order, gfp_mask);
754                 dump_stack();
755         }
756         return NULL;
757 got_pg:
758         zone_statistics(zonelist, z);
759         kernel_map_pages(page, 1 << order, 1);
760         return page;
761 }
762
763 EXPORT_SYMBOL(__alloc_pages);
764
765 /*
766  * Common helper functions.
767  */
768 fastcall unsigned long __get_free_pages(unsigned int gfp_mask, unsigned int order)
769 {
770         struct page * page;
771         page = alloc_pages(gfp_mask, order);
772         if (!page)
773                 return 0;
774         return (unsigned long) page_address(page);
775 }
776
777 EXPORT_SYMBOL(__get_free_pages);
778
779 fastcall unsigned long get_zeroed_page(unsigned int gfp_mask)
780 {
781         struct page * page;
782
783         /*
784          * get_zeroed_page() returns a 32-bit address, which cannot represent
785          * a highmem page
786          */
787         BUG_ON(gfp_mask & __GFP_HIGHMEM);
788
789         page = alloc_pages(gfp_mask, 0);
790         if (page) {
791                 void *address = page_address(page);
792                 clear_page(address);
793                 return (unsigned long) address;
794         }
795         return 0;
796 }
797
798 EXPORT_SYMBOL(get_zeroed_page);
799
800 void __pagevec_free(struct pagevec *pvec)
801 {
802         int i = pagevec_count(pvec);
803
804         while (--i >= 0)
805                 free_hot_cold_page(pvec->pages[i], pvec->cold);
806 }
807
808 fastcall void __free_pages(struct page *page, unsigned int order)
809 {
810         if (!PageReserved(page) && put_page_testzero(page)) {
811                 if (order == 0)
812                         free_hot_page(page);
813                 else
814                         __free_pages_ok(page, order);
815         }
816 }
817
818 EXPORT_SYMBOL(__free_pages);
819
820 fastcall void free_pages(unsigned long addr, unsigned int order)
821 {
822         if (addr != 0) {
823                 BUG_ON(!virt_addr_valid((void *)addr));
824                 __free_pages(virt_to_page((void *)addr), order);
825         }
826 }
827
828 EXPORT_SYMBOL(free_pages);
829
830 /*
831  * Total amount of free (allocatable) RAM:
832  */
833 unsigned int nr_free_pages(void)
834 {
835         unsigned int sum = 0;
836         struct zone *zone;
837
838         for_each_zone(zone)
839                 sum += zone->free_pages;
840
841         return sum;
842 }
843
844 EXPORT_SYMBOL(nr_free_pages);
845
846 #ifdef CONFIG_NUMA
847 unsigned int nr_free_pages_pgdat(pg_data_t *pgdat)
848 {
849         unsigned int i, sum = 0;
850
851         for (i = 0; i < MAX_NR_ZONES; i++)
852                 sum += pgdat->node_zones[i].free_pages;
853
854         return sum;
855 }
856 #endif
857
858 static unsigned int nr_free_zone_pages(int offset)
859 {
860         pg_data_t *pgdat;
861         unsigned int sum = 0;
862
863         for_each_pgdat(pgdat) {
864                 struct zonelist *zonelist = pgdat->node_zonelists + offset;
865                 struct zone **zonep = zonelist->zones;
866                 struct zone *zone;
867
868                 for (zone = *zonep++; zone; zone = *zonep++) {
869                         unsigned long size = zone->present_pages;
870                         unsigned long high = zone->pages_high;
871                         if (size > high)
872                                 sum += size - high;
873                 }
874         }
875
876         return sum;
877 }
878
879 /*
880  * Amount of free RAM allocatable within ZONE_DMA and ZONE_NORMAL
881  */
882 unsigned int nr_free_buffer_pages(void)
883 {
884         return nr_free_zone_pages(GFP_USER & GFP_ZONEMASK);
885 }
886
887 /*
888  * Amount of free RAM allocatable within all zones
889  */
890 unsigned int nr_free_pagecache_pages(void)
891 {
892         return nr_free_zone_pages(GFP_HIGHUSER & GFP_ZONEMASK);
893 }
894
895 #ifdef CONFIG_HIGHMEM
896 unsigned int nr_free_highpages (void)
897 {
898         pg_data_t *pgdat;
899         unsigned int pages = 0;
900
901         for_each_pgdat(pgdat)
902                 pages += pgdat->node_zones[ZONE_HIGHMEM].free_pages;
903
904         return pages;
905 }
906 #endif
907
908 #ifdef CONFIG_NUMA
909 static void show_node(struct zone *zone)
910 {
911         printk("Node %d ", zone->zone_pgdat->node_id);
912 }
913 #else
914 #define show_node(zone) do { } while (0)
915 #endif
916
917 /*
918  * Accumulate the page_state information across all CPUs.
919  * The result is unavoidably approximate - it can change
920  * during and after execution of this function.
921  */
922 DEFINE_PER_CPU(struct page_state, page_states) = {0};
923 EXPORT_PER_CPU_SYMBOL(page_states);
924
925 atomic_t nr_pagecache = ATOMIC_INIT(0);
926 EXPORT_SYMBOL(nr_pagecache);
927 #ifdef CONFIG_SMP
928 DEFINE_PER_CPU(long, nr_pagecache_local) = 0;
929 #endif
930
931 void __get_page_state(struct page_state *ret, int nr)
932 {
933         int cpu = 0;
934
935         memset(ret, 0, sizeof(*ret));
936         while (cpu < NR_CPUS) {
937                 unsigned long *in, *out, off;
938
939                 if (!cpu_possible(cpu)) {
940                         cpu++;
941                         continue;
942                 }
943
944                 in = (unsigned long *)&per_cpu(page_states, cpu);
945                 cpu++;
946                 if (cpu < NR_CPUS && cpu_possible(cpu))
947                         prefetch(&per_cpu(page_states, cpu));
948                 out = (unsigned long *)ret;
949                 for (off = 0; off < nr; off++)
950                         *out++ += *in++;
951         }
952 }
953
954 void get_page_state(struct page_state *ret)
955 {
956         int nr;
957
958         nr = offsetof(struct page_state, GET_PAGE_STATE_LAST);
959         nr /= sizeof(unsigned long);
960
961         __get_page_state(ret, nr + 1);
962 }
963
964 void get_full_page_state(struct page_state *ret)
965 {
966         __get_page_state(ret, sizeof(*ret) / sizeof(unsigned long));
967 }
968
969 unsigned long __read_page_state(unsigned offset)
970 {
971         unsigned long ret = 0;
972         int cpu;
973
974         for (cpu = 0; cpu < NR_CPUS; cpu++) {
975                 unsigned long in;
976
977                 if (!cpu_possible(cpu))
978                         continue;
979
980                 in = (unsigned long)&per_cpu(page_states, cpu) + offset;
981                 ret += *((unsigned long *)in);
982         }
983         return ret;
984 }
985
986 void __get_zone_counts(unsigned long *active, unsigned long *inactive,
987                         unsigned long *free, struct pglist_data *pgdat)
988 {
989         struct zone *zones = pgdat->node_zones;
990         int i;
991
992         *active = 0;
993         *inactive = 0;
994         *free = 0;
995         for (i = 0; i < MAX_NR_ZONES; i++) {
996                 *active += zones[i].nr_active;
997                 *inactive += zones[i].nr_inactive;
998                 *free += zones[i].free_pages;
999         }
1000 }
1001
1002 void get_zone_counts(unsigned long *active,
1003                 unsigned long *inactive, unsigned long *free)
1004 {
1005         struct pglist_data *pgdat;
1006
1007         *active = 0;
1008         *inactive = 0;
1009         *free = 0;
1010         for_each_pgdat(pgdat) {
1011                 unsigned long l, m, n;
1012                 __get_zone_counts(&l, &m, &n, pgdat);
1013                 *active += l;
1014                 *inactive += m;
1015                 *free += n;
1016         }
1017 }
1018
1019 void si_meminfo(struct sysinfo *val)
1020 {
1021         val->totalram = totalram_pages;
1022         val->sharedram = 0;
1023         val->freeram = nr_free_pages();
1024         val->bufferram = nr_blockdev_pages();
1025 #ifdef CONFIG_HIGHMEM
1026         val->totalhigh = totalhigh_pages;
1027         val->freehigh = nr_free_highpages();
1028 #else
1029         val->totalhigh = 0;
1030         val->freehigh = 0;
1031 #endif
1032         val->mem_unit = PAGE_SIZE;
1033         if (vx_flags(VXF_VIRT_MEM, 0))
1034                 vx_vsi_meminfo(val);
1035 }
1036
1037 EXPORT_SYMBOL(si_meminfo);
1038
1039 #ifdef CONFIG_NUMA
1040 void si_meminfo_node(struct sysinfo *val, int nid)
1041 {
1042         pg_data_t *pgdat = NODE_DATA(nid);
1043
1044         val->totalram = pgdat->node_present_pages;
1045         val->freeram = nr_free_pages_pgdat(pgdat);
1046         val->totalhigh = pgdat->node_zones[ZONE_HIGHMEM].present_pages;
1047         val->freehigh = pgdat->node_zones[ZONE_HIGHMEM].free_pages;
1048         val->mem_unit = PAGE_SIZE;
1049 }
1050 #endif
1051
1052 #define K(x) ((x) << (PAGE_SHIFT-10))
1053
1054 /*
1055  * Show free area list (used inside shift_scroll-lock stuff)
1056  * We also calculate the percentage fragmentation. We do this by counting the
1057  * memory on each free list with the exception of the first item on the list.
1058  */
1059 void show_free_areas(void)
1060 {
1061         struct page_state ps;
1062         int cpu, temperature;
1063         unsigned long active;
1064         unsigned long inactive;
1065         unsigned long free;
1066         struct zone *zone;
1067
1068         for_each_zone(zone) {
1069                 show_node(zone);
1070                 printk("%s per-cpu:", zone->name);
1071
1072                 if (!zone->present_pages) {
1073                         printk(" empty\n");
1074                         continue;
1075                 } else
1076                         printk("\n");
1077
1078                 for (cpu = 0; cpu < NR_CPUS; ++cpu) {
1079                         struct per_cpu_pageset *pageset;
1080
1081                         if (!cpu_possible(cpu))
1082                                 continue;
1083
1084                         pageset = zone->pageset + cpu;
1085
1086                         for (temperature = 0; temperature < 2; temperature++)
1087                                 printk("cpu %d %s: low %d, high %d, batch %d\n",
1088                                         cpu,
1089                                         temperature ? "cold" : "hot",
1090                                         pageset->pcp[temperature].low,
1091                                         pageset->pcp[temperature].high,
1092                                         pageset->pcp[temperature].batch);
1093                 }
1094         }
1095
1096         get_page_state(&ps);
1097         get_zone_counts(&active, &inactive, &free);
1098
1099         printk("\nFree pages: %11ukB (%ukB HighMem)\n",
1100                 K(nr_free_pages()),
1101                 K(nr_free_highpages()));
1102
1103         printk("Active:%lu inactive:%lu dirty:%lu writeback:%lu "
1104                 "unstable:%lu free:%u slab:%lu mapped:%lu pagetables:%lu\n",
1105                 active,
1106                 inactive,
1107                 ps.nr_dirty,
1108                 ps.nr_writeback,
1109                 ps.nr_unstable,
1110                 nr_free_pages(),
1111                 ps.nr_slab,
1112                 ps.nr_mapped,
1113                 ps.nr_page_table_pages);
1114
1115         for_each_zone(zone) {
1116                 int i;
1117
1118                 show_node(zone);
1119                 printk("%s"
1120                         " free:%lukB"
1121                         " min:%lukB"
1122                         " low:%lukB"
1123                         " high:%lukB"
1124                         " active:%lukB"
1125                         " inactive:%lukB"
1126                         " present:%lukB"
1127                         " pages_scanned:%lu"
1128                         " all_unreclaimable? %s"
1129                         "\n",
1130                         zone->name,
1131                         K(zone->free_pages),
1132                         K(zone->pages_min),
1133                         K(zone->pages_low),
1134                         K(zone->pages_high),
1135                         K(zone->nr_active),
1136                         K(zone->nr_inactive),
1137                         K(zone->present_pages),
1138                         zone->pages_scanned,
1139                         (zone->all_unreclaimable ? "yes" : "no")
1140                         );
1141                 printk("protections[]:");
1142                 for (i = 0; i < MAX_NR_ZONES; i++)
1143                         printk(" %lu", zone->protection[i]);
1144                 printk("\n");
1145         }
1146
1147         for_each_zone(zone) {
1148                 struct list_head *elem;
1149                 unsigned long nr, flags, order, total = 0;
1150
1151                 show_node(zone);
1152                 printk("%s: ", zone->name);
1153                 if (!zone->present_pages) {
1154                         printk("empty\n");
1155                         continue;
1156                 }
1157
1158                 spin_lock_irqsave(&zone->lock, flags);
1159                 for (order = 0; order < MAX_ORDER; order++) {
1160                         nr = 0;
1161                         list_for_each(elem, &zone->free_area[order].free_list)
1162                                 ++nr;
1163                         total += nr << order;
1164                         printk("%lu*%lukB ", nr, K(1UL) << order);
1165                 }
1166                 spin_unlock_irqrestore(&zone->lock, flags);
1167                 printk("= %lukB\n", K(total));
1168         }
1169
1170         show_swap_cache_info();
1171 }
1172
1173 /*
1174  * Builds allocation fallback zone lists.
1175  */
1176 static int __init build_zonelists_node(pg_data_t *pgdat, struct zonelist *zonelist, int j, int k)
1177 {
1178         switch (k) {
1179                 struct zone *zone;
1180         default:
1181                 BUG();
1182         case ZONE_HIGHMEM:
1183                 zone = pgdat->node_zones + ZONE_HIGHMEM;
1184                 if (zone->present_pages) {
1185 #ifndef CONFIG_HIGHMEM
1186                         BUG();
1187 #endif
1188                         zonelist->zones[j++] = zone;
1189                 }
1190         case ZONE_NORMAL:
1191                 zone = pgdat->node_zones + ZONE_NORMAL;
1192                 if (zone->present_pages)
1193                         zonelist->zones[j++] = zone;
1194         case ZONE_DMA:
1195                 zone = pgdat->node_zones + ZONE_DMA;
1196                 if (zone->present_pages)
1197                         zonelist->zones[j++] = zone;
1198         }
1199
1200         return j;
1201 }
1202
1203 #ifdef CONFIG_NUMA
1204 #define MAX_NODE_LOAD (numnodes)
1205 static int __initdata node_load[MAX_NUMNODES];
1206 /**
1207  * find_next_best_node - find the next node that should appear in a given
1208  *    node's fallback list
1209  * @node: node whose fallback list we're appending
1210  * @used_node_mask: pointer to the bitmap of already used nodes
1211  *
1212  * We use a number of factors to determine which is the next node that should
1213  * appear on a given node's fallback list.  The node should not have appeared
1214  * already in @node's fallback list, and it should be the next closest node
1215  * according to the distance array (which contains arbitrary distance values
1216  * from each node to each node in the system), and should also prefer nodes
1217  * with no CPUs, since presumably they'll have very little allocation pressure
1218  * on them otherwise.
1219  * It returns -1 if no node is found.
1220  */
1221 static int __init find_next_best_node(int node, void *used_node_mask)
1222 {
1223         int i, n, val;
1224         int min_val = INT_MAX;
1225         int best_node = -1;
1226
1227         for (i = 0; i < numnodes; i++) {
1228                 cpumask_t tmp;
1229
1230                 /* Start from local node */
1231                 n = (node+i)%numnodes;
1232
1233                 /* Don't want a node to appear more than once */
1234                 if (test_bit(n, used_node_mask))
1235                         continue;
1236
1237                 /* Use the local node if we haven't already */
1238                 if (!test_bit(node, used_node_mask)) {
1239                         best_node = node;
1240                         break;
1241                 }
1242
1243                 /* Use the distance array to find the distance */
1244                 val = node_distance(node, n);
1245
1246                 /* Give preference to headless and unused nodes */
1247                 tmp = node_to_cpumask(n);
1248                 if (!cpus_empty(tmp))
1249                         val += PENALTY_FOR_NODE_WITH_CPUS;
1250
1251                 /* Slight preference for less loaded node */
1252                 val *= (MAX_NODE_LOAD*MAX_NUMNODES);
1253                 val += node_load[n];
1254
1255                 if (val < min_val) {
1256                         min_val = val;
1257                         best_node = n;
1258                 }
1259         }
1260
1261         if (best_node >= 0)
1262                 set_bit(best_node, used_node_mask);
1263
1264         return best_node;
1265 }
1266
1267 static void __init build_zonelists(pg_data_t *pgdat)
1268 {
1269         int i, j, k, node, local_node;
1270         int prev_node, load;
1271         struct zonelist *zonelist;
1272         DECLARE_BITMAP(used_mask, MAX_NUMNODES);
1273
1274         /* initialize zonelists */
1275         for (i = 0; i < GFP_ZONETYPES; i++) {
1276                 zonelist = pgdat->node_zonelists + i;
1277                 memset(zonelist, 0, sizeof(*zonelist));
1278                 zonelist->zones[0] = NULL;
1279         }
1280
1281         /* NUMA-aware ordering of nodes */
1282         local_node = pgdat->node_id;
1283         load = numnodes;
1284         prev_node = local_node;
1285         bitmap_zero(used_mask, MAX_NUMNODES);
1286         while ((node = find_next_best_node(local_node, used_mask)) >= 0) {
1287                 /*
1288                  * We don't want to pressure a particular node.
1289                  * So adding penalty to the first node in same
1290                  * distance group to make it round-robin.
1291                  */
1292                 if (node_distance(local_node, node) !=
1293                                 node_distance(local_node, prev_node))
1294                         node_load[node] += load;
1295                 prev_node = node;
1296                 load--;
1297                 for (i = 0; i < GFP_ZONETYPES; i++) {
1298                         zonelist = pgdat->node_zonelists + i;
1299                         for (j = 0; zonelist->zones[j] != NULL; j++);
1300
1301                         k = ZONE_NORMAL;
1302                         if (i & __GFP_HIGHMEM)
1303                                 k = ZONE_HIGHMEM;
1304                         if (i & __GFP_DMA)
1305                                 k = ZONE_DMA;
1306
1307                         j = build_zonelists_node(NODE_DATA(node), zonelist, j, k);
1308                         zonelist->zones[j] = NULL;
1309                 }
1310         }
1311 }
1312
1313 #else   /* CONFIG_NUMA */
1314
1315 static void __init build_zonelists(pg_data_t *pgdat)
1316 {
1317         int i, j, k, node, local_node;
1318
1319         local_node = pgdat->node_id;
1320         for (i = 0; i < GFP_ZONETYPES; i++) {
1321                 struct zonelist *zonelist;
1322
1323                 zonelist = pgdat->node_zonelists + i;
1324                 memset(zonelist, 0, sizeof(*zonelist));
1325
1326                 j = 0;
1327                 k = ZONE_NORMAL;
1328                 if (i & __GFP_HIGHMEM)
1329                         k = ZONE_HIGHMEM;
1330                 if (i & __GFP_DMA)
1331                         k = ZONE_DMA;
1332
1333                 j = build_zonelists_node(pgdat, zonelist, j, k);
1334                 /*
1335                  * Now we build the zonelist so that it contains the zones
1336                  * of all the other nodes.
1337                  * We don't want to pressure a particular node, so when
1338                  * building the zones for node N, we make sure that the
1339                  * zones coming right after the local ones are those from
1340                  * node N+1 (modulo N)
1341                  */
1342                 for (node = local_node + 1; node < numnodes; node++)
1343                         j = build_zonelists_node(NODE_DATA(node), zonelist, j, k);
1344                 for (node = 0; node < local_node; node++)
1345                         j = build_zonelists_node(NODE_DATA(node), zonelist, j, k);
1346  
1347                 zonelist->zones[j] = NULL;
1348         }
1349 }
1350
1351 #endif  /* CONFIG_NUMA */
1352
1353 void __init build_all_zonelists(void)
1354 {
1355         int i;
1356
1357         for(i = 0 ; i < numnodes ; i++)
1358                 build_zonelists(NODE_DATA(i));
1359         printk("Built %i zonelists\n", numnodes);
1360 }
1361
1362 /*
1363  * Helper functions to size the waitqueue hash table.
1364  * Essentially these want to choose hash table sizes sufficiently
1365  * large so that collisions trying to wait on pages are rare.
1366  * But in fact, the number of active page waitqueues on typical
1367  * systems is ridiculously low, less than 200. So this is even
1368  * conservative, even though it seems large.
1369  *
1370  * The constant PAGES_PER_WAITQUEUE specifies the ratio of pages to
1371  * waitqueues, i.e. the size of the waitq table given the number of pages.
1372  */
1373 #define PAGES_PER_WAITQUEUE     256
1374
1375 static inline unsigned long wait_table_size(unsigned long pages)
1376 {
1377         unsigned long size = 1;
1378
1379         pages /= PAGES_PER_WAITQUEUE;
1380
1381         while (size < pages)
1382                 size <<= 1;
1383
1384         /*
1385          * Once we have dozens or even hundreds of threads sleeping
1386          * on IO we've got bigger problems than wait queue collision.
1387          * Limit the size of the wait table to a reasonable size.
1388          */
1389         size = min(size, 4096UL);
1390
1391         return max(size, 4UL);
1392 }
1393
1394 /*
1395  * This is an integer logarithm so that shifts can be used later
1396  * to extract the more random high bits from the multiplicative
1397  * hash function before the remainder is taken.
1398  */
1399 static inline unsigned long wait_table_bits(unsigned long size)
1400 {
1401         return ffz(~size);
1402 }
1403
1404 #define LONG_ALIGN(x) (((x)+(sizeof(long))-1)&~((sizeof(long))-1))
1405
1406 static void __init calculate_zone_totalpages(struct pglist_data *pgdat,
1407                 unsigned long *zones_size, unsigned long *zholes_size)
1408 {
1409         unsigned long realtotalpages, totalpages = 0;
1410         int i;
1411
1412         for (i = 0; i < MAX_NR_ZONES; i++)
1413                 totalpages += zones_size[i];
1414         pgdat->node_spanned_pages = totalpages;
1415
1416         realtotalpages = totalpages;
1417         if (zholes_size)
1418                 for (i = 0; i < MAX_NR_ZONES; i++)
1419                         realtotalpages -= zholes_size[i];
1420         pgdat->node_present_pages = realtotalpages;
1421         printk(KERN_DEBUG "On node %d totalpages: %lu\n", pgdat->node_id, realtotalpages);
1422 }
1423
1424
1425 /*
1426  * Initially all pages are reserved - free ones are freed
1427  * up by free_all_bootmem() once the early boot process is
1428  * done. Non-atomic initialization, single-pass.
1429  */
1430 void __init memmap_init_zone(unsigned long size, int nid, unsigned long zone,
1431                 unsigned long start_pfn)
1432 {
1433         struct page *start = pfn_to_page(start_pfn);
1434         struct page *page;
1435
1436         for (page = start; page < (start + size); page++) {
1437                 set_page_zone(page, NODEZONE(nid, zone));
1438                 set_page_count(page, 0);
1439                 reset_page_mapcount(page);
1440                 SetPageReserved(page);
1441                 INIT_LIST_HEAD(&page->lru);
1442 #ifdef WANT_PAGE_VIRTUAL
1443                 /* The shift won't overflow because ZONE_NORMAL is below 4G. */
1444                 if (!is_highmem_idx(zone))
1445                         set_page_address(page, __va(start_pfn << PAGE_SHIFT));
1446 #endif
1447                 start_pfn++;
1448         }
1449 }
1450
1451 /*
1452  * Page buddy system uses "index >> (i+1)", where "index" is
1453  * at most "size-1".
1454  *
1455  * The extra "+3" is to round down to byte size (8 bits per byte
1456  * assumption). Thus we get "(size-1) >> (i+4)" as the last byte
1457  * we can access.
1458  *
1459  * The "+1" is because we want to round the byte allocation up
1460  * rather than down. So we should have had a "+7" before we shifted
1461  * down by three. Also, we have to add one as we actually _use_ the
1462  * last bit (it's [0,n] inclusive, not [0,n[).
1463  *
1464  * So we actually had +7+1 before we shift down by 3. But
1465  * (n+8) >> 3 == (n >> 3) + 1 (modulo overflows, which we do not have).
1466  *
1467  * Finally, we LONG_ALIGN because all bitmap operations are on longs.
1468  */
1469 unsigned long pages_to_bitmap_size(unsigned long order, unsigned long nr_pages)
1470 {
1471         unsigned long bitmap_size;
1472
1473         bitmap_size = (nr_pages-1) >> (order+4);
1474         bitmap_size = LONG_ALIGN(bitmap_size+1);
1475
1476         return bitmap_size;
1477 }
1478
1479 void zone_init_free_lists(struct pglist_data *pgdat, struct zone *zone, unsigned long size)
1480 {
1481         int order;
1482         for (order = 0; ; order++) {
1483                 unsigned long bitmap_size;
1484
1485                 INIT_LIST_HEAD(&zone->free_area[order].free_list);
1486                 if (order == MAX_ORDER-1) {
1487                         zone->free_area[order].map = NULL;
1488                         break;
1489                 }
1490
1491                 bitmap_size = pages_to_bitmap_size(order, size);
1492                 zone->free_area[order].map =
1493                   (unsigned long *) alloc_bootmem_node(pgdat, bitmap_size);
1494         }
1495 }
1496
1497 #ifndef __HAVE_ARCH_MEMMAP_INIT
1498 #define memmap_init(size, nid, zone, start_pfn) \
1499         memmap_init_zone((size), (nid), (zone), (start_pfn))
1500 #endif
1501
1502 /*
1503  * Set up the zone data structures:
1504  *   - mark all pages reserved
1505  *   - mark all memory queues empty
1506  *   - clear the memory bitmaps
1507  */
1508 static void __init free_area_init_core(struct pglist_data *pgdat,
1509                 unsigned long *zones_size, unsigned long *zholes_size)
1510 {
1511         unsigned long i, j;
1512         const unsigned long zone_required_alignment = 1UL << (MAX_ORDER-1);
1513         int cpu, nid = pgdat->node_id;
1514         unsigned long zone_start_pfn = pgdat->node_start_pfn;
1515
1516         pgdat->nr_zones = 0;
1517         init_waitqueue_head(&pgdat->kswapd_wait);
1518         
1519         for (j = 0; j < MAX_NR_ZONES; j++) {
1520                 struct zone *zone = pgdat->node_zones + j;
1521                 unsigned long size, realsize;
1522                 unsigned long batch;
1523
1524                 zone_table[NODEZONE(nid, j)] = zone;
1525                 realsize = size = zones_size[j];
1526                 if (zholes_size)
1527                         realsize -= zholes_size[j];
1528
1529                 if (j == ZONE_DMA || j == ZONE_NORMAL)
1530                         nr_kernel_pages += realsize;
1531                 nr_all_pages += realsize;
1532
1533                 zone->spanned_pages = size;
1534                 zone->present_pages = realsize;
1535                 zone->name = zone_names[j];
1536                 spin_lock_init(&zone->lock);
1537                 spin_lock_init(&zone->lru_lock);
1538                 zone->zone_pgdat = pgdat;
1539                 zone->free_pages = 0;
1540
1541                 zone->temp_priority = zone->prev_priority = DEF_PRIORITY;
1542
1543                 /*
1544                  * The per-cpu-pages pools are set to around 1000th of the
1545                  * size of the zone.  But no more than 1/4 of a meg - there's
1546                  * no point in going beyond the size of L2 cache.
1547                  *
1548                  * OK, so we don't know how big the cache is.  So guess.
1549                  */
1550                 batch = zone->present_pages / 1024;
1551                 if (batch * PAGE_SIZE > 256 * 1024)
1552                         batch = (256 * 1024) / PAGE_SIZE;
1553                 batch /= 4;             /* We effectively *= 4 below */
1554                 if (batch < 1)
1555                         batch = 1;
1556
1557                 for (cpu = 0; cpu < NR_CPUS; cpu++) {
1558                         struct per_cpu_pages *pcp;
1559
1560                         pcp = &zone->pageset[cpu].pcp[0];       /* hot */
1561                         pcp->count = 0;
1562                         pcp->low = 2 * batch;
1563                         pcp->high = 6 * batch;
1564                         pcp->batch = 1 * batch;
1565                         INIT_LIST_HEAD(&pcp->list);
1566
1567                         pcp = &zone->pageset[cpu].pcp[1];       /* cold */
1568                         pcp->count = 0;
1569                         pcp->low = 0;
1570                         pcp->high = 2 * batch;
1571                         pcp->batch = 1 * batch;
1572                         INIT_LIST_HEAD(&pcp->list);
1573                 }
1574                 printk(KERN_DEBUG "  %s zone: %lu pages, LIFO batch:%lu\n",
1575                                 zone_names[j], realsize, batch);
1576 #ifndef CONFIG_CKRM_RES_MEM
1577                 INIT_LIST_HEAD(&zone->active_list);
1578                 INIT_LIST_HEAD(&zone->inactive_list);
1579 #endif
1580                 zone->nr_scan_active = 0;
1581                 zone->nr_scan_inactive = 0;
1582                 zone->nr_active = 0;
1583                 zone->nr_inactive = 0;
1584                 if (!size)
1585                         continue;
1586
1587                 /*
1588                  * The per-page waitqueue mechanism uses hashed waitqueues
1589                  * per zone.
1590                  */
1591                 zone->wait_table_size = wait_table_size(size);
1592                 zone->wait_table_bits =
1593                         wait_table_bits(zone->wait_table_size);
1594                 zone->wait_table = (wait_queue_head_t *)
1595                         alloc_bootmem_node(pgdat, zone->wait_table_size
1596                                                 * sizeof(wait_queue_head_t));
1597
1598                 for(i = 0; i < zone->wait_table_size; ++i)
1599                         init_waitqueue_head(zone->wait_table + i);
1600
1601                 pgdat->nr_zones = j+1;
1602
1603                 zone->zone_mem_map = pfn_to_page(zone_start_pfn);
1604                 zone->zone_start_pfn = zone_start_pfn;
1605
1606                 if ((zone_start_pfn) & (zone_required_alignment-1))
1607                         printk("BUG: wrong zone alignment, it will crash\n");
1608
1609                 memmap_init(size, nid, j, zone_start_pfn);
1610
1611                 zone_start_pfn += size;
1612
1613                 zone_init_free_lists(pgdat, zone, zone->spanned_pages);
1614         }
1615 }
1616
1617 void __init node_alloc_mem_map(struct pglist_data *pgdat)
1618 {
1619         unsigned long size;
1620
1621         size = (pgdat->node_spanned_pages + 1) * sizeof(struct page);
1622         pgdat->node_mem_map = alloc_bootmem_node(pgdat, size);
1623 #ifndef CONFIG_DISCONTIGMEM
1624         mem_map = contig_page_data.node_mem_map;
1625 #endif
1626 }
1627
1628 void __init free_area_init_node(int nid, struct pglist_data *pgdat,
1629                 unsigned long *zones_size, unsigned long node_start_pfn,
1630                 unsigned long *zholes_size)
1631 {
1632         pgdat->node_id = nid;
1633         pgdat->node_start_pfn = node_start_pfn;
1634         calculate_zone_totalpages(pgdat, zones_size, zholes_size);
1635
1636         if (!pfn_to_page(node_start_pfn))
1637                 node_alloc_mem_map(pgdat);
1638
1639         free_area_init_core(pgdat, zones_size, zholes_size);
1640 }
1641
1642 #ifndef CONFIG_DISCONTIGMEM
1643 static bootmem_data_t contig_bootmem_data;
1644 struct pglist_data contig_page_data = { .bdata = &contig_bootmem_data };
1645
1646 EXPORT_SYMBOL(contig_page_data);
1647
1648 void __init free_area_init(unsigned long *zones_size)
1649 {
1650         free_area_init_node(0, &contig_page_data, zones_size,
1651                         __pa(PAGE_OFFSET) >> PAGE_SHIFT, NULL);
1652 }
1653 #endif
1654
1655 #ifdef CONFIG_PROC_FS
1656
1657 #include <linux/seq_file.h>
1658
1659 static void *frag_start(struct seq_file *m, loff_t *pos)
1660 {
1661         pg_data_t *pgdat;
1662         loff_t node = *pos;
1663
1664         for (pgdat = pgdat_list; pgdat && node; pgdat = pgdat->pgdat_next)
1665                 --node;
1666
1667         return pgdat;
1668 }
1669
1670 static void *frag_next(struct seq_file *m, void *arg, loff_t *pos)
1671 {
1672         pg_data_t *pgdat = (pg_data_t *)arg;
1673
1674         (*pos)++;
1675         return pgdat->pgdat_next;
1676 }
1677
1678 static void frag_stop(struct seq_file *m, void *arg)
1679 {
1680 }
1681
1682 /* 
1683  * This walks the freelist for each zone. Whilst this is slow, I'd rather 
1684  * be slow here than slow down the fast path by keeping stats - mjbligh
1685  */
1686 static int frag_show(struct seq_file *m, void *arg)
1687 {
1688         pg_data_t *pgdat = (pg_data_t *)arg;
1689         struct zone *zone;
1690         struct zone *node_zones = pgdat->node_zones;
1691         unsigned long flags;
1692         int order;
1693
1694         for (zone = node_zones; zone - node_zones < MAX_NR_ZONES; ++zone) {
1695                 if (!zone->present_pages)
1696                         continue;
1697
1698                 spin_lock_irqsave(&zone->lock, flags);
1699                 seq_printf(m, "Node %d, zone %8s ", pgdat->node_id, zone->name);
1700                 for (order = 0; order < MAX_ORDER; ++order) {
1701                         unsigned long nr_bufs = 0;
1702                         struct list_head *elem;
1703
1704                         list_for_each(elem, &(zone->free_area[order].free_list))
1705                                 ++nr_bufs;
1706                         seq_printf(m, "%6lu ", nr_bufs);
1707                 }
1708                 spin_unlock_irqrestore(&zone->lock, flags);
1709                 seq_putc(m, '\n');
1710         }
1711         return 0;
1712 }
1713
1714 struct seq_operations fragmentation_op = {
1715         .start  = frag_start,
1716         .next   = frag_next,
1717         .stop   = frag_stop,
1718         .show   = frag_show,
1719 };
1720
1721 static char *vmstat_text[] = {
1722         "nr_dirty",
1723         "nr_writeback",
1724         "nr_unstable",
1725         "nr_page_table_pages",
1726         "nr_mapped",
1727         "nr_slab",
1728
1729         "pgpgin",
1730         "pgpgout",
1731         "pswpin",
1732         "pswpout",
1733         "pgalloc_high",
1734
1735         "pgalloc_normal",
1736         "pgalloc_dma",
1737         "pgfree",
1738         "pgactivate",
1739         "pgdeactivate",
1740
1741         "pgfault",
1742         "pgmajfault",
1743         "pgrefill_high",
1744         "pgrefill_normal",
1745         "pgrefill_dma",
1746
1747         "pgsteal_high",
1748         "pgsteal_normal",
1749         "pgsteal_dma",
1750         "pgscan_kswapd_high",
1751         "pgscan_kswapd_normal",
1752
1753         "pgscan_kswapd_dma",
1754         "pgscan_direct_high",
1755         "pgscan_direct_normal",
1756         "pgscan_direct_dma",
1757         "pginodesteal",
1758
1759         "slabs_scanned",
1760         "kswapd_steal",
1761         "kswapd_inodesteal",
1762         "pageoutrun",
1763         "allocstall",
1764
1765         "pgrotated",
1766 };
1767
1768 static void *vmstat_start(struct seq_file *m, loff_t *pos)
1769 {
1770         struct page_state *ps;
1771
1772         if (*pos >= ARRAY_SIZE(vmstat_text))
1773                 return NULL;
1774
1775         ps = kmalloc(sizeof(*ps), GFP_KERNEL);
1776         m->private = ps;
1777         if (!ps)
1778                 return ERR_PTR(-ENOMEM);
1779         get_full_page_state(ps);
1780         ps->pgpgin /= 2;                /* sectors -> kbytes */
1781         ps->pgpgout /= 2;
1782         return (unsigned long *)ps + *pos;
1783 }
1784
1785 static void *vmstat_next(struct seq_file *m, void *arg, loff_t *pos)
1786 {
1787         (*pos)++;
1788         if (*pos >= ARRAY_SIZE(vmstat_text))
1789                 return NULL;
1790         return (unsigned long *)m->private + *pos;
1791 }
1792
1793 static int vmstat_show(struct seq_file *m, void *arg)
1794 {
1795         unsigned long *l = arg;
1796         unsigned long off = l - (unsigned long *)m->private;
1797
1798         seq_printf(m, "%s %lu\n", vmstat_text[off], *l);
1799         return 0;
1800 }
1801
1802 static void vmstat_stop(struct seq_file *m, void *arg)
1803 {
1804         kfree(m->private);
1805         m->private = NULL;
1806 }
1807
1808 struct seq_operations vmstat_op = {
1809         .start  = vmstat_start,
1810         .next   = vmstat_next,
1811         .stop   = vmstat_stop,
1812         .show   = vmstat_show,
1813 };
1814
1815 #endif /* CONFIG_PROC_FS */
1816
1817 #ifdef CONFIG_HOTPLUG_CPU
1818 static int page_alloc_cpu_notify(struct notifier_block *self,
1819                                  unsigned long action, void *hcpu)
1820 {
1821         int cpu = (unsigned long)hcpu;
1822         long *count;
1823
1824         if (action == CPU_DEAD) {
1825                 /* Drain local pagecache count. */
1826                 count = &per_cpu(nr_pagecache_local, cpu);
1827                 atomic_add(*count, &nr_pagecache);
1828                 *count = 0;
1829                 local_irq_disable();
1830                 __drain_pages(cpu);
1831                 local_irq_enable();
1832         }
1833         return NOTIFY_OK;
1834 }
1835 #endif /* CONFIG_HOTPLUG_CPU */
1836
1837 void __init page_alloc_init(void)
1838 {
1839         hotcpu_notifier(page_alloc_cpu_notify, 0);
1840 }
1841
1842 static unsigned long higherzone_val(struct zone *z, int max_zone,
1843                                         int alloc_type)
1844 {
1845         int z_idx = zone_idx(z);
1846         struct zone *higherzone;
1847         unsigned long pages;
1848
1849         /* there is no higher zone to get a contribution from */
1850         if (z_idx == MAX_NR_ZONES-1)
1851                 return 0;
1852
1853         higherzone = &z->zone_pgdat->node_zones[z_idx+1];
1854
1855         /* We always start with the higher zone's protection value */
1856         pages = higherzone->protection[alloc_type];
1857
1858         /*
1859          * We get a lower-zone-protection contribution only if there are
1860          * pages in the higher zone and if we're not the highest zone
1861          * in the current zonelist.  e.g., never happens for GFP_DMA. Happens
1862          * only for ZONE_DMA in a GFP_KERNEL allocation and happens for ZONE_DMA
1863          * and ZONE_NORMAL for a GFP_HIGHMEM allocation.
1864          */
1865         if (higherzone->present_pages && z_idx < alloc_type)
1866                 pages += higherzone->pages_low * sysctl_lower_zone_protection;
1867
1868         return pages;
1869 }
1870
1871 /*
1872  * setup_per_zone_protection - called whenver min_free_kbytes or
1873  *      sysctl_lower_zone_protection changes.  Ensures that each zone
1874  *      has a correct pages_protected value, so an adequate number of
1875  *      pages are left in the zone after a successful __alloc_pages().
1876  *
1877  *      This algorithm is way confusing.  I tries to keep the same behavior
1878  *      as we had with the incremental min iterative algorithm.
1879  */
1880 static void setup_per_zone_protection(void)
1881 {
1882         struct pglist_data *pgdat;
1883         struct zone *zones, *zone;
1884         int max_zone;
1885         int i, j;
1886
1887         for_each_pgdat(pgdat) {
1888                 zones = pgdat->node_zones;
1889
1890                 for (i = 0, max_zone = 0; i < MAX_NR_ZONES; i++)
1891                         if (zones[i].present_pages)
1892                                 max_zone = i;
1893
1894                 /*
1895                  * For each of the different allocation types:
1896                  * GFP_DMA -> GFP_KERNEL -> GFP_HIGHMEM
1897                  */
1898                 for (i = 0; i < GFP_ZONETYPES; i++) {
1899                         /*
1900                          * For each of the zones:
1901                          * ZONE_HIGHMEM -> ZONE_NORMAL -> ZONE_DMA
1902                          */
1903                         for (j = MAX_NR_ZONES-1; j >= 0; j--) {
1904                                 zone = &zones[j];
1905
1906                                 /*
1907                                  * We never protect zones that don't have memory
1908                                  * in them (j>max_zone) or zones that aren't in
1909                                  * the zonelists for a certain type of
1910                                  * allocation (j>=i).  We have to assign these
1911                                  * to zero because the lower zones take
1912                                  * contributions from the higher zones.
1913                                  */
1914                                 if (j > max_zone || j >= i) {
1915                                         zone->protection[i] = 0;
1916                                         continue;
1917                                 }
1918                                 /*
1919                                  * The contribution of the next higher zone
1920                                  */
1921                                 zone->protection[i] = higherzone_val(zone,
1922                                                                 max_zone, i);
1923                         }
1924                 }
1925         }
1926 }
1927
1928 /*
1929  * setup_per_zone_pages_min - called when min_free_kbytes changes.  Ensures 
1930  *      that the pages_{min,low,high} values for each zone are set correctly 
1931  *      with respect to min_free_kbytes.
1932  */
1933 static void setup_per_zone_pages_min(void)
1934 {
1935         unsigned long pages_min = min_free_kbytes >> (PAGE_SHIFT - 10);
1936         unsigned long lowmem_pages = 0;
1937         struct zone *zone;
1938         unsigned long flags;
1939
1940         /* Calculate total number of !ZONE_HIGHMEM pages */
1941         for_each_zone(zone) {
1942                 if (!is_highmem(zone))
1943                         lowmem_pages += zone->present_pages;
1944         }
1945
1946         for_each_zone(zone) {
1947                 spin_lock_irqsave(&zone->lru_lock, flags);
1948                 if (is_highmem(zone)) {
1949                         /*
1950                          * Often, highmem doesn't need to reserve any pages.
1951                          * But the pages_min/low/high values are also used for
1952                          * batching up page reclaim activity so we need a
1953                          * decent value here.
1954                          */
1955                         int min_pages;
1956
1957                         min_pages = zone->present_pages / 1024;
1958                         if (min_pages < SWAP_CLUSTER_MAX)
1959                                 min_pages = SWAP_CLUSTER_MAX;
1960                         if (min_pages > 128)
1961                                 min_pages = 128;
1962                         zone->pages_min = min_pages;
1963                 } else {
1964                         /* if it's a lowmem zone, reserve a number of pages 
1965                          * proportionate to the zone's size.
1966                          */
1967                         zone->pages_min = (pages_min * zone->present_pages) / 
1968                                            lowmem_pages;
1969                 }
1970
1971                 /*
1972                  * When interpreting these watermarks, just keep in mind that:
1973                  * zone->pages_min == (zone->pages_min * 4) / 4;
1974                  */
1975                 zone->pages_low   = (zone->pages_min * 5) / 4;
1976                 zone->pages_high  = (zone->pages_min * 6) / 4;
1977                 spin_unlock_irqrestore(&zone->lru_lock, flags);
1978         }
1979 }
1980
1981 /*
1982  * Initialise min_free_kbytes.
1983  *
1984  * For small machines we want it small (128k min).  For large machines
1985  * we want it large (64MB max).  But it is not linear, because network
1986  * bandwidth does not increase linearly with machine size.  We use
1987  *
1988  *      min_free_kbytes = 4 * sqrt(lowmem_kbytes), for better accuracy:
1989  *      min_free_kbytes = sqrt(lowmem_kbytes * 16)
1990  *
1991  * which yields
1992  *
1993  * 16MB:        512k
1994  * 32MB:        724k
1995  * 64MB:        1024k
1996  * 128MB:       1448k
1997  * 256MB:       2048k
1998  * 512MB:       2896k
1999  * 1024MB:      4096k
2000  * 2048MB:      5792k
2001  * 4096MB:      8192k
2002  * 8192MB:      11584k
2003  * 16384MB:     16384k
2004  */
2005 static int __init init_per_zone_pages_min(void)
2006 {
2007         unsigned long lowmem_kbytes;
2008
2009         lowmem_kbytes = nr_free_buffer_pages() * (PAGE_SIZE >> 10);
2010
2011         min_free_kbytes = int_sqrt(lowmem_kbytes * 16);
2012         if (min_free_kbytes < 128)
2013                 min_free_kbytes = 128;
2014         if (min_free_kbytes > 65536)
2015                 min_free_kbytes = 65536;
2016         setup_per_zone_pages_min();
2017         setup_per_zone_protection();
2018         return 0;
2019 }
2020 module_init(init_per_zone_pages_min)
2021
2022 /*
2023  * min_free_kbytes_sysctl_handler - just a wrapper around proc_dointvec() so 
2024  *      that we can call two helper functions whenever min_free_kbytes
2025  *      changes.
2026  */
2027 int min_free_kbytes_sysctl_handler(ctl_table *table, int write, 
2028                 struct file *file, void __user *buffer, size_t *length, loff_t *ppos)
2029 {
2030         proc_dointvec(table, write, file, buffer, length, ppos);
2031         setup_per_zone_pages_min();
2032         setup_per_zone_protection();
2033         return 0;
2034 }
2035
2036 /*
2037  * lower_zone_protection_sysctl_handler - just a wrapper around
2038  *      proc_dointvec() so that we can call setup_per_zone_protection()
2039  *      whenever sysctl_lower_zone_protection changes.
2040  */
2041 int lower_zone_protection_sysctl_handler(ctl_table *table, int write,
2042                  struct file *file, void __user *buffer, size_t *length, loff_t *ppos)
2043 {
2044         proc_dointvec_minmax(table, write, file, buffer, length, ppos);
2045         setup_per_zone_protection();
2046         return 0;
2047 }
2048
2049 /*
2050  * allocate a large system hash table from bootmem
2051  * - it is assumed that the hash table must contain an exact power-of-2
2052  *   quantity of entries
2053  */
2054 void *__init alloc_large_system_hash(const char *tablename,
2055                                      unsigned long bucketsize,
2056                                      unsigned long numentries,
2057                                      int scale,
2058                                      int consider_highmem,
2059                                      unsigned int *_hash_shift,
2060                                      unsigned int *_hash_mask)
2061 {
2062         unsigned long long max;
2063         unsigned long log2qty, size;
2064         void *table;
2065
2066         /* allow the kernel cmdline to have a say */
2067         if (!numentries) {
2068                 /* round applicable memory size up to nearest megabyte */
2069                 numentries = consider_highmem ? nr_all_pages : nr_kernel_pages;
2070                 numentries += (1UL << (20 - PAGE_SHIFT)) - 1;
2071                 numentries >>= 20 - PAGE_SHIFT;
2072                 numentries <<= 20 - PAGE_SHIFT;
2073
2074                 /* limit to 1 bucket per 2^scale bytes of low memory */
2075                 if (scale > PAGE_SHIFT)
2076                         numentries >>= (scale - PAGE_SHIFT);
2077                 else
2078                         numentries <<= (PAGE_SHIFT - scale);
2079         }
2080         /* rounded up to nearest power of 2 in size */
2081         numentries = 1UL << (long_log2(numentries) + 1);
2082
2083         /* limit allocation size to 1/16 total memory */
2084         max = ((unsigned long long)nr_all_pages << PAGE_SHIFT) >> 4;
2085         do_div(max, bucketsize);
2086
2087         if (numentries > max)
2088                 numentries = max;
2089
2090         log2qty = long_log2(numentries);
2091
2092         do {
2093                 size = bucketsize << log2qty;
2094                 table = alloc_bootmem(size);
2095         } while (!table && size > PAGE_SIZE && --log2qty);
2096
2097         if (!table)
2098                 panic("Failed to allocate %s hash table\n", tablename);
2099
2100         printk("%s hash table entries: %d (order: %d, %lu bytes)\n",
2101                tablename,
2102                (1U << log2qty),
2103                long_log2(size) - PAGE_SHIFT,
2104                size);
2105
2106         if (_hash_shift)
2107                 *_hash_shift = log2qty;
2108         if (_hash_mask)
2109                 *_hash_mask = (1 << log2qty) - 1;
2110
2111         return table;
2112 }