XenevaOS
Loading...
Searching...
No Matches
mmzone.h
Go to the documentation of this file.
1/* SPDX-License-Identifier: GPL-2.0 */
2#ifndef _LINUX_MMZONE_H
3#define _LINUX_MMZONE_H
4
5#ifndef __ASSEMBLY__
6#ifndef __GENERATING_BOUNDS_H
7
8#include <linux/spinlock.h>
9#include <linux/list.h>
10#include <linux/list_nulls.h>
11#include <linux/wait.h>
12#include <linux/bitops.h>
13#include <linux/cache.h>
14#include <linux/threads.h>
15#include <linux/numa.h>
16#include <linux/init.h>
17#include <linux/seqlock.h>
18#include <linux/nodemask.h>
19#include <linux/pageblock-flags.h>
20#include <linux/page-flags-layout.h>
21#include <linux/atomic.h>
22#include <linux/mm_types.h>
23#include <linux/page-flags.h>
24#include <linux/local_lock.h>
25#include <linux/zswap.h>
26#include <linux/sizes.h>
27#include <asm/page.h>
28
29/* Free memory management - zoned buddy allocator. */
30#ifndef CONFIG_ARCH_FORCE_MAX_ORDER
31#define MAX_PAGE_ORDER 10
32#else
33#define MAX_PAGE_ORDER CONFIG_ARCH_FORCE_MAX_ORDER
34#endif
35#define MAX_ORDER_NR_PAGES (1 << MAX_PAGE_ORDER)
36
37#define IS_MAX_ORDER_ALIGNED(pfn) IS_ALIGNED(pfn, MAX_ORDER_NR_PAGES)
38
39#define NR_PAGE_ORDERS (MAX_PAGE_ORDER + 1)
40
41/* Defines the order for the number of pages that have a migrate type. */
42#ifndef CONFIG_PAGE_BLOCK_MAX_ORDER
43#define PAGE_BLOCK_MAX_ORDER MAX_PAGE_ORDER
44#else
45#define PAGE_BLOCK_MAX_ORDER CONFIG_PAGE_BLOCK_MAX_ORDER
46#endif /* CONFIG_PAGE_BLOCK_MAX_ORDER */
47
48/*
49 * The MAX_PAGE_ORDER, which defines the max order of pages to be allocated
50 * by the buddy allocator, has to be larger or equal to the PAGE_BLOCK_MAX_ORDER,
51 * which defines the order for the number of pages that can have a migrate type
52 */
53#if (PAGE_BLOCK_MAX_ORDER > MAX_PAGE_ORDER)
54#error MAX_PAGE_ORDER must be >= PAGE_BLOCK_MAX_ORDER
55#endif
56
57/*
58 * PAGE_ALLOC_COSTLY_ORDER is the order at which allocations are deemed
59 * costly to service. That is between allocation orders which should
60 * coalesce naturally under reasonable reclaim pressure and those which
61 * will not.
62 */
63#define PAGE_ALLOC_COSTLY_ORDER 3
64
65#if !defined(CONFIG_HAVE_GIGANTIC_FOLIOS)
66/*
67 * We don't expect any folios that exceed buddy sizes (and consequently
68 * memory sections).
69 */
70#define MAX_FOLIO_ORDER MAX_PAGE_ORDER
71#elif defined(CONFIG_SPARSEMEM) && !defined(CONFIG_SPARSEMEM_VMEMMAP)
72/*
73 * Only pages within a single memory section are guaranteed to be
74 * contiguous. By limiting folios to a single memory section, all folio
75 * pages are guaranteed to be contiguous.
76 */
77#define MAX_FOLIO_ORDER PFN_SECTION_SHIFT
78#elif defined(CONFIG_HUGETLB_PAGE)
79/*
80 * There is no real limit on the folio size. We limit them to the maximum we
81 * currently expect (see CONFIG_HAVE_GIGANTIC_FOLIOS): with hugetlb, we expect
82 * no folios larger than 16 GiB on 64bit and 1 GiB on 32bit.
83 */
84#ifdef CONFIG_64BIT
85#define MAX_FOLIO_ORDER (ilog2(SZ_16G) - PAGE_SHIFT)
86#else
87#define MAX_FOLIO_ORDER (ilog2(SZ_1G) - PAGE_SHIFT)
88#endif
89#else
90/*
91 * Without hugetlb, gigantic folios that are bigger than a single PUD are
92 * currently impossible.
93 */
94#define MAX_FOLIO_ORDER (PUD_SHIFT - PAGE_SHIFT)
95#endif
96
97#define MAX_FOLIO_NR_PAGES (1UL << MAX_FOLIO_ORDER)
98
99/*
100 * HugeTLB Vmemmap Optimization (HVO) requires struct pages of the head page to
101 * be naturally aligned with regard to the folio size.
102 *
103 * HVO which is only active if the size of struct page is a power of 2.
104 */
105#define MAX_FOLIO_VMEMMAP_ALIGN \
106 (IS_ENABLED(CONFIG_HUGETLB_PAGE_OPTIMIZE_VMEMMAP) && \
107 is_power_of_2(sizeof(struct page)) ? \
108 MAX_FOLIO_NR_PAGES * sizeof(struct page) : 0)
109
110/*
111 * vmemmap optimization (like HVO) is only possible for page orders that fill
112 * two or more pages with struct pages.
113 */
114#define VMEMMAP_TAIL_MIN_ORDER (ilog2(2 * PAGE_SIZE / sizeof(struct page)))
115#define __NR_VMEMMAP_TAILS (MAX_FOLIO_ORDER - VMEMMAP_TAIL_MIN_ORDER + 1)
116#define NR_VMEMMAP_TAILS (__NR_VMEMMAP_TAILS > 0 ? __NR_VMEMMAP_TAILS : 0)
117
122 MIGRATE_PCPTYPES, /* the number of types on the pcp lists */
124#ifdef CONFIG_CMA
125 /*
126 * MIGRATE_CMA migration type is designed to mimic the way
127 * ZONE_MOVABLE works. Only movable pages can be allocated
128 * from MIGRATE_CMA pageblocks and page allocator never
129 * implicitly change migration type of MIGRATE_CMA pageblock.
130 *
131 * The way to use it is to change migratetype of a range of
132 * pageblocks to MIGRATE_CMA which can be done by
133 * __free_pageblock_cma() function.
134 */
135 MIGRATE_CMA,
136 __MIGRATE_TYPE_END = MIGRATE_CMA,
137#else
139#endif
140#ifdef CONFIG_MEMORY_ISOLATION
141 MIGRATE_ISOLATE, /* can't allocate from here */
142#endif
145
146/* In mm/page_alloc.c; keep in sync also with show_migration_types() there */
147extern const char * const migratetype_names[MIGRATE_TYPES];
148
149#ifdef CONFIG_CMA
150# define is_migrate_cma(migratetype) unlikely((migratetype) == MIGRATE_CMA)
151# define is_migrate_cma_page(_page) (get_pageblock_migratetype(_page) == MIGRATE_CMA)
152/*
153 * __dump_folio() in mm/debug.c passes a folio pointer to on-stack struct folio,
154 * so folio_pfn() cannot be used and pfn is needed.
155 */
156# define is_migrate_cma_folio(folio, pfn) \
157 (get_pfnblock_migratetype(&folio->page, pfn) == MIGRATE_CMA)
158#else
159# define is_migrate_cma(migratetype) false
160# define is_migrate_cma_page(_page) false
161# define is_migrate_cma_folio(folio, pfn) false
162#endif
163
164static inline bool is_migrate_movable(int mt)
165{
166 return is_migrate_cma(mt) || mt == MIGRATE_MOVABLE;
167}
168
169/*
170 * Check whether a migratetype can be merged with another migratetype.
171 *
172 * It is only mergeable when it can fall back to other migratetypes for
173 * allocation. See fallbacks[MIGRATE_TYPES][3] in page_alloc.c.
174 */
175static inline bool migratetype_is_mergeable(int mt)
176{
177 return mt < MIGRATE_PCPTYPES;
178}
179
180#define for_each_free_list(list, zone, order) \
181 for (order = 0; order < NR_PAGE_ORDERS; order++) \
182 for (unsigned int __type = 0; \
183 __type < MIGRATE_TYPES && \
184 (list = &(zone)->free_area[order].free_list[__type], 1); \
185 __type++)
186
188
189#define get_pageblock_migratetype(page) \
190 get_pfnblock_migratetype(page, page_to_pfn(page))
191
192#define folio_migratetype(folio) \
193 get_pageblock_migratetype(&folio->page)
194
195struct free_area {
197 unsigned long nr_free;
198};
199
200struct pglist_data;
201
202#ifdef CONFIG_NUMA
203enum numa_stat_item {
204 NUMA_HIT, /* allocated in intended node */
205 NUMA_MISS, /* allocated in non intended node */
206 NUMA_FOREIGN, /* was intended here, hit elsewhere */
207 NUMA_INTERLEAVE_HIT, /* interleaver preferred this zone */
208 NUMA_LOCAL, /* allocation from local node */
209 NUMA_OTHER, /* allocation from other node */
211};
212#else
213#define NR_VM_NUMA_EVENT_ITEMS 0
214#endif
215
219 NR_ZONE_LRU_BASE, /* Used only for compaction and reclaim retry */
225 NR_ZONE_WRITE_PENDING, /* Count of dirty, writeback and unstable pages */
226 NR_MLOCK, /* mlock()ed pages found and moved off LRU */
227#if IS_ENABLED(CONFIG_ZSMALLOC)
228 NR_ZSPAGES, /* allocated in zsmalloc */
229#endif
231#ifdef CONFIG_UNACCEPTED_MEMORY
232 NR_UNACCEPTED,
233#endif
235
238 NR_INACTIVE_ANON = NR_LRU_BASE, /* must match order of LRU_[IN]ACTIVE */
239 NR_ACTIVE_ANON, /* " " " " " */
240 NR_INACTIVE_FILE, /* " " " " " */
241 NR_ACTIVE_FILE, /* " " " " " */
242 NR_UNEVICTABLE, /* " " " " " */
245 NR_ISOLATED_ANON, /* Temporary isolated pages from anon lru */
246 NR_ISOLATED_FILE, /* Temporary isolated pages from file lru */
258 NR_ANON_MAPPED, /* Mapped anonymous pages */
259 NR_FILE_MAPPED, /* pagecache pages mapped into pagetables.
260 only modified from process context */
264 NR_SHMEM, /* shmem pages (included tmpfs/GEM pages) */
271 NR_VMSCAN_IMMEDIATE, /* Prioritise for reclaim when writeback ends */
272 NR_DIRTIED, /* page dirtyings since bootup */
273 NR_WRITTEN, /* page writings since bootup */
274 NR_THROTTLED_WRITTEN, /* NR_WRITTEN while reclaim throttled */
275 NR_KERNEL_MISC_RECLAIMABLE, /* reclaimable non-slab kernel pages */
276 NR_FOLL_PIN_ACQUIRED, /* via: pin_user_page(), gup flag: FOLL_PIN */
277 NR_FOLL_PIN_RELEASED, /* pages returned via unpin_user_page() */
279 NR_KERNEL_STACK_KB, /* measured in KiB */
280#if IS_ENABLED(CONFIG_SHADOW_CALL_STACK)
281 NR_KERNEL_SCS_KB, /* measured in KiB */
282#endif
283 NR_PAGETABLE, /* used for pagetables */
284 NR_SECONDARY_PAGETABLE, /* secondary pagetables, KVM & IOMMU */
285#ifdef CONFIG_IOMMU_SUPPORT
286 NR_IOMMU_PAGES, /* # of pages allocated by IOMMU */
287#endif
288#ifdef CONFIG_SWAP
289 NR_SWAPCACHE,
290#endif
291#ifdef CONFIG_NUMA_BALANCING
292 PGPROMOTE_SUCCESS, /* promote successfully */
298 PGPROMOTE_CANDIDATE,
307 PGPROMOTE_CANDIDATE_NRL,
308#endif
309 /* PGDEMOTE_*: pages demoted */
327#ifdef CONFIG_HUGETLB_PAGE
328 NR_HUGETLB,
329#endif
332 NR_GPU_ACTIVE, /* Pages assigned to GPU objects */
333 NR_GPU_RECLAIM, /* Pages in shrinkable GPU pools */
336
337/*
338 * Returns true if the item should be printed in THPs (/proc/vmstat
339 * currently prints number of anon, file and shmem THPs. But the item
340 * is charged in pages).
341 */
342static __always_inline bool vmstat_item_print_in_thp(enum node_stat_item item)
343{
344 if (!IS_ENABLED(CONFIG_TRANSPARENT_HUGEPAGE))
345 return false;
346
347 return item == NR_ANON_THPS ||
348 item == NR_FILE_THPS ||
349 item == NR_SHMEM_THPS ||
350 item == NR_SHMEM_PMDMAPPED ||
351 item == NR_FILE_PMDMAPPED;
352}
353
354/*
355 * Returns true if the value is measured in bytes (most vmstat values are
356 * measured in pages). This defines the API part, the internal representation
357 * might be different.
358 */
359static __always_inline bool vmstat_item_in_bytes(int idx)
360{
361 /*
362 * Global and per-node slab counters track slab pages.
363 * It's expected that changes are multiples of PAGE_SIZE.
364 * Internally values are stored in pages.
365 *
366 * Per-memcg and per-lruvec counters track memory, consumed
367 * by individual slab objects. These counters are actually
368 * byte-precise.
369 */
370 return (idx == NR_SLAB_RECLAIMABLE_B ||
372}
373
374/*
375 * We do arithmetic on the LRU lists in various places in the code,
376 * so it is important to keep the active lists LRU_ACTIVE higher in
377 * the array than the corresponding inactive lists, and to keep
378 * the *_FILE lists LRU_FILE higher than the corresponding _ANON lists.
379 *
380 * This has to be kept in sync with the statistics in zone_stat_item
381 * above and the descriptions in vmstat_text in mm/vmstat.c
382 */
383#define LRU_BASE 0
384#define LRU_ACTIVE 1
385#define LRU_FILE 2
386
395
403
404#define for_each_lru(lru) for (lru = 0; lru < NR_LRU_LISTS; lru++)
405
406#define for_each_evictable_lru(lru) for (lru = 0; lru <= LRU_ACTIVE_FILE; lru++)
407
408static inline bool is_file_lru(enum lru_list lru)
409{
410 return (lru == LRU_INACTIVE_FILE || lru == LRU_ACTIVE_FILE);
411}
412
413static inline bool is_active_lru(enum lru_list lru)
414{
415 return (lru == LRU_ACTIVE_ANON || lru == LRU_ACTIVE_FILE);
416}
417
418#define WORKINGSET_ANON 0
419#define WORKINGSET_FILE 1
420#define ANON_AND_FILE 2
421
423 /*
424 * An lruvec has many dirty pages backed by a congested BDI:
425 * 1. LRUVEC_CGROUP_CONGESTED is set by cgroup-level reclaim.
426 * It can be cleared by cgroup reclaim or kswapd.
427 * 2. LRUVEC_NODE_CONGESTED is set by kswapd node-level reclaim.
428 * It can only be cleared by kswapd.
429 *
430 * Essentially, kswapd can unthrottle an lruvec throttled by cgroup
431 * reclaim, but not vice versa. This only applies to the root cgroup.
432 * The goal is to prevent cgroup reclaim on the root cgroup (e.g.
433 * memory.reclaim) to unthrottle an unbalanced node (that was throttled
434 * by kswapd).
435 */
438};
439
440#endif /* !__GENERATING_BOUNDS_H */
441
442/*
443 * Evictable folios are divided into multiple generations. The youngest and the
444 * oldest generation numbers, max_seq and min_seq, are monotonically increasing.
445 * They form a sliding window of a variable size [MIN_NR_GENS, MAX_NR_GENS]. An
446 * offset within MAX_NR_GENS, i.e., gen, indexes the LRU list of the
447 * corresponding generation. The gen counter in folio->flags stores gen+1 while
448 * a folio is on one of lrugen->folios[]. Otherwise it stores 0.
449 *
450 * After a folio is faulted in, the aging needs to check the accessed bit at
451 * least twice before handing this folio over to the eviction. The first check
452 * clears the accessed bit from the initial fault; the second check makes sure
453 * this folio hasn't been used since then. This process, AKA second chance,
454 * requires a minimum of two generations, hence MIN_NR_GENS. And to maintain ABI
455 * compatibility with the active/inactive LRU, e.g., /proc/vmstat, these two
456 * generations are considered active; the rest of generations, if they exist,
457 * are considered inactive. See lru_gen_is_active().
458 *
459 * PG_active is always cleared while a folio is on one of lrugen->folios[] so
460 * that the sliding window needs not to worry about it. And it's set again when
461 * a folio considered active is isolated for non-reclaiming purposes, e.g.,
462 * migration. See lru_gen_add_folio() and lru_gen_del_folio().
463 *
464 * MAX_NR_GENS is set to 4 so that the multi-gen LRU can support twice the
465 * number of categories of the active/inactive LRU when keeping track of
466 * accesses through page tables. This requires order_base_2(MAX_NR_GENS+1) bits
467 * in folio->flags, masked by LRU_GEN_MASK.
468 */
469#define MIN_NR_GENS 2U
470#define MAX_NR_GENS 4U
471
472/*
473 * Each generation is divided into multiple tiers. A folio accessed N times
474 * through file descriptors is in tier order_base_2(N). A folio in the first
475 * tier (N=0,1) is marked by PG_referenced unless it was faulted in through page
476 * tables or read ahead. A folio in the last tier (MAX_NR_TIERS-1) is marked by
477 * PG_workingset. A folio in any other tier (1<N<5) between the first and last
478 * is marked by additional bits of LRU_REFS_WIDTH in folio->flags.
479 *
480 * In contrast to moving across generations which requires the LRU lock, moving
481 * across tiers only involves atomic operations on folio->flags and therefore
482 * has a negligible cost in the buffered access path. In the eviction path,
483 * comparisons of refaulted/(evicted+protected) from the first tier and the rest
484 * infer whether folios accessed multiple times through file descriptors are
485 * statistically hot and thus worth protecting.
486 *
487 * MAX_NR_TIERS is set to 4 so that the multi-gen LRU can support twice the
488 * number of categories of the active/inactive LRU when keeping track of
489 * accesses through file descriptors. This uses MAX_NR_TIERS-2 spare bits in
490 * folio->flags, masked by LRU_REFS_MASK.
491 */
492#define MAX_NR_TIERS 4U
493
494#ifndef __GENERATING_BOUNDS_H
495
496#define LRU_GEN_MASK ((BIT(LRU_GEN_WIDTH) - 1) << LRU_GEN_PGOFF)
497#define LRU_REFS_MASK ((BIT(LRU_REFS_WIDTH) - 1) << LRU_REFS_PGOFF)
498
499/*
500 * For folios accessed multiple times through file descriptors,
501 * lru_gen_inc_refs() sets additional bits of LRU_REFS_WIDTH in folio->flags
502 * after PG_referenced, then PG_workingset after LRU_REFS_WIDTH. After all its
503 * bits are set, i.e., LRU_REFS_FLAGS|BIT(PG_workingset), a folio is lazily
504 * promoted into the second oldest generation in the eviction path. And when
505 * folio_inc_gen() does that, it clears LRU_REFS_FLAGS so that
506 * lru_gen_inc_refs() can start over. Note that for this case, LRU_REFS_MASK is
507 * only valid when PG_referenced is set.
508 *
509 * For folios accessed multiple times through page tables, folio_update_gen()
510 * from a page table walk or lru_gen_set_refs() from a rmap walk sets
511 * PG_referenced after the accessed bit is cleared for the first time.
512 * Thereafter, those two paths set PG_workingset and promote folios to the
513 * youngest generation. Like folio_inc_gen(), folio_update_gen() also clears
514 * PG_referenced. Note that for this case, LRU_REFS_MASK is not used.
515 *
516 * For both cases above, after PG_workingset is set on a folio, it remains until
517 * this folio is either reclaimed, or "deactivated" by lru_gen_clear_refs(). It
518 * can be set again if lru_gen_test_recent() returns true upon a refault.
519 */
520#define LRU_REFS_FLAGS (LRU_REFS_MASK | BIT(PG_referenced))
521
522struct lruvec;
523struct page_vma_mapped_walk;
524
525#ifdef CONFIG_LRU_GEN
526
527enum {
528 LRU_GEN_ANON,
529 LRU_GEN_FILE,
530};
531
532enum {
533 LRU_GEN_CORE,
534 LRU_GEN_MM_WALK,
535 LRU_GEN_NONLEAF_YOUNG,
536 NR_LRU_GEN_CAPS
537};
538
539#define MIN_LRU_BATCH BITS_PER_LONG
540#define MAX_LRU_BATCH (MIN_LRU_BATCH * 64)
541
542/* whether to keep historical stats from evicted generations */
543#ifdef CONFIG_LRU_GEN_STATS
544#define NR_HIST_GENS MAX_NR_GENS
545#else
546#define NR_HIST_GENS 1U
547#endif
548
549/*
550 * The youngest generation number is stored in max_seq for both anon and file
551 * types as they are aged on an equal footing. The oldest generation numbers are
552 * stored in min_seq[] separately for anon and file types so that they can be
553 * incremented independently. Ideally min_seq[] are kept in sync when both anon
554 * and file types are evictable. However, to adapt to situations like extreme
555 * swappiness, they are allowed to be out of sync by at most
556 * MAX_NR_GENS-MIN_NR_GENS-1.
557 *
558 * The number of pages in each generation is eventually consistent and therefore
559 * can be transiently negative when reset_batch_size() is pending.
560 */
561struct lru_gen_folio {
562 /* the aging increments the youngest generation number */
563 unsigned long max_seq;
564 /* the eviction increments the oldest generation numbers */
565 unsigned long min_seq[ANON_AND_FILE];
566 /* the birth time of each generation in jiffies */
567 unsigned long timestamps[MAX_NR_GENS];
568 /* the multi-gen LRU lists, lazily sorted on eviction */
569 struct list_head folios[MAX_NR_GENS][ANON_AND_FILE][MAX_NR_ZONES];
570 /* the multi-gen LRU sizes, eventually consistent */
571 long nr_pages[MAX_NR_GENS][ANON_AND_FILE][MAX_NR_ZONES];
572 /* the exponential moving average of refaulted */
573 unsigned long avg_refaulted[ANON_AND_FILE][MAX_NR_TIERS];
574 /* the exponential moving average of evicted+protected */
575 unsigned long avg_total[ANON_AND_FILE][MAX_NR_TIERS];
576 /* can only be modified under the LRU lock */
577 unsigned long protected[NR_HIST_GENS][ANON_AND_FILE][MAX_NR_TIERS];
578 /* can be modified without holding the LRU lock */
579 atomic_long_t evicted[NR_HIST_GENS][ANON_AND_FILE][MAX_NR_TIERS];
580 atomic_long_t refaulted[NR_HIST_GENS][ANON_AND_FILE][MAX_NR_TIERS];
581 /* whether the multi-gen LRU is enabled */
582 bool enabled;
583 /* the memcg generation this lru_gen_folio belongs to */
584 u8 gen;
585 /* the list segment this lru_gen_folio belongs to */
586 u8 seg;
587 /* per-node lru_gen_folio list for global reclaim */
588 struct hlist_nulls_node list;
589};
590
591enum {
592 MM_LEAF_TOTAL, /* total leaf entries */
593 MM_LEAF_YOUNG, /* young leaf entries */
594 MM_NONLEAF_FOUND, /* non-leaf entries found in Bloom filters */
595 MM_NONLEAF_ADDED, /* non-leaf entries added to Bloom filters */
596 NR_MM_STATS
597};
598
599/* double-buffering Bloom filters */
600#define NR_BLOOM_FILTERS 2
601
602struct lru_gen_mm_state {
603 /* synced with max_seq after each iteration */
604 unsigned long seq;
605 /* where the current iteration continues after */
606 struct list_head *head;
607 /* where the last iteration ended before */
608 struct list_head *tail;
609 /* Bloom filters flip after each iteration */
610 unsigned long *filters[NR_BLOOM_FILTERS];
611 /* the mm stats for debugging */
612 unsigned long stats[NR_HIST_GENS][NR_MM_STATS];
613};
614
615struct lru_gen_mm_walk {
616 /* the lruvec under reclaim */
617 struct lruvec *lruvec;
618 /* max_seq from lru_gen_folio: can be out of date */
619 unsigned long seq;
620 /* the next address within an mm to scan */
621 unsigned long next_addr;
622 /* to batch promoted pages */
623 int nr_pages[MAX_NR_GENS][ANON_AND_FILE][MAX_NR_ZONES];
624 /* to batch the mm stats */
625 int mm_stats[NR_MM_STATS];
626 /* total batched items */
627 int batched;
628 int swappiness;
629 bool force_scan;
630};
631
632/*
633 * For each node, memcgs are divided into two generations: the old and the
634 * young. For each generation, memcgs are randomly sharded into multiple bins
635 * to improve scalability. For each bin, the hlist_nulls is virtually divided
636 * into three segments: the head, the tail and the default.
637 *
638 * An onlining memcg is added to the tail of a random bin in the old generation.
639 * The eviction starts at the head of a random bin in the old generation. The
640 * per-node memcg generation counter, whose reminder (mod MEMCG_NR_GENS) indexes
641 * the old generation, is incremented when all its bins become empty.
642 *
643 * There are four operations:
644 * 1. MEMCG_LRU_HEAD, which moves a memcg to the head of a random bin in its
645 * current generation (old or young) and updates its "seg" to "head";
646 * 2. MEMCG_LRU_TAIL, which moves a memcg to the tail of a random bin in its
647 * current generation (old or young) and updates its "seg" to "tail";
648 * 3. MEMCG_LRU_OLD, which moves a memcg to the head of a random bin in the old
649 * generation, updates its "gen" to "old" and resets its "seg" to "default";
650 * 4. MEMCG_LRU_YOUNG, which moves a memcg to the tail of a random bin in the
651 * young generation, updates its "gen" to "young" and resets its "seg" to
652 * "default".
653 *
654 * The events that trigger the above operations are:
655 * 1. Exceeding the soft limit, which triggers MEMCG_LRU_HEAD;
656 * 2. The first attempt to reclaim a memcg below low, which triggers
657 * MEMCG_LRU_TAIL;
658 * 3. The first attempt to reclaim a memcg offlined or below reclaimable size
659 * threshold, which triggers MEMCG_LRU_TAIL;
660 * 4. The second attempt to reclaim a memcg offlined or below reclaimable size
661 * threshold, which triggers MEMCG_LRU_YOUNG;
662 * 5. Attempting to reclaim a memcg below min, which triggers MEMCG_LRU_YOUNG;
663 * 6. Finishing the aging on the eviction path, which triggers MEMCG_LRU_YOUNG;
664 * 7. Offlining a memcg, which triggers MEMCG_LRU_OLD.
665 *
666 * Notes:
667 * 1. Memcg LRU only applies to global reclaim, and the round-robin incrementing
668 * of their max_seq counters ensures the eventual fairness to all eligible
669 * memcgs. For memcg reclaim, it still relies on mem_cgroup_iter().
670 * 2. There are only two valid generations: old (seq) and young (seq+1).
671 * MEMCG_NR_GENS is set to three so that when reading the generation counter
672 * locklessly, a stale value (seq-1) does not wraparound to young.
673 */
674#define MEMCG_NR_GENS 3
675#define MEMCG_NR_BINS 8
676
677struct lru_gen_memcg {
678 /* the per-node memcg generation counter */
679 unsigned long seq;
680 /* each memcg has one lru_gen_folio per node */
681 unsigned long nr_memcgs[MEMCG_NR_GENS];
682 /* per-node lru_gen_folio list for global reclaim */
683 struct hlist_nulls_head fifo[MEMCG_NR_GENS][MEMCG_NR_BINS];
684 /* protects the above */
685 spinlock_t lock;
686};
687
688void lru_gen_init_pgdat(struct pglist_data *pgdat);
689void lru_gen_init_lruvec(struct lruvec *lruvec);
690bool lru_gen_look_around(struct page_vma_mapped_walk *pvmw, unsigned int nr);
691
692void lru_gen_init_memcg(struct mem_cgroup *memcg);
693void lru_gen_exit_memcg(struct mem_cgroup *memcg);
694void lru_gen_online_memcg(struct mem_cgroup *memcg);
695void lru_gen_offline_memcg(struct mem_cgroup *memcg);
696void lru_gen_release_memcg(struct mem_cgroup *memcg);
697void lru_gen_soft_reclaim(struct mem_cgroup *memcg, int nid);
698void max_lru_gen_memcg(struct mem_cgroup *memcg, int nid);
699bool recheck_lru_gen_max_memcg(struct mem_cgroup *memcg, int nid);
700void lru_gen_reparent_memcg(struct mem_cgroup *memcg, struct mem_cgroup *parent, int nid);
701
702#else /* !CONFIG_LRU_GEN */
703
704static inline void lru_gen_init_pgdat(struct pglist_data *pgdat)
705{
706}
707
708static inline void lru_gen_init_lruvec(struct lruvec *lruvec)
709{
710}
711
712static inline bool lru_gen_look_around(struct page_vma_mapped_walk *pvmw,
713 unsigned int nr)
714{
715 return false;
716}
717
718static inline void lru_gen_init_memcg(struct mem_cgroup *memcg)
719{
720}
721
722static inline void lru_gen_exit_memcg(struct mem_cgroup *memcg)
723{
724}
725
726static inline void lru_gen_online_memcg(struct mem_cgroup *memcg)
727{
728}
729
730static inline void lru_gen_offline_memcg(struct mem_cgroup *memcg)
731{
732}
733
734static inline void lru_gen_release_memcg(struct mem_cgroup *memcg)
735{
736}
737
738static inline void lru_gen_soft_reclaim(struct mem_cgroup *memcg, int nid)
739{
740}
741
742static inline void max_lru_gen_memcg(struct mem_cgroup *memcg, int nid)
743{
744}
745
746static inline bool recheck_lru_gen_max_memcg(struct mem_cgroup *memcg, int nid)
747{
748 return true;
749}
750
751static inline
752void lru_gen_reparent_memcg(struct mem_cgroup *memcg, struct mem_cgroup *parent, int nid)
753{
754}
755
756#endif /* CONFIG_LRU_GEN */
757
758struct lruvec {
760 /* per lruvec lru_lock for memcg */
762 /*
763 * These track the cost of reclaiming one LRU - file or anon -
764 * over the other. As the observed cost of reclaiming one LRU
765 * increases, the reclaim scan balance tips toward the other.
766 */
767 unsigned long anon_cost;
768 unsigned long file_cost;
769 /* Non-resident age, driven by LRU movement */
771 /* Refaults at the time of last reclaim cycle */
772 unsigned long refaults[ANON_AND_FILE];
773 /* Various lruvec state flags (enum lruvec_flags) */
774 unsigned long flags;
775#ifdef CONFIG_LRU_GEN
776 /* evictable pages divided into generations */
777 struct lru_gen_folio lrugen;
778#ifdef CONFIG_LRU_GEN_WALKS_MMU
779 /* to concurrently iterate lru_gen_mm_list */
780 struct lru_gen_mm_state mm_state;
781#endif
782#endif /* CONFIG_LRU_GEN */
783#ifdef CONFIG_MEMCG
784 struct pglist_data *pgdat;
785#endif
787};
788
789/* Isolate for asynchronous migration */
790#define ISOLATE_ASYNC_MIGRATE ((__force isolate_mode_t)0x4)
791/* Isolate unevictable pages */
792#define ISOLATE_UNEVICTABLE ((__force isolate_mode_t)0x8)
793
794/* LRU Isolation modes. */
795typedef unsigned __bitwise isolate_mode_t;
796
804
805/*
806 * One per migratetype for each PAGE_ALLOC_COSTLY_ORDER. Two additional lists
807 * are added for THP. One PCP list is used by GPF_MOVABLE, and the other PCP list
808 * is used by GFP_UNMOVABLE and GFP_RECLAIMABLE.
809 */
810#ifdef CONFIG_TRANSPARENT_HUGEPAGE
811#define NR_PCP_THP 2
812#else
813#define NR_PCP_THP 0
814#endif
815#define NR_LOWORDER_PCP_LISTS (MIGRATE_PCPTYPES * (PAGE_ALLOC_COSTLY_ORDER + 1))
816#define NR_PCP_LISTS (NR_LOWORDER_PCP_LISTS + NR_PCP_THP)
817
818/*
819 * Flags used in pcp->flags field.
820 *
821 * PCPF_PREV_FREE_HIGH_ORDER: a high-order page is freed in the
822 * previous page freeing. To avoid to drain PCP for an accident
823 * high-order page freeing.
824 *
825 * PCPF_FREE_HIGH_BATCH: preserve "pcp->batch" pages in PCP before
826 * draining PCP for consecutive high-order pages freeing without
827 * allocation if data cache slice of CPU is large enough. To reduce
828 * zone lock contention and keep cache-hot pages reusing.
829 */
830#define PCPF_PREV_FREE_HIGH_ORDER BIT(0)
831#define PCPF_FREE_HIGH_BATCH BIT(1)
832
834 spinlock_t lock; /* Protects lists field */
835 int count; /* number of pages in the list */
836 int high; /* high watermark, emptying needed */
837 int high_min; /* min high watermark */
838 int high_max; /* max high watermark */
839 int batch; /* chunk size for buddy add/remove */
840 u8 flags; /* protected by pcp->lock */
841 u8 alloc_factor; /* batch scaling factor during allocate */
842#ifdef CONFIG_NUMA
843 u8 expire; /* When 0, remote pagesets are drained */
844#endif
845 short free_count; /* consecutive free count */
846
847 /* Lists of pages, one per migrate type stored on the pcp-lists */
850
852#ifdef CONFIG_SMP
853 s8 vm_stat_diff[NR_VM_ZONE_STAT_ITEMS];
854 s8 stat_threshold;
855#endif
856#ifdef CONFIG_NUMA
857 /*
858 * Low priority inaccurate counters that are only folded
859 * on demand. Use a large type to avoid the overhead of
860 * folding during refresh_cpu_vm_stats.
861 */
862 unsigned long vm_numa_event[NR_VM_NUMA_EVENT_ITEMS];
863#endif
864};
865
870
871#endif /* !__GENERATING_BOUNDS.H */
872
874 /*
875 * ZONE_DMA and ZONE_DMA32 are used when there are peripherals not able
876 * to DMA to all of the addressable memory (ZONE_NORMAL).
877 * On architectures where this area covers the whole 32 bit address
878 * space ZONE_DMA32 is used. ZONE_DMA is left for the ones with smaller
879 * DMA addressing constraints. This distinction is important as a 32bit
880 * DMA mask is assumed when ZONE_DMA32 is defined. Some 64-bit
881 * platforms may need both zones as they support peripherals with
882 * different DMA addressing limitations.
883 */
884#ifdef CONFIG_ZONE_DMA
885 ZONE_DMA,
886#endif
887#ifdef CONFIG_ZONE_DMA32
888 ZONE_DMA32,
889#endif
890 /*
891 * Normal addressable memory is in ZONE_NORMAL. DMA operations can be
892 * performed on pages in ZONE_NORMAL if the DMA devices support
893 * transfers to all addressable memory.
894 */
896#ifdef CONFIG_HIGHMEM
897 /*
898 * A memory area that is only addressable by the kernel through
899 * mapping portions into its own address space. This is for example
900 * used by i386 to allow the kernel to address the memory beyond
901 * 900MB. The kernel will set up special mappings (page
902 * table entries on i386) for each page that the kernel needs to
903 * access.
904 */
905 ZONE_HIGHMEM,
906#endif
907 /*
908 * ZONE_MOVABLE is similar to ZONE_NORMAL, except that it contains
909 * movable pages with few exceptional cases described below. Main use
910 * cases for ZONE_MOVABLE are to make memory offlining/unplug more
911 * likely to succeed, and to locally limit unmovable allocations - e.g.,
912 * to increase the number of THP/huge pages. Notable special cases are:
913 *
914 * 1. Pinned pages: (long-term) pinning of movable pages might
915 * essentially turn such pages unmovable. Therefore, we do not allow
916 * pinning long-term pages in ZONE_MOVABLE. When pages are pinned and
917 * faulted, they come from the right zone right away. However, it is
918 * still possible that address space already has pages in
919 * ZONE_MOVABLE at the time when pages are pinned (i.e. user has
920 * touches that memory before pinning). In such case we migrate them
921 * to a different zone. When migration fails - pinning fails.
922 * 2. memblock allocations: kernelcore/movablecore setups might create
923 * situations where ZONE_MOVABLE contains unmovable allocations
924 * after boot. Memory offlining and allocations fail early.
925 * 3. Memory holes: kernelcore/movablecore setups might create very rare
926 * situations where ZONE_MOVABLE contains memory holes after boot,
927 * for example, if we have sections that are only partially
928 * populated. Memory offlining and allocations fail early.
929 * 4. PG_hwpoison pages: while poisoned pages can be skipped during
930 * memory offlining, such pages cannot be allocated.
931 * 5. Unmovable PG_offline pages: in paravirtualized environments,
932 * hotplugged memory blocks might only partially be managed by the
933 * buddy (e.g., via XEN-balloon, Hyper-V balloon, virtio-mem). The
934 * parts not manged by the buddy are unmovable PG_offline pages. In
935 * some cases (virtio-mem), such pages can be skipped during
936 * memory offlining, however, cannot be moved/allocated. These
937 * techniques might use alloc_contig_range() to hide previously
938 * exposed pages from the buddy again (e.g., to implement some sort
939 * of memory unplug in virtio-mem).
940 * 6. ZERO_PAGE(0), kernelcore/movablecore setups might create
941 * situations where ZERO_PAGE(0) which is allocated differently
942 * on different platforms may end up in a movable zone. ZERO_PAGE(0)
943 * cannot be migrated.
944 * 7. Memory-hotplug: when using memmap_on_memory and onlining the
945 * memory to the MOVABLE zone, the vmemmap pages are also placed in
946 * such zone. Such pages cannot be really moved around as they are
947 * self-stored in the range, but they are treated as movable when
948 * the range they describe is about to be offlined.
949 *
950 * In general, no unmovable allocations that degrade memory offlining
951 * should end up in ZONE_MOVABLE. Allocators (like alloc_contig_range())
952 * have to expect that migrating pages in ZONE_MOVABLE can fail (even
953 * if has_unmovable_pages() states that there are no unmovable pages,
954 * there can be false negatives).
955 */
957#ifdef CONFIG_ZONE_DEVICE
958 ZONE_DEVICE,
959#endif
961
963
964#ifndef __GENERATING_BOUNDS_H
965
966#define ASYNC_AND_SYNC 2
967
968struct zone {
969 /* Read-mostly fields */
970
971 /* zone watermarks, access with *_wmark_pages(zone) macros */
972 unsigned long _watermark[NR_WMARK];
973 unsigned long watermark_boost;
974
976 unsigned long nr_free_highatomic;
977
978 /*
979 * We don't know if the memory that we're going to allocate will be
980 * freeable or/and it will be released eventually, so to avoid totally
981 * wasting several GB of ram we must reserve some of the lower zone
982 * memory (otherwise we risk to run OOM on the lower zones despite
983 * there being tons of freeable ram on the higher zones). This array is
984 * recalculated at runtime if the sysctl_lowmem_reserve_ratio sysctl
985 * changes.
986 */
987 long lowmem_reserve[MAX_NR_ZONES];
988
989#ifdef CONFIG_NUMA
990 int node;
991#endif
995 /*
996 * the high and batch values are copied to individual pagesets for
997 * faster access
998 */
1002
1003#ifndef CONFIG_SPARSEMEM
1004 /*
1005 * Flags for a pageblock_nr_pages block. See pageblock-flags.h.
1006 * In SPARSEMEM, this map is stored in struct mem_section
1007 */
1008 unsigned long *pageblock_flags;
1009#endif /* CONFIG_SPARSEMEM */
1010
1011 /* zone_start_pfn == zone_start_paddr >> PAGE_SHIFT */
1012 unsigned long zone_start_pfn;
1013
1014 /*
1015 * spanned_pages is the total pages spanned by the zone, including
1016 * holes, which is calculated as:
1017 * spanned_pages = zone_end_pfn - zone_start_pfn;
1018 *
1019 * present_pages is physical pages existing within the zone, which
1020 * is calculated as:
1021 * present_pages = spanned_pages - absent_pages(pages in holes);
1022 *
1023 * present_early_pages is present pages existing within the zone
1024 * located on memory available since early boot, excluding hotplugged
1025 * memory.
1026 *
1027 * managed_pages is present pages managed by the buddy system, which
1028 * is calculated as (reserved_pages includes pages allocated by the
1029 * bootmem allocator):
1030 * managed_pages = present_pages - reserved_pages;
1031 *
1032 * cma pages is present pages that are assigned for CMA use
1033 * (MIGRATE_CMA).
1034 *
1035 * So present_pages may be used by memory hotplug or memory power
1036 * management logic to figure out unmanaged pages by checking
1037 * (present_pages - managed_pages). And managed_pages should be used
1038 * by page allocator and vm scanner to calculate all kinds of watermarks
1039 * and thresholds.
1040 *
1041 * Locking rules:
1042 *
1043 * zone_start_pfn and spanned_pages are protected by span_seqlock.
1044 * It is a seqlock because it has to be read outside of zone->lock,
1045 * and it is done in the main allocator path. But, it is written
1046 * quite infrequently.
1047 *
1048 * The span_seq lock is declared along with zone->lock because it is
1049 * frequently read in proximity to zone->lock. It's good to
1050 * give them a chance of being in the same cacheline.
1051 *
1052 * Write access to present_pages at runtime should be protected by
1053 * mem_hotplug_begin/done(). Any reader who can't tolerant drift of
1054 * present_pages should use get_online_mems() to get a stable value.
1055 */
1057 unsigned long spanned_pages;
1058 unsigned long present_pages;
1059#if defined(CONFIG_MEMORY_HOTPLUG)
1060 unsigned long present_early_pages;
1061#endif
1062#ifdef CONFIG_CMA
1063 unsigned long cma_pages;
1064#endif
1065
1066 const char *name;
1067
1068#ifdef CONFIG_MEMORY_ISOLATION
1069 /*
1070 * Number of isolated pageblock. It is used to solve incorrect
1071 * freepage counting problem due to racy retrieving migratetype
1072 * of pageblock. Protected by zone->lock.
1073 */
1074 unsigned long nr_isolate_pageblock;
1075#endif
1076
1077#ifdef CONFIG_MEMORY_HOTPLUG
1078 /* see spanned/present_pages for more description */
1079 seqlock_t span_seqlock;
1080#endif
1081
1083
1084 /* Write-intensive fields used from the page allocator */
1086
1087 /* free areas of different sizes */
1089
1090#ifdef CONFIG_UNACCEPTED_MEMORY
1091 /* Pages to be accepted. All pages on the list are MAX_PAGE_ORDER */
1092 struct list_head unaccepted_pages;
1093
1094 /* To be called once the last page in the zone is accepted */
1095 struct work_struct unaccepted_cleanup;
1096#endif
1097
1098 /* zone flags, see below */
1099 unsigned long flags;
1100
1101 /* Primarily protects free_area */
1103
1104 /* Pages to be freed when next trylock succeeds */
1106
1107 /* Write-intensive fields used by compaction and vmstats. */
1109
1110 /*
1111 * When free pages are below this point, additional steps are taken
1112 * when reading the number of free pages to avoid per-cpu counter
1113 * drift allowing watermarks to be breached
1114 */
1115 unsigned long percpu_drift_mark;
1116
1117#if defined CONFIG_COMPACTION || defined CONFIG_CMA
1118 /* pfn where compaction free scanner should start */
1119 unsigned long compact_cached_free_pfn;
1120 /* pfn where compaction migration scanner should start */
1121 unsigned long compact_cached_migrate_pfn[ASYNC_AND_SYNC];
1122 unsigned long compact_init_migrate_pfn;
1123 unsigned long compact_init_free_pfn;
1124#endif
1125
1126#ifdef CONFIG_COMPACTION
1127 /*
1128 * On compaction failure, 1<<compact_defer_shift compactions
1129 * are skipped before trying again. The number attempted since
1130 * last failure is tracked with compact_considered.
1131 * compact_order_failed is the minimum compaction failed order.
1132 */
1133 unsigned int compact_considered;
1134 unsigned int compact_defer_shift;
1135 int compact_order_failed;
1136#endif
1137
1138#if defined CONFIG_COMPACTION || defined CONFIG_CMA
1139 /* Set to true when the PG_migrate_skip bits should be cleared */
1140 bool compact_blockskip_flush;
1141#endif
1142
1144
1146 /* Zone statistics */
1149#ifdef CONFIG_HUGETLB_PAGE_OPTIMIZE_VMEMMAP
1150 struct page *vmemmap_tails[NR_VMEMMAP_TAILS];
1151#endif
1153
1155 PGDAT_WRITEBACK, /* reclaim scanning has recently found
1156 * many pages under writeback
1157 */
1158 PGDAT_RECLAIM_LOCKED, /* prevents concurrent reclaim */
1159};
1160
1162 ZONE_BOOSTED_WATERMARK, /* zone recently boosted watermarks.
1163 * Cleared when kswapd is woken.
1164 */
1165 ZONE_RECLAIM_ACTIVE, /* kswapd may be scanning the zone. */
1166 ZONE_BELOW_HIGH, /* zone is below high watermark. */
1167};
1168
1169static inline unsigned long wmark_pages(const struct zone *z,
1170 enum zone_watermarks w)
1171{
1172 return z->_watermark[w] + z->watermark_boost;
1173}
1174
1175static inline unsigned long min_wmark_pages(const struct zone *z)
1176{
1177 return wmark_pages(z, WMARK_MIN);
1178}
1179
1180static inline unsigned long low_wmark_pages(const struct zone *z)
1181{
1182 return wmark_pages(z, WMARK_LOW);
1183}
1184
1185static inline unsigned long high_wmark_pages(const struct zone *z)
1186{
1187 return wmark_pages(z, WMARK_HIGH);
1188}
1189
1190static inline unsigned long promo_wmark_pages(const struct zone *z)
1191{
1192 return wmark_pages(z, WMARK_PROMO);
1193}
1194
1195static inline unsigned long zone_managed_pages(const struct zone *zone)
1196{
1197 return (unsigned long)atomic_long_read(&zone->managed_pages);
1198}
1199
1200static inline unsigned long zone_cma_pages(struct zone *zone)
1201{
1202#ifdef CONFIG_CMA
1203 return zone->cma_pages;
1204#else
1205 return 0;
1206#endif
1207}
1208
1209static inline unsigned long zone_end_pfn(const struct zone *zone)
1210{
1212}
1213
1214static inline bool zone_spans_pfn(const struct zone *zone, unsigned long pfn)
1215{
1216 return zone->zone_start_pfn <= pfn && pfn < zone_end_pfn(zone);
1217}
1218
1219static inline bool zone_is_initialized(const struct zone *zone)
1220{
1221 return zone->initialized;
1222}
1223
1224static inline bool zone_is_empty(const struct zone *zone)
1225{
1226 return zone->spanned_pages == 0;
1227}
1228
1229#ifndef BUILD_VDSO32_64
1230/*
1231 * The zone field is never updated after free_area_init_core()
1232 * sets it, so none of the operations on it need to be atomic.
1233 */
1234
1235/* Page flags: | [SECTION] | [NODE] | ZONE | [LAST_CPUPID] | ... | FLAGS | */
1236#define SECTIONS_PGOFF ((sizeof(unsigned long)*8) - SECTIONS_WIDTH)
1237#define NODES_PGOFF (SECTIONS_PGOFF - NODES_WIDTH)
1238#define ZONES_PGOFF (NODES_PGOFF - ZONES_WIDTH)
1239#define LAST_CPUPID_PGOFF (ZONES_PGOFF - LAST_CPUPID_WIDTH)
1240#define KASAN_TAG_PGOFF (LAST_CPUPID_PGOFF - KASAN_TAG_WIDTH)
1241#define LRU_GEN_PGOFF (KASAN_TAG_PGOFF - LRU_GEN_WIDTH)
1242#define LRU_REFS_PGOFF (LRU_GEN_PGOFF - LRU_REFS_WIDTH)
1243
1244/*
1245 * Define the bit shifts to access each section. For non-existent
1246 * sections we define the shift as 0; that plus a 0 mask ensures
1247 * the compiler will optimise away reference to them.
1248 */
1249#define SECTIONS_PGSHIFT (SECTIONS_PGOFF * (SECTIONS_WIDTH != 0))
1250#define NODES_PGSHIFT (NODES_PGOFF * (NODES_WIDTH != 0))
1251#define ZONES_PGSHIFT (ZONES_PGOFF * (ZONES_WIDTH != 0))
1252#define LAST_CPUPID_PGSHIFT (LAST_CPUPID_PGOFF * (LAST_CPUPID_WIDTH != 0))
1253#define KASAN_TAG_PGSHIFT (KASAN_TAG_PGOFF * (KASAN_TAG_WIDTH != 0))
1254
1255/* NODE:ZONE or SECTION:ZONE is used to ID a zone for the buddy allocator */
1256#ifdef NODE_NOT_IN_PAGE_FLAGS
1257#define ZONEID_SHIFT (SECTIONS_SHIFT + ZONES_SHIFT)
1258#define ZONEID_PGOFF ((SECTIONS_PGOFF < ZONES_PGOFF) ? \
1259 SECTIONS_PGOFF : ZONES_PGOFF)
1260#else
1261#define ZONEID_SHIFT (NODES_SHIFT + ZONES_SHIFT)
1262#define ZONEID_PGOFF ((NODES_PGOFF < ZONES_PGOFF) ? \
1263 NODES_PGOFF : ZONES_PGOFF)
1264#endif
1265
1266#define ZONEID_PGSHIFT (ZONEID_PGOFF * (ZONEID_SHIFT != 0))
1267
1268#define ZONES_MASK ((1UL << ZONES_WIDTH) - 1)
1269#define NODES_MASK ((1UL << NODES_WIDTH) - 1)
1270#define SECTIONS_MASK ((1UL << SECTIONS_WIDTH) - 1)
1271#define LAST_CPUPID_MASK ((1UL << LAST_CPUPID_SHIFT) - 1)
1272#define KASAN_TAG_MASK ((1UL << KASAN_TAG_WIDTH) - 1)
1273#define ZONEID_MASK ((1UL << ZONEID_SHIFT) - 1)
1274
1275static inline enum zone_type memdesc_zonenum(memdesc_flags_t flags)
1276{
1278 return (flags.f >> ZONES_PGSHIFT) & ZONES_MASK;
1279}
1280
1281static inline enum zone_type page_zonenum(const struct page *page)
1282{
1283 return memdesc_zonenum(page->flags);
1284}
1285
1286static inline enum zone_type folio_zonenum(const struct folio *folio)
1287{
1288 return memdesc_zonenum(folio->flags);
1289}
1290
1291#ifdef CONFIG_ZONE_DEVICE
1292static inline bool memdesc_is_zone_device(memdesc_flags_t mdf)
1293{
1294 return memdesc_zonenum(mdf) == ZONE_DEVICE;
1295}
1296
1297static inline struct dev_pagemap *page_pgmap(const struct page *page)
1298{
1299 VM_WARN_ON_ONCE_PAGE(!memdesc_is_zone_device(page->flags), page);
1300 return page_folio(page)->pgmap;
1301}
1302
1303/*
1304 * Consecutive zone device pages should not be merged into the same sgl
1305 * or bvec segment with other types of pages or if they belong to different
1306 * pgmaps. Otherwise getting the pgmap of a given segment is not possible
1307 * without scanning the entire segment. This helper returns true either if
1308 * both pages are not zone device pages or both pages are zone device pages
1309 * with the same pgmap.
1310 */
1311static inline bool zone_device_pages_have_same_pgmap(const struct page *a,
1312 const struct page *b)
1313{
1314 if (memdesc_is_zone_device(a->flags) != memdesc_is_zone_device(b->flags))
1315 return false;
1316 if (!memdesc_is_zone_device(a->flags))
1317 return true;
1318 return page_pgmap(a) == page_pgmap(b);
1319}
1320
1321extern void memmap_init_zone_device(struct zone *, unsigned long,
1322 unsigned long, struct dev_pagemap *);
1323#else
1324static inline bool memdesc_is_zone_device(memdesc_flags_t mdf)
1325{
1326 return false;
1327}
1328static inline bool zone_device_pages_have_same_pgmap(const struct page *a,
1329 const struct page *b)
1330{
1331 return true;
1332}
1333static inline struct dev_pagemap *page_pgmap(const struct page *page)
1334{
1335 return NULL;
1336}
1337#endif
1338
1339static inline bool is_zone_device_page(const struct page *page)
1340{
1341 return memdesc_is_zone_device(page->flags);
1342}
1343
1344static inline bool folio_is_zone_device(const struct folio *folio)
1345{
1346 return memdesc_is_zone_device(folio->flags);
1347}
1348
1349static inline bool is_zone_movable_page(const struct page *page)
1350{
1351 return page_zonenum(page) == ZONE_MOVABLE;
1352}
1353
1354static inline bool folio_is_zone_movable(const struct folio *folio)
1355{
1356 return folio_zonenum(folio) == ZONE_MOVABLE;
1357}
1358#endif
1359
1360/*
1361 * Return true if [start_pfn, start_pfn + nr_pages) range has a non-empty
1362 * intersection with the given zone
1363 */
1364static inline bool zone_intersects(const struct zone *zone,
1365 unsigned long start_pfn, unsigned long nr_pages)
1366{
1367 if (zone_is_empty(zone))
1368 return false;
1369 if (start_pfn >= zone_end_pfn(zone) ||
1370 start_pfn + nr_pages <= zone->zone_start_pfn)
1371 return false;
1372
1373 return true;
1374}
1375
1376/*
1377 * The "priority" of VM scanning is how much of the queues we will scan in one
1378 * go. A value of 12 for DEF_PRIORITY implies that we will scan 1/4096th of the
1379 * queues ("queue_length >> 12") during an aging round.
1380 */
1381#define DEF_PRIORITY 12
1382
1383/* Maximum number of zones on a zonelist */
1384#define MAX_ZONES_PER_ZONELIST (MAX_NUMNODES * MAX_NR_ZONES)
1385
1386enum {
1387 ZONELIST_FALLBACK, /* zonelist with fallback */
1388#ifdef CONFIG_NUMA
1389 /*
1390 * The NUMA zonelists are doubled because we need zonelists that
1391 * restrict the allocations to a single node for __GFP_THISNODE.
1392 */
1393 ZONELIST_NOFALLBACK, /* zonelist without fallback (__GFP_THISNODE) */
1394#endif
1397
1398/*
1399 * This struct contains information about a zone in a zonelist. It is stored
1400 * here to avoid dereferences into large structures and lookups of tables
1401 */
1402struct zoneref {
1403 struct zone *zone; /* Pointer to actual zone */
1404 int zone_idx; /* zone_idx(zoneref->zone) */
1405};
1406
1407/*
1408 * One allocation request operates on a zonelist. A zonelist
1409 * is a list of zones, the first one is the 'goal' of the
1410 * allocation, the other zones are fallback zones, in decreasing
1411 * priority.
1412 *
1413 * To speed the reading of the zonelist, the zonerefs contain the zone index
1414 * of the entry being read. Helper functions to access information given
1415 * a struct zoneref are
1416 *
1417 * zonelist_zone() - Return the struct zone * for an entry in _zonerefs
1418 * zonelist_zone_idx() - Return the index of the zone for an entry
1419 * zonelist_node_idx() - Return the index of the node for an entry
1420 */
1424
1425/*
1426 * The array of struct pages for flatmem.
1427 * It must be declared for SPARSEMEM as well because there are configurations
1428 * that rely on that.
1429 */
1430extern struct page *mem_map;
1431
1432#ifdef CONFIG_MEMORY_FAILURE
1433/*
1434 * Per NUMA node memory failure handling statistics.
1435 */
1436struct memory_failure_stats {
1437 /*
1438 * Number of raw pages poisoned.
1439 * Cases not accounted: memory outside kernel control, offline page,
1440 * arch-specific memory_failure (SGX), hwpoison_filter() filtered
1441 * error events, and unpoison actions from hwpoison_unpoison.
1442 */
1443 unsigned long total;
1444 /*
1445 * Recovery results of poisoned raw pages handled by memory_failure,
1446 * in sync with mf_result.
1447 * total = ignored + failed + delayed + recovered.
1448 * total * PAGE_SIZE * #nodes = /proc/meminfo/HardwareCorrupted.
1449 */
1450 unsigned long ignored;
1451 unsigned long failed;
1452 unsigned long delayed;
1453 unsigned long recovered;
1454};
1455#endif
1456
1457/*
1458 * On NUMA machines, each NUMA node would have a pg_data_t to describe
1459 * it's memory layout. On UMA machines there is a single pglist_data which
1460 * describes the whole memory.
1461 *
1462 * Memory statistics and page replacement data structures are maintained on a
1463 * per-zone basis.
1464 */
1465typedef struct pglist_data {
1466 /*
1467 * node_zones contains just the zones for THIS node. Not all of the
1468 * zones may be populated, but it is the full list. It is referenced by
1469 * this node's node_zonelists as well as other node's node_zonelists.
1470 */
1471 struct zone node_zones[MAX_NR_ZONES];
1472
1473 /*
1474 * node_zonelists contains references to all zones in all nodes.
1475 * Generally the first zones will be references to this node's
1476 * node_zones.
1477 */
1479
1480 int nr_zones; /* number of populated zones in this node */
1481#ifdef CONFIG_FLATMEM /* means !SPARSEMEM */
1482 struct page *node_mem_map;
1483#ifdef CONFIG_PAGE_EXTENSION
1484 struct page_ext *node_page_ext;
1485#endif
1486#endif
1487#if defined(CONFIG_MEMORY_HOTPLUG) || defined(CONFIG_DEFERRED_STRUCT_PAGE_INIT)
1488 /*
1489 * Must be held any time you expect node_start_pfn,
1490 * node_present_pages, node_spanned_pages or nr_zones to stay constant.
1491 * Also synchronizes pgdat->first_deferred_pfn during deferred page
1492 * init.
1493 *
1494 * pgdat_resize_lock() and pgdat_resize_unlock() are provided to
1495 * manipulate node_size_lock without checking for CONFIG_MEMORY_HOTPLUG
1496 * or CONFIG_DEFERRED_STRUCT_PAGE_INIT.
1497 *
1498 * Nests above zone->lock and zone->span_seqlock
1499 */
1500 spinlock_t node_size_lock;
1501#endif
1502 unsigned long node_start_pfn;
1503 unsigned long node_present_pages; /* total number of physical pages */
1504 unsigned long node_spanned_pages; /* total size of physical page
1505 range, including holes */
1509
1510 /* workqueues for throttling reclaim for different reasons. */
1512
1513 atomic_t nr_writeback_throttled;/* nr of writeback-throttled tasks */
1514 unsigned long nr_reclaim_start; /* nr pages written while throttled
1515 * when throttling started. */
1516#ifdef CONFIG_MEMORY_HOTPLUG
1517 struct mutex kswapd_lock;
1518#endif
1519 struct task_struct *kswapd; /* Protected by kswapd_lock */
1522
1523 atomic_t kswapd_failures; /* Number of 'reclaimed == 0' runs */
1524
1525#ifdef CONFIG_COMPACTION
1526 int kcompactd_max_order;
1527 enum zone_type kcompactd_highest_zoneidx;
1528 wait_queue_head_t kcompactd_wait;
1529 struct task_struct *kcompactd;
1530 bool proactive_compact_trigger;
1531#endif
1532 /*
1533 * This is a per-node reserve of pages that are not available
1534 * to userspace allocations.
1535 */
1536 unsigned long totalreserve_pages;
1537
1538#ifdef CONFIG_NUMA
1539 /*
1540 * node reclaim becomes active if more unmapped pages exist.
1541 */
1542 unsigned long min_unmapped_pages;
1543 unsigned long min_slab_pages;
1544#endif /* CONFIG_NUMA */
1545
1546 /* Write-intensive fields used by page reclaim */
1548
1549#ifdef CONFIG_DEFERRED_STRUCT_PAGE_INIT
1550 /*
1551 * If memory initialisation on large machines is deferred then this
1552 * is the first PFN that needs to be initialised.
1553 */
1554 unsigned long first_deferred_pfn;
1555#endif /* CONFIG_DEFERRED_STRUCT_PAGE_INIT */
1556
1557#ifdef CONFIG_NUMA_BALANCING
1558 /* start time in ms of current promote rate limit period */
1559 unsigned int nbp_rl_start;
1560 /* number of promote candidate pages at start time of current rate limit period */
1561 unsigned long nbp_rl_nr_cand;
1562 /* promote threshold in ms */
1563 unsigned int nbp_threshold;
1564 /* start time in ms of current promote threshold adjustment period */
1565 unsigned int nbp_th_start;
1566 /*
1567 * number of promote candidate pages at start time of current promote
1568 * threshold adjustment period
1569 */
1570 unsigned long nbp_th_nr_cand;
1571#endif
1572 /* Fields commonly accessed by the page reclaim scanner */
1573
1574 /*
1575 * NOTE: THIS IS UNUSED IF MEMCG IS ENABLED.
1576 *
1577 * Use mem_cgroup_lruvec() to look up lruvecs.
1578 */
1580
1581 unsigned long flags;
1582
1583#ifdef CONFIG_LRU_GEN
1584 /* kswap mm walk data */
1585 struct lru_gen_mm_walk mm_walk;
1586 /* lru_gen_folio list */
1587 struct lru_gen_memcg memcg_lru;
1588#endif
1589
1591
1592 /* Per-node vmstats */
1595#ifdef CONFIG_NUMA
1596 struct memory_tier __rcu *memtier;
1597#endif
1598#ifdef CONFIG_MEMORY_FAILURE
1599 struct memory_failure_stats mf_stats;
1600#endif
1602
1603#define node_present_pages(nid) (NODE_DATA(nid)->node_present_pages)
1604#define node_spanned_pages(nid) (NODE_DATA(nid)->node_spanned_pages)
1605
1606#define node_start_pfn(nid) (NODE_DATA(nid)->node_start_pfn)
1607#define node_end_pfn(nid) pgdat_end_pfn(NODE_DATA(nid))
1608
1609static inline unsigned long pgdat_end_pfn(pg_data_t *pgdat)
1610{
1611 return pgdat->node_start_pfn + pgdat->node_spanned_pages;
1612}
1613
1614#include <linux/memory_hotplug.h>
1615
1617bool __zone_watermark_ok(struct zone *z, unsigned int order, unsigned long mark,
1618 int highest_zoneidx, unsigned int alloc_flags,
1619 long free_pages);
1620bool zone_watermark_ok(struct zone *z, unsigned int order,
1621 unsigned long mark, int highest_zoneidx,
1622 unsigned int alloc_flags);
1623
1630
1631void wakeup_kswapd(struct zone *zone, gfp_t gfp_mask, int order,
1632 enum zone_type highest_zoneidx);
1634 unsigned int order, int highest_zoneidx);
1637
1638/*
1639 * Memory initialization context, use to differentiate memory added by
1640 * the platform statically or via memory hotplug interface.
1641 */
1646
1647extern void init_currently_empty_zone(struct zone *zone, unsigned long start_pfn,
1648 unsigned long size);
1649
1650extern void lruvec_init(struct lruvec *lruvec);
1651
1652static inline struct pglist_data *lruvec_pgdat(struct lruvec *lruvec)
1653{
1654#ifdef CONFIG_MEMCG
1655 return lruvec->pgdat;
1656#else
1657 return container_of(lruvec, struct pglist_data, __lruvec);
1658#endif
1659}
1660
1661#ifdef CONFIG_HAVE_MEMORYLESS_NODES
1662int local_memory_node(int node_id);
1663#else
1664static inline int local_memory_node(int node_id) { return node_id; };
1665#endif
1666
1667/*
1668 * zone_idx() returns 0 for the ZONE_DMA zone, 1 for the ZONE_NORMAL zone, etc.
1669 */
1670#define zone_idx(zone) ((zone) - (zone)->zone_pgdat->node_zones)
1671
1672#ifdef CONFIG_ZONE_DEVICE
1673static inline bool zone_is_zone_device(const struct zone *zone)
1674{
1675 return zone_idx(zone) == ZONE_DEVICE;
1676}
1677#else
1678static inline bool zone_is_zone_device(const struct zone *zone)
1679{
1680 return false;
1681}
1682#endif
1683
1684/*
1685 * Returns true if a zone has pages managed by the buddy allocator.
1686 * All the reclaim decisions have to use this function rather than
1687 * populated_zone(). If the whole zone is reserved then we can easily
1688 * end up with populated_zone() && !managed_zone().
1689 */
1690static inline bool managed_zone(const struct zone *zone)
1691{
1692 return zone_managed_pages(zone);
1693}
1694
1695/* Returns true if a zone has memory */
1696static inline bool populated_zone(const struct zone *zone)
1697{
1698 return zone->present_pages;
1699}
1700
1701#ifdef CONFIG_NUMA
1702static inline int zone_to_nid(const struct zone *zone)
1703{
1704 return zone->node;
1705}
1706
1707static inline void zone_set_nid(struct zone *zone, int nid)
1708{
1709 zone->node = nid;
1710}
1711#else
1712static inline int zone_to_nid(const struct zone *zone)
1713{
1714 return 0;
1715}
1716
1717static inline void zone_set_nid(struct zone *zone, int nid) {}
1718#endif
1719
1720extern int movable_zone;
1721
1722static inline int is_highmem_idx(enum zone_type idx)
1723{
1724#ifdef CONFIG_HIGHMEM
1725 return (idx == ZONE_HIGHMEM ||
1726 (idx == ZONE_MOVABLE && movable_zone == ZONE_HIGHMEM));
1727#else
1728 return 0;
1729#endif
1730}
1731
1739static inline int is_highmem(const struct zone *zone)
1740{
1741 return is_highmem_idx(zone_idx(zone));
1742}
1743
1745static inline bool has_managed_dma(void)
1746{
1747#ifdef CONFIG_ZONE_DMA
1748 return has_managed_zone(ZONE_DMA);
1749#else
1750 return false;
1751#endif
1752}
1753
1754
1755#ifndef CONFIG_NUMA
1756
1757extern struct pglist_data contig_page_data;
1758static inline struct pglist_data *NODE_DATA(int nid)
1759{
1760 return &contig_page_data;
1761}
1762
1763#else /* CONFIG_NUMA */
1764
1765#include <asm/mmzone.h>
1766
1767#endif /* !CONFIG_NUMA */
1768
1769extern struct pglist_data *first_online_pgdat(void);
1770extern struct pglist_data *next_online_pgdat(struct pglist_data *pgdat);
1771extern struct zone *next_zone(struct zone *zone);
1772
1777#define for_each_online_pgdat(pgdat) \
1778 for (pgdat = first_online_pgdat(); \
1779 pgdat; \
1780 pgdat = next_online_pgdat(pgdat))
1788#define for_each_zone(zone) \
1789 for (zone = (first_online_pgdat())->node_zones; \
1790 zone; \
1791 zone = next_zone(zone))
1792
1793#define for_each_populated_zone(zone) \
1794 for (zone = (first_online_pgdat())->node_zones; \
1795 zone; \
1796 zone = next_zone(zone)) \
1797 if (!populated_zone(zone)) \
1798 ; /* do nothing */ \
1799 else
1800
1801static inline struct zone *zonelist_zone(struct zoneref *zoneref)
1802{
1803 return zoneref->zone;
1804}
1805
1806static inline int zonelist_zone_idx(const struct zoneref *zoneref)
1807{
1808 return zoneref->zone_idx;
1809}
1810
1811static inline int zonelist_node_idx(const struct zoneref *zoneref)
1812{
1813 return zone_to_nid(zoneref->zone);
1814}
1815
1817 enum zone_type highest_zoneidx,
1818 nodemask_t *nodes);
1819
1835static __always_inline struct zoneref *next_zones_zonelist(struct zoneref *z,
1836 enum zone_type highest_zoneidx,
1838{
1839 if (likely(!nodes && zonelist_zone_idx(z) <= highest_zoneidx))
1840 return z;
1841 return __next_zones_zonelist(z, highest_zoneidx, nodes);
1842}
1843
1861static inline struct zoneref *first_zones_zonelist(struct zonelist *zonelist,
1862 enum zone_type highest_zoneidx,
1864{
1865 return next_zones_zonelist(zonelist->_zonerefs,
1866 highest_zoneidx, nodes);
1867}
1868
1880#define for_each_zone_zonelist_nodemask(zone, z, zlist, highidx, nodemask) \
1881 for (z = first_zones_zonelist(zlist, highidx, nodemask), zone = zonelist_zone(z); \
1882 zone; \
1883 z = next_zones_zonelist(++z, highidx, nodemask), \
1884 zone = zonelist_zone(z))
1885
1886#define for_next_zone_zonelist_nodemask(zone, z, highidx, nodemask) \
1887 for (zone = zonelist_zone(z); \
1888 zone; \
1889 z = next_zones_zonelist(++z, highidx, nodemask), \
1890 zone = zonelist_zone(z))
1891
1892
1902#define for_each_zone_zonelist(zone, z, zlist, highidx) \
1903 for_each_zone_zonelist_nodemask(zone, z, zlist, highidx, NULL)
1904
1905/* Whether the 'nodes' are all movable nodes */
1906static inline bool movable_only_nodes(nodemask_t *nodes)
1907{
1908 struct zonelist *zonelist;
1909 struct zoneref *z;
1910 int nid;
1911
1912 if (nodes_empty(*nodes))
1913 return false;
1914
1915 /*
1916 * We can chose arbitrary node from the nodemask to get a
1917 * zonelist as they are interlinked. We just need to find
1918 * at least one zone that can satisfy kernel allocations.
1919 */
1920 nid = first_node(*nodes);
1921 zonelist = &NODE_DATA(nid)->node_zonelists[ZONELIST_FALLBACK];
1922 z = first_zones_zonelist(zonelist, ZONE_NORMAL, nodes);
1923 return (!zonelist_zone(z)) ? true : false;
1924}
1925
1926
1927#ifdef CONFIG_SPARSEMEM
1928#include <asm/sparsemem.h>
1929#endif
1930
1931#ifdef CONFIG_FLATMEM
1932#define pfn_to_nid(pfn) (0)
1933#endif
1934
1935#ifdef CONFIG_SPARSEMEM
1936
1937/*
1938 * PA_SECTION_SHIFT physical address to/from section number
1939 * PFN_SECTION_SHIFT pfn to/from section number
1940 */
1941#define PA_SECTION_SHIFT (SECTION_SIZE_BITS)
1942#define PFN_SECTION_SHIFT (SECTION_SIZE_BITS - PAGE_SHIFT)
1943
1944#define NR_MEM_SECTIONS (1UL << SECTIONS_SHIFT)
1945
1946#define PAGES_PER_SECTION (1UL << PFN_SECTION_SHIFT)
1947#define PAGE_SECTION_MASK (~(PAGES_PER_SECTION-1))
1948
1949#define SECTION_BLOCKFLAGS_BITS \
1950 ((1UL << (PFN_SECTION_SHIFT - pageblock_order)) * NR_PAGEBLOCK_BITS)
1951
1952#if (MAX_PAGE_ORDER + PAGE_SHIFT) > SECTION_SIZE_BITS
1953#error Allocator MAX_PAGE_ORDER exceeds SECTION_SIZE
1954#endif
1955
1956static inline unsigned long pfn_to_section_nr(unsigned long pfn)
1957{
1958 return pfn >> PFN_SECTION_SHIFT;
1959}
1960static inline unsigned long section_nr_to_pfn(unsigned long sec)
1961{
1962 return sec << PFN_SECTION_SHIFT;
1963}
1964
1965#define SECTION_ALIGN_UP(pfn) (((pfn) + PAGES_PER_SECTION - 1) & PAGE_SECTION_MASK)
1966#define SECTION_ALIGN_DOWN(pfn) ((pfn) & PAGE_SECTION_MASK)
1967
1968#define SUBSECTION_SHIFT 21
1969#define SUBSECTION_SIZE (1UL << SUBSECTION_SHIFT)
1970
1971#define PFN_SUBSECTION_SHIFT (SUBSECTION_SHIFT - PAGE_SHIFT)
1972#define PAGES_PER_SUBSECTION (1UL << PFN_SUBSECTION_SHIFT)
1973#define PAGE_SUBSECTION_MASK (~(PAGES_PER_SUBSECTION-1))
1974
1975#if SUBSECTION_SHIFT > SECTION_SIZE_BITS
1976#error Subsection size exceeds section size
1977#else
1978#define SUBSECTIONS_PER_SECTION (1UL << (SECTION_SIZE_BITS - SUBSECTION_SHIFT))
1979#endif
1980
1981#define SUBSECTION_ALIGN_UP(pfn) ALIGN((pfn), PAGES_PER_SUBSECTION)
1982#define SUBSECTION_ALIGN_DOWN(pfn) ((pfn) & PAGE_SUBSECTION_MASK)
1983
1984struct mem_section_usage {
1985 struct rcu_head rcu;
1986#ifdef CONFIG_SPARSEMEM_VMEMMAP
1987 DECLARE_BITMAP(subsection_map, SUBSECTIONS_PER_SECTION);
1988#endif
1989 /* See declaration of similar field in struct zone */
1990 unsigned long pageblock_flags[0];
1991};
1992
1993struct page;
1994struct page_ext;
1995struct mem_section {
1996 /*
1997 * This is, logically, a pointer to an array of struct
1998 * pages. However, it is stored with some other magic.
1999 * (see sparse_init_one_section())
2000 *
2001 * Additionally during early boot we encode node id of
2002 * the location of the section here to guide allocation.
2003 * (see sparse.c::memory_present())
2004 *
2005 * Making it a UL at least makes someone do a cast
2006 * before using it wrong.
2007 */
2008 unsigned long section_mem_map;
2009
2010 struct mem_section_usage *usage;
2011#ifdef CONFIG_PAGE_EXTENSION
2012 /*
2013 * If SPARSEMEM, pgdat doesn't have page_ext pointer. We use
2014 * section. (see page_ext.h about this.)
2015 */
2016 struct page_ext *page_ext;
2017 unsigned long pad;
2018#endif
2019 /*
2020 * WARNING: mem_section must be a power-of-2 in size for the
2021 * calculation and use of SECTION_ROOT_MASK to make sense.
2022 */
2023};
2024
2025#ifdef CONFIG_SPARSEMEM_EXTREME
2026#define SECTIONS_PER_ROOT (PAGE_SIZE / sizeof (struct mem_section))
2027#else
2028#define SECTIONS_PER_ROOT 1
2029#endif
2030
2031#define SECTION_NR_TO_ROOT(sec) ((sec) / SECTIONS_PER_ROOT)
2032#define NR_SECTION_ROOTS DIV_ROUND_UP(NR_MEM_SECTIONS, SECTIONS_PER_ROOT)
2033#define SECTION_ROOT_MASK (SECTIONS_PER_ROOT - 1)
2034
2035#ifdef CONFIG_SPARSEMEM_EXTREME
2036extern struct mem_section **mem_section;
2037#else
2038extern struct mem_section mem_section[NR_SECTION_ROOTS][SECTIONS_PER_ROOT];
2039#endif
2040
2041static inline unsigned long *section_to_usemap(struct mem_section *ms)
2042{
2043 return ms->usage->pageblock_flags;
2044}
2045
2046static inline struct mem_section *__nr_to_section(unsigned long nr)
2047{
2048 unsigned long root = SECTION_NR_TO_ROOT(nr);
2049
2050 if (unlikely(root >= NR_SECTION_ROOTS))
2051 return NULL;
2052
2053#ifdef CONFIG_SPARSEMEM_EXTREME
2054 if (!mem_section || !mem_section[root])
2055 return NULL;
2056#endif
2057 return &mem_section[root][nr & SECTION_ROOT_MASK];
2058}
2059extern size_t mem_section_usage_size(void);
2060
2061/*
2062 * We use the lower bits of the mem_map pointer to store a little bit of
2063 * information. The pointer is calculated as mem_map - section_nr_to_pfn().
2064 * The result is aligned to the minimum alignment of the two values:
2065 *
2066 * 1. All mem_map arrays are page-aligned.
2067 * 2. section_nr_to_pfn() always clears PFN_SECTION_SHIFT lowest bits.
2068 *
2069 * We always expect a single section to cover full pages. Therefore,
2070 * we can safely assume that PFN_SECTION_SHIFT is large enough to
2071 * accommodate SECTION_MAP_LAST_BIT. We use BUILD_BUG_ON() to ensure this.
2072 */
2073enum {
2074 SECTION_MARKED_PRESENT_BIT,
2075 SECTION_HAS_MEM_MAP_BIT,
2076 SECTION_IS_ONLINE_BIT,
2077 SECTION_IS_EARLY_BIT,
2078#ifdef CONFIG_ZONE_DEVICE
2079 SECTION_TAINT_ZONE_DEVICE_BIT,
2080#endif
2081#ifdef CONFIG_SPARSEMEM_VMEMMAP_PREINIT
2082 SECTION_IS_VMEMMAP_PREINIT_BIT,
2083#endif
2084 SECTION_MAP_LAST_BIT,
2085};
2086
2087#define SECTION_MARKED_PRESENT BIT(SECTION_MARKED_PRESENT_BIT)
2088#define SECTION_HAS_MEM_MAP BIT(SECTION_HAS_MEM_MAP_BIT)
2089#define SECTION_IS_ONLINE BIT(SECTION_IS_ONLINE_BIT)
2090#define SECTION_IS_EARLY BIT(SECTION_IS_EARLY_BIT)
2091#ifdef CONFIG_ZONE_DEVICE
2092#define SECTION_TAINT_ZONE_DEVICE BIT(SECTION_TAINT_ZONE_DEVICE_BIT)
2093#endif
2094#ifdef CONFIG_SPARSEMEM_VMEMMAP_PREINIT
2095#define SECTION_IS_VMEMMAP_PREINIT BIT(SECTION_IS_VMEMMAP_PREINIT_BIT)
2096#endif
2097#define SECTION_MAP_MASK (~(BIT(SECTION_MAP_LAST_BIT) - 1))
2098#define SECTION_NID_SHIFT SECTION_MAP_LAST_BIT
2099
2100static inline struct page *__section_mem_map_addr(struct mem_section *section)
2101{
2102 unsigned long map = section->section_mem_map;
2103 map &= SECTION_MAP_MASK;
2104 return (struct page *)map;
2105}
2106
2107static inline int present_section(const struct mem_section *section)
2108{
2109 return (section && (section->section_mem_map & SECTION_MARKED_PRESENT));
2110}
2111
2112static inline int present_section_nr(unsigned long nr)
2113{
2114 return present_section(__nr_to_section(nr));
2115}
2116
2117static inline int valid_section(const struct mem_section *section)
2118{
2119 return (section && (section->section_mem_map & SECTION_HAS_MEM_MAP));
2120}
2121
2122static inline int early_section(const struct mem_section *section)
2123{
2124 return (section && (section->section_mem_map & SECTION_IS_EARLY));
2125}
2126
2127static inline int valid_section_nr(unsigned long nr)
2128{
2129 return valid_section(__nr_to_section(nr));
2130}
2131
2132static inline int online_section(const struct mem_section *section)
2133{
2134 return (section && (section->section_mem_map & SECTION_IS_ONLINE));
2135}
2136
2137#ifdef CONFIG_ZONE_DEVICE
2138static inline int online_device_section(const struct mem_section *section)
2139{
2140 unsigned long flags = SECTION_IS_ONLINE | SECTION_TAINT_ZONE_DEVICE;
2141
2142 return section && ((section->section_mem_map & flags) == flags);
2143}
2144#else
2145static inline int online_device_section(const struct mem_section *section)
2146{
2147 return 0;
2148}
2149#endif
2150
2151#ifdef CONFIG_SPARSEMEM_VMEMMAP_PREINIT
2152static inline int preinited_vmemmap_section(const struct mem_section *section)
2153{
2154 return (section &&
2155 (section->section_mem_map & SECTION_IS_VMEMMAP_PREINIT));
2156}
2157
2158void sparse_vmemmap_init_nid_early(int nid);
2159void sparse_vmemmap_init_nid_late(int nid);
2160
2161#else
2162static inline int preinited_vmemmap_section(const struct mem_section *section)
2163{
2164 return 0;
2165}
2166static inline void sparse_vmemmap_init_nid_early(int nid)
2167{
2168}
2169
2170static inline void sparse_vmemmap_init_nid_late(int nid)
2171{
2172}
2173#endif
2174
2175static inline int online_section_nr(unsigned long nr)
2176{
2177 return online_section(__nr_to_section(nr));
2178}
2179
2180#ifdef CONFIG_MEMORY_HOTPLUG
2181void online_mem_sections(unsigned long start_pfn, unsigned long end_pfn);
2182void offline_mem_sections(unsigned long start_pfn, unsigned long end_pfn);
2183#endif
2184
2185static inline struct mem_section *__pfn_to_section(unsigned long pfn)
2186{
2187 return __nr_to_section(pfn_to_section_nr(pfn));
2188}
2189
2190extern unsigned long __highest_present_section_nr;
2191
2192static inline int subsection_map_index(unsigned long pfn)
2193{
2194 return (pfn & ~(PAGE_SECTION_MASK)) / PAGES_PER_SUBSECTION;
2195}
2196
2197#ifdef CONFIG_SPARSEMEM_VMEMMAP
2198static inline int pfn_section_valid(struct mem_section *ms, unsigned long pfn)
2199{
2200 int idx = subsection_map_index(pfn);
2201 struct mem_section_usage *usage = READ_ONCE(ms->usage);
2202
2203 return usage ? test_bit(idx, usage->subsection_map) : 0;
2204}
2205
2206static inline bool pfn_section_first_valid(struct mem_section *ms, unsigned long *pfn)
2207{
2208 struct mem_section_usage *usage = READ_ONCE(ms->usage);
2209 int idx = subsection_map_index(*pfn);
2210 unsigned long bit;
2211
2212 if (!usage)
2213 return false;
2214
2215 if (test_bit(idx, usage->subsection_map))
2216 return true;
2217
2218 /* Find the next subsection that exists */
2219 bit = find_next_bit(usage->subsection_map, SUBSECTIONS_PER_SECTION, idx);
2220 if (bit == SUBSECTIONS_PER_SECTION)
2221 return false;
2222
2223 *pfn = (*pfn & PAGE_SECTION_MASK) + (bit * PAGES_PER_SUBSECTION);
2224 return true;
2225}
2226#else
2227static inline int pfn_section_valid(struct mem_section *ms, unsigned long pfn)
2228{
2229 return 1;
2230}
2231
2232static inline bool pfn_section_first_valid(struct mem_section *ms, unsigned long *pfn)
2233{
2234 return true;
2235}
2236#endif
2237
2238void sparse_init_early_section(int nid, struct page *map, unsigned long pnum,
2239 unsigned long flags);
2240
2241#ifndef CONFIG_HAVE_ARCH_PFN_VALID
2253static inline int pfn_valid(unsigned long pfn)
2254{
2255 struct mem_section *ms;
2256 int ret;
2257
2258 /*
2259 * Ensure the upper PAGE_SHIFT bits are clear in the
2260 * pfn. Else it might lead to false positives when
2261 * some of the upper bits are set, but the lower bits
2262 * match a valid pfn.
2263 */
2264 if (PHYS_PFN(PFN_PHYS(pfn)) != pfn)
2265 return 0;
2266
2267 if (pfn_to_section_nr(pfn) >= NR_MEM_SECTIONS)
2268 return 0;
2269 ms = __pfn_to_section(pfn);
2271 if (!valid_section(ms)) {
2273 return 0;
2274 }
2275 /*
2276 * Traditionally early sections always returned pfn_valid() for
2277 * the entire section-sized span.
2278 */
2279 ret = early_section(ms) || pfn_section_valid(ms, pfn);
2281
2282 return ret;
2283}
2284
2285/* Returns end_pfn or higher if no valid PFN remaining in range */
2286static inline unsigned long first_valid_pfn(unsigned long pfn, unsigned long end_pfn)
2287{
2288 unsigned long nr = pfn_to_section_nr(pfn);
2289
2291
2292 while (nr <= __highest_present_section_nr && pfn < end_pfn) {
2293 struct mem_section *ms = __pfn_to_section(pfn);
2294
2295 if (valid_section(ms) &&
2296 (early_section(ms) || pfn_section_first_valid(ms, &pfn))) {
2298 return pfn;
2299 }
2300
2301 /* Nothing left in this section? Skip to next section */
2302 nr++;
2303 pfn = section_nr_to_pfn(nr);
2304 }
2305
2307 return end_pfn;
2308}
2309
2310static inline unsigned long next_valid_pfn(unsigned long pfn, unsigned long end_pfn)
2311{
2312 pfn++;
2313
2314 if (pfn >= end_pfn)
2315 return end_pfn;
2316
2317 /*
2318 * Either every PFN within the section (or subsection for VMEMMAP) is
2319 * valid, or none of them are. So there's no point repeating the check
2320 * for every PFN; only call first_valid_pfn() again when crossing a
2321 * (sub)section boundary (i.e. !(pfn & ~PAGE_{SUB,}SECTION_MASK)).
2322 */
2323 if (pfn & ~(IS_ENABLED(CONFIG_SPARSEMEM_VMEMMAP) ?
2324 PAGE_SUBSECTION_MASK : PAGE_SECTION_MASK))
2325 return pfn;
2326
2327 return first_valid_pfn(pfn, end_pfn);
2328}
2329
2330
2331#define for_each_valid_pfn(_pfn, _start_pfn, _end_pfn) \
2332 for ((_pfn) = first_valid_pfn((_start_pfn), (_end_pfn)); \
2333 (_pfn) < (_end_pfn); \
2334 (_pfn) = next_valid_pfn((_pfn), (_end_pfn)))
2335
2336#endif
2337
2338static inline int pfn_in_present_section(unsigned long pfn)
2339{
2340 if (pfn_to_section_nr(pfn) >= NR_MEM_SECTIONS)
2341 return 0;
2342 return present_section(__pfn_to_section(pfn));
2343}
2344
2345static inline unsigned long next_present_section_nr(unsigned long section_nr)
2346{
2347 while (++section_nr <= __highest_present_section_nr) {
2348 if (present_section_nr(section_nr))
2349 return section_nr;
2350 }
2351
2352 return -1;
2353}
2354
2355#define for_each_present_section_nr(start, section_nr) \
2356 for (section_nr = next_present_section_nr(start - 1); \
2357 section_nr != -1; \
2358 section_nr = next_present_section_nr(section_nr))
2359
2360/*
2361 * These are _only_ used during initialisation, therefore they
2362 * can use __initdata ... They could have names to indicate
2363 * this restriction.
2364 */
2365#ifdef CONFIG_NUMA
2366#define pfn_to_nid(pfn) \
2367({ \
2368 unsigned long __pfn_to_nid_pfn = (pfn); \
2369 page_to_nid(pfn_to_page(__pfn_to_nid_pfn)); \
2370})
2371#else
2372#define pfn_to_nid(pfn) (0)
2373#endif
2374
2375#else
2376#define sparse_vmemmap_init_nid_early(_nid) do {} while (0)
2377#define sparse_vmemmap_init_nid_late(_nid) do {} while (0)
2378#define pfn_in_present_section pfn_valid
2379#endif /* CONFIG_SPARSEMEM */
2380
2381/*
2382 * Fallback case for when the architecture provides its own pfn_valid() but
2383 * not a corresponding for_each_valid_pfn().
2384 */
2385#ifndef for_each_valid_pfn
2386#define for_each_valid_pfn(_pfn, _start_pfn, _end_pfn) \
2387 for ((_pfn) = (_start_pfn); (_pfn) < (_end_pfn); (_pfn)++) \
2388 if (pfn_valid(_pfn))
2389#endif
2390
2391#endif /* !__GENERATING_BOUNDS.H */
2392#endif /* !__ASSEMBLY__ */
2393#endif /* _LINUX_MMZONE_H */
#define true
Definition stdbool.h:36
uint8_t flags
Definition virtio.h:0
size_t a
Definition main.cpp:156
size_t b
Definition main.cpp:156
XEProcessList * list
Definition main.cpp:27
#define NULL
Definition actypes.h:561
#define test_bit(nr, addr)
Definition bitops.h:124
#define DECLARE_BITMAP(name, bits)
Definition bitops.h:63
#define __bitwise
Definition compiler.h:57
#define likely(x)
Definition compiler.h:29
#define unlikely(x)
Definition compiler.h:30
#define __always_inline
Definition compiler_attributes.h:55
#define __rcu
Definition compiler_types.h:72
#define __percpu
Definition compiler_types.h:71
bool enabled
Definition compose3d.cpp:135
#define container_of(ptr, type, member)
Definition container_of.h:19
int map
Definition d_mode.c:31
size_t size
Definition drm_bridge.h:1299
#define IS_ENABLED(option)
Definition kconfig.h:80
#define ASSERT_EXCLUSIVE_BITS(var, mask)
Definition kcsan-checks.h:525
struct kobject * parent
Definition kobject.h:91
void int node
Definition kthread.h:31
int w
Definition layout.c:118
uint8_t u8
Definition kernel.h:14
#define READ_ONCE(x)
Definition kernel.h:605
unsigned int gfp_t
Definition kernel.h:56
int8_t s8
Definition kernel.h:18
int spinlock_t
Definition kernel.h:44
int const struct list_head const struct list_head struct list_head * head
Definition list_sort.h:13
void kswapd_clear_hopeless(pg_data_t *pgdat, enum kswapd_clear_hopeless_reason reason)
int page_group_by_mobility_disabled
void init_currently_empty_zone(struct zone *zone, unsigned long start_pfn, unsigned long size)
#define NR_VM_NUMA_EVENT_ITEMS
Definition mmzone.h:213
void kswapd_try_clear_hopeless(struct pglist_data *pgdat, unsigned int order, int highest_zoneidx)
node_stat_item
Definition mmzone.h:236
@ NR_BALLOON_PAGES
Definition mmzone.h:330
@ NR_ACTIVE_FILE
Definition mmzone.h:241
@ WORKINGSET_RESTORE_ANON
Definition mmzone.h:255
@ WORKINGSET_ACTIVATE_ANON
Definition mmzone.h:252
@ NR_GPU_RECLAIM
Definition mmzone.h:333
@ NR_FILE_THPS
Definition mmzone.h:267
@ NR_INACTIVE_FILE
Definition mmzone.h:240
@ NR_WRITTEN
Definition mmzone.h:273
@ PGDEMOTE_KHUGEPAGED
Definition mmzone.h:312
@ NR_SLAB_UNRECLAIMABLE_B
Definition mmzone.h:244
@ WORKINGSET_ACTIVATE_FILE
Definition mmzone.h:253
@ NR_FOLL_PIN_RELEASED
Definition mmzone.h:277
@ NR_DIRTIED
Definition mmzone.h:272
@ PGSCAN_DIRECT
Definition mmzone.h:321
@ NR_FILE_PMDMAPPED
Definition mmzone.h:268
@ WORKINGSET_RESTORE_BASE
Definition mmzone.h:254
@ NR_FILE_MAPPED
Definition mmzone.h:259
@ NR_KERNEL_FILE_PAGES
Definition mmzone.h:331
@ PGSTEAL_KHUGEPAGED
Definition mmzone.h:316
@ PGSCAN_KHUGEPAGED
Definition mmzone.h:322
@ NR_SHMEM_THPS
Definition mmzone.h:265
@ NR_SHMEM
Definition mmzone.h:264
@ NR_SHMEM_PMDMAPPED
Definition mmzone.h:266
@ PGREFILL
Definition mmzone.h:326
@ NR_SECONDARY_PAGETABLE
Definition mmzone.h:284
@ PGSTEAL_DIRECT
Definition mmzone.h:315
@ NR_KERNEL_STACK_KB
Definition mmzone.h:279
@ WORKINGSET_REFAULT_BASE
Definition mmzone.h:248
@ NR_VMSCAN_IMMEDIATE
Definition mmzone.h:271
@ NR_KERNEL_MISC_RECLAIMABLE
Definition mmzone.h:275
@ NR_FILE_DIRTY
Definition mmzone.h:262
@ PGSTEAL_KSWAPD
Definition mmzone.h:314
@ PGSTEAL_FILE
Definition mmzone.h:319
@ WORKINGSET_REFAULT_ANON
Definition mmzone.h:249
@ NR_ANON_MAPPED
Definition mmzone.h:258
@ WORKINGSET_REFAULT_FILE
Definition mmzone.h:250
@ PGSTEAL_ANON
Definition mmzone.h:318
@ WORKINGSET_NODES
Definition mmzone.h:247
@ PGSCAN_KSWAPD
Definition mmzone.h:320
@ PGDEMOTE_DIRECT
Definition mmzone.h:311
@ WORKINGSET_NODERECLAIM
Definition mmzone.h:257
@ NR_THROTTLED_WRITTEN
Definition mmzone.h:274
@ NR_ACTIVE_ANON
Definition mmzone.h:239
@ NR_FOLL_PIN_ACQUIRED
Definition mmzone.h:276
@ NR_INACTIVE_ANON
Definition mmzone.h:238
@ NR_WRITEBACK
Definition mmzone.h:263
@ NR_ISOLATED_ANON
Definition mmzone.h:245
@ NR_GPU_ACTIVE
Definition mmzone.h:332
@ NR_UNEVICTABLE
Definition mmzone.h:242
@ NR_VMSCAN_WRITE
Definition mmzone.h:270
@ NR_VMALLOC
Definition mmzone.h:278
@ NR_LRU_BASE
Definition mmzone.h:237
@ WORKINGSET_ACTIVATE_BASE
Definition mmzone.h:251
@ NR_PAGETABLE
Definition mmzone.h:283
@ PGSCAN_PROACTIVE
Definition mmzone.h:323
@ NR_SLAB_RECLAIMABLE_B
Definition mmzone.h:243
@ PGDEMOTE_PROACTIVE
Definition mmzone.h:313
@ PGSCAN_ANON
Definition mmzone.h:324
@ NR_ANON_THPS
Definition mmzone.h:269
@ PGDEMOTE_KSWAPD
Definition mmzone.h:310
@ PGSTEAL_PROACTIVE
Definition mmzone.h:317
@ NR_VM_NODE_STAT_ITEMS
Definition mmzone.h:334
@ PGSCAN_FILE
Definition mmzone.h:325
@ WORKINGSET_RESTORE_FILE
Definition mmzone.h:256
@ NR_ISOLATED_FILE
Definition mmzone.h:246
@ NR_FILE_PAGES
Definition mmzone.h:261
zone_type
Definition mmzone.h:873
@ ZONE_MOVABLE
Definition mmzone.h:956
@ __MAX_NR_ZONES
Definition mmzone.h:960
@ ZONE_NORMAL
Definition mmzone.h:895
bool zone_watermark_ok(struct zone *z, unsigned int order, unsigned long mark, int highest_zoneidx, unsigned int alloc_flags)
#define MAX_NR_GENS
Definition mmzone.h:470
kswapd_clear_hopeless_reason
Definition mmzone.h:1624
@ KSWAPD_CLEAR_HOPELESS_KSWAPD
Definition mmzone.h:1626
@ KSWAPD_CLEAR_HOPELESS_OTHER
Definition mmzone.h:1625
@ KSWAPD_CLEAR_HOPELESS_PCP
Definition mmzone.h:1628
@ KSWAPD_CLEAR_HOPELESS_DIRECT
Definition mmzone.h:1627
bool __zone_watermark_ok(struct zone *z, unsigned int order, unsigned long mark, int highest_zoneidx, unsigned int alloc_flags, long free_pages)
#define zone_idx(zone)
Definition mmzone.h:1670
void wakeup_kswapd(struct zone *zone, gfp_t gfp_mask, int order, enum zone_type highest_zoneidx)
#define NR_VMEMMAP_TAILS
Definition mmzone.h:116
struct pglist_data * first_online_pgdat(void)
zone_watermarks
Definition mmzone.h:797
@ WMARK_LOW
Definition mmzone.h:799
@ WMARK_MIN
Definition mmzone.h:798
@ NR_WMARK
Definition mmzone.h:802
@ WMARK_HIGH
Definition mmzone.h:800
@ WMARK_PROMO
Definition mmzone.h:801
struct page * mem_map
#define MAX_NR_TIERS
Definition mmzone.h:492
@ MAX_ZONELISTS
Definition mmzone.h:1395
@ ZONELIST_FALLBACK
Definition mmzone.h:1387
meminit_context
Definition mmzone.h:1642
@ MEMINIT_EARLY
Definition mmzone.h:1643
@ MEMINIT_HOTPLUG
Definition mmzone.h:1644
unsigned __bitwise isolate_mode_t
Definition mmzone.h:795
struct pglist_data * next_online_pgdat(struct pglist_data *pgdat)
#define ZONES_MASK
Definition mmzone.h:1268
void build_all_zonelists(pg_data_t *pgdat)
struct zoneref * __next_zones_zonelist(struct zoneref *z, enum zone_type highest_zoneidx, nodemask_t *nodes)
#define ASYNC_AND_SYNC
Definition mmzone.h:966
#define is_migrate_cma(migratetype)
Definition mmzone.h:159
#define MAX_ZONES_PER_ZONELIST
Definition mmzone.h:1384
#define LRU_FILE
Definition mmzone.h:385
#define sparse_vmemmap_init_nid_early(_nid)
Definition mmzone.h:2376
#define ZONES_PGSHIFT
Definition mmzone.h:1251
#define NR_PCP_LISTS
Definition mmzone.h:816
lruvec_flags
Definition mmzone.h:422
@ LRUVEC_NODE_CONGESTED
Definition mmzone.h:437
@ LRUVEC_CGROUP_CONGESTED
Definition mmzone.h:436
lru_list
Definition mmzone.h:387
@ LRU_INACTIVE_FILE
Definition mmzone.h:390
@ LRU_UNEVICTABLE
Definition mmzone.h:392
@ LRU_ACTIVE_FILE
Definition mmzone.h:391
@ NR_LRU_LISTS
Definition mmzone.h:393
@ LRU_INACTIVE_ANON
Definition mmzone.h:388
@ LRU_ACTIVE_ANON
Definition mmzone.h:389
void lruvec_init(struct lruvec *lruvec)
int movable_zone
zone_flags
Definition mmzone.h:1161
@ ZONE_RECLAIM_ACTIVE
Definition mmzone.h:1165
@ ZONE_BOOSTED_WATERMARK
Definition mmzone.h:1162
@ ZONE_BELOW_HIGH
Definition mmzone.h:1166
const char *const migratetype_names[MIGRATE_TYPES]
#define sparse_vmemmap_init_nid_late(_nid)
Definition mmzone.h:2377
bool has_managed_zone(enum zone_type zone)
struct zone ____cacheline_internodealigned_in_smp
zone_stat_item
Definition mmzone.h:216
@ NR_ZONE_ACTIVE_ANON
Definition mmzone.h:221
@ NR_ZONE_UNEVICTABLE
Definition mmzone.h:224
@ NR_ZONE_LRU_BASE
Definition mmzone.h:219
@ NR_FREE_PAGES
Definition mmzone.h:217
@ NR_FREE_CMA_PAGES
Definition mmzone.h:230
@ NR_ZONE_INACTIVE_ANON
Definition mmzone.h:220
@ NR_ZONE_INACTIVE_FILE
Definition mmzone.h:222
@ NR_ZONE_ACTIVE_FILE
Definition mmzone.h:223
@ NR_ZONE_WRITE_PENDING
Definition mmzone.h:225
@ NR_MLOCK
Definition mmzone.h:226
@ NR_FREE_PAGES_BLOCKS
Definition mmzone.h:218
@ NR_VM_ZONE_STAT_ITEMS
Definition mmzone.h:234
struct pglist_data pg_data_t
#define LRU_ACTIVE
Definition mmzone.h:384
struct pglist_data contig_page_data
#define NR_PAGE_ORDERS
Definition mmzone.h:39
bool kswapd_test_hopeless(pg_data_t *pgdat)
pgdat_flags
Definition mmzone.h:1154
@ PGDAT_RECLAIM_LOCKED
Definition mmzone.h:1158
@ PGDAT_WRITEBACK
Definition mmzone.h:1155
#define ANON_AND_FILE
Definition mmzone.h:420
struct zone * next_zone(struct zone *zone)
migratetype
Definition mmzone.h:118
@ MIGRATE_UNMOVABLE
Definition mmzone.h:119
@ MIGRATE_RECLAIMABLE
Definition mmzone.h:121
@ MIGRATE_PCPTYPES
Definition mmzone.h:122
@ MIGRATE_HIGHATOMIC
Definition mmzone.h:123
@ MIGRATE_TYPES
Definition mmzone.h:143
@ __MIGRATE_TYPE_END
Definition mmzone.h:138
@ MIGRATE_MOVABLE
Definition mmzone.h:120
#define LRU_BASE
Definition mmzone.h:383
vmscan_throttle_state
Definition mmzone.h:396
@ NR_VMSCAN_THROTTLE
Definition mmzone.h:401
@ VMSCAN_THROTTLE_NOPROGRESS
Definition mmzone.h:399
@ VMSCAN_THROTTLE_CONGESTED
Definition mmzone.h:400
@ VMSCAN_THROTTLE_WRITEBACK
Definition mmzone.h:397
@ VMSCAN_THROTTLE_ISOLATED
Definition mmzone.h:398
struct per_cpu_pages ____cacheline_aligned_in_smp
#define pfn_in_present_section
Definition mmzone.h:2378
#define nodes_empty(src)
Definition nodemask.h:229
#define first_node(src)
Definition nodemask.h:250
node_t * nodes
Definition p_setup.c:64
#define rcu_read_unlock_sched()
Definition rcupdate.h:35
#define rcu_read_lock_sched()
Definition rcupdate.h:34
struct seqlock seqlock_t
Definition seqlock_types.h:108
Definition atomic.h:211
Definition atomic.h:31
Definition mm_types.h:16
unsigned long flags
Definition mm_types.h:17
Definition mmzone.h:195
unsigned long nr_free
Definition mmzone.h:197
struct list_head free_list[MIGRATE_TYPES]
Definition mmzone.h:196
Definition list_nulls.h:21
Definition list_nulls.h:25
Definition list.h:11
Definition llist.h:46
Definition mmzone.h:758
atomic_long_t nonresident_age
Definition mmzone.h:770
unsigned long flags
Definition mmzone.h:774
unsigned long file_cost
Definition mmzone.h:768
struct zswap_lruvec_state zswap_lruvec_state
Definition mmzone.h:786
unsigned long refaults[ANON_AND_FILE]
Definition mmzone.h:772
spinlock_t lru_lock
Definition mmzone.h:761
unsigned long anon_cost
Definition mmzone.h:767
struct list_head lists[NR_LRU_LISTS]
Definition mmzone.h:759
Definition mutex.h:59
Definition nodemask_types.h:17
Definition pagemap.h:38
Definition mmzone.h:866
s8 stat_threshold
Definition mmzone.h:867
s8 vm_node_stat_diff[NR_VM_NODE_STAT_ITEMS]
Definition mmzone.h:868
Definition mmzone.h:833
short free_count
Definition mmzone.h:845
int batch
Definition mmzone.h:839
int high
Definition mmzone.h:836
u8 flags
Definition mmzone.h:840
int high_min
Definition mmzone.h:837
spinlock_t lock
Definition mmzone.h:834
int count
Definition mmzone.h:835
int high_max
Definition mmzone.h:838
struct list_head lists[NR_PCP_LISTS]
Definition mmzone.h:848
u8 alloc_factor
Definition mmzone.h:841
Definition mmzone.h:851
Definition mmzone.h:1465
int kswapd_order
Definition mmzone.h:1520
CACHELINE_PADDING(_pad1_)
enum zone_type kswapd_highest_zoneidx
Definition mmzone.h:1521
atomic_t nr_writeback_throttled
Definition mmzone.h:1513
struct zone node_zones[MAX_NR_ZONES]
Definition mmzone.h:1471
CACHELINE_PADDING(_pad2_)
struct lruvec __lruvec
Definition mmzone.h:1579
int nr_zones
Definition mmzone.h:1480
wait_queue_head_t pfmemalloc_wait
Definition mmzone.h:1508
wait_queue_head_t kswapd_wait
Definition mmzone.h:1507
unsigned long node_present_pages
Definition mmzone.h:1503
struct per_cpu_nodestat __percpu * per_cpu_nodestats
Definition mmzone.h:1593
struct zonelist node_zonelists[MAX_ZONELISTS]
Definition mmzone.h:1478
unsigned long node_start_pfn
Definition mmzone.h:1502
atomic_t kswapd_failures
Definition mmzone.h:1523
unsigned long nr_reclaim_start
Definition mmzone.h:1514
atomic_long_t vm_stat[NR_VM_NODE_STAT_ITEMS]
Definition mmzone.h:1594
struct task_struct * kswapd
Definition mmzone.h:1519
unsigned long totalreserve_pages
Definition mmzone.h:1536
wait_queue_head_t reclaim_wait[NR_VMSCAN_THROTTLE]
Definition mmzone.h:1511
unsigned long flags
Definition mmzone.h:1581
unsigned long node_spanned_pages
Definition mmzone.h:1504
int node_id
Definition mmzone.h:1506
Definition rcupdate.h:18
Definition sched.h:121
Definition wait.h:75
Definition workqueue.h:44
Definition mmzone.h:968
unsigned long nr_reserved_highatomic
Definition mmzone.h:975
unsigned long spanned_pages
Definition mmzone.h:1057
struct per_cpu_pages __percpu * per_cpu_pageset
Definition mmzone.h:993
const char * name
Definition mmzone.h:1066
unsigned long nr_free_highatomic
Definition mmzone.h:976
unsigned long _watermark[NR_WMARK]
Definition mmzone.h:972
CACHELINE_PADDING(_pad3_)
atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS]
Definition mmzone.h:1147
int initialized
Definition mmzone.h:1082
int pageset_high_min
Definition mmzone.h:999
unsigned long watermark_boost
Definition mmzone.h:973
atomic_long_t managed_pages
Definition mmzone.h:1056
int pageset_batch
Definition mmzone.h:1001
unsigned long flags
Definition mmzone.h:1099
bool contiguous
Definition mmzone.h:1143
struct per_cpu_zonestat __percpu * per_cpu_zonestats
Definition mmzone.h:994
struct pglist_data * zone_pgdat
Definition mmzone.h:992
unsigned long zone_start_pfn
Definition mmzone.h:1012
CACHELINE_PADDING(_pad1_)
spinlock_t lock
Definition mmzone.h:1102
atomic_long_t vm_numa_event[NR_VM_NUMA_EVENT_ITEMS]
Definition mmzone.h:1148
struct llist_head trylock_free_pages
Definition mmzone.h:1105
int pageset_high_max
Definition mmzone.h:1000
long lowmem_reserve[MAX_NR_ZONES]
Definition mmzone.h:987
unsigned long present_pages
Definition mmzone.h:1058
CACHELINE_PADDING(_pad2_)
unsigned long percpu_drift_mark
Definition mmzone.h:1115
unsigned long * pageblock_flags
Definition mmzone.h:1008
Definition mmzone.h:1421
struct zoneref _zonerefs[MAX_ZONES_PER_ZONELIST+1]
Definition mmzone.h:1422
Definition mmzone.h:1402
int zone_idx
Definition mmzone.h:1404
struct zone * zone
Definition mmzone.h:1403
TTY * root
Definition tty.cpp:47