aboutsummaryrefslogtreecommitdiffstats
path: root/mm/page_alloc.c
diff options
context:
space:
mode:
Diffstat (limited to 'mm/page_alloc.c')
-rw-r--r--mm/page_alloc.c111
1 files changed, 111 insertions, 0 deletions
diff --git a/mm/page_alloc.c b/mm/page_alloc.c
index e69f19e841e5..332f46d70d2d 100644
--- a/mm/page_alloc.c
+++ b/mm/page_alloc.c
@@ -2931,6 +2931,41 @@ static void __meminit calculate_node_totalpages(struct pglist_data *pgdat,
2931 realtotalpages); 2931 realtotalpages);
2932} 2932}
2933 2933
2934#ifndef CONFIG_SPARSEMEM
2935/*
2936 * Calculate the size of the zone->blockflags rounded to an unsigned long
2937 * Start by making sure zonesize is a multiple of MAX_ORDER-1 by rounding up
2938 * Then figure 1 NR_PAGEBLOCK_BITS worth of bits per MAX_ORDER-1, finally
2939 * round what is now in bits to nearest long in bits, then return it in
2940 * bytes.
2941 */
2942static unsigned long __init usemap_size(unsigned long zonesize)
2943{
2944 unsigned long usemapsize;
2945
2946 usemapsize = roundup(zonesize, MAX_ORDER_NR_PAGES);
2947 usemapsize = usemapsize >> (MAX_ORDER-1);
2948 usemapsize *= NR_PAGEBLOCK_BITS;
2949 usemapsize = roundup(usemapsize, 8 * sizeof(unsigned long));
2950
2951 return usemapsize / 8;
2952}
2953
2954static void __init setup_usemap(struct pglist_data *pgdat,
2955 struct zone *zone, unsigned long zonesize)
2956{
2957 unsigned long usemapsize = usemap_size(zonesize);
2958 zone->pageblock_flags = NULL;
2959 if (usemapsize) {
2960 zone->pageblock_flags = alloc_bootmem_node(pgdat, usemapsize);
2961 memset(zone->pageblock_flags, 0, usemapsize);
2962 }
2963}
2964#else
2965static void inline setup_usemap(struct pglist_data *pgdat,
2966 struct zone *zone, unsigned long zonesize) {}
2967#endif /* CONFIG_SPARSEMEM */
2968
2934/* 2969/*
2935 * Set up the zone data structures: 2970 * Set up the zone data structures:
2936 * - mark all pages reserved 2971 * - mark all pages reserved
@@ -3011,6 +3046,7 @@ static void __meminit free_area_init_core(struct pglist_data *pgdat,
3011 if (!size) 3046 if (!size)
3012 continue; 3047 continue;
3013 3048
3049 setup_usemap(pgdat, zone, size);
3014 ret = init_currently_empty_zone(zone, zone_start_pfn, 3050 ret = init_currently_empty_zone(zone, zone_start_pfn,
3015 size, MEMMAP_EARLY); 3051 size, MEMMAP_EARLY);
3016 BUG_ON(ret); 3052 BUG_ON(ret);
@@ -3991,4 +4027,79 @@ EXPORT_SYMBOL(pfn_to_page);
3991EXPORT_SYMBOL(page_to_pfn); 4027EXPORT_SYMBOL(page_to_pfn);
3992#endif /* CONFIG_OUT_OF_LINE_PFN_TO_PAGE */ 4028#endif /* CONFIG_OUT_OF_LINE_PFN_TO_PAGE */
3993 4029
4030/* Return a pointer to the bitmap storing bits affecting a block of pages */
4031static inline unsigned long *get_pageblock_bitmap(struct zone *zone,
4032 unsigned long pfn)
4033{
4034#ifdef CONFIG_SPARSEMEM
4035 return __pfn_to_section(pfn)->pageblock_flags;
4036#else
4037 return zone->pageblock_flags;
4038#endif /* CONFIG_SPARSEMEM */
4039}
4040
4041static inline int pfn_to_bitidx(struct zone *zone, unsigned long pfn)
4042{
4043#ifdef CONFIG_SPARSEMEM
4044 pfn &= (PAGES_PER_SECTION-1);
4045 return (pfn >> (MAX_ORDER-1)) * NR_PAGEBLOCK_BITS;
4046#else
4047 pfn = pfn - zone->zone_start_pfn;
4048 return (pfn >> (MAX_ORDER-1)) * NR_PAGEBLOCK_BITS;
4049#endif /* CONFIG_SPARSEMEM */
4050}
4051
4052/**
4053 * get_pageblock_flags_group - Return the requested group of flags for the MAX_ORDER_NR_PAGES block of pages
4054 * @page: The page within the block of interest
4055 * @start_bitidx: The first bit of interest to retrieve
4056 * @end_bitidx: The last bit of interest
4057 * returns pageblock_bits flags
4058 */
4059unsigned long get_pageblock_flags_group(struct page *page,
4060 int start_bitidx, int end_bitidx)
4061{
4062 struct zone *zone;
4063 unsigned long *bitmap;
4064 unsigned long pfn, bitidx;
4065 unsigned long flags = 0;
4066 unsigned long value = 1;
4067
4068 zone = page_zone(page);
4069 pfn = page_to_pfn(page);
4070 bitmap = get_pageblock_bitmap(zone, pfn);
4071 bitidx = pfn_to_bitidx(zone, pfn);
4072
4073 for (; start_bitidx <= end_bitidx; start_bitidx++, value <<= 1)
4074 if (test_bit(bitidx + start_bitidx, bitmap))
4075 flags |= value;
3994 4076
4077 return flags;
4078}
4079
4080/**
4081 * set_pageblock_flags_group - Set the requested group of flags for a MAX_ORDER_NR_PAGES block of pages
4082 * @page: The page within the block of interest
4083 * @start_bitidx: The first bit of interest
4084 * @end_bitidx: The last bit of interest
4085 * @flags: The flags to set
4086 */
4087void set_pageblock_flags_group(struct page *page, unsigned long flags,
4088 int start_bitidx, int end_bitidx)
4089{
4090 struct zone *zone;
4091 unsigned long *bitmap;
4092 unsigned long pfn, bitidx;
4093 unsigned long value = 1;
4094
4095 zone = page_zone(page);
4096 pfn = page_to_pfn(page);
4097 bitmap = get_pageblock_bitmap(zone, pfn);
4098 bitidx = pfn_to_bitidx(zone, pfn);
4099
4100 for (; start_bitidx <= end_bitidx; start_bitidx++, value <<= 1)
4101 if (flags & value)
4102 __set_bit(bitidx + start_bitidx, bitmap);
4103 else
4104 __clear_bit(bitidx + start_bitidx, bitmap);
4105}