2 * linux/mm/page_alloc.c
4 * Manages the free list, the system allocates free pages here.
5 * Note that kmalloc() lives in slab.c
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)
17 #include <linux/config.h>
18 #include <linux/stddef.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/kernel.h>
26 #include <linux/module.h>
27 #include <linux/suspend.h>
28 #include <linux/pagevec.h>
29 #include <linux/blkdev.h>
30 #include <linux/slab.h>
31 #include <linux/notifier.h>
32 #include <linux/topology.h>
33 #include <linux/sysctl.h>
34 #include <linux/cpu.h>
35 #include <linux/cpuset.h>
36 #include <linux/memory_hotplug.h>
37 #include <linux/nodemask.h>
38 #include <linux/vmalloc.h>
40 #include <asm/tlbflush.h>
44 * MCD - HACK: Find somewhere to initialize this EARLY, or make this
47 nodemask_t node_online_map __read_mostly
= { { [0] = 1UL } };
48 EXPORT_SYMBOL(node_online_map
);
49 nodemask_t node_possible_map __read_mostly
= NODE_MASK_ALL
;
50 EXPORT_SYMBOL(node_possible_map
);
51 struct pglist_data
*pgdat_list __read_mostly
;
52 unsigned long totalram_pages __read_mostly
;
53 unsigned long totalhigh_pages __read_mostly
;
57 * results with 256, 32 in the lowmem_reserve sysctl:
58 * 1G machine -> (16M dma, 800M-16M normal, 1G-800M high)
59 * 1G machine -> (16M dma, 784M normal, 224M high)
60 * NORMAL allocation will leave 784M/256 of ram reserved in the ZONE_DMA
61 * HIGHMEM allocation will leave 224M/32 of ram reserved in ZONE_NORMAL
62 * HIGHMEM allocation will (224M+784M)/256 of ram reserved in ZONE_DMA
64 * TBD: should special case ZONE_DMA32 machines here - in those we normally
65 * don't need any ZONE_NORMAL reservation
67 int sysctl_lowmem_reserve_ratio
[MAX_NR_ZONES
-1] = { 256, 256, 32 };
69 EXPORT_SYMBOL(totalram_pages
);
72 * Used by page_zone() to look up the address of the struct zone whose
73 * id is encoded in the upper bits of page->flags
75 struct zone
*zone_table
[1 << ZONETABLE_SHIFT
] __read_mostly
;
76 EXPORT_SYMBOL(zone_table
);
78 static char *zone_names
[MAX_NR_ZONES
] = { "DMA", "DMA32", "Normal", "HighMem" };
79 int min_free_kbytes
= 1024;
81 unsigned long __initdata nr_kernel_pages
;
82 unsigned long __initdata nr_all_pages
;
84 static int page_outside_zone_boundaries(struct zone
*zone
, struct page
*page
)
88 unsigned long pfn
= page_to_pfn(page
);
91 seq
= zone_span_seqbegin(zone
);
92 if (pfn
>= zone
->zone_start_pfn
+ zone
->spanned_pages
)
94 else if (pfn
< zone
->zone_start_pfn
)
96 } while (zone_span_seqretry(zone
, seq
));
101 static int page_is_consistent(struct zone
*zone
, struct page
*page
)
103 #ifdef CONFIG_HOLES_IN_ZONE
104 if (!pfn_valid(page_to_pfn(page
)))
107 if (zone
!= page_zone(page
))
113 * Temporary debugging check for pages not lying within a given zone.
115 static int bad_range(struct zone
*zone
, struct page
*page
)
117 if (page_outside_zone_boundaries(zone
, page
))
119 if (!page_is_consistent(zone
, page
))
125 static void bad_page(const char *function
, struct page
*page
)
127 printk(KERN_EMERG
"Bad page state at %s (in process '%s', page %p)\n",
128 function
, current
->comm
, page
);
129 printk(KERN_EMERG
"flags:0x%0*lx mapping:%p mapcount:%d count:%d\n",
130 (int)(2*sizeof(unsigned long)), (unsigned long)page
->flags
,
131 page
->mapping
, page_mapcount(page
), page_count(page
));
132 printk(KERN_EMERG
"Backtrace:\n");
134 printk(KERN_EMERG
"Trying to fix it up, but a reboot is needed\n");
135 page
->flags
&= ~(1 << PG_lru
|
145 set_page_count(page
, 0);
146 reset_page_mapcount(page
);
147 page
->mapping
= NULL
;
148 add_taint(TAINT_BAD_PAGE
);
151 #ifndef CONFIG_HUGETLB_PAGE
152 #define prep_compound_page(page, order) do { } while (0)
153 #define destroy_compound_page(page, order) do { } while (0)
156 * Higher-order pages are called "compound pages". They are structured thusly:
158 * The first PAGE_SIZE page is called the "head page".
160 * The remaining PAGE_SIZE pages are called "tail pages".
162 * All pages have PG_compound set. All pages have their ->private pointing at
163 * the head page (even the head page has this).
165 * The first tail page's ->mapping, if non-zero, holds the address of the
166 * compound page's put_page() function.
168 * The order of the allocation is stored in the first tail page's ->index
169 * This is only for debug at present. This usage means that zero-order pages
170 * may not be compound.
172 static void prep_compound_page(struct page
*page
, unsigned long order
)
175 int nr_pages
= 1 << order
;
177 page
[1].mapping
= NULL
;
178 page
[1].index
= order
;
179 for (i
= 0; i
< nr_pages
; i
++) {
180 struct page
*p
= page
+ i
;
183 set_page_private(p
, (unsigned long)page
);
187 static void destroy_compound_page(struct page
*page
, unsigned long order
)
190 int nr_pages
= 1 << order
;
192 if (!PageCompound(page
))
195 if (page
[1].index
!= order
)
196 bad_page(__FUNCTION__
, page
);
198 for (i
= 0; i
< nr_pages
; i
++) {
199 struct page
*p
= page
+ i
;
201 if (!PageCompound(p
))
202 bad_page(__FUNCTION__
, page
);
203 if (page_private(p
) != (unsigned long)page
)
204 bad_page(__FUNCTION__
, page
);
205 ClearPageCompound(p
);
208 #endif /* CONFIG_HUGETLB_PAGE */
211 * function for dealing with page's order in buddy system.
212 * zone->lock is already acquired when we use these.
213 * So, we don't need atomic page->flags operations here.
215 static inline unsigned long page_order(struct page
*page
) {
216 return page_private(page
);
219 static inline void set_page_order(struct page
*page
, int order
) {
220 set_page_private(page
, order
);
221 __SetPagePrivate(page
);
224 static inline void rmv_page_order(struct page
*page
)
226 __ClearPagePrivate(page
);
227 set_page_private(page
, 0);
231 * Locate the struct page for both the matching buddy in our
232 * pair (buddy1) and the combined O(n+1) page they form (page).
234 * 1) Any buddy B1 will have an order O twin B2 which satisfies
235 * the following equation:
237 * For example, if the starting buddy (buddy2) is #8 its order
239 * B2 = 8 ^ (1 << 1) = 8 ^ 2 = 10
241 * 2) Any buddy B will have an order O+1 parent P which
242 * satisfies the following equation:
245 * Assumption: *_mem_map is contigious at least up to MAX_ORDER
247 static inline struct page
*
248 __page_find_buddy(struct page
*page
, unsigned long page_idx
, unsigned int order
)
250 unsigned long buddy_idx
= page_idx
^ (1 << order
);
252 return page
+ (buddy_idx
- page_idx
);
255 static inline unsigned long
256 __find_combined_index(unsigned long page_idx
, unsigned int order
)
258 return (page_idx
& ~(1 << order
));
262 * This function checks whether a page is free && is the buddy
263 * we can do coalesce a page and its buddy if
264 * (a) the buddy is free &&
265 * (b) the buddy is on the buddy system &&
266 * (c) a page and its buddy have the same order.
267 * for recording page's order, we use page_private(page) and PG_private.
270 static inline int page_is_buddy(struct page
*page
, int order
)
272 if (PagePrivate(page
) &&
273 (page_order(page
) == order
) &&
274 page_count(page
) == 0)
280 * Freeing function for a buddy system allocator.
282 * The concept of a buddy system is to maintain direct-mapped table
283 * (containing bit values) for memory blocks of various "orders".
284 * The bottom level table contains the map for the smallest allocatable
285 * units of memory (here, pages), and each level above it describes
286 * pairs of units from the levels below, hence, "buddies".
287 * At a high level, all that happens here is marking the table entry
288 * at the bottom level available, and propagating the changes upward
289 * as necessary, plus some accounting needed to play nicely with other
290 * parts of the VM system.
291 * At each level, we keep a list of pages, which are heads of continuous
292 * free pages of length of (1 << order) and marked with PG_Private.Page's
293 * order is recorded in page_private(page) field.
294 * So when we are allocating or freeing one, we can derive the state of the
295 * other. That is, if we allocate a small block, and both were
296 * free, the remainder of the region must be split into blocks.
297 * If a block is freed, and its buddy is also free, then this
298 * triggers coalescing into a block of larger size.
303 static inline void __free_pages_bulk (struct page
*page
,
304 struct zone
*zone
, unsigned int order
)
306 unsigned long page_idx
;
307 int order_size
= 1 << order
;
310 destroy_compound_page(page
, order
);
312 page_idx
= page_to_pfn(page
) & ((1 << MAX_ORDER
) - 1);
314 BUG_ON(page_idx
& (order_size
- 1));
315 BUG_ON(bad_range(zone
, page
));
317 zone
->free_pages
+= order_size
;
318 while (order
< MAX_ORDER
-1) {
319 unsigned long combined_idx
;
320 struct free_area
*area
;
323 combined_idx
= __find_combined_index(page_idx
, order
);
324 buddy
= __page_find_buddy(page
, page_idx
, order
);
326 if (bad_range(zone
, buddy
))
328 if (!page_is_buddy(buddy
, order
))
329 break; /* Move the buddy up one level. */
330 list_del(&buddy
->lru
);
331 area
= zone
->free_area
+ order
;
333 rmv_page_order(buddy
);
334 page
= page
+ (combined_idx
- page_idx
);
335 page_idx
= combined_idx
;
338 set_page_order(page
, order
);
339 list_add(&page
->lru
, &zone
->free_area
[order
].free_list
);
340 zone
->free_area
[order
].nr_free
++;
343 static inline void free_pages_check(const char *function
, struct page
*page
)
345 if ( page_mapcount(page
) ||
346 page
->mapping
!= NULL
||
347 page_count(page
) != 0 ||
358 bad_page(function
, page
);
360 __ClearPageDirty(page
);
364 * Frees a list of pages.
365 * Assumes all pages on list are in same zone, and of same order.
366 * count is the number of pages to free.
368 * If the zone was previously in an "all pages pinned" state then look to
369 * see if this freeing clears that state.
371 * And clear the zone's pages_scanned counter, to hold off the "all pages are
372 * pinned" detection logic.
375 free_pages_bulk(struct zone
*zone
, int count
,
376 struct list_head
*list
, unsigned int order
)
379 struct page
*page
= NULL
;
382 spin_lock_irqsave(&zone
->lock
, flags
);
383 zone
->all_unreclaimable
= 0;
384 zone
->pages_scanned
= 0;
385 while (!list_empty(list
) && count
--) {
386 page
= list_entry(list
->prev
, struct page
, lru
);
387 /* have to delete it as __free_pages_bulk list manipulates */
388 list_del(&page
->lru
);
389 __free_pages_bulk(page
, zone
, order
);
392 spin_unlock_irqrestore(&zone
->lock
, flags
);
396 void __free_pages_ok(struct page
*page
, unsigned int order
)
401 arch_free_page(page
, order
);
403 mod_page_state(pgfree
, 1 << order
);
407 for (i
= 1 ; i
< (1 << order
) ; ++i
)
408 __put_page(page
+ i
);
411 for (i
= 0 ; i
< (1 << order
) ; ++i
)
412 free_pages_check(__FUNCTION__
, page
+ i
);
413 list_add(&page
->lru
, &list
);
414 kernel_map_pages(page
, 1<<order
, 0);
415 free_pages_bulk(page_zone(page
), 1, &list
, order
);
420 * The order of subdivision here is critical for the IO subsystem.
421 * Please do not alter this order without good reasons and regression
422 * testing. Specifically, as large blocks of memory are subdivided,
423 * the order in which smaller blocks are delivered depends on the order
424 * they're subdivided in this function. This is the primary factor
425 * influencing the order in which pages are delivered to the IO
426 * subsystem according to empirical testing, and this is also justified
427 * by considering the behavior of a buddy system containing a single
428 * large block of memory acted on by a series of small allocations.
429 * This behavior is a critical factor in sglist merging's success.
433 static inline struct page
*
434 expand(struct zone
*zone
, struct page
*page
,
435 int low
, int high
, struct free_area
*area
)
437 unsigned long size
= 1 << high
;
443 BUG_ON(bad_range(zone
, &page
[size
]));
444 list_add(&page
[size
].lru
, &area
->free_list
);
446 set_page_order(&page
[size
], high
);
451 void set_page_refs(struct page
*page
, int order
)
454 set_page_count(page
, 1);
459 * We need to reference all the pages for this order, otherwise if
460 * anyone accesses one of the pages with (get/put) it will be freed.
461 * - eg: access_process_vm()
463 for (i
= 0; i
< (1 << order
); i
++)
464 set_page_count(page
+ i
, 1);
465 #endif /* CONFIG_MMU */
469 * This page is about to be returned from the page allocator
471 static void prep_new_page(struct page
*page
, int order
)
473 if ( page_mapcount(page
) ||
474 page
->mapping
!= NULL
||
475 page_count(page
) != 0 ||
487 bad_page(__FUNCTION__
, page
);
489 page
->flags
&= ~(1 << PG_uptodate
| 1 << PG_error
|
490 1 << PG_referenced
| 1 << PG_arch_1
|
491 1 << PG_checked
| 1 << PG_mappedtodisk
);
492 set_page_private(page
, 0);
493 set_page_refs(page
, order
);
494 kernel_map_pages(page
, 1 << order
, 1);
498 * Do the hard work of removing an element from the buddy allocator.
499 * Call me with the zone->lock already held.
501 static struct page
*__rmqueue(struct zone
*zone
, unsigned int order
)
503 struct free_area
* area
;
504 unsigned int current_order
;
507 for (current_order
= order
; current_order
< MAX_ORDER
; ++current_order
) {
508 area
= zone
->free_area
+ current_order
;
509 if (list_empty(&area
->free_list
))
512 page
= list_entry(area
->free_list
.next
, struct page
, lru
);
513 list_del(&page
->lru
);
514 rmv_page_order(page
);
516 zone
->free_pages
-= 1UL << order
;
517 return expand(zone
, page
, order
, current_order
, area
);
524 * Obtain a specified number of elements from the buddy allocator, all under
525 * a single hold of the lock, for efficiency. Add them to the supplied list.
526 * Returns the number of new pages which were placed at *list.
528 static int rmqueue_bulk(struct zone
*zone
, unsigned int order
,
529 unsigned long count
, struct list_head
*list
)
536 spin_lock_irqsave(&zone
->lock
, flags
);
537 for (i
= 0; i
< count
; ++i
) {
538 page
= __rmqueue(zone
, order
);
542 list_add_tail(&page
->lru
, list
);
544 spin_unlock_irqrestore(&zone
->lock
, flags
);
549 /* Called from the slab reaper to drain remote pagesets */
550 void drain_remote_pages(void)
556 local_irq_save(flags
);
557 for_each_zone(zone
) {
558 struct per_cpu_pageset
*pset
;
560 /* Do not drain local pagesets */
561 if (zone
->zone_pgdat
->node_id
== numa_node_id())
564 pset
= zone
->pageset
[smp_processor_id()];
565 for (i
= 0; i
< ARRAY_SIZE(pset
->pcp
); i
++) {
566 struct per_cpu_pages
*pcp
;
570 pcp
->count
-= free_pages_bulk(zone
, pcp
->count
,
574 local_irq_restore(flags
);
578 #if defined(CONFIG_PM) || defined(CONFIG_HOTPLUG_CPU)
579 static void __drain_pages(unsigned int cpu
)
584 for_each_zone(zone
) {
585 struct per_cpu_pageset
*pset
;
587 pset
= zone_pcp(zone
, cpu
);
588 for (i
= 0; i
< ARRAY_SIZE(pset
->pcp
); i
++) {
589 struct per_cpu_pages
*pcp
;
592 pcp
->count
-= free_pages_bulk(zone
, pcp
->count
,
597 #endif /* CONFIG_PM || CONFIG_HOTPLUG_CPU */
601 void mark_free_pages(struct zone
*zone
)
603 unsigned long zone_pfn
, flags
;
605 struct list_head
*curr
;
607 if (!zone
->spanned_pages
)
610 spin_lock_irqsave(&zone
->lock
, flags
);
611 for (zone_pfn
= 0; zone_pfn
< zone
->spanned_pages
; ++zone_pfn
)
612 ClearPageNosaveFree(pfn_to_page(zone_pfn
+ zone
->zone_start_pfn
));
614 for (order
= MAX_ORDER
- 1; order
>= 0; --order
)
615 list_for_each(curr
, &zone
->free_area
[order
].free_list
) {
616 unsigned long start_pfn
, i
;
618 start_pfn
= page_to_pfn(list_entry(curr
, struct page
, lru
));
620 for (i
=0; i
< (1<<order
); i
++)
621 SetPageNosaveFree(pfn_to_page(start_pfn
+i
));
623 spin_unlock_irqrestore(&zone
->lock
, flags
);
627 * Spill all of this CPU's per-cpu pages back into the buddy allocator.
629 void drain_local_pages(void)
633 local_irq_save(flags
);
634 __drain_pages(smp_processor_id());
635 local_irq_restore(flags
);
637 #endif /* CONFIG_PM */
639 static void zone_statistics(struct zonelist
*zonelist
, struct zone
*z
)
644 pg_data_t
*pg
= z
->zone_pgdat
;
645 pg_data_t
*orig
= zonelist
->zones
[0]->zone_pgdat
;
646 struct per_cpu_pageset
*p
;
648 local_irq_save(flags
);
649 cpu
= smp_processor_id();
655 zone_pcp(zonelist
->zones
[0], cpu
)->numa_foreign
++;
657 if (pg
== NODE_DATA(numa_node_id()))
661 local_irq_restore(flags
);
666 * Free a 0-order page
668 static void FASTCALL(free_hot_cold_page(struct page
*page
, int cold
));
669 static void fastcall
free_hot_cold_page(struct page
*page
, int cold
)
671 struct zone
*zone
= page_zone(page
);
672 struct per_cpu_pages
*pcp
;
675 arch_free_page(page
, 0);
677 kernel_map_pages(page
, 1, 0);
678 inc_page_state(pgfree
);
680 page
->mapping
= NULL
;
681 free_pages_check(__FUNCTION__
, page
);
682 pcp
= &zone_pcp(zone
, get_cpu())->pcp
[cold
];
683 local_irq_save(flags
);
684 list_add(&page
->lru
, &pcp
->list
);
686 if (pcp
->count
>= pcp
->high
)
687 pcp
->count
-= free_pages_bulk(zone
, pcp
->batch
, &pcp
->list
, 0);
688 local_irq_restore(flags
);
692 void fastcall
free_hot_page(struct page
*page
)
694 free_hot_cold_page(page
, 0);
697 void fastcall
free_cold_page(struct page
*page
)
699 free_hot_cold_page(page
, 1);
702 static inline void prep_zero_page(struct page
*page
, int order
, gfp_t gfp_flags
)
706 BUG_ON((gfp_flags
& (__GFP_WAIT
| __GFP_HIGHMEM
)) == __GFP_HIGHMEM
);
707 for(i
= 0; i
< (1 << order
); i
++)
708 clear_highpage(page
+ i
);
712 * Really, prep_compound_page() should be called from __rmqueue_bulk(). But
713 * we cheat by calling it from here, in the order > 0 path. Saves a branch
717 buffered_rmqueue(struct zone
*zone
, int order
, gfp_t gfp_flags
)
720 struct page
*page
= NULL
;
721 int cold
= !!(gfp_flags
& __GFP_COLD
);
724 struct per_cpu_pages
*pcp
;
726 pcp
= &zone_pcp(zone
, get_cpu())->pcp
[cold
];
727 local_irq_save(flags
);
728 if (pcp
->count
<= pcp
->low
)
729 pcp
->count
+= rmqueue_bulk(zone
, 0,
730 pcp
->batch
, &pcp
->list
);
732 page
= list_entry(pcp
->list
.next
, struct page
, lru
);
733 list_del(&page
->lru
);
736 local_irq_restore(flags
);
739 spin_lock_irqsave(&zone
->lock
, flags
);
740 page
= __rmqueue(zone
, order
);
741 spin_unlock_irqrestore(&zone
->lock
, flags
);
745 BUG_ON(bad_range(zone
, page
));
746 mod_page_state_zone(zone
, pgalloc
, 1 << order
);
747 prep_new_page(page
, order
);
749 if (gfp_flags
& __GFP_ZERO
)
750 prep_zero_page(page
, order
, gfp_flags
);
752 if (order
&& (gfp_flags
& __GFP_COMP
))
753 prep_compound_page(page
, order
);
758 #define ALLOC_NO_WATERMARKS 0x01 /* don't check watermarks at all */
759 #define ALLOC_HARDER 0x02 /* try to alloc harder */
760 #define ALLOC_HIGH 0x04 /* __GFP_HIGH set */
761 #define ALLOC_CPUSET 0x08 /* check for correct cpuset */
764 * Return 1 if free pages are above 'mark'. This takes into account the order
767 int zone_watermark_ok(struct zone
*z
, int order
, unsigned long mark
,
768 int classzone_idx
, int alloc_flags
)
770 /* free_pages my go negative - that's OK */
771 long min
= mark
, free_pages
= z
->free_pages
- (1 << order
) + 1;
774 if (alloc_flags
& ALLOC_HIGH
)
776 if (alloc_flags
& ALLOC_HARDER
)
779 if (free_pages
<= min
+ z
->lowmem_reserve
[classzone_idx
])
781 for (o
= 0; o
< order
; o
++) {
782 /* At the next order, this order's pages become unavailable */
783 free_pages
-= z
->free_area
[o
].nr_free
<< o
;
785 /* Require fewer higher order pages to be free */
788 if (free_pages
<= min
)
795 * get_page_from_freeliest goes through the zonelist trying to allocate
799 get_page_from_freelist(gfp_t gfp_mask
, unsigned int order
,
800 struct zonelist
*zonelist
, int alloc_flags
)
802 struct zone
**z
= zonelist
->zones
;
803 struct page
*page
= NULL
;
804 int classzone_idx
= zone_idx(*z
);
807 * Go through the zonelist once, looking for a zone with enough free.
808 * See also cpuset_zone_allowed() comment in kernel/cpuset.c.
811 if ((alloc_flags
& ALLOC_CPUSET
) &&
812 !cpuset_zone_allowed(*z
, gfp_mask
))
815 if (!(alloc_flags
& ALLOC_NO_WATERMARKS
)) {
816 if (!zone_watermark_ok(*z
, order
, (*z
)->pages_low
,
817 classzone_idx
, alloc_flags
))
821 page
= buffered_rmqueue(*z
, order
, gfp_mask
);
823 zone_statistics(zonelist
, *z
);
826 } while (*(++z
) != NULL
);
831 * This is the 'heart' of the zoned buddy allocator.
833 struct page
* fastcall
834 __alloc_pages(gfp_t gfp_mask
, unsigned int order
,
835 struct zonelist
*zonelist
)
837 const gfp_t wait
= gfp_mask
& __GFP_WAIT
;
840 struct reclaim_state reclaim_state
;
841 struct task_struct
*p
= current
;
844 int did_some_progress
;
846 might_sleep_if(wait
);
848 z
= zonelist
->zones
; /* the list of zones suitable for gfp_mask */
850 if (unlikely(*z
== NULL
)) {
851 /* Should this ever happen?? */
855 page
= get_page_from_freelist(gfp_mask
|__GFP_HARDWALL
, order
,
856 zonelist
, ALLOC_CPUSET
);
861 wakeup_kswapd(*z
, order
);
865 * OK, we're below the kswapd watermark and have kicked background
866 * reclaim. Now things get more complex, so set up alloc_flags according
867 * to how we want to proceed.
869 * The caller may dip into page reserves a bit more if the caller
870 * cannot run direct reclaim, or if the caller has realtime scheduling
874 if ((unlikely(rt_task(p
)) && !in_interrupt()) || !wait
)
875 alloc_flags
|= ALLOC_HARDER
;
876 if (gfp_mask
& __GFP_HIGH
)
877 alloc_flags
|= ALLOC_HIGH
;
879 alloc_flags
|= ALLOC_CPUSET
;
882 * Go through the zonelist again. Let __GFP_HIGH and allocations
883 * coming from realtime tasks go deeper into reserves.
885 * This is the last chance, in general, before the goto nopage.
886 * Ignore cpuset if GFP_ATOMIC (!wait) rather than fail alloc.
887 * See also cpuset_zone_allowed() comment in kernel/cpuset.c.
889 page
= get_page_from_freelist(gfp_mask
, order
, zonelist
, alloc_flags
);
893 /* This allocation should allow future memory freeing. */
895 if (((p
->flags
& PF_MEMALLOC
) || unlikely(test_thread_flag(TIF_MEMDIE
)))
896 && !in_interrupt()) {
897 if (!(gfp_mask
& __GFP_NOMEMALLOC
)) {
899 /* go through the zonelist yet again, ignoring mins */
900 page
= get_page_from_freelist(gfp_mask
, order
,
901 zonelist
, ALLOC_NO_WATERMARKS
|ALLOC_CPUSET
);
904 if (gfp_mask
& __GFP_NOFAIL
) {
905 blk_congestion_wait(WRITE
, HZ
/50);
912 /* Atomic allocations - we can't balance anything */
919 /* We now go into synchronous reclaim */
920 p
->flags
|= PF_MEMALLOC
;
921 reclaim_state
.reclaimed_slab
= 0;
922 p
->reclaim_state
= &reclaim_state
;
924 did_some_progress
= try_to_free_pages(zonelist
->zones
, gfp_mask
);
926 p
->reclaim_state
= NULL
;
927 p
->flags
&= ~PF_MEMALLOC
;
931 if (likely(did_some_progress
)) {
932 page
= get_page_from_freelist(gfp_mask
, order
,
933 zonelist
, alloc_flags
);
936 } else if ((gfp_mask
& __GFP_FS
) && !(gfp_mask
& __GFP_NORETRY
)) {
938 * Go through the zonelist yet one more time, keep
939 * very high watermark here, this is only to catch
940 * a parallel oom killing, we must fail if we're still
941 * under heavy pressure.
943 page
= get_page_from_freelist(gfp_mask
|__GFP_HARDWALL
, order
,
944 zonelist
, ALLOC_CPUSET
);
948 out_of_memory(gfp_mask
, order
);
953 * Don't let big-order allocations loop unless the caller explicitly
954 * requests that. Wait for some write requests to complete then retry.
956 * In this implementation, __GFP_REPEAT means __GFP_NOFAIL for order
957 * <= 3, but that may not be true in other implementations.
960 if (!(gfp_mask
& __GFP_NORETRY
)) {
961 if ((order
<= 3) || (gfp_mask
& __GFP_REPEAT
))
963 if (gfp_mask
& __GFP_NOFAIL
)
967 blk_congestion_wait(WRITE
, HZ
/50);
972 if (!(gfp_mask
& __GFP_NOWARN
) && printk_ratelimit()) {
973 printk(KERN_WARNING
"%s: page allocation failure."
974 " order:%d, mode:0x%x\n",
975 p
->comm
, order
, gfp_mask
);
983 EXPORT_SYMBOL(__alloc_pages
);
986 * Common helper functions.
988 fastcall
unsigned long __get_free_pages(gfp_t gfp_mask
, unsigned int order
)
991 page
= alloc_pages(gfp_mask
, order
);
994 return (unsigned long) page_address(page
);
997 EXPORT_SYMBOL(__get_free_pages
);
999 fastcall
unsigned long get_zeroed_page(gfp_t gfp_mask
)
1004 * get_zeroed_page() returns a 32-bit address, which cannot represent
1007 BUG_ON((gfp_mask
& __GFP_HIGHMEM
) != 0);
1009 page
= alloc_pages(gfp_mask
| __GFP_ZERO
, 0);
1011 return (unsigned long) page_address(page
);
1015 EXPORT_SYMBOL(get_zeroed_page
);
1017 void __pagevec_free(struct pagevec
*pvec
)
1019 int i
= pagevec_count(pvec
);
1022 free_hot_cold_page(pvec
->pages
[i
], pvec
->cold
);
1025 fastcall
void __free_pages(struct page
*page
, unsigned int order
)
1027 if (put_page_testzero(page
)) {
1029 free_hot_page(page
);
1031 __free_pages_ok(page
, order
);
1035 EXPORT_SYMBOL(__free_pages
);
1037 fastcall
void free_pages(unsigned long addr
, unsigned int order
)
1040 BUG_ON(!virt_addr_valid((void *)addr
));
1041 __free_pages(virt_to_page((void *)addr
), order
);
1045 EXPORT_SYMBOL(free_pages
);
1048 * Total amount of free (allocatable) RAM:
1050 unsigned int nr_free_pages(void)
1052 unsigned int sum
= 0;
1056 sum
+= zone
->free_pages
;
1061 EXPORT_SYMBOL(nr_free_pages
);
1064 unsigned int nr_free_pages_pgdat(pg_data_t
*pgdat
)
1066 unsigned int i
, sum
= 0;
1068 for (i
= 0; i
< MAX_NR_ZONES
; i
++)
1069 sum
+= pgdat
->node_zones
[i
].free_pages
;
1075 static unsigned int nr_free_zone_pages(int offset
)
1077 /* Just pick one node, since fallback list is circular */
1078 pg_data_t
*pgdat
= NODE_DATA(numa_node_id());
1079 unsigned int sum
= 0;
1081 struct zonelist
*zonelist
= pgdat
->node_zonelists
+ offset
;
1082 struct zone
**zonep
= zonelist
->zones
;
1085 for (zone
= *zonep
++; zone
; zone
= *zonep
++) {
1086 unsigned long size
= zone
->present_pages
;
1087 unsigned long high
= zone
->pages_high
;
1096 * Amount of free RAM allocatable within ZONE_DMA and ZONE_NORMAL
1098 unsigned int nr_free_buffer_pages(void)
1100 return nr_free_zone_pages(gfp_zone(GFP_USER
));
1104 * Amount of free RAM allocatable within all zones
1106 unsigned int nr_free_pagecache_pages(void)
1108 return nr_free_zone_pages(gfp_zone(GFP_HIGHUSER
));
1111 #ifdef CONFIG_HIGHMEM
1112 unsigned int nr_free_highpages (void)
1115 unsigned int pages
= 0;
1117 for_each_pgdat(pgdat
)
1118 pages
+= pgdat
->node_zones
[ZONE_HIGHMEM
].free_pages
;
1125 static void show_node(struct zone
*zone
)
1127 printk("Node %d ", zone
->zone_pgdat
->node_id
);
1130 #define show_node(zone) do { } while (0)
1134 * Accumulate the page_state information across all CPUs.
1135 * The result is unavoidably approximate - it can change
1136 * during and after execution of this function.
1138 static DEFINE_PER_CPU(struct page_state
, page_states
) = {0};
1140 atomic_t nr_pagecache
= ATOMIC_INIT(0);
1141 EXPORT_SYMBOL(nr_pagecache
);
1143 DEFINE_PER_CPU(long, nr_pagecache_local
) = 0;
1146 void __get_page_state(struct page_state
*ret
, int nr
, cpumask_t
*cpumask
)
1150 memset(ret
, 0, sizeof(*ret
));
1151 cpus_and(*cpumask
, *cpumask
, cpu_online_map
);
1153 cpu
= first_cpu(*cpumask
);
1154 while (cpu
< NR_CPUS
) {
1155 unsigned long *in
, *out
, off
;
1157 in
= (unsigned long *)&per_cpu(page_states
, cpu
);
1159 cpu
= next_cpu(cpu
, *cpumask
);
1162 prefetch(&per_cpu(page_states
, cpu
));
1164 out
= (unsigned long *)ret
;
1165 for (off
= 0; off
< nr
; off
++)
1170 void get_page_state_node(struct page_state
*ret
, int node
)
1173 cpumask_t mask
= node_to_cpumask(node
);
1175 nr
= offsetof(struct page_state
, GET_PAGE_STATE_LAST
);
1176 nr
/= sizeof(unsigned long);
1178 __get_page_state(ret
, nr
+1, &mask
);
1181 void get_page_state(struct page_state
*ret
)
1184 cpumask_t mask
= CPU_MASK_ALL
;
1186 nr
= offsetof(struct page_state
, GET_PAGE_STATE_LAST
);
1187 nr
/= sizeof(unsigned long);
1189 __get_page_state(ret
, nr
+ 1, &mask
);
1192 void get_full_page_state(struct page_state
*ret
)
1194 cpumask_t mask
= CPU_MASK_ALL
;
1196 __get_page_state(ret
, sizeof(*ret
) / sizeof(unsigned long), &mask
);
1199 unsigned long __read_page_state(unsigned long offset
)
1201 unsigned long ret
= 0;
1204 for_each_online_cpu(cpu
) {
1207 in
= (unsigned long)&per_cpu(page_states
, cpu
) + offset
;
1208 ret
+= *((unsigned long *)in
);
1213 void __mod_page_state(unsigned long offset
, unsigned long delta
)
1215 unsigned long flags
;
1218 local_irq_save(flags
);
1219 ptr
= &__get_cpu_var(page_states
);
1220 *(unsigned long*)(ptr
+ offset
) += delta
;
1221 local_irq_restore(flags
);
1224 EXPORT_SYMBOL(__mod_page_state
);
1226 void __get_zone_counts(unsigned long *active
, unsigned long *inactive
,
1227 unsigned long *free
, struct pglist_data
*pgdat
)
1229 struct zone
*zones
= pgdat
->node_zones
;
1235 for (i
= 0; i
< MAX_NR_ZONES
; i
++) {
1236 *active
+= zones
[i
].nr_active
;
1237 *inactive
+= zones
[i
].nr_inactive
;
1238 *free
+= zones
[i
].free_pages
;
1242 void get_zone_counts(unsigned long *active
,
1243 unsigned long *inactive
, unsigned long *free
)
1245 struct pglist_data
*pgdat
;
1250 for_each_pgdat(pgdat
) {
1251 unsigned long l
, m
, n
;
1252 __get_zone_counts(&l
, &m
, &n
, pgdat
);
1259 void si_meminfo(struct sysinfo
*val
)
1261 val
->totalram
= totalram_pages
;
1263 val
->freeram
= nr_free_pages();
1264 val
->bufferram
= nr_blockdev_pages();
1265 #ifdef CONFIG_HIGHMEM
1266 val
->totalhigh
= totalhigh_pages
;
1267 val
->freehigh
= nr_free_highpages();
1272 val
->mem_unit
= PAGE_SIZE
;
1275 EXPORT_SYMBOL(si_meminfo
);
1278 void si_meminfo_node(struct sysinfo
*val
, int nid
)
1280 pg_data_t
*pgdat
= NODE_DATA(nid
);
1282 val
->totalram
= pgdat
->node_present_pages
;
1283 val
->freeram
= nr_free_pages_pgdat(pgdat
);
1284 val
->totalhigh
= pgdat
->node_zones
[ZONE_HIGHMEM
].present_pages
;
1285 val
->freehigh
= pgdat
->node_zones
[ZONE_HIGHMEM
].free_pages
;
1286 val
->mem_unit
= PAGE_SIZE
;
1290 #define K(x) ((x) << (PAGE_SHIFT-10))
1293 * Show free area list (used inside shift_scroll-lock stuff)
1294 * We also calculate the percentage fragmentation. We do this by counting the
1295 * memory on each free list with the exception of the first item on the list.
1297 void show_free_areas(void)
1299 struct page_state ps
;
1300 int cpu
, temperature
;
1301 unsigned long active
;
1302 unsigned long inactive
;
1306 for_each_zone(zone
) {
1308 printk("%s per-cpu:", zone
->name
);
1310 if (!zone
->present_pages
) {
1316 for_each_online_cpu(cpu
) {
1317 struct per_cpu_pageset
*pageset
;
1319 pageset
= zone_pcp(zone
, cpu
);
1321 for (temperature
= 0; temperature
< 2; temperature
++)
1322 printk("cpu %d %s: low %d, high %d, batch %d used:%d\n",
1324 temperature
? "cold" : "hot",
1325 pageset
->pcp
[temperature
].low
,
1326 pageset
->pcp
[temperature
].high
,
1327 pageset
->pcp
[temperature
].batch
,
1328 pageset
->pcp
[temperature
].count
);
1332 get_page_state(&ps
);
1333 get_zone_counts(&active
, &inactive
, &free
);
1335 printk("Free pages: %11ukB (%ukB HighMem)\n",
1337 K(nr_free_highpages()));
1339 printk("Active:%lu inactive:%lu dirty:%lu writeback:%lu "
1340 "unstable:%lu free:%u slab:%lu mapped:%lu pagetables:%lu\n",
1349 ps
.nr_page_table_pages
);
1351 for_each_zone(zone
) {
1363 " pages_scanned:%lu"
1364 " all_unreclaimable? %s"
1367 K(zone
->free_pages
),
1370 K(zone
->pages_high
),
1372 K(zone
->nr_inactive
),
1373 K(zone
->present_pages
),
1374 zone
->pages_scanned
,
1375 (zone
->all_unreclaimable
? "yes" : "no")
1377 printk("lowmem_reserve[]:");
1378 for (i
= 0; i
< MAX_NR_ZONES
; i
++)
1379 printk(" %lu", zone
->lowmem_reserve
[i
]);
1383 for_each_zone(zone
) {
1384 unsigned long nr
, flags
, order
, total
= 0;
1387 printk("%s: ", zone
->name
);
1388 if (!zone
->present_pages
) {
1393 spin_lock_irqsave(&zone
->lock
, flags
);
1394 for (order
= 0; order
< MAX_ORDER
; order
++) {
1395 nr
= zone
->free_area
[order
].nr_free
;
1396 total
+= nr
<< order
;
1397 printk("%lu*%lukB ", nr
, K(1UL) << order
);
1399 spin_unlock_irqrestore(&zone
->lock
, flags
);
1400 printk("= %lukB\n", K(total
));
1403 show_swap_cache_info();
1407 * Builds allocation fallback zone lists.
1409 static int __init
build_zonelists_node(pg_data_t
*pgdat
, struct zonelist
*zonelist
, int j
, int k
)
1416 zone
= pgdat
->node_zones
+ ZONE_HIGHMEM
;
1417 if (zone
->present_pages
) {
1418 #ifndef CONFIG_HIGHMEM
1421 zonelist
->zones
[j
++] = zone
;
1424 zone
= pgdat
->node_zones
+ ZONE_NORMAL
;
1425 if (zone
->present_pages
)
1426 zonelist
->zones
[j
++] = zone
;
1428 zone
= pgdat
->node_zones
+ ZONE_DMA32
;
1429 if (zone
->present_pages
)
1430 zonelist
->zones
[j
++] = zone
;
1432 zone
= pgdat
->node_zones
+ ZONE_DMA
;
1433 if (zone
->present_pages
)
1434 zonelist
->zones
[j
++] = zone
;
1440 static inline int highest_zone(int zone_bits
)
1442 int res
= ZONE_NORMAL
;
1443 if (zone_bits
& (__force
int)__GFP_HIGHMEM
)
1445 if (zone_bits
& (__force
int)__GFP_DMA32
)
1447 if (zone_bits
& (__force
int)__GFP_DMA
)
1453 #define MAX_NODE_LOAD (num_online_nodes())
1454 static int __initdata node_load
[MAX_NUMNODES
];
1456 * find_next_best_node - find the next node that should appear in a given node's fallback list
1457 * @node: node whose fallback list we're appending
1458 * @used_node_mask: nodemask_t of already used nodes
1460 * We use a number of factors to determine which is the next node that should
1461 * appear on a given node's fallback list. The node should not have appeared
1462 * already in @node's fallback list, and it should be the next closest node
1463 * according to the distance array (which contains arbitrary distance values
1464 * from each node to each node in the system), and should also prefer nodes
1465 * with no CPUs, since presumably they'll have very little allocation pressure
1466 * on them otherwise.
1467 * It returns -1 if no node is found.
1469 static int __init
find_next_best_node(int node
, nodemask_t
*used_node_mask
)
1472 int min_val
= INT_MAX
;
1475 for_each_online_node(i
) {
1478 /* Start from local node */
1479 n
= (node
+i
) % num_online_nodes();
1481 /* Don't want a node to appear more than once */
1482 if (node_isset(n
, *used_node_mask
))
1485 /* Use the local node if we haven't already */
1486 if (!node_isset(node
, *used_node_mask
)) {
1491 /* Use the distance array to find the distance */
1492 val
= node_distance(node
, n
);
1494 /* Give preference to headless and unused nodes */
1495 tmp
= node_to_cpumask(n
);
1496 if (!cpus_empty(tmp
))
1497 val
+= PENALTY_FOR_NODE_WITH_CPUS
;
1499 /* Slight preference for less loaded node */
1500 val
*= (MAX_NODE_LOAD
*MAX_NUMNODES
);
1501 val
+= node_load
[n
];
1503 if (val
< min_val
) {
1510 node_set(best_node
, *used_node_mask
);
1515 static void __init
build_zonelists(pg_data_t
*pgdat
)
1517 int i
, j
, k
, node
, local_node
;
1518 int prev_node
, load
;
1519 struct zonelist
*zonelist
;
1520 nodemask_t used_mask
;
1522 /* initialize zonelists */
1523 for (i
= 0; i
< GFP_ZONETYPES
; i
++) {
1524 zonelist
= pgdat
->node_zonelists
+ i
;
1525 zonelist
->zones
[0] = NULL
;
1528 /* NUMA-aware ordering of nodes */
1529 local_node
= pgdat
->node_id
;
1530 load
= num_online_nodes();
1531 prev_node
= local_node
;
1532 nodes_clear(used_mask
);
1533 while ((node
= find_next_best_node(local_node
, &used_mask
)) >= 0) {
1535 * We don't want to pressure a particular node.
1536 * So adding penalty to the first node in same
1537 * distance group to make it round-robin.
1539 if (node_distance(local_node
, node
) !=
1540 node_distance(local_node
, prev_node
))
1541 node_load
[node
] += load
;
1544 for (i
= 0; i
< GFP_ZONETYPES
; i
++) {
1545 zonelist
= pgdat
->node_zonelists
+ i
;
1546 for (j
= 0; zonelist
->zones
[j
] != NULL
; j
++);
1548 k
= highest_zone(i
);
1550 j
= build_zonelists_node(NODE_DATA(node
), zonelist
, j
, k
);
1551 zonelist
->zones
[j
] = NULL
;
1556 #else /* CONFIG_NUMA */
1558 static void __init
build_zonelists(pg_data_t
*pgdat
)
1560 int i
, j
, k
, node
, local_node
;
1562 local_node
= pgdat
->node_id
;
1563 for (i
= 0; i
< GFP_ZONETYPES
; i
++) {
1564 struct zonelist
*zonelist
;
1566 zonelist
= pgdat
->node_zonelists
+ i
;
1569 k
= highest_zone(i
);
1570 j
= build_zonelists_node(pgdat
, zonelist
, j
, k
);
1572 * Now we build the zonelist so that it contains the zones
1573 * of all the other nodes.
1574 * We don't want to pressure a particular node, so when
1575 * building the zones for node N, we make sure that the
1576 * zones coming right after the local ones are those from
1577 * node N+1 (modulo N)
1579 for (node
= local_node
+ 1; node
< MAX_NUMNODES
; node
++) {
1580 if (!node_online(node
))
1582 j
= build_zonelists_node(NODE_DATA(node
), zonelist
, j
, k
);
1584 for (node
= 0; node
< local_node
; node
++) {
1585 if (!node_online(node
))
1587 j
= build_zonelists_node(NODE_DATA(node
), zonelist
, j
, k
);
1590 zonelist
->zones
[j
] = NULL
;
1594 #endif /* CONFIG_NUMA */
1596 void __init
build_all_zonelists(void)
1600 for_each_online_node(i
)
1601 build_zonelists(NODE_DATA(i
));
1602 printk("Built %i zonelists\n", num_online_nodes());
1603 cpuset_init_current_mems_allowed();
1607 * Helper functions to size the waitqueue hash table.
1608 * Essentially these want to choose hash table sizes sufficiently
1609 * large so that collisions trying to wait on pages are rare.
1610 * But in fact, the number of active page waitqueues on typical
1611 * systems is ridiculously low, less than 200. So this is even
1612 * conservative, even though it seems large.
1614 * The constant PAGES_PER_WAITQUEUE specifies the ratio of pages to
1615 * waitqueues, i.e. the size of the waitq table given the number of pages.
1617 #define PAGES_PER_WAITQUEUE 256
1619 static inline unsigned long wait_table_size(unsigned long pages
)
1621 unsigned long size
= 1;
1623 pages
/= PAGES_PER_WAITQUEUE
;
1625 while (size
< pages
)
1629 * Once we have dozens or even hundreds of threads sleeping
1630 * on IO we've got bigger problems than wait queue collision.
1631 * Limit the size of the wait table to a reasonable size.
1633 size
= min(size
, 4096UL);
1635 return max(size
, 4UL);
1639 * This is an integer logarithm so that shifts can be used later
1640 * to extract the more random high bits from the multiplicative
1641 * hash function before the remainder is taken.
1643 static inline unsigned long wait_table_bits(unsigned long size
)
1648 #define LONG_ALIGN(x) (((x)+(sizeof(long))-1)&~((sizeof(long))-1))
1650 static void __init
calculate_zone_totalpages(struct pglist_data
*pgdat
,
1651 unsigned long *zones_size
, unsigned long *zholes_size
)
1653 unsigned long realtotalpages
, totalpages
= 0;
1656 for (i
= 0; i
< MAX_NR_ZONES
; i
++)
1657 totalpages
+= zones_size
[i
];
1658 pgdat
->node_spanned_pages
= totalpages
;
1660 realtotalpages
= totalpages
;
1662 for (i
= 0; i
< MAX_NR_ZONES
; i
++)
1663 realtotalpages
-= zholes_size
[i
];
1664 pgdat
->node_present_pages
= realtotalpages
;
1665 printk(KERN_DEBUG
"On node %d totalpages: %lu\n", pgdat
->node_id
, realtotalpages
);
1670 * Initially all pages are reserved - free ones are freed
1671 * up by free_all_bootmem() once the early boot process is
1672 * done. Non-atomic initialization, single-pass.
1674 void __devinit
memmap_init_zone(unsigned long size
, int nid
, unsigned long zone
,
1675 unsigned long start_pfn
)
1678 unsigned long end_pfn
= start_pfn
+ size
;
1681 for (pfn
= start_pfn
; pfn
< end_pfn
; pfn
++, page
++) {
1682 if (!early_pfn_valid(pfn
))
1684 if (!early_pfn_in_nid(pfn
, nid
))
1686 page
= pfn_to_page(pfn
);
1687 set_page_links(page
, zone
, nid
, pfn
);
1688 set_page_count(page
, 1);
1689 reset_page_mapcount(page
);
1690 SetPageReserved(page
);
1691 INIT_LIST_HEAD(&page
->lru
);
1692 #ifdef WANT_PAGE_VIRTUAL
1693 /* The shift won't overflow because ZONE_NORMAL is below 4G. */
1694 if (!is_highmem_idx(zone
))
1695 set_page_address(page
, __va(pfn
<< PAGE_SHIFT
));
1700 void zone_init_free_lists(struct pglist_data
*pgdat
, struct zone
*zone
,
1704 for (order
= 0; order
< MAX_ORDER
; order
++) {
1705 INIT_LIST_HEAD(&zone
->free_area
[order
].free_list
);
1706 zone
->free_area
[order
].nr_free
= 0;
1710 #define ZONETABLE_INDEX(x, zone_nr) ((x << ZONES_SHIFT) | zone_nr)
1711 void zonetable_add(struct zone
*zone
, int nid
, int zid
, unsigned long pfn
,
1714 unsigned long snum
= pfn_to_section_nr(pfn
);
1715 unsigned long end
= pfn_to_section_nr(pfn
+ size
);
1718 zone_table
[ZONETABLE_INDEX(nid
, zid
)] = zone
;
1720 for (; snum
<= end
; snum
++)
1721 zone_table
[ZONETABLE_INDEX(snum
, zid
)] = zone
;
1724 #ifndef __HAVE_ARCH_MEMMAP_INIT
1725 #define memmap_init(size, nid, zone, start_pfn) \
1726 memmap_init_zone((size), (nid), (zone), (start_pfn))
1729 static int __devinit
zone_batchsize(struct zone
*zone
)
1734 * The per-cpu-pages pools are set to around 1000th of the
1735 * size of the zone. But no more than 1/2 of a meg.
1737 * OK, so we don't know how big the cache is. So guess.
1739 batch
= zone
->present_pages
/ 1024;
1740 if (batch
* PAGE_SIZE
> 512 * 1024)
1741 batch
= (512 * 1024) / PAGE_SIZE
;
1742 batch
/= 4; /* We effectively *= 4 below */
1747 * We will be trying to allcoate bigger chunks of contiguous
1748 * memory of the order of fls(batch). This should result in
1749 * better cache coloring.
1751 * A sanity check also to ensure that batch is still in limits.
1753 batch
= (1 << fls(batch
+ batch
/2));
1755 if (fls(batch
) >= (PAGE_SHIFT
+ MAX_ORDER
- 2))
1756 batch
= PAGE_SHIFT
+ ((MAX_ORDER
- 1 - PAGE_SHIFT
)/2);
1761 inline void setup_pageset(struct per_cpu_pageset
*p
, unsigned long batch
)
1763 struct per_cpu_pages
*pcp
;
1765 memset(p
, 0, sizeof(*p
));
1767 pcp
= &p
->pcp
[0]; /* hot */
1770 pcp
->high
= 6 * batch
;
1771 pcp
->batch
= max(1UL, 1 * batch
);
1772 INIT_LIST_HEAD(&pcp
->list
);
1774 pcp
= &p
->pcp
[1]; /* cold*/
1777 pcp
->high
= 2 * batch
;
1778 pcp
->batch
= max(1UL, batch
/2);
1779 INIT_LIST_HEAD(&pcp
->list
);
1784 * Boot pageset table. One per cpu which is going to be used for all
1785 * zones and all nodes. The parameters will be set in such a way
1786 * that an item put on a list will immediately be handed over to
1787 * the buddy list. This is safe since pageset manipulation is done
1788 * with interrupts disabled.
1790 * Some NUMA counter updates may also be caught by the boot pagesets.
1792 * The boot_pagesets must be kept even after bootup is complete for
1793 * unused processors and/or zones. They do play a role for bootstrapping
1794 * hotplugged processors.
1796 * zoneinfo_show() and maybe other functions do
1797 * not check if the processor is online before following the pageset pointer.
1798 * Other parts of the kernel may not check if the zone is available.
1800 static struct per_cpu_pageset
1801 boot_pageset
[NR_CPUS
];
1804 * Dynamically allocate memory for the
1805 * per cpu pageset array in struct zone.
1807 static int __devinit
process_zones(int cpu
)
1809 struct zone
*zone
, *dzone
;
1811 for_each_zone(zone
) {
1813 zone
->pageset
[cpu
] = kmalloc_node(sizeof(struct per_cpu_pageset
),
1814 GFP_KERNEL
, cpu_to_node(cpu
));
1815 if (!zone
->pageset
[cpu
])
1818 setup_pageset(zone
->pageset
[cpu
], zone_batchsize(zone
));
1823 for_each_zone(dzone
) {
1826 kfree(dzone
->pageset
[cpu
]);
1827 dzone
->pageset
[cpu
] = NULL
;
1832 static inline void free_zone_pagesets(int cpu
)
1837 for_each_zone(zone
) {
1838 struct per_cpu_pageset
*pset
= zone_pcp(zone
, cpu
);
1840 zone_pcp(zone
, cpu
) = NULL
;
1846 static int __devinit
pageset_cpuup_callback(struct notifier_block
*nfb
,
1847 unsigned long action
,
1850 int cpu
= (long)hcpu
;
1851 int ret
= NOTIFY_OK
;
1854 case CPU_UP_PREPARE
:
1855 if (process_zones(cpu
))
1858 case CPU_UP_CANCELED
:
1860 free_zone_pagesets(cpu
);
1868 static struct notifier_block pageset_notifier
=
1869 { &pageset_cpuup_callback
, NULL
, 0 };
1871 void __init
setup_per_cpu_pageset()
1875 /* Initialize per_cpu_pageset for cpu 0.
1876 * A cpuup callback will do this for every cpu
1877 * as it comes online
1879 err
= process_zones(smp_processor_id());
1881 register_cpu_notifier(&pageset_notifier
);
1887 void zone_wait_table_init(struct zone
*zone
, unsigned long zone_size_pages
)
1890 struct pglist_data
*pgdat
= zone
->zone_pgdat
;
1893 * The per-page waitqueue mechanism uses hashed waitqueues
1896 zone
->wait_table_size
= wait_table_size(zone_size_pages
);
1897 zone
->wait_table_bits
= wait_table_bits(zone
->wait_table_size
);
1898 zone
->wait_table
= (wait_queue_head_t
*)
1899 alloc_bootmem_node(pgdat
, zone
->wait_table_size
1900 * sizeof(wait_queue_head_t
));
1902 for(i
= 0; i
< zone
->wait_table_size
; ++i
)
1903 init_waitqueue_head(zone
->wait_table
+ i
);
1906 static __devinit
void zone_pcp_init(struct zone
*zone
)
1909 unsigned long batch
= zone_batchsize(zone
);
1911 for (cpu
= 0; cpu
< NR_CPUS
; cpu
++) {
1913 /* Early boot. Slab allocator not functional yet */
1914 zone
->pageset
[cpu
] = &boot_pageset
[cpu
];
1915 setup_pageset(&boot_pageset
[cpu
],0);
1917 setup_pageset(zone_pcp(zone
,cpu
), batch
);
1920 printk(KERN_DEBUG
" %s zone: %lu pages, LIFO batch:%lu\n",
1921 zone
->name
, zone
->present_pages
, batch
);
1924 static __devinit
void init_currently_empty_zone(struct zone
*zone
,
1925 unsigned long zone_start_pfn
, unsigned long size
)
1927 struct pglist_data
*pgdat
= zone
->zone_pgdat
;
1929 zone_wait_table_init(zone
, size
);
1930 pgdat
->nr_zones
= zone_idx(zone
) + 1;
1932 zone
->zone_mem_map
= pfn_to_page(zone_start_pfn
);
1933 zone
->zone_start_pfn
= zone_start_pfn
;
1935 memmap_init(size
, pgdat
->node_id
, zone_idx(zone
), zone_start_pfn
);
1937 zone_init_free_lists(pgdat
, zone
, zone
->spanned_pages
);
1941 * Set up the zone data structures:
1942 * - mark all pages reserved
1943 * - mark all memory queues empty
1944 * - clear the memory bitmaps
1946 static void __init
free_area_init_core(struct pglist_data
*pgdat
,
1947 unsigned long *zones_size
, unsigned long *zholes_size
)
1950 int nid
= pgdat
->node_id
;
1951 unsigned long zone_start_pfn
= pgdat
->node_start_pfn
;
1953 pgdat_resize_init(pgdat
);
1954 pgdat
->nr_zones
= 0;
1955 init_waitqueue_head(&pgdat
->kswapd_wait
);
1956 pgdat
->kswapd_max_order
= 0;
1958 for (j
= 0; j
< MAX_NR_ZONES
; j
++) {
1959 struct zone
*zone
= pgdat
->node_zones
+ j
;
1960 unsigned long size
, realsize
;
1962 realsize
= size
= zones_size
[j
];
1964 realsize
-= zholes_size
[j
];
1966 if (j
< ZONE_HIGHMEM
)
1967 nr_kernel_pages
+= realsize
;
1968 nr_all_pages
+= realsize
;
1970 zone
->spanned_pages
= size
;
1971 zone
->present_pages
= realsize
;
1972 zone
->name
= zone_names
[j
];
1973 spin_lock_init(&zone
->lock
);
1974 spin_lock_init(&zone
->lru_lock
);
1975 zone_seqlock_init(zone
);
1976 zone
->zone_pgdat
= pgdat
;
1977 zone
->free_pages
= 0;
1979 zone
->temp_priority
= zone
->prev_priority
= DEF_PRIORITY
;
1981 zone_pcp_init(zone
);
1982 INIT_LIST_HEAD(&zone
->active_list
);
1983 INIT_LIST_HEAD(&zone
->inactive_list
);
1984 zone
->nr_scan_active
= 0;
1985 zone
->nr_scan_inactive
= 0;
1986 zone
->nr_active
= 0;
1987 zone
->nr_inactive
= 0;
1988 atomic_set(&zone
->reclaim_in_progress
, 0);
1992 zonetable_add(zone
, nid
, j
, zone_start_pfn
, size
);
1993 init_currently_empty_zone(zone
, zone_start_pfn
, size
);
1994 zone_start_pfn
+= size
;
1998 static void __init
alloc_node_mem_map(struct pglist_data
*pgdat
)
2000 /* Skip empty nodes */
2001 if (!pgdat
->node_spanned_pages
)
2004 #ifdef CONFIG_FLAT_NODE_MEM_MAP
2005 /* ia64 gets its own node_mem_map, before this, without bootmem */
2006 if (!pgdat
->node_mem_map
) {
2010 size
= (pgdat
->node_spanned_pages
+ 1) * sizeof(struct page
);
2011 map
= alloc_remap(pgdat
->node_id
, size
);
2013 map
= alloc_bootmem_node(pgdat
, size
);
2014 pgdat
->node_mem_map
= map
;
2016 #ifdef CONFIG_FLATMEM
2018 * With no DISCONTIG, the global mem_map is just set as node 0's
2020 if (pgdat
== NODE_DATA(0))
2021 mem_map
= NODE_DATA(0)->node_mem_map
;
2023 #endif /* CONFIG_FLAT_NODE_MEM_MAP */
2026 void __init
free_area_init_node(int nid
, struct pglist_data
*pgdat
,
2027 unsigned long *zones_size
, unsigned long node_start_pfn
,
2028 unsigned long *zholes_size
)
2030 pgdat
->node_id
= nid
;
2031 pgdat
->node_start_pfn
= node_start_pfn
;
2032 calculate_zone_totalpages(pgdat
, zones_size
, zholes_size
);
2034 alloc_node_mem_map(pgdat
);
2036 free_area_init_core(pgdat
, zones_size
, zholes_size
);
2039 #ifndef CONFIG_NEED_MULTIPLE_NODES
2040 static bootmem_data_t contig_bootmem_data
;
2041 struct pglist_data contig_page_data
= { .bdata
= &contig_bootmem_data
};
2043 EXPORT_SYMBOL(contig_page_data
);
2046 void __init
free_area_init(unsigned long *zones_size
)
2048 free_area_init_node(0, NODE_DATA(0), zones_size
,
2049 __pa(PAGE_OFFSET
) >> PAGE_SHIFT
, NULL
);
2052 #ifdef CONFIG_PROC_FS
2054 #include <linux/seq_file.h>
2056 static void *frag_start(struct seq_file
*m
, loff_t
*pos
)
2061 for (pgdat
= pgdat_list
; pgdat
&& node
; pgdat
= pgdat
->pgdat_next
)
2067 static void *frag_next(struct seq_file
*m
, void *arg
, loff_t
*pos
)
2069 pg_data_t
*pgdat
= (pg_data_t
*)arg
;
2072 return pgdat
->pgdat_next
;
2075 static void frag_stop(struct seq_file
*m
, void *arg
)
2080 * This walks the free areas for each zone.
2082 static int frag_show(struct seq_file
*m
, void *arg
)
2084 pg_data_t
*pgdat
= (pg_data_t
*)arg
;
2086 struct zone
*node_zones
= pgdat
->node_zones
;
2087 unsigned long flags
;
2090 for (zone
= node_zones
; zone
- node_zones
< MAX_NR_ZONES
; ++zone
) {
2091 if (!zone
->present_pages
)
2094 spin_lock_irqsave(&zone
->lock
, flags
);
2095 seq_printf(m
, "Node %d, zone %8s ", pgdat
->node_id
, zone
->name
);
2096 for (order
= 0; order
< MAX_ORDER
; ++order
)
2097 seq_printf(m
, "%6lu ", zone
->free_area
[order
].nr_free
);
2098 spin_unlock_irqrestore(&zone
->lock
, flags
);
2104 struct seq_operations fragmentation_op
= {
2105 .start
= frag_start
,
2112 * Output information about zones in @pgdat.
2114 static int zoneinfo_show(struct seq_file
*m
, void *arg
)
2116 pg_data_t
*pgdat
= arg
;
2118 struct zone
*node_zones
= pgdat
->node_zones
;
2119 unsigned long flags
;
2121 for (zone
= node_zones
; zone
- node_zones
< MAX_NR_ZONES
; zone
++) {
2124 if (!zone
->present_pages
)
2127 spin_lock_irqsave(&zone
->lock
, flags
);
2128 seq_printf(m
, "Node %d, zone %8s", pgdat
->node_id
, zone
->name
);
2136 "\n scanned %lu (a: %lu i: %lu)"
2145 zone
->pages_scanned
,
2146 zone
->nr_scan_active
, zone
->nr_scan_inactive
,
2147 zone
->spanned_pages
,
2148 zone
->present_pages
);
2150 "\n protection: (%lu",
2151 zone
->lowmem_reserve
[0]);
2152 for (i
= 1; i
< ARRAY_SIZE(zone
->lowmem_reserve
); i
++)
2153 seq_printf(m
, ", %lu", zone
->lowmem_reserve
[i
]);
2157 for (i
= 0; i
< ARRAY_SIZE(zone
->pageset
); i
++) {
2158 struct per_cpu_pageset
*pageset
;
2161 pageset
= zone_pcp(zone
, i
);
2162 for (j
= 0; j
< ARRAY_SIZE(pageset
->pcp
); j
++) {
2163 if (pageset
->pcp
[j
].count
)
2166 if (j
== ARRAY_SIZE(pageset
->pcp
))
2168 for (j
= 0; j
< ARRAY_SIZE(pageset
->pcp
); j
++) {
2170 "\n cpu: %i pcp: %i"
2176 pageset
->pcp
[j
].count
,
2177 pageset
->pcp
[j
].low
,
2178 pageset
->pcp
[j
].high
,
2179 pageset
->pcp
[j
].batch
);
2185 "\n numa_foreign: %lu"
2186 "\n interleave_hit: %lu"
2187 "\n local_node: %lu"
2188 "\n other_node: %lu",
2191 pageset
->numa_foreign
,
2192 pageset
->interleave_hit
,
2193 pageset
->local_node
,
2194 pageset
->other_node
);
2198 "\n all_unreclaimable: %u"
2199 "\n prev_priority: %i"
2200 "\n temp_priority: %i"
2201 "\n start_pfn: %lu",
2202 zone
->all_unreclaimable
,
2203 zone
->prev_priority
,
2204 zone
->temp_priority
,
2205 zone
->zone_start_pfn
);
2206 spin_unlock_irqrestore(&zone
->lock
, flags
);
2212 struct seq_operations zoneinfo_op
= {
2213 .start
= frag_start
, /* iterate over all zones. The same as in
2217 .show
= zoneinfo_show
,
2220 static char *vmstat_text
[] = {
2224 "nr_page_table_pages",
2249 "pgscan_kswapd_high",
2250 "pgscan_kswapd_normal",
2252 "pgscan_kswapd_dma",
2253 "pgscan_direct_high",
2254 "pgscan_direct_normal",
2255 "pgscan_direct_dma",
2260 "kswapd_inodesteal",
2268 static void *vmstat_start(struct seq_file
*m
, loff_t
*pos
)
2270 struct page_state
*ps
;
2272 if (*pos
>= ARRAY_SIZE(vmstat_text
))
2275 ps
= kmalloc(sizeof(*ps
), GFP_KERNEL
);
2278 return ERR_PTR(-ENOMEM
);
2279 get_full_page_state(ps
);
2280 ps
->pgpgin
/= 2; /* sectors -> kbytes */
2282 return (unsigned long *)ps
+ *pos
;
2285 static void *vmstat_next(struct seq_file
*m
, void *arg
, loff_t
*pos
)
2288 if (*pos
>= ARRAY_SIZE(vmstat_text
))
2290 return (unsigned long *)m
->private + *pos
;
2293 static int vmstat_show(struct seq_file
*m
, void *arg
)
2295 unsigned long *l
= arg
;
2296 unsigned long off
= l
- (unsigned long *)m
->private;
2298 seq_printf(m
, "%s %lu\n", vmstat_text
[off
], *l
);
2302 static void vmstat_stop(struct seq_file
*m
, void *arg
)
2308 struct seq_operations vmstat_op
= {
2309 .start
= vmstat_start
,
2310 .next
= vmstat_next
,
2311 .stop
= vmstat_stop
,
2312 .show
= vmstat_show
,
2315 #endif /* CONFIG_PROC_FS */
2317 #ifdef CONFIG_HOTPLUG_CPU
2318 static int page_alloc_cpu_notify(struct notifier_block
*self
,
2319 unsigned long action
, void *hcpu
)
2321 int cpu
= (unsigned long)hcpu
;
2323 unsigned long *src
, *dest
;
2325 if (action
== CPU_DEAD
) {
2328 /* Drain local pagecache count. */
2329 count
= &per_cpu(nr_pagecache_local
, cpu
);
2330 atomic_add(*count
, &nr_pagecache
);
2332 local_irq_disable();
2335 /* Add dead cpu's page_states to our own. */
2336 dest
= (unsigned long *)&__get_cpu_var(page_states
);
2337 src
= (unsigned long *)&per_cpu(page_states
, cpu
);
2339 for (i
= 0; i
< sizeof(struct page_state
)/sizeof(unsigned long);
2349 #endif /* CONFIG_HOTPLUG_CPU */
2351 void __init
page_alloc_init(void)
2353 hotcpu_notifier(page_alloc_cpu_notify
, 0);
2357 * setup_per_zone_lowmem_reserve - called whenever
2358 * sysctl_lower_zone_reserve_ratio changes. Ensures that each zone
2359 * has a correct pages reserved value, so an adequate number of
2360 * pages are left in the zone after a successful __alloc_pages().
2362 static void setup_per_zone_lowmem_reserve(void)
2364 struct pglist_data
*pgdat
;
2367 for_each_pgdat(pgdat
) {
2368 for (j
= 0; j
< MAX_NR_ZONES
; j
++) {
2369 struct zone
*zone
= pgdat
->node_zones
+ j
;
2370 unsigned long present_pages
= zone
->present_pages
;
2372 zone
->lowmem_reserve
[j
] = 0;
2374 for (idx
= j
-1; idx
>= 0; idx
--) {
2375 struct zone
*lower_zone
;
2377 if (sysctl_lowmem_reserve_ratio
[idx
] < 1)
2378 sysctl_lowmem_reserve_ratio
[idx
] = 1;
2380 lower_zone
= pgdat
->node_zones
+ idx
;
2381 lower_zone
->lowmem_reserve
[j
] = present_pages
/
2382 sysctl_lowmem_reserve_ratio
[idx
];
2383 present_pages
+= lower_zone
->present_pages
;
2390 * setup_per_zone_pages_min - called when min_free_kbytes changes. Ensures
2391 * that the pages_{min,low,high} values for each zone are set correctly
2392 * with respect to min_free_kbytes.
2394 void setup_per_zone_pages_min(void)
2396 unsigned long pages_min
= min_free_kbytes
>> (PAGE_SHIFT
- 10);
2397 unsigned long lowmem_pages
= 0;
2399 unsigned long flags
;
2401 /* Calculate total number of !ZONE_HIGHMEM pages */
2402 for_each_zone(zone
) {
2403 if (!is_highmem(zone
))
2404 lowmem_pages
+= zone
->present_pages
;
2407 for_each_zone(zone
) {
2409 spin_lock_irqsave(&zone
->lru_lock
, flags
);
2410 tmp
= (pages_min
* zone
->present_pages
) / lowmem_pages
;
2411 if (is_highmem(zone
)) {
2413 * __GFP_HIGH and PF_MEMALLOC allocations usually don't
2414 * need highmem pages, so cap pages_min to a small
2417 * The (pages_high-pages_low) and (pages_low-pages_min)
2418 * deltas controls asynch page reclaim, and so should
2419 * not be capped for highmem.
2423 min_pages
= zone
->present_pages
/ 1024;
2424 if (min_pages
< SWAP_CLUSTER_MAX
)
2425 min_pages
= SWAP_CLUSTER_MAX
;
2426 if (min_pages
> 128)
2428 zone
->pages_min
= min_pages
;
2431 * If it's a lowmem zone, reserve a number of pages
2432 * proportionate to the zone's size.
2434 zone
->pages_min
= tmp
;
2437 zone
->pages_low
= zone
->pages_min
+ tmp
/ 4;
2438 zone
->pages_high
= zone
->pages_min
+ tmp
/ 2;
2439 spin_unlock_irqrestore(&zone
->lru_lock
, flags
);
2444 * Initialise min_free_kbytes.
2446 * For small machines we want it small (128k min). For large machines
2447 * we want it large (64MB max). But it is not linear, because network
2448 * bandwidth does not increase linearly with machine size. We use
2450 * min_free_kbytes = 4 * sqrt(lowmem_kbytes), for better accuracy:
2451 * min_free_kbytes = sqrt(lowmem_kbytes * 16)
2467 static int __init
init_per_zone_pages_min(void)
2469 unsigned long lowmem_kbytes
;
2471 lowmem_kbytes
= nr_free_buffer_pages() * (PAGE_SIZE
>> 10);
2473 min_free_kbytes
= int_sqrt(lowmem_kbytes
* 16);
2474 if (min_free_kbytes
< 128)
2475 min_free_kbytes
= 128;
2476 if (min_free_kbytes
> 65536)
2477 min_free_kbytes
= 65536;
2478 setup_per_zone_pages_min();
2479 setup_per_zone_lowmem_reserve();
2482 module_init(init_per_zone_pages_min
)
2485 * min_free_kbytes_sysctl_handler - just a wrapper around proc_dointvec() so
2486 * that we can call two helper functions whenever min_free_kbytes
2489 int min_free_kbytes_sysctl_handler(ctl_table
*table
, int write
,
2490 struct file
*file
, void __user
*buffer
, size_t *length
, loff_t
*ppos
)
2492 proc_dointvec(table
, write
, file
, buffer
, length
, ppos
);
2493 setup_per_zone_pages_min();
2498 * lowmem_reserve_ratio_sysctl_handler - just a wrapper around
2499 * proc_dointvec() so that we can call setup_per_zone_lowmem_reserve()
2500 * whenever sysctl_lowmem_reserve_ratio changes.
2502 * The reserve ratio obviously has absolutely no relation with the
2503 * pages_min watermarks. The lowmem reserve ratio can only make sense
2504 * if in function of the boot time zone sizes.
2506 int lowmem_reserve_ratio_sysctl_handler(ctl_table
*table
, int write
,
2507 struct file
*file
, void __user
*buffer
, size_t *length
, loff_t
*ppos
)
2509 proc_dointvec_minmax(table
, write
, file
, buffer
, length
, ppos
);
2510 setup_per_zone_lowmem_reserve();
2514 __initdata
int hashdist
= HASHDIST_DEFAULT
;
2517 static int __init
set_hashdist(char *str
)
2521 hashdist
= simple_strtoul(str
, &str
, 0);
2524 __setup("hashdist=", set_hashdist
);
2528 * allocate a large system hash table from bootmem
2529 * - it is assumed that the hash table must contain an exact power-of-2
2530 * quantity of entries
2531 * - limit is the number of hash buckets, not the total allocation size
2533 void *__init
alloc_large_system_hash(const char *tablename
,
2534 unsigned long bucketsize
,
2535 unsigned long numentries
,
2538 unsigned int *_hash_shift
,
2539 unsigned int *_hash_mask
,
2540 unsigned long limit
)
2542 unsigned long long max
= limit
;
2543 unsigned long log2qty
, size
;
2546 /* allow the kernel cmdline to have a say */
2548 /* round applicable memory size up to nearest megabyte */
2549 numentries
= (flags
& HASH_HIGHMEM
) ? nr_all_pages
: nr_kernel_pages
;
2550 numentries
+= (1UL << (20 - PAGE_SHIFT
)) - 1;
2551 numentries
>>= 20 - PAGE_SHIFT
;
2552 numentries
<<= 20 - PAGE_SHIFT
;
2554 /* limit to 1 bucket per 2^scale bytes of low memory */
2555 if (scale
> PAGE_SHIFT
)
2556 numentries
>>= (scale
- PAGE_SHIFT
);
2558 numentries
<<= (PAGE_SHIFT
- scale
);
2560 /* rounded up to nearest power of 2 in size */
2561 numentries
= 1UL << (long_log2(numentries
) + 1);
2563 /* limit allocation size to 1/16 total memory by default */
2565 max
= ((unsigned long long)nr_all_pages
<< PAGE_SHIFT
) >> 4;
2566 do_div(max
, bucketsize
);
2569 if (numentries
> max
)
2572 log2qty
= long_log2(numentries
);
2575 size
= bucketsize
<< log2qty
;
2576 if (flags
& HASH_EARLY
)
2577 table
= alloc_bootmem(size
);
2579 table
= __vmalloc(size
, GFP_ATOMIC
, PAGE_KERNEL
);
2581 unsigned long order
;
2582 for (order
= 0; ((1UL << order
) << PAGE_SHIFT
) < size
; order
++)
2584 table
= (void*) __get_free_pages(GFP_ATOMIC
, order
);
2586 } while (!table
&& size
> PAGE_SIZE
&& --log2qty
);
2589 panic("Failed to allocate %s hash table\n", tablename
);
2591 printk("%s hash table entries: %d (order: %d, %lu bytes)\n",
2594 long_log2(size
) - PAGE_SHIFT
,
2598 *_hash_shift
= log2qty
;
2600 *_hash_mask
= (1 << log2qty
) - 1;