aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--include/linux/mmzone.h13
-rw-r--r--include/linux/pageblock-flags.h51
-rw-r--r--mm/page_alloc.c111
3 files changed, 175 insertions, 0 deletions
diff --git a/include/linux/mmzone.h b/include/linux/mmzone.h
index f6167f2fd7fb..322e8048463e 100644
--- a/include/linux/mmzone.h
+++ b/include/linux/mmzone.h
@@ -13,6 +13,7 @@
13#include <linux/init.h> 13#include <linux/init.h>
14#include <linux/seqlock.h> 14#include <linux/seqlock.h>
15#include <linux/nodemask.h> 15#include <linux/nodemask.h>
16#include <linux/pageblock-flags.h>
16#include <asm/atomic.h> 17#include <asm/atomic.h>
17#include <asm/page.h> 18#include <asm/page.h>
18 19
@@ -222,6 +223,14 @@ struct zone {
222#endif 223#endif
223 struct free_area free_area[MAX_ORDER]; 224 struct free_area free_area[MAX_ORDER];
224 225
226#ifndef CONFIG_SPARSEMEM
227 /*
228 * Flags for a MAX_ORDER_NR_PAGES block. See pageblock-flags.h.
229 * In SPARSEMEM, this map is stored in struct mem_section
230 */
231 unsigned long *pageblock_flags;
232#endif /* CONFIG_SPARSEMEM */
233
225 234
226 ZONE_PADDING(_pad1_) 235 ZONE_PADDING(_pad1_)
227 236
@@ -720,6 +729,9 @@ extern struct zone *next_zone(struct zone *zone);
720#define PAGES_PER_SECTION (1UL << PFN_SECTION_SHIFT) 729#define PAGES_PER_SECTION (1UL << PFN_SECTION_SHIFT)
721#define PAGE_SECTION_MASK (~(PAGES_PER_SECTION-1)) 730#define PAGE_SECTION_MASK (~(PAGES_PER_SECTION-1))
722 731
732#define SECTION_BLOCKFLAGS_BITS \
733 ((SECTION_SIZE_BITS - (MAX_ORDER-1)) * NR_PAGEBLOCK_BITS)
734
723#if (MAX_ORDER - 1 + PAGE_SHIFT) > SECTION_SIZE_BITS 735#if (MAX_ORDER - 1 + PAGE_SHIFT) > SECTION_SIZE_BITS
724#error Allocator MAX_ORDER exceeds SECTION_SIZE 736#error Allocator MAX_ORDER exceeds SECTION_SIZE
725#endif 737#endif
@@ -739,6 +751,7 @@ struct mem_section {
739 * before using it wrong. 751 * before using it wrong.
740 */ 752 */
741 unsigned long section_mem_map; 753 unsigned long section_mem_map;
754 DECLARE_BITMAP(pageblock_flags, SECTION_BLOCKFLAGS_BITS);
742}; 755};
743 756
744#ifdef CONFIG_SPARSEMEM_EXTREME 757#ifdef CONFIG_SPARSEMEM_EXTREME
diff --git a/include/linux/pageblock-flags.h b/include/linux/pageblock-flags.h
new file mode 100644
index 000000000000..96b623f9b4db
--- /dev/null
+++ b/include/linux/pageblock-flags.h
@@ -0,0 +1,51 @@
1/*
2 * Macros for manipulating and testing flags related to a
3 * MAX_ORDER_NR_PAGES block of pages.
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation version 2 of the License
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17 *
18 * Copyright (C) IBM Corporation, 2006
19 *
20 * Original author, Mel Gorman
21 * Major cleanups and reduction of bit operations, Andy Whitcroft
22 */
23#ifndef PAGEBLOCK_FLAGS_H
24#define PAGEBLOCK_FLAGS_H
25
26#include <linux/types.h>
27
28/* Macro to aid the definition of ranges of bits */
29#define PB_range(name, required_bits) \
30 name, name ## _end = (name + required_bits) - 1
31
32/* Bit indices that affect a whole block of pages */
33enum pageblock_bits {
34 NR_PAGEBLOCK_BITS
35};
36
37/* Forward declaration */
38struct page;
39
40/* Declarations for getting and setting flags. See mm/page_alloc.c */
41unsigned long get_pageblock_flags_group(struct page *page,
42 int start_bitidx, int end_bitidx);
43void set_pageblock_flags_group(struct page *page, unsigned long flags,
44 int start_bitidx, int end_bitidx);
45
46#define get_pageblock_flags(page) \
47 get_pageblock_flags_group(page, 0, NR_PAGEBLOCK_BITS-1)
48#define set_pageblock_flags(page) \
49 set_pageblock_flags_group(page, 0, NR_PAGEBLOCK_BITS-1)
50
51#endif /* PAGEBLOCK_FLAGS_H */
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}