mmzone.h 36 KB

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