1#ifndef _LINUX_MMZONE_H
2#define _LINUX_MMZONE_H
3
4#ifdef __KERNEL__
5#ifndef __ASSEMBLY__
6
7#include <linux/spinlock.h>
8#include <linux/list.h>
9#include <linux/wait.h>
10#include <linux/cache.h>
11#include <linux/threads.h>
12#include <linux/numa.h>
13#include <linux/init.h>
14#include <linux/seqlock.h>
15#include <linux/nodemask.h>
16#include <asm/atomic.h>
17#include <asm/page.h>
18
19
20#ifndef CONFIG_FORCE_MAX_ZONEORDER
21#define MAX_ORDER 11
22#else
23#define MAX_ORDER CONFIG_FORCE_MAX_ZONEORDER
24#endif
25#define MAX_ORDER_NR_PAGES (1 << (MAX_ORDER - 1))
26
27struct free_area {
28 struct list_head free_list;
29 unsigned long nr_free;
30};
31
32struct pglist_data;
33
34
35
36
37
38
39
40#if defined(CONFIG_SMP)
41struct zone_padding {
42 char x[0];
43} ____cacheline_internodealigned_in_smp;
44#define ZONE_PADDING(name) struct zone_padding name;
45#else
46#define ZONE_PADDING(name)
47#endif
48
49enum zone_stat_item {
50 NR_ANON_PAGES,
51 NR_FILE_MAPPED,
52
53 NR_FILE_PAGES,
54 NR_SLAB,
55 NR_PAGETABLE,
56 NR_FILE_DIRTY,
57 NR_WRITEBACK,
58 NR_UNSTABLE_NFS,
59 NR_BOUNCE,
60#ifdef CONFIG_NUMA
61 NUMA_HIT,
62 NUMA_MISS,
63 NUMA_FOREIGN,
64 NUMA_INTERLEAVE_HIT,
65 NUMA_LOCAL,
66 NUMA_OTHER,
67#endif
68 NR_VM_ZONE_STAT_ITEMS };
69
70struct per_cpu_pages {
71 int count;
72 int high;
73 int batch;
74 struct list_head list;
75};
76
77struct per_cpu_pageset {
78 struct per_cpu_pages pcp[2];
79#ifdef CONFIG_SMP
80 s8 stat_threshold;
81 s8 vm_stat_diff[NR_VM_ZONE_STAT_ITEMS];
82#endif
83} ____cacheline_aligned_in_smp;
84
85#ifdef CONFIG_NUMA
86#define zone_pcp(__z, __cpu) ((__z)->pageset[(__cpu)])
87#else
88#define zone_pcp(__z, __cpu) (&(__z)->pageset[(__cpu)])
89#endif
90
91#define ZONE_DMA 0
92#define ZONE_DMA32 1
93#define ZONE_NORMAL 2
94#define ZONE_HIGHMEM 3
95
96#define MAX_NR_ZONES 4
97#define ZONES_SHIFT 2
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125#define GFP_ZONEMASK 0x07
126
127#define GFP_ZONETYPES ((GFP_ZONEMASK + 1) / 2 + 1)
128
129
130
131
132
133
134
135
136
137
138
139struct zone {
140
141 unsigned long free_pages;
142 unsigned long pages_min, pages_low, pages_high;
143
144
145
146
147
148
149
150
151 unsigned long lowmem_reserve[MAX_NR_ZONES];
152
153#ifdef CONFIG_NUMA
154
155
156
157 unsigned long min_unmapped_ratio;
158 struct per_cpu_pageset *pageset[NR_CPUS];
159#else
160 struct per_cpu_pageset pageset[NR_CPUS];
161#endif
162
163
164
165 spinlock_t lock;
166#ifdef CONFIG_MEMORY_HOTPLUG
167
168 seqlock_t span_seqlock;
169#endif
170 struct free_area free_area[MAX_ORDER];
171
172
173 ZONE_PADDING(_pad1_)
174
175
176 spinlock_t lru_lock;
177 struct list_head active_list;
178 struct list_head inactive_list;
179 unsigned long nr_scan_active;
180 unsigned long nr_scan_inactive;
181 unsigned long nr_active;
182 unsigned long nr_inactive;
183 unsigned long pages_scanned;
184 int all_unreclaimable;
185
186
187 atomic_t reclaim_in_progress;
188
189
190 atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208 int temp_priority;
209 int prev_priority;
210
211
212 ZONE_PADDING(_pad2_)
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239 wait_queue_head_t * wait_table;
240 unsigned long wait_table_hash_nr_entries;
241 unsigned long wait_table_bits;
242
243
244
245
246 struct pglist_data *zone_pgdat;
247
248 unsigned long zone_start_pfn;
249
250
251
252
253
254
255
256
257
258
259
260 unsigned long spanned_pages;
261 unsigned long present_pages;
262
263
264
265
266 char *name;
267} ____cacheline_internodealigned_in_smp;
268
269
270
271
272
273
274
275#define DEF_PRIORITY 12
276
277
278
279
280
281
282
283
284
285
286
287
288struct zonelist {
289 struct zone *zones[MAX_NUMNODES * MAX_NR_ZONES + 1];
290};
291
292
293
294
295
296
297
298
299
300
301
302
303
304struct bootmem_data;
305typedef struct pglist_data {
306 struct zone node_zones[MAX_NR_ZONES];
307 struct zonelist node_zonelists[GFP_ZONETYPES];
308 int nr_zones;
309#ifdef CONFIG_FLAT_NODE_MEM_MAP
310 struct page *node_mem_map;
311#endif
312 struct bootmem_data *bdata;
313#ifdef CONFIG_MEMORY_HOTPLUG
314
315
316
317
318
319
320
321 spinlock_t node_size_lock;
322#endif
323 unsigned long node_start_pfn;
324 unsigned long node_present_pages;
325 unsigned long node_spanned_pages;
326
327 int node_id;
328 wait_queue_head_t kswapd_wait;
329 struct task_struct *kswapd;
330 int kswapd_max_order;
331} pg_data_t;
332
333#define node_present_pages(nid) (NODE_DATA(nid)->node_present_pages)
334#define node_spanned_pages(nid) (NODE_DATA(nid)->node_spanned_pages)
335#ifdef CONFIG_FLAT_NODE_MEM_MAP
336#define pgdat_page_nr(pgdat, pagenr) ((pgdat)->node_mem_map + (pagenr))
337#else
338#define pgdat_page_nr(pgdat, pagenr) pfn_to_page((pgdat)->node_start_pfn + (pagenr))
339#endif
340#define nid_page_nr(nid, pagenr) pgdat_page_nr(NODE_DATA(nid),(pagenr))
341
342#include <linux/memory_hotplug.h>
343
344void __get_zone_counts(unsigned long *active, unsigned long *inactive,
345 unsigned long *free, struct pglist_data *pgdat);
346void get_zone_counts(unsigned long *active, unsigned long *inactive,
347 unsigned long *free);
348void build_all_zonelists(void);
349void wakeup_kswapd(struct zone *zone, int order);
350int zone_watermark_ok(struct zone *z, int order, unsigned long mark,
351 int classzone_idx, int alloc_flags);
352
353extern int init_currently_empty_zone(struct zone *zone, unsigned long start_pfn,
354 unsigned long size);
355
356#ifdef CONFIG_HAVE_MEMORY_PRESENT
357void memory_present(int nid, unsigned long start, unsigned long end);
358#else
359static inline void memory_present(int nid, unsigned long start, unsigned long end) {}
360#endif
361
362#ifdef CONFIG_NEED_NODE_MEMMAP_SIZE
363unsigned long __init node_memmap_size_bytes(int, unsigned long, unsigned long);
364#endif
365
366
367
368
369#define zone_idx(zone) ((zone) - (zone)->zone_pgdat->node_zones)
370
371static inline int populated_zone(struct zone *zone)
372{
373 return (!!zone->present_pages);
374}
375
376static inline int is_highmem_idx(int idx)
377{
378 return (idx == ZONE_HIGHMEM);
379}
380
381static inline int is_normal_idx(int idx)
382{
383 return (idx == ZONE_NORMAL);
384}
385
386
387
388
389
390
391
392static inline int is_highmem(struct zone *zone)
393{
394 return zone == zone->zone_pgdat->node_zones + ZONE_HIGHMEM;
395}
396
397static inline int is_normal(struct zone *zone)
398{
399 return zone == zone->zone_pgdat->node_zones + ZONE_NORMAL;
400}
401
402static inline int is_dma32(struct zone *zone)
403{
404 return zone == zone->zone_pgdat->node_zones + ZONE_DMA32;
405}
406
407static inline int is_dma(struct zone *zone)
408{
409 return zone == zone->zone_pgdat->node_zones + ZONE_DMA;
410}
411
412
413struct ctl_table;
414struct file;
415int min_free_kbytes_sysctl_handler(struct ctl_table *, int, struct file *,
416 void __user *, size_t *, loff_t *);
417extern int sysctl_lowmem_reserve_ratio[MAX_NR_ZONES-1];
418int lowmem_reserve_ratio_sysctl_handler(struct ctl_table *, int, struct file *,
419 void __user *, size_t *, loff_t *);
420int percpu_pagelist_fraction_sysctl_handler(struct ctl_table *, int, struct file *,
421 void __user *, size_t *, loff_t *);
422int sysctl_min_unmapped_ratio_sysctl_handler(struct ctl_table *, int,
423 struct file *, void __user *, size_t *, loff_t *);
424
425#include <linux/topology.h>
426
427#ifndef numa_node_id
428#define numa_node_id() (cpu_to_node(raw_smp_processor_id()))
429#endif
430
431#ifndef CONFIG_NEED_MULTIPLE_NODES
432
433extern struct pglist_data contig_page_data;
434#define NODE_DATA(nid) (&contig_page_data)
435#define NODE_MEM_MAP(nid) mem_map
436#define MAX_NODES_SHIFT 1
437
438#else
439
440#include <asm/mmzone.h>
441
442#endif
443
444extern struct pglist_data *first_online_pgdat(void);
445extern struct pglist_data *next_online_pgdat(struct pglist_data *pgdat);
446extern struct zone *next_zone(struct zone *zone);
447
448
449
450
451
452#define for_each_online_pgdat(pgdat) \
453 for (pgdat = first_online_pgdat(); \
454 pgdat; \
455 pgdat = next_online_pgdat(pgdat))
456
457
458
459
460
461
462
463#define for_each_zone(zone) \
464 for (zone = (first_online_pgdat())->node_zones; \
465 zone; \
466 zone = next_zone(zone))
467
468#ifdef CONFIG_SPARSEMEM
469#include <asm/sparsemem.h>
470#endif
471
472#if BITS_PER_LONG == 32
473
474
475
476
477#define FLAGS_RESERVED 9
478
479#elif BITS_PER_LONG == 64
480
481
482
483#define FLAGS_RESERVED 32
484
485#else
486
487#error BITS_PER_LONG not defined
488
489#endif
490
491#ifndef CONFIG_HAVE_ARCH_EARLY_PFN_TO_NID
492#define early_pfn_to_nid(nid) (0UL)
493#endif
494
495#ifdef CONFIG_FLATMEM
496#define pfn_to_nid(pfn) (0)
497#endif
498
499#define pfn_to_section_nr(pfn) ((pfn) >> PFN_SECTION_SHIFT)
500#define section_nr_to_pfn(sec) ((sec) << PFN_SECTION_SHIFT)
501
502#ifdef CONFIG_SPARSEMEM
503
504
505
506
507
508
509
510#define SECTIONS_SHIFT (MAX_PHYSMEM_BITS - SECTION_SIZE_BITS)
511
512#define PA_SECTION_SHIFT (SECTION_SIZE_BITS)
513#define PFN_SECTION_SHIFT (SECTION_SIZE_BITS - PAGE_SHIFT)
514
515#define NR_MEM_SECTIONS (1UL << SECTIONS_SHIFT)
516
517#define PAGES_PER_SECTION (1UL << PFN_SECTION_SHIFT)
518#define PAGE_SECTION_MASK (~(PAGES_PER_SECTION-1))
519
520#if (MAX_ORDER - 1 + PAGE_SHIFT) > SECTION_SIZE_BITS
521#error Allocator MAX_ORDER exceeds SECTION_SIZE
522#endif
523
524struct page;
525struct mem_section {
526
527
528
529
530
531
532
533
534
535
536
537
538 unsigned long section_mem_map;
539};
540
541#ifdef CONFIG_SPARSEMEM_EXTREME
542#define SECTIONS_PER_ROOT (PAGE_SIZE / sizeof (struct mem_section))
543#else
544#define SECTIONS_PER_ROOT 1
545#endif
546
547#define SECTION_NR_TO_ROOT(sec) ((sec) / SECTIONS_PER_ROOT)
548#define NR_SECTION_ROOTS (NR_MEM_SECTIONS / SECTIONS_PER_ROOT)
549#define SECTION_ROOT_MASK (SECTIONS_PER_ROOT - 1)
550
551#ifdef CONFIG_SPARSEMEM_EXTREME
552extern struct mem_section *mem_section[NR_SECTION_ROOTS];
553#else
554extern struct mem_section mem_section[NR_SECTION_ROOTS][SECTIONS_PER_ROOT];
555#endif
556
557static inline struct mem_section *__nr_to_section(unsigned long nr)
558{
559 if (!mem_section[SECTION_NR_TO_ROOT(nr)])
560 return NULL;
561 return &mem_section[SECTION_NR_TO_ROOT(nr)][nr & SECTION_ROOT_MASK];
562}
563extern int __section_nr(struct mem_section* ms);
564
565
566
567
568
569
570#define SECTION_MARKED_PRESENT (1UL<<0)
571#define SECTION_HAS_MEM_MAP (1UL<<1)
572#define SECTION_MAP_LAST_BIT (1UL<<2)
573#define SECTION_MAP_MASK (~(SECTION_MAP_LAST_BIT-1))
574#define SECTION_NID_SHIFT 2
575
576static inline struct page *__section_mem_map_addr(struct mem_section *section)
577{
578 unsigned long map = section->section_mem_map;
579 map &= SECTION_MAP_MASK;
580 return (struct page *)map;
581}
582
583static inline int valid_section(struct mem_section *section)
584{
585 return (section && (section->section_mem_map & SECTION_MARKED_PRESENT));
586}
587
588static inline int section_has_mem_map(struct mem_section *section)
589{
590 return (section && (section->section_mem_map & SECTION_HAS_MEM_MAP));
591}
592
593static inline int valid_section_nr(unsigned long nr)
594{
595 return valid_section(__nr_to_section(nr));
596}
597
598static inline struct mem_section *__pfn_to_section(unsigned long pfn)
599{
600 return __nr_to_section(pfn_to_section_nr(pfn));
601}
602
603static inline int pfn_valid(unsigned long pfn)
604{
605 if (pfn_to_section_nr(pfn) >= NR_MEM_SECTIONS)
606 return 0;
607 return valid_section(__nr_to_section(pfn_to_section_nr(pfn)));
608}
609
610
611
612
613
614
615#ifdef CONFIG_NUMA
616#define pfn_to_nid(pfn) \
617({ \
618 unsigned long __pfn_to_nid_pfn = (pfn); \
619 page_to_nid(pfn_to_page(__pfn_to_nid_pfn)); \
620})
621#else
622#define pfn_to_nid(pfn) (0)
623#endif
624
625#define early_pfn_valid(pfn) pfn_valid(pfn)
626void sparse_init(void);
627#else
628#define sparse_init() do {} while (0)
629#define sparse_index_init(_sec, _nid) do {} while (0)
630#endif
631
632#ifndef early_pfn_valid
633#define early_pfn_valid(pfn) (1)
634#endif
635
636void memory_present(int nid, unsigned long start, unsigned long end);
637unsigned long __init node_memmap_size_bytes(int, unsigned long, unsigned long);
638
639#endif
640#endif
641#endif
642