]>
Commit | Line | Data |
---|---|---|
1da177e4 LT |
1 | #ifndef _LINUX_MMZONE_H |
2 | #define _LINUX_MMZONE_H | |
3 | ||
1da177e4 | 4 | #ifndef __ASSEMBLY__ |
97965478 | 5 | #ifndef __GENERATING_BOUNDS_H |
1da177e4 | 6 | |
1da177e4 LT |
7 | #include <linux/spinlock.h> |
8 | #include <linux/list.h> | |
9 | #include <linux/wait.h> | |
e815af95 | 10 | #include <linux/bitops.h> |
1da177e4 LT |
11 | #include <linux/cache.h> |
12 | #include <linux/threads.h> | |
13 | #include <linux/numa.h> | |
14 | #include <linux/init.h> | |
bdc8cb98 | 15 | #include <linux/seqlock.h> |
8357f869 | 16 | #include <linux/nodemask.h> |
835c134e | 17 | #include <linux/pageblock-flags.h> |
97965478 | 18 | #include <linux/bounds.h> |
1da177e4 | 19 | #include <asm/atomic.h> |
93ff66bf | 20 | #include <asm/page.h> |
1da177e4 LT |
21 | |
22 | /* Free memory management - zoned buddy allocator. */ | |
23 | #ifndef CONFIG_FORCE_MAX_ZONEORDER | |
24 | #define MAX_ORDER 11 | |
25 | #else | |
26 | #define MAX_ORDER CONFIG_FORCE_MAX_ZONEORDER | |
27 | #endif | |
e984bb43 | 28 | #define MAX_ORDER_NR_PAGES (1 << (MAX_ORDER - 1)) |
1da177e4 | 29 | |
5ad333eb AW |
30 | /* |
31 | * PAGE_ALLOC_COSTLY_ORDER is the order at which allocations are deemed | |
32 | * costly to service. That is between allocation orders which should | |
33 | * coelesce naturally under reasonable reclaim pressure and those which | |
34 | * will not. | |
35 | */ | |
36 | #define PAGE_ALLOC_COSTLY_ORDER 3 | |
37 | ||
b2a0ac88 | 38 | #define MIGRATE_UNMOVABLE 0 |
e12ba74d MG |
39 | #define MIGRATE_RECLAIMABLE 1 |
40 | #define MIGRATE_MOVABLE 2 | |
64c5e135 | 41 | #define MIGRATE_RESERVE 3 |
a5d76b54 KH |
42 | #define MIGRATE_ISOLATE 4 /* can't allocate from here */ |
43 | #define MIGRATE_TYPES 5 | |
b2a0ac88 MG |
44 | |
45 | #define for_each_migratetype_order(order, type) \ | |
46 | for (order = 0; order < MAX_ORDER; order++) \ | |
47 | for (type = 0; type < MIGRATE_TYPES; type++) | |
48 | ||
467c996c MG |
49 | extern int page_group_by_mobility_disabled; |
50 | ||
51 | static inline int get_pageblock_migratetype(struct page *page) | |
52 | { | |
53 | if (unlikely(page_group_by_mobility_disabled)) | |
54 | return MIGRATE_UNMOVABLE; | |
55 | ||
56 | return get_pageblock_flags_group(page, PB_migrate, PB_migrate_end); | |
57 | } | |
58 | ||
1da177e4 | 59 | struct free_area { |
b2a0ac88 | 60 | struct list_head free_list[MIGRATE_TYPES]; |
1da177e4 LT |
61 | unsigned long nr_free; |
62 | }; | |
63 | ||
64 | struct pglist_data; | |
65 | ||
66 | /* | |
67 | * zone->lock and zone->lru_lock are two of the hottest locks in the kernel. | |
68 | * So add a wild amount of padding here to ensure that they fall into separate | |
69 | * cachelines. There are very few zone structures in the machine, so space | |
70 | * consumption is not a concern here. | |
71 | */ | |
72 | #if defined(CONFIG_SMP) | |
73 | struct zone_padding { | |
74 | char x[0]; | |
22fc6ecc | 75 | } ____cacheline_internodealigned_in_smp; |
1da177e4 LT |
76 | #define ZONE_PADDING(name) struct zone_padding name; |
77 | #else | |
78 | #define ZONE_PADDING(name) | |
79 | #endif | |
80 | ||
2244b95a | 81 | enum zone_stat_item { |
51ed4491 | 82 | /* First 128 byte cacheline (assuming 64 bit words) */ |
d23ad423 | 83 | NR_FREE_PAGES, |
b69408e8 CL |
84 | NR_LRU_BASE, |
85 | NR_INACTIVE = NR_LRU_BASE, /* must match order of LRU_[IN]ACTIVE */ | |
86 | NR_ACTIVE, /* " " " " " */ | |
f3dbd344 CL |
87 | NR_ANON_PAGES, /* Mapped anonymous pages */ |
88 | NR_FILE_MAPPED, /* pagecache pages mapped into pagetables. | |
65ba55f5 | 89 | only modified from process context */ |
347ce434 | 90 | NR_FILE_PAGES, |
b1e7a8fd | 91 | NR_FILE_DIRTY, |
ce866b34 | 92 | NR_WRITEBACK, |
51ed4491 CL |
93 | /* Second 128 byte cacheline */ |
94 | NR_SLAB_RECLAIMABLE, | |
95 | NR_SLAB_UNRECLAIMABLE, | |
96 | NR_PAGETABLE, /* used for pagetables */ | |
fd39fc85 | 97 | NR_UNSTABLE_NFS, /* NFS unstable pages */ |
d2c5e30c | 98 | NR_BOUNCE, |
e129b5c2 | 99 | NR_VMSCAN_WRITE, |
fc3ba692 | 100 | NR_WRITEBACK_TEMP, /* Writeback using temporary buffers */ |
ca889e6c CL |
101 | #ifdef CONFIG_NUMA |
102 | NUMA_HIT, /* allocated in intended node */ | |
103 | NUMA_MISS, /* allocated in non intended node */ | |
104 | NUMA_FOREIGN, /* was intended here, hit elsewhere */ | |
105 | NUMA_INTERLEAVE_HIT, /* interleaver preferred this zone */ | |
106 | NUMA_LOCAL, /* allocation from local node */ | |
107 | NUMA_OTHER, /* allocation from other node */ | |
108 | #endif | |
2244b95a CL |
109 | NR_VM_ZONE_STAT_ITEMS }; |
110 | ||
b69408e8 CL |
111 | enum lru_list { |
112 | LRU_BASE, | |
113 | LRU_INACTIVE=LRU_BASE, /* must match order of NR_[IN]ACTIVE */ | |
114 | LRU_ACTIVE, /* " " " " " */ | |
115 | NR_LRU_LISTS }; | |
116 | ||
117 | #define for_each_lru(l) for (l = 0; l < NR_LRU_LISTS; l++) | |
118 | ||
119 | static inline int is_active_lru(enum lru_list l) | |
120 | { | |
121 | return (l == LRU_ACTIVE); | |
122 | } | |
123 | ||
1da177e4 LT |
124 | struct per_cpu_pages { |
125 | int count; /* number of pages in the list */ | |
1da177e4 LT |
126 | int high; /* high watermark, emptying needed */ |
127 | int batch; /* chunk size for buddy add/remove */ | |
128 | struct list_head list; /* the list of pages */ | |
129 | }; | |
130 | ||
131 | struct per_cpu_pageset { | |
3dfa5721 | 132 | struct per_cpu_pages pcp; |
4037d452 CL |
133 | #ifdef CONFIG_NUMA |
134 | s8 expire; | |
135 | #endif | |
2244b95a | 136 | #ifdef CONFIG_SMP |
df9ecaba | 137 | s8 stat_threshold; |
2244b95a CL |
138 | s8 vm_stat_diff[NR_VM_ZONE_STAT_ITEMS]; |
139 | #endif | |
1da177e4 LT |
140 | } ____cacheline_aligned_in_smp; |
141 | ||
e7c8d5c9 CL |
142 | #ifdef CONFIG_NUMA |
143 | #define zone_pcp(__z, __cpu) ((__z)->pageset[(__cpu)]) | |
144 | #else | |
145 | #define zone_pcp(__z, __cpu) (&(__z)->pageset[(__cpu)]) | |
146 | #endif | |
147 | ||
97965478 CL |
148 | #endif /* !__GENERATING_BOUNDS.H */ |
149 | ||
2f1b6248 | 150 | enum zone_type { |
4b51d669 | 151 | #ifdef CONFIG_ZONE_DMA |
2f1b6248 CL |
152 | /* |
153 | * ZONE_DMA is used when there are devices that are not able | |
154 | * to do DMA to all of addressable memory (ZONE_NORMAL). Then we | |
155 | * carve out the portion of memory that is needed for these devices. | |
156 | * The range is arch specific. | |
157 | * | |
158 | * Some examples | |
159 | * | |
160 | * Architecture Limit | |
161 | * --------------------------- | |
162 | * parisc, ia64, sparc <4G | |
163 | * s390 <2G | |
2f1b6248 CL |
164 | * arm Various |
165 | * alpha Unlimited or 0-16MB. | |
166 | * | |
167 | * i386, x86_64 and multiple other arches | |
168 | * <16M. | |
169 | */ | |
170 | ZONE_DMA, | |
4b51d669 | 171 | #endif |
fb0e7942 | 172 | #ifdef CONFIG_ZONE_DMA32 |
2f1b6248 CL |
173 | /* |
174 | * x86_64 needs two ZONE_DMAs because it supports devices that are | |
175 | * only able to do DMA to the lower 16M but also 32 bit devices that | |
176 | * can only do DMA areas below 4G. | |
177 | */ | |
178 | ZONE_DMA32, | |
fb0e7942 | 179 | #endif |
2f1b6248 CL |
180 | /* |
181 | * Normal addressable memory is in ZONE_NORMAL. DMA operations can be | |
182 | * performed on pages in ZONE_NORMAL if the DMA devices support | |
183 | * transfers to all addressable memory. | |
184 | */ | |
185 | ZONE_NORMAL, | |
e53ef38d | 186 | #ifdef CONFIG_HIGHMEM |
2f1b6248 CL |
187 | /* |
188 | * A memory area that is only addressable by the kernel through | |
189 | * mapping portions into its own address space. This is for example | |
190 | * used by i386 to allow the kernel to address the memory beyond | |
191 | * 900MB. The kernel will set up special mappings (page | |
192 | * table entries on i386) for each page that the kernel needs to | |
193 | * access. | |
194 | */ | |
195 | ZONE_HIGHMEM, | |
e53ef38d | 196 | #endif |
2a1e274a | 197 | ZONE_MOVABLE, |
97965478 | 198 | __MAX_NR_ZONES |
2f1b6248 | 199 | }; |
1da177e4 | 200 | |
97965478 CL |
201 | #ifndef __GENERATING_BOUNDS_H |
202 | ||
1da177e4 LT |
203 | /* |
204 | * When a memory allocation must conform to specific limitations (such | |
205 | * as being suitable for DMA) the caller will pass in hints to the | |
206 | * allocator in the gfp_mask, in the zone modifier bits. These bits | |
207 | * are used to select a priority ordered list of memory zones which | |
19655d34 | 208 | * match the requested limits. See gfp_zone() in include/linux/gfp.h |
1da177e4 | 209 | */ |
fb0e7942 | 210 | |
97965478 | 211 | #if MAX_NR_ZONES < 2 |
4b51d669 | 212 | #define ZONES_SHIFT 0 |
97965478 | 213 | #elif MAX_NR_ZONES <= 2 |
19655d34 | 214 | #define ZONES_SHIFT 1 |
97965478 | 215 | #elif MAX_NR_ZONES <= 4 |
19655d34 | 216 | #define ZONES_SHIFT 2 |
4b51d669 CL |
217 | #else |
218 | #error ZONES_SHIFT -- too many zones configured adjust calculation | |
fb0e7942 | 219 | #endif |
1da177e4 | 220 | |
1da177e4 LT |
221 | struct zone { |
222 | /* Fields commonly accessed by the page allocator */ | |
1da177e4 LT |
223 | unsigned long pages_min, pages_low, pages_high; |
224 | /* | |
225 | * We don't know if the memory that we're going to allocate will be freeable | |
226 | * or/and it will be released eventually, so to avoid totally wasting several | |
227 | * GB of ram we must reserve some of the lower zone memory (otherwise we risk | |
228 | * to run OOM on the lower zones despite there's tons of freeable ram | |
229 | * on the higher zones). This array is recalculated at runtime if the | |
230 | * sysctl_lowmem_reserve_ratio sysctl changes. | |
231 | */ | |
232 | unsigned long lowmem_reserve[MAX_NR_ZONES]; | |
233 | ||
e7c8d5c9 | 234 | #ifdef CONFIG_NUMA |
d5f541ed | 235 | int node; |
9614634f CL |
236 | /* |
237 | * zone reclaim becomes active if more unmapped pages exist. | |
238 | */ | |
8417bba4 | 239 | unsigned long min_unmapped_pages; |
0ff38490 | 240 | unsigned long min_slab_pages; |
e7c8d5c9 CL |
241 | struct per_cpu_pageset *pageset[NR_CPUS]; |
242 | #else | |
1da177e4 | 243 | struct per_cpu_pageset pageset[NR_CPUS]; |
e7c8d5c9 | 244 | #endif |
1da177e4 LT |
245 | /* |
246 | * free areas of different sizes | |
247 | */ | |
248 | spinlock_t lock; | |
bdc8cb98 DH |
249 | #ifdef CONFIG_MEMORY_HOTPLUG |
250 | /* see spanned/present_pages for more description */ | |
251 | seqlock_t span_seqlock; | |
252 | #endif | |
1da177e4 LT |
253 | struct free_area free_area[MAX_ORDER]; |
254 | ||
835c134e MG |
255 | #ifndef CONFIG_SPARSEMEM |
256 | /* | |
d9c23400 | 257 | * Flags for a pageblock_nr_pages block. See pageblock-flags.h. |
835c134e MG |
258 | * In SPARSEMEM, this map is stored in struct mem_section |
259 | */ | |
260 | unsigned long *pageblock_flags; | |
261 | #endif /* CONFIG_SPARSEMEM */ | |
262 | ||
1da177e4 LT |
263 | |
264 | ZONE_PADDING(_pad1_) | |
265 | ||
266 | /* Fields commonly accessed by the page reclaim scanner */ | |
267 | spinlock_t lru_lock; | |
b69408e8 CL |
268 | struct { |
269 | struct list_head list; | |
270 | unsigned long nr_scan; | |
271 | } lru[NR_LRU_LISTS]; | |
1da177e4 | 272 | unsigned long pages_scanned; /* since last reclaim */ |
e815af95 | 273 | unsigned long flags; /* zone flags, see below */ |
753ee728 | 274 | |
2244b95a CL |
275 | /* Zone statistics */ |
276 | atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS]; | |
9eeff239 | 277 | |
1da177e4 LT |
278 | /* |
279 | * prev_priority holds the scanning priority for this zone. It is | |
280 | * defined as the scanning priority at which we achieved our reclaim | |
281 | * target at the previous try_to_free_pages() or balance_pgdat() | |
282 | * invokation. | |
283 | * | |
284 | * We use prev_priority as a measure of how much stress page reclaim is | |
285 | * under - it drives the swappiness decision: whether to unmap mapped | |
286 | * pages. | |
287 | * | |
3bb1a852 | 288 | * Access to both this field is quite racy even on uniprocessor. But |
1da177e4 LT |
289 | * it is expected to average out OK. |
290 | */ | |
1da177e4 LT |
291 | int prev_priority; |
292 | ||
293 | ||
294 | ZONE_PADDING(_pad2_) | |
295 | /* Rarely used or read-mostly fields */ | |
296 | ||
297 | /* | |
298 | * wait_table -- the array holding the hash table | |
02b694de | 299 | * wait_table_hash_nr_entries -- the size of the hash table array |
1da177e4 LT |
300 | * wait_table_bits -- wait_table_size == (1 << wait_table_bits) |
301 | * | |
302 | * The purpose of all these is to keep track of the people | |
303 | * waiting for a page to become available and make them | |
304 | * runnable again when possible. The trouble is that this | |
305 | * consumes a lot of space, especially when so few things | |
306 | * wait on pages at a given time. So instead of using | |
307 | * per-page waitqueues, we use a waitqueue hash table. | |
308 | * | |
309 | * The bucket discipline is to sleep on the same queue when | |
310 | * colliding and wake all in that wait queue when removing. | |
311 | * When something wakes, it must check to be sure its page is | |
312 | * truly available, a la thundering herd. The cost of a | |
313 | * collision is great, but given the expected load of the | |
314 | * table, they should be so rare as to be outweighed by the | |
315 | * benefits from the saved space. | |
316 | * | |
317 | * __wait_on_page_locked() and unlock_page() in mm/filemap.c, are the | |
318 | * primary users of these fields, and in mm/page_alloc.c | |
319 | * free_area_init_core() performs the initialization of them. | |
320 | */ | |
321 | wait_queue_head_t * wait_table; | |
02b694de | 322 | unsigned long wait_table_hash_nr_entries; |
1da177e4 LT |
323 | unsigned long wait_table_bits; |
324 | ||
325 | /* | |
326 | * Discontig memory support fields. | |
327 | */ | |
328 | struct pglist_data *zone_pgdat; | |
1da177e4 LT |
329 | /* zone_start_pfn == zone_start_paddr >> PAGE_SHIFT */ |
330 | unsigned long zone_start_pfn; | |
331 | ||
bdc8cb98 DH |
332 | /* |
333 | * zone_start_pfn, spanned_pages and present_pages are all | |
334 | * protected by span_seqlock. It is a seqlock because it has | |
335 | * to be read outside of zone->lock, and it is done in the main | |
336 | * allocator path. But, it is written quite infrequently. | |
337 | * | |
338 | * The lock is declared along with zone->lock because it is | |
339 | * frequently read in proximity to zone->lock. It's good to | |
340 | * give them a chance of being in the same cacheline. | |
341 | */ | |
1da177e4 LT |
342 | unsigned long spanned_pages; /* total size, including holes */ |
343 | unsigned long present_pages; /* amount of memory (excluding holes) */ | |
344 | ||
345 | /* | |
346 | * rarely used fields: | |
347 | */ | |
15ad7cdc | 348 | const char *name; |
22fc6ecc | 349 | } ____cacheline_internodealigned_in_smp; |
1da177e4 | 350 | |
e815af95 DR |
351 | typedef enum { |
352 | ZONE_ALL_UNRECLAIMABLE, /* all pages pinned */ | |
353 | ZONE_RECLAIM_LOCKED, /* prevents concurrent reclaim */ | |
098d7f12 | 354 | ZONE_OOM_LOCKED, /* zone is in OOM killer zonelist */ |
e815af95 DR |
355 | } zone_flags_t; |
356 | ||
357 | static inline void zone_set_flag(struct zone *zone, zone_flags_t flag) | |
358 | { | |
359 | set_bit(flag, &zone->flags); | |
360 | } | |
d773ed6b DR |
361 | |
362 | static inline int zone_test_and_set_flag(struct zone *zone, zone_flags_t flag) | |
363 | { | |
364 | return test_and_set_bit(flag, &zone->flags); | |
365 | } | |
366 | ||
e815af95 DR |
367 | static inline void zone_clear_flag(struct zone *zone, zone_flags_t flag) |
368 | { | |
369 | clear_bit(flag, &zone->flags); | |
370 | } | |
371 | ||
372 | static inline int zone_is_all_unreclaimable(const struct zone *zone) | |
373 | { | |
374 | return test_bit(ZONE_ALL_UNRECLAIMABLE, &zone->flags); | |
375 | } | |
d773ed6b | 376 | |
e815af95 DR |
377 | static inline int zone_is_reclaim_locked(const struct zone *zone) |
378 | { | |
379 | return test_bit(ZONE_RECLAIM_LOCKED, &zone->flags); | |
380 | } | |
d773ed6b | 381 | |
098d7f12 DR |
382 | static inline int zone_is_oom_locked(const struct zone *zone) |
383 | { | |
384 | return test_bit(ZONE_OOM_LOCKED, &zone->flags); | |
385 | } | |
e815af95 | 386 | |
1da177e4 LT |
387 | /* |
388 | * The "priority" of VM scanning is how much of the queues we will scan in one | |
389 | * go. A value of 12 for DEF_PRIORITY implies that we will scan 1/4096th of the | |
390 | * queues ("queue_length >> 12") during an aging round. | |
391 | */ | |
392 | #define DEF_PRIORITY 12 | |
393 | ||
9276b1bc PJ |
394 | /* Maximum number of zones on a zonelist */ |
395 | #define MAX_ZONES_PER_ZONELIST (MAX_NUMNODES * MAX_NR_ZONES) | |
396 | ||
397 | #ifdef CONFIG_NUMA | |
523b9458 CL |
398 | |
399 | /* | |
400 | * The NUMA zonelists are doubled becausse we need zonelists that restrict the | |
401 | * allocations to a single node for GFP_THISNODE. | |
402 | * | |
54a6eb5c MG |
403 | * [0] : Zonelist with fallback |
404 | * [1] : No fallback (GFP_THISNODE) | |
523b9458 | 405 | */ |
54a6eb5c | 406 | #define MAX_ZONELISTS 2 |
523b9458 CL |
407 | |
408 | ||
9276b1bc PJ |
409 | /* |
410 | * We cache key information from each zonelist for smaller cache | |
411 | * footprint when scanning for free pages in get_page_from_freelist(). | |
412 | * | |
413 | * 1) The BITMAP fullzones tracks which zones in a zonelist have come | |
414 | * up short of free memory since the last time (last_fullzone_zap) | |
415 | * we zero'd fullzones. | |
416 | * 2) The array z_to_n[] maps each zone in the zonelist to its node | |
417 | * id, so that we can efficiently evaluate whether that node is | |
418 | * set in the current tasks mems_allowed. | |
419 | * | |
420 | * Both fullzones and z_to_n[] are one-to-one with the zonelist, | |
421 | * indexed by a zones offset in the zonelist zones[] array. | |
422 | * | |
423 | * The get_page_from_freelist() routine does two scans. During the | |
424 | * first scan, we skip zones whose corresponding bit in 'fullzones' | |
425 | * is set or whose corresponding node in current->mems_allowed (which | |
426 | * comes from cpusets) is not set. During the second scan, we bypass | |
427 | * this zonelist_cache, to ensure we look methodically at each zone. | |
428 | * | |
429 | * Once per second, we zero out (zap) fullzones, forcing us to | |
430 | * reconsider nodes that might have regained more free memory. | |
431 | * The field last_full_zap is the time we last zapped fullzones. | |
432 | * | |
433 | * This mechanism reduces the amount of time we waste repeatedly | |
434 | * reexaming zones for free memory when they just came up low on | |
435 | * memory momentarilly ago. | |
436 | * | |
437 | * The zonelist_cache struct members logically belong in struct | |
438 | * zonelist. However, the mempolicy zonelists constructed for | |
439 | * MPOL_BIND are intentionally variable length (and usually much | |
440 | * shorter). A general purpose mechanism for handling structs with | |
441 | * multiple variable length members is more mechanism than we want | |
442 | * here. We resort to some special case hackery instead. | |
443 | * | |
444 | * The MPOL_BIND zonelists don't need this zonelist_cache (in good | |
445 | * part because they are shorter), so we put the fixed length stuff | |
446 | * at the front of the zonelist struct, ending in a variable length | |
447 | * zones[], as is needed by MPOL_BIND. | |
448 | * | |
449 | * Then we put the optional zonelist cache on the end of the zonelist | |
450 | * struct. This optional stuff is found by a 'zlcache_ptr' pointer in | |
451 | * the fixed length portion at the front of the struct. This pointer | |
452 | * both enables us to find the zonelist cache, and in the case of | |
453 | * MPOL_BIND zonelists, (which will just set the zlcache_ptr to NULL) | |
454 | * to know that the zonelist cache is not there. | |
455 | * | |
456 | * The end result is that struct zonelists come in two flavors: | |
457 | * 1) The full, fixed length version, shown below, and | |
458 | * 2) The custom zonelists for MPOL_BIND. | |
459 | * The custom MPOL_BIND zonelists have a NULL zlcache_ptr and no zlcache. | |
460 | * | |
461 | * Even though there may be multiple CPU cores on a node modifying | |
462 | * fullzones or last_full_zap in the same zonelist_cache at the same | |
463 | * time, we don't lock it. This is just hint data - if it is wrong now | |
464 | * and then, the allocator will still function, perhaps a bit slower. | |
465 | */ | |
466 | ||
467 | ||
468 | struct zonelist_cache { | |
9276b1bc | 469 | unsigned short z_to_n[MAX_ZONES_PER_ZONELIST]; /* zone->nid */ |
7253f4ef | 470 | DECLARE_BITMAP(fullzones, MAX_ZONES_PER_ZONELIST); /* zone full? */ |
9276b1bc PJ |
471 | unsigned long last_full_zap; /* when last zap'd (jiffies) */ |
472 | }; | |
473 | #else | |
54a6eb5c | 474 | #define MAX_ZONELISTS 1 |
9276b1bc PJ |
475 | struct zonelist_cache; |
476 | #endif | |
477 | ||
dd1a239f MG |
478 | /* |
479 | * This struct contains information about a zone in a zonelist. It is stored | |
480 | * here to avoid dereferences into large structures and lookups of tables | |
481 | */ | |
482 | struct zoneref { | |
483 | struct zone *zone; /* Pointer to actual zone */ | |
484 | int zone_idx; /* zone_idx(zoneref->zone) */ | |
485 | }; | |
486 | ||
1da177e4 LT |
487 | /* |
488 | * One allocation request operates on a zonelist. A zonelist | |
489 | * is a list of zones, the first one is the 'goal' of the | |
490 | * allocation, the other zones are fallback zones, in decreasing | |
491 | * priority. | |
492 | * | |
9276b1bc PJ |
493 | * If zlcache_ptr is not NULL, then it is just the address of zlcache, |
494 | * as explained above. If zlcache_ptr is NULL, there is no zlcache. | |
dd1a239f MG |
495 | * * |
496 | * To speed the reading of the zonelist, the zonerefs contain the zone index | |
497 | * of the entry being read. Helper functions to access information given | |
498 | * a struct zoneref are | |
499 | * | |
500 | * zonelist_zone() - Return the struct zone * for an entry in _zonerefs | |
501 | * zonelist_zone_idx() - Return the index of the zone for an entry | |
502 | * zonelist_node_idx() - Return the index of the node for an entry | |
1da177e4 LT |
503 | */ |
504 | struct zonelist { | |
9276b1bc | 505 | struct zonelist_cache *zlcache_ptr; // NULL or &zlcache |
dd1a239f | 506 | struct zoneref _zonerefs[MAX_ZONES_PER_ZONELIST + 1]; |
9276b1bc PJ |
507 | #ifdef CONFIG_NUMA |
508 | struct zonelist_cache zlcache; // optional ... | |
509 | #endif | |
1da177e4 LT |
510 | }; |
511 | ||
c713216d MG |
512 | #ifdef CONFIG_ARCH_POPULATES_NODE_MAP |
513 | struct node_active_region { | |
514 | unsigned long start_pfn; | |
515 | unsigned long end_pfn; | |
516 | int nid; | |
517 | }; | |
518 | #endif /* CONFIG_ARCH_POPULATES_NODE_MAP */ | |
1da177e4 | 519 | |
5b99cd0e HC |
520 | #ifndef CONFIG_DISCONTIGMEM |
521 | /* The array of struct pages - for discontigmem use pgdat->lmem_map */ | |
522 | extern struct page *mem_map; | |
523 | #endif | |
524 | ||
1da177e4 LT |
525 | /* |
526 | * The pg_data_t structure is used in machines with CONFIG_DISCONTIGMEM | |
527 | * (mostly NUMA machines?) to denote a higher-level memory zone than the | |
528 | * zone denotes. | |
529 | * | |
530 | * On NUMA machines, each NUMA node would have a pg_data_t to describe | |
531 | * it's memory layout. | |
532 | * | |
533 | * Memory statistics and page replacement data structures are maintained on a | |
534 | * per-zone basis. | |
535 | */ | |
536 | struct bootmem_data; | |
537 | typedef struct pglist_data { | |
538 | struct zone node_zones[MAX_NR_ZONES]; | |
523b9458 | 539 | struct zonelist node_zonelists[MAX_ZONELISTS]; |
1da177e4 | 540 | int nr_zones; |
d41dee36 | 541 | #ifdef CONFIG_FLAT_NODE_MEM_MAP |
1da177e4 | 542 | struct page *node_mem_map; |
d41dee36 | 543 | #endif |
1da177e4 | 544 | struct bootmem_data *bdata; |
208d54e5 DH |
545 | #ifdef CONFIG_MEMORY_HOTPLUG |
546 | /* | |
547 | * Must be held any time you expect node_start_pfn, node_present_pages | |
548 | * or node_spanned_pages stay constant. Holding this will also | |
549 | * guarantee that any pfn_valid() stays that way. | |
550 | * | |
551 | * Nests above zone->lock and zone->size_seqlock. | |
552 | */ | |
553 | spinlock_t node_size_lock; | |
554 | #endif | |
1da177e4 LT |
555 | unsigned long node_start_pfn; |
556 | unsigned long node_present_pages; /* total number of physical pages */ | |
557 | unsigned long node_spanned_pages; /* total size of physical page | |
558 | range, including holes */ | |
559 | int node_id; | |
1da177e4 LT |
560 | wait_queue_head_t kswapd_wait; |
561 | struct task_struct *kswapd; | |
562 | int kswapd_max_order; | |
563 | } pg_data_t; | |
564 | ||
565 | #define node_present_pages(nid) (NODE_DATA(nid)->node_present_pages) | |
566 | #define node_spanned_pages(nid) (NODE_DATA(nid)->node_spanned_pages) | |
d41dee36 | 567 | #ifdef CONFIG_FLAT_NODE_MEM_MAP |
408fde81 | 568 | #define pgdat_page_nr(pgdat, pagenr) ((pgdat)->node_mem_map + (pagenr)) |
d41dee36 AW |
569 | #else |
570 | #define pgdat_page_nr(pgdat, pagenr) pfn_to_page((pgdat)->node_start_pfn + (pagenr)) | |
571 | #endif | |
408fde81 | 572 | #define nid_page_nr(nid, pagenr) pgdat_page_nr(NODE_DATA(nid),(pagenr)) |
1da177e4 | 573 | |
208d54e5 DH |
574 | #include <linux/memory_hotplug.h> |
575 | ||
1da177e4 LT |
576 | void get_zone_counts(unsigned long *active, unsigned long *inactive, |
577 | unsigned long *free); | |
578 | void build_all_zonelists(void); | |
579 | void wakeup_kswapd(struct zone *zone, int order); | |
580 | int zone_watermark_ok(struct zone *z, int order, unsigned long mark, | |
7fb1d9fc | 581 | int classzone_idx, int alloc_flags); |
a2f3aa02 DH |
582 | enum memmap_context { |
583 | MEMMAP_EARLY, | |
584 | MEMMAP_HOTPLUG, | |
585 | }; | |
718127cc | 586 | extern int init_currently_empty_zone(struct zone *zone, unsigned long start_pfn, |
a2f3aa02 DH |
587 | unsigned long size, |
588 | enum memmap_context context); | |
718127cc | 589 | |
1da177e4 LT |
590 | #ifdef CONFIG_HAVE_MEMORY_PRESENT |
591 | void memory_present(int nid, unsigned long start, unsigned long end); | |
592 | #else | |
593 | static inline void memory_present(int nid, unsigned long start, unsigned long end) {} | |
594 | #endif | |
595 | ||
596 | #ifdef CONFIG_NEED_NODE_MEMMAP_SIZE | |
597 | unsigned long __init node_memmap_size_bytes(int, unsigned long, unsigned long); | |
598 | #endif | |
599 | ||
600 | /* | |
601 | * zone_idx() returns 0 for the ZONE_DMA zone, 1 for the ZONE_NORMAL zone, etc. | |
602 | */ | |
603 | #define zone_idx(zone) ((zone) - (zone)->zone_pgdat->node_zones) | |
604 | ||
f3fe6512 CK |
605 | static inline int populated_zone(struct zone *zone) |
606 | { | |
607 | return (!!zone->present_pages); | |
608 | } | |
609 | ||
2a1e274a MG |
610 | extern int movable_zone; |
611 | ||
612 | static inline int zone_movable_is_highmem(void) | |
613 | { | |
614 | #if defined(CONFIG_HIGHMEM) && defined(CONFIG_ARCH_POPULATES_NODE_MAP) | |
615 | return movable_zone == ZONE_HIGHMEM; | |
616 | #else | |
617 | return 0; | |
618 | #endif | |
619 | } | |
620 | ||
2f1b6248 | 621 | static inline int is_highmem_idx(enum zone_type idx) |
1da177e4 | 622 | { |
e53ef38d | 623 | #ifdef CONFIG_HIGHMEM |
2a1e274a MG |
624 | return (idx == ZONE_HIGHMEM || |
625 | (idx == ZONE_MOVABLE && zone_movable_is_highmem())); | |
e53ef38d CL |
626 | #else |
627 | return 0; | |
628 | #endif | |
1da177e4 LT |
629 | } |
630 | ||
2f1b6248 | 631 | static inline int is_normal_idx(enum zone_type idx) |
1da177e4 LT |
632 | { |
633 | return (idx == ZONE_NORMAL); | |
634 | } | |
9328b8fa | 635 | |
1da177e4 LT |
636 | /** |
637 | * is_highmem - helper function to quickly check if a struct zone is a | |
638 | * highmem zone or not. This is an attempt to keep references | |
639 | * to ZONE_{DMA/NORMAL/HIGHMEM/etc} in general code to a minimum. | |
640 | * @zone - pointer to struct zone variable | |
641 | */ | |
642 | static inline int is_highmem(struct zone *zone) | |
643 | { | |
e53ef38d | 644 | #ifdef CONFIG_HIGHMEM |
ddc81ed2 HH |
645 | int zone_off = (char *)zone - (char *)zone->zone_pgdat->node_zones; |
646 | return zone_off == ZONE_HIGHMEM * sizeof(*zone) || | |
647 | (zone_off == ZONE_MOVABLE * sizeof(*zone) && | |
648 | zone_movable_is_highmem()); | |
e53ef38d CL |
649 | #else |
650 | return 0; | |
651 | #endif | |
1da177e4 LT |
652 | } |
653 | ||
654 | static inline int is_normal(struct zone *zone) | |
655 | { | |
656 | return zone == zone->zone_pgdat->node_zones + ZONE_NORMAL; | |
657 | } | |
658 | ||
9328b8fa NP |
659 | static inline int is_dma32(struct zone *zone) |
660 | { | |
fb0e7942 | 661 | #ifdef CONFIG_ZONE_DMA32 |
9328b8fa | 662 | return zone == zone->zone_pgdat->node_zones + ZONE_DMA32; |
fb0e7942 CL |
663 | #else |
664 | return 0; | |
665 | #endif | |
9328b8fa NP |
666 | } |
667 | ||
668 | static inline int is_dma(struct zone *zone) | |
669 | { | |
4b51d669 | 670 | #ifdef CONFIG_ZONE_DMA |
9328b8fa | 671 | return zone == zone->zone_pgdat->node_zones + ZONE_DMA; |
4b51d669 CL |
672 | #else |
673 | return 0; | |
674 | #endif | |
9328b8fa NP |
675 | } |
676 | ||
1da177e4 LT |
677 | /* These two functions are used to setup the per zone pages min values */ |
678 | struct ctl_table; | |
679 | struct file; | |
680 | int min_free_kbytes_sysctl_handler(struct ctl_table *, int, struct file *, | |
681 | void __user *, size_t *, loff_t *); | |
682 | extern int sysctl_lowmem_reserve_ratio[MAX_NR_ZONES-1]; | |
683 | int lowmem_reserve_ratio_sysctl_handler(struct ctl_table *, int, struct file *, | |
684 | void __user *, size_t *, loff_t *); | |
8ad4b1fb RS |
685 | int percpu_pagelist_fraction_sysctl_handler(struct ctl_table *, int, struct file *, |
686 | void __user *, size_t *, loff_t *); | |
9614634f CL |
687 | int sysctl_min_unmapped_ratio_sysctl_handler(struct ctl_table *, int, |
688 | struct file *, void __user *, size_t *, loff_t *); | |
0ff38490 CL |
689 | int sysctl_min_slab_ratio_sysctl_handler(struct ctl_table *, int, |
690 | struct file *, void __user *, size_t *, loff_t *); | |
1da177e4 | 691 | |
f0c0b2b8 KH |
692 | extern int numa_zonelist_order_handler(struct ctl_table *, int, |
693 | struct file *, void __user *, size_t *, loff_t *); | |
694 | extern char numa_zonelist_order[]; | |
695 | #define NUMA_ZONELIST_ORDER_LEN 16 /* string buffer size */ | |
696 | ||
1da177e4 LT |
697 | #include <linux/topology.h> |
698 | /* Returns the number of the current Node. */ | |
69d81fcd | 699 | #ifndef numa_node_id |
39c715b7 | 700 | #define numa_node_id() (cpu_to_node(raw_smp_processor_id())) |
69d81fcd | 701 | #endif |
1da177e4 | 702 | |
93b7504e | 703 | #ifndef CONFIG_NEED_MULTIPLE_NODES |
1da177e4 LT |
704 | |
705 | extern struct pglist_data contig_page_data; | |
706 | #define NODE_DATA(nid) (&contig_page_data) | |
707 | #define NODE_MEM_MAP(nid) mem_map | |
1da177e4 | 708 | |
93b7504e | 709 | #else /* CONFIG_NEED_MULTIPLE_NODES */ |
1da177e4 LT |
710 | |
711 | #include <asm/mmzone.h> | |
712 | ||
93b7504e | 713 | #endif /* !CONFIG_NEED_MULTIPLE_NODES */ |
348f8b6c | 714 | |
95144c78 KH |
715 | extern struct pglist_data *first_online_pgdat(void); |
716 | extern struct pglist_data *next_online_pgdat(struct pglist_data *pgdat); | |
717 | extern struct zone *next_zone(struct zone *zone); | |
8357f869 KH |
718 | |
719 | /** | |
12d15f0d | 720 | * for_each_online_pgdat - helper macro to iterate over all online nodes |
8357f869 KH |
721 | * @pgdat - pointer to a pg_data_t variable |
722 | */ | |
723 | #define for_each_online_pgdat(pgdat) \ | |
724 | for (pgdat = first_online_pgdat(); \ | |
725 | pgdat; \ | |
726 | pgdat = next_online_pgdat(pgdat)) | |
8357f869 KH |
727 | /** |
728 | * for_each_zone - helper macro to iterate over all memory zones | |
729 | * @zone - pointer to struct zone variable | |
730 | * | |
731 | * The user only needs to declare the zone variable, for_each_zone | |
732 | * fills it in. | |
733 | */ | |
734 | #define for_each_zone(zone) \ | |
735 | for (zone = (first_online_pgdat())->node_zones; \ | |
736 | zone; \ | |
737 | zone = next_zone(zone)) | |
738 | ||
dd1a239f MG |
739 | static inline struct zone *zonelist_zone(struct zoneref *zoneref) |
740 | { | |
741 | return zoneref->zone; | |
742 | } | |
743 | ||
744 | static inline int zonelist_zone_idx(struct zoneref *zoneref) | |
745 | { | |
746 | return zoneref->zone_idx; | |
747 | } | |
748 | ||
749 | static inline int zonelist_node_idx(struct zoneref *zoneref) | |
750 | { | |
751 | #ifdef CONFIG_NUMA | |
752 | /* zone_to_nid not available in this context */ | |
753 | return zoneref->zone->node; | |
754 | #else | |
755 | return 0; | |
756 | #endif /* CONFIG_NUMA */ | |
757 | } | |
758 | ||
19770b32 MG |
759 | /** |
760 | * next_zones_zonelist - Returns the next zone at or below highest_zoneidx within the allowed nodemask using a cursor within a zonelist as a starting point | |
761 | * @z - The cursor used as a starting point for the search | |
762 | * @highest_zoneidx - The zone index of the highest zone to return | |
763 | * @nodes - An optional nodemask to filter the zonelist with | |
764 | * @zone - The first suitable zone found is returned via this parameter | |
765 | * | |
766 | * This function returns the next zone at or below a given zone index that is | |
767 | * within the allowed nodemask using a cursor as the starting point for the | |
5bead2a0 MG |
768 | * search. The zoneref returned is a cursor that represents the current zone |
769 | * being examined. It should be advanced by one before calling | |
770 | * next_zones_zonelist again. | |
19770b32 MG |
771 | */ |
772 | struct zoneref *next_zones_zonelist(struct zoneref *z, | |
773 | enum zone_type highest_zoneidx, | |
774 | nodemask_t *nodes, | |
775 | struct zone **zone); | |
dd1a239f | 776 | |
19770b32 MG |
777 | /** |
778 | * first_zones_zonelist - Returns the first zone at or below highest_zoneidx within the allowed nodemask in a zonelist | |
779 | * @zonelist - The zonelist to search for a suitable zone | |
780 | * @highest_zoneidx - The zone index of the highest zone to return | |
781 | * @nodes - An optional nodemask to filter the zonelist with | |
782 | * @zone - The first suitable zone found is returned via this parameter | |
783 | * | |
784 | * This function returns the first zone at or below a given zone index that is | |
785 | * within the allowed nodemask. The zoneref returned is a cursor that can be | |
5bead2a0 MG |
786 | * used to iterate the zonelist with next_zones_zonelist by advancing it by |
787 | * one before calling. | |
19770b32 | 788 | */ |
dd1a239f | 789 | static inline struct zoneref *first_zones_zonelist(struct zonelist *zonelist, |
19770b32 MG |
790 | enum zone_type highest_zoneidx, |
791 | nodemask_t *nodes, | |
792 | struct zone **zone) | |
54a6eb5c | 793 | { |
19770b32 MG |
794 | return next_zones_zonelist(zonelist->_zonerefs, highest_zoneidx, nodes, |
795 | zone); | |
54a6eb5c MG |
796 | } |
797 | ||
19770b32 MG |
798 | /** |
799 | * for_each_zone_zonelist_nodemask - helper macro to iterate over valid zones in a zonelist at or below a given zone index and within a nodemask | |
800 | * @zone - The current zone in the iterator | |
801 | * @z - The current pointer within zonelist->zones being iterated | |
802 | * @zlist - The zonelist being iterated | |
803 | * @highidx - The zone index of the highest zone to return | |
804 | * @nodemask - Nodemask allowed by the allocator | |
805 | * | |
806 | * This iterator iterates though all zones at or below a given zone index and | |
807 | * within a given nodemask | |
808 | */ | |
809 | #define for_each_zone_zonelist_nodemask(zone, z, zlist, highidx, nodemask) \ | |
810 | for (z = first_zones_zonelist(zlist, highidx, nodemask, &zone); \ | |
811 | zone; \ | |
5bead2a0 | 812 | z = next_zones_zonelist(++z, highidx, nodemask, &zone)) \ |
54a6eb5c MG |
813 | |
814 | /** | |
815 | * for_each_zone_zonelist - helper macro to iterate over valid zones in a zonelist at or below a given zone index | |
816 | * @zone - The current zone in the iterator | |
817 | * @z - The current pointer within zonelist->zones being iterated | |
818 | * @zlist - The zonelist being iterated | |
819 | * @highidx - The zone index of the highest zone to return | |
820 | * | |
821 | * This iterator iterates though all zones at or below a given zone index. | |
822 | */ | |
823 | #define for_each_zone_zonelist(zone, z, zlist, highidx) \ | |
19770b32 | 824 | for_each_zone_zonelist_nodemask(zone, z, zlist, highidx, NULL) |
54a6eb5c | 825 | |
d41dee36 AW |
826 | #ifdef CONFIG_SPARSEMEM |
827 | #include <asm/sparsemem.h> | |
828 | #endif | |
829 | ||
c713216d MG |
830 | #if !defined(CONFIG_HAVE_ARCH_EARLY_PFN_TO_NID) && \ |
831 | !defined(CONFIG_ARCH_POPULATES_NODE_MAP) | |
b4544568 AM |
832 | static inline unsigned long early_pfn_to_nid(unsigned long pfn) |
833 | { | |
834 | return 0; | |
835 | } | |
b159d43f AW |
836 | #endif |
837 | ||
2bdaf115 AW |
838 | #ifdef CONFIG_FLATMEM |
839 | #define pfn_to_nid(pfn) (0) | |
840 | #endif | |
841 | ||
d41dee36 AW |
842 | #define pfn_to_section_nr(pfn) ((pfn) >> PFN_SECTION_SHIFT) |
843 | #define section_nr_to_pfn(sec) ((sec) << PFN_SECTION_SHIFT) | |
844 | ||
845 | #ifdef CONFIG_SPARSEMEM | |
846 | ||
847 | /* | |
848 | * SECTION_SHIFT #bits space required to store a section # | |
849 | * | |
850 | * PA_SECTION_SHIFT physical address to/from section number | |
851 | * PFN_SECTION_SHIFT pfn to/from section number | |
852 | */ | |
853 | #define SECTIONS_SHIFT (MAX_PHYSMEM_BITS - SECTION_SIZE_BITS) | |
854 | ||
855 | #define PA_SECTION_SHIFT (SECTION_SIZE_BITS) | |
856 | #define PFN_SECTION_SHIFT (SECTION_SIZE_BITS - PAGE_SHIFT) | |
857 | ||
858 | #define NR_MEM_SECTIONS (1UL << SECTIONS_SHIFT) | |
859 | ||
860 | #define PAGES_PER_SECTION (1UL << PFN_SECTION_SHIFT) | |
861 | #define PAGE_SECTION_MASK (~(PAGES_PER_SECTION-1)) | |
862 | ||
835c134e | 863 | #define SECTION_BLOCKFLAGS_BITS \ |
d9c23400 | 864 | ((1UL << (PFN_SECTION_SHIFT - pageblock_order)) * NR_PAGEBLOCK_BITS) |
835c134e | 865 | |
d41dee36 AW |
866 | #if (MAX_ORDER - 1 + PAGE_SHIFT) > SECTION_SIZE_BITS |
867 | #error Allocator MAX_ORDER exceeds SECTION_SIZE | |
868 | #endif | |
869 | ||
870 | struct page; | |
871 | struct mem_section { | |
29751f69 AW |
872 | /* |
873 | * This is, logically, a pointer to an array of struct | |
874 | * pages. However, it is stored with some other magic. | |
875 | * (see sparse.c::sparse_init_one_section()) | |
876 | * | |
30c253e6 AW |
877 | * Additionally during early boot we encode node id of |
878 | * the location of the section here to guide allocation. | |
879 | * (see sparse.c::memory_present()) | |
880 | * | |
29751f69 AW |
881 | * Making it a UL at least makes someone do a cast |
882 | * before using it wrong. | |
883 | */ | |
884 | unsigned long section_mem_map; | |
5c0e3066 MG |
885 | |
886 | /* See declaration of similar field in struct zone */ | |
887 | unsigned long *pageblock_flags; | |
d41dee36 AW |
888 | }; |
889 | ||
3e347261 BP |
890 | #ifdef CONFIG_SPARSEMEM_EXTREME |
891 | #define SECTIONS_PER_ROOT (PAGE_SIZE / sizeof (struct mem_section)) | |
892 | #else | |
893 | #define SECTIONS_PER_ROOT 1 | |
894 | #endif | |
802f192e | 895 | |
3e347261 BP |
896 | #define SECTION_NR_TO_ROOT(sec) ((sec) / SECTIONS_PER_ROOT) |
897 | #define NR_SECTION_ROOTS (NR_MEM_SECTIONS / SECTIONS_PER_ROOT) | |
898 | #define SECTION_ROOT_MASK (SECTIONS_PER_ROOT - 1) | |
802f192e | 899 | |
3e347261 BP |
900 | #ifdef CONFIG_SPARSEMEM_EXTREME |
901 | extern struct mem_section *mem_section[NR_SECTION_ROOTS]; | |
802f192e | 902 | #else |
3e347261 BP |
903 | extern struct mem_section mem_section[NR_SECTION_ROOTS][SECTIONS_PER_ROOT]; |
904 | #endif | |
d41dee36 | 905 | |
29751f69 AW |
906 | static inline struct mem_section *__nr_to_section(unsigned long nr) |
907 | { | |
3e347261 BP |
908 | if (!mem_section[SECTION_NR_TO_ROOT(nr)]) |
909 | return NULL; | |
910 | return &mem_section[SECTION_NR_TO_ROOT(nr)][nr & SECTION_ROOT_MASK]; | |
29751f69 | 911 | } |
4ca644d9 | 912 | extern int __section_nr(struct mem_section* ms); |
04753278 | 913 | extern unsigned long usemap_size(void); |
29751f69 AW |
914 | |
915 | /* | |
916 | * We use the lower bits of the mem_map pointer to store | |
917 | * a little bit of information. There should be at least | |
918 | * 3 bits here due to 32-bit alignment. | |
919 | */ | |
920 | #define SECTION_MARKED_PRESENT (1UL<<0) | |
921 | #define SECTION_HAS_MEM_MAP (1UL<<1) | |
922 | #define SECTION_MAP_LAST_BIT (1UL<<2) | |
923 | #define SECTION_MAP_MASK (~(SECTION_MAP_LAST_BIT-1)) | |
30c253e6 | 924 | #define SECTION_NID_SHIFT 2 |
29751f69 AW |
925 | |
926 | static inline struct page *__section_mem_map_addr(struct mem_section *section) | |
927 | { | |
928 | unsigned long map = section->section_mem_map; | |
929 | map &= SECTION_MAP_MASK; | |
930 | return (struct page *)map; | |
931 | } | |
932 | ||
540557b9 | 933 | static inline int present_section(struct mem_section *section) |
29751f69 | 934 | { |
802f192e | 935 | return (section && (section->section_mem_map & SECTION_MARKED_PRESENT)); |
29751f69 AW |
936 | } |
937 | ||
540557b9 AW |
938 | static inline int present_section_nr(unsigned long nr) |
939 | { | |
940 | return present_section(__nr_to_section(nr)); | |
941 | } | |
942 | ||
943 | static inline int valid_section(struct mem_section *section) | |
29751f69 | 944 | { |
802f192e | 945 | return (section && (section->section_mem_map & SECTION_HAS_MEM_MAP)); |
29751f69 AW |
946 | } |
947 | ||
948 | static inline int valid_section_nr(unsigned long nr) | |
949 | { | |
950 | return valid_section(__nr_to_section(nr)); | |
951 | } | |
952 | ||
d41dee36 AW |
953 | static inline struct mem_section *__pfn_to_section(unsigned long pfn) |
954 | { | |
29751f69 | 955 | return __nr_to_section(pfn_to_section_nr(pfn)); |
d41dee36 AW |
956 | } |
957 | ||
d41dee36 AW |
958 | static inline int pfn_valid(unsigned long pfn) |
959 | { | |
960 | if (pfn_to_section_nr(pfn) >= NR_MEM_SECTIONS) | |
961 | return 0; | |
29751f69 | 962 | return valid_section(__nr_to_section(pfn_to_section_nr(pfn))); |
d41dee36 AW |
963 | } |
964 | ||
540557b9 AW |
965 | static inline int pfn_present(unsigned long pfn) |
966 | { | |
967 | if (pfn_to_section_nr(pfn) >= NR_MEM_SECTIONS) | |
968 | return 0; | |
969 | return present_section(__nr_to_section(pfn_to_section_nr(pfn))); | |
970 | } | |
971 | ||
d41dee36 AW |
972 | /* |
973 | * These are _only_ used during initialisation, therefore they | |
974 | * can use __initdata ... They could have names to indicate | |
975 | * this restriction. | |
976 | */ | |
977 | #ifdef CONFIG_NUMA | |
161599ff AW |
978 | #define pfn_to_nid(pfn) \ |
979 | ({ \ | |
980 | unsigned long __pfn_to_nid_pfn = (pfn); \ | |
981 | page_to_nid(pfn_to_page(__pfn_to_nid_pfn)); \ | |
982 | }) | |
2bdaf115 AW |
983 | #else |
984 | #define pfn_to_nid(pfn) (0) | |
d41dee36 AW |
985 | #endif |
986 | ||
d41dee36 AW |
987 | #define early_pfn_valid(pfn) pfn_valid(pfn) |
988 | void sparse_init(void); | |
989 | #else | |
990 | #define sparse_init() do {} while (0) | |
28ae55c9 | 991 | #define sparse_index_init(_sec, _nid) do {} while (0) |
d41dee36 AW |
992 | #endif /* CONFIG_SPARSEMEM */ |
993 | ||
75167957 AW |
994 | #ifdef CONFIG_NODES_SPAN_OTHER_NODES |
995 | #define early_pfn_in_nid(pfn, nid) (early_pfn_to_nid(pfn) == (nid)) | |
996 | #else | |
997 | #define early_pfn_in_nid(pfn, nid) (1) | |
998 | #endif | |
999 | ||
d41dee36 AW |
1000 | #ifndef early_pfn_valid |
1001 | #define early_pfn_valid(pfn) (1) | |
1002 | #endif | |
1003 | ||
1004 | void memory_present(int nid, unsigned long start, unsigned long end); | |
1005 | unsigned long __init node_memmap_size_bytes(int, unsigned long, unsigned long); | |
1006 | ||
14e07298 AW |
1007 | /* |
1008 | * If it is possible to have holes within a MAX_ORDER_NR_PAGES, then we | |
1009 | * need to check pfn validility within that MAX_ORDER_NR_PAGES block. | |
1010 | * pfn_valid_within() should be used in this case; we optimise this away | |
1011 | * when we have no holes within a MAX_ORDER_NR_PAGES block. | |
1012 | */ | |
1013 | #ifdef CONFIG_HOLES_IN_ZONE | |
1014 | #define pfn_valid_within(pfn) pfn_valid(pfn) | |
1015 | #else | |
1016 | #define pfn_valid_within(pfn) (1) | |
1017 | #endif | |
1018 | ||
97965478 | 1019 | #endif /* !__GENERATING_BOUNDS.H */ |
1da177e4 | 1020 | #endif /* !__ASSEMBLY__ */ |
1da177e4 | 1021 | #endif /* _LINUX_MMZONE_H */ |