page-flags.h 36 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. /*
  3. * Macros for manipulating and testing page->flags
  4. */
  5. #ifndef PAGE_FLAGS_H
  6. #define PAGE_FLAGS_H
  7. #include <linux/types.h>
  8. #include <linux/bug.h>
  9. #include <linux/mmdebug.h>
  10. #ifndef __GENERATING_BOUNDS_H
  11. #include <linux/mm_types.h>
  12. #include <generated/bounds.h>
  13. #endif /* !__GENERATING_BOUNDS_H */
  14. /*
  15. * Various page->flags bits:
  16. *
  17. * PG_reserved is set for special pages. The "struct page" of such a page
  18. * should in general not be touched (e.g. set dirty) except by its owner.
  19. * Pages marked as PG_reserved include:
  20. * - Pages part of the kernel image (including vDSO) and similar (e.g. BIOS,
  21. * initrd, HW tables)
  22. * - Pages reserved or allocated early during boot (before the page allocator
  23. * was initialized). This includes (depending on the architecture) the
  24. * initial vmemmap, initial page tables, crashkernel, elfcorehdr, and much
  25. * much more. Once (if ever) freed, PG_reserved is cleared and they will
  26. * be given to the page allocator.
  27. * - Pages falling into physical memory gaps - not IORESOURCE_SYSRAM. Trying
  28. * to read/write these pages might end badly. Don't touch!
  29. * - The zero page(s)
  30. * - Pages not added to the page allocator when onlining a section because
  31. * they were excluded via the online_page_callback() or because they are
  32. * PG_hwpoison.
  33. * - Pages allocated in the context of kexec/kdump (loaded kernel image,
  34. * control pages, vmcoreinfo)
  35. * - MMIO/DMA pages. Some architectures don't allow to ioremap pages that are
  36. * not marked PG_reserved (as they might be in use by somebody else who does
  37. * not respect the caching strategy).
  38. * - Pages part of an offline section (struct pages of offline sections should
  39. * not be trusted as they will be initialized when first onlined).
  40. * - MCA pages on ia64
  41. * - Pages holding CPU notes for POWER Firmware Assisted Dump
  42. * - Device memory (e.g. PMEM, DAX, HMM)
  43. * Some PG_reserved pages will be excluded from the hibernation image.
  44. * PG_reserved does in general not hinder anybody from dumping or swapping
  45. * and is no longer required for remap_pfn_range(). ioremap might require it.
  46. * Consequently, PG_reserved for a page mapped into user space can indicate
  47. * the zero page, the vDSO, MMIO pages or device memory.
  48. *
  49. * The PG_private bitflag is set on pagecache pages if they contain filesystem
  50. * specific data (which is normally at page->private). It can be used by
  51. * private allocations for its own usage.
  52. *
  53. * During initiation of disk I/O, PG_locked is set. This bit is set before I/O
  54. * and cleared when writeback _starts_ or when read _completes_. PG_writeback
  55. * is set before writeback starts and cleared when it finishes.
  56. *
  57. * PG_locked also pins a page in pagecache, and blocks truncation of the file
  58. * while it is held.
  59. *
  60. * page_waitqueue(page) is a wait queue of all tasks waiting for the page
  61. * to become unlocked.
  62. *
  63. * PG_swapbacked is set when a page uses swap as a backing storage. This are
  64. * usually PageAnon or shmem pages but please note that even anonymous pages
  65. * might lose their PG_swapbacked flag when they simply can be dropped (e.g. as
  66. * a result of MADV_FREE).
  67. *
  68. * PG_referenced, PG_reclaim are used for page reclaim for anonymous and
  69. * file-backed pagecache (see mm/vmscan.c).
  70. *
  71. * PG_error is set to indicate that an I/O error occurred on this page.
  72. *
  73. * PG_arch_1 is an architecture specific page state bit. The generic code
  74. * guarantees that this bit is cleared for a page when it first is entered into
  75. * the page cache.
  76. *
  77. * PG_hwpoison indicates that a page got corrupted in hardware and contains
  78. * data with incorrect ECC bits that triggered a machine check. Accessing is
  79. * not safe since it may cause another machine check. Don't touch!
  80. */
  81. /*
  82. * Don't use the pageflags directly. Use the PageFoo macros.
  83. *
  84. * The page flags field is split into two parts, the main flags area
  85. * which extends from the low bits upwards, and the fields area which
  86. * extends from the high bits downwards.
  87. *
  88. * | FIELD | ... | FLAGS |
  89. * N-1 ^ 0
  90. * (NR_PAGEFLAGS)
  91. *
  92. * The fields area is reserved for fields mapping zone, node (for NUMA) and
  93. * SPARSEMEM section (for variants of SPARSEMEM that require section ids like
  94. * SPARSEMEM_EXTREME with !SPARSEMEM_VMEMMAP).
  95. */
  96. enum pageflags {
  97. PG_locked, /* Page is locked. Don't touch. */
  98. PG_referenced,
  99. PG_uptodate,
  100. PG_dirty,
  101. PG_lru,
  102. PG_active,
  103. PG_workingset,
  104. PG_waiters, /* Page has waiters, check its waitqueue. Must be bit #7 and in the same byte as "PG_locked" */
  105. PG_error,
  106. PG_slab,
  107. PG_owner_priv_1, /* Owner use. If pagecache, fs may use*/
  108. PG_arch_1,
  109. PG_reserved,
  110. PG_private, /* If pagecache, has fs-private data */
  111. PG_private_2, /* If pagecache, has fs aux data */
  112. PG_writeback, /* Page is under writeback */
  113. PG_head, /* A head page */
  114. PG_mappedtodisk, /* Has blocks allocated on-disk */
  115. PG_reclaim, /* To be reclaimed asap */
  116. PG_swapbacked, /* Page is backed by RAM/swap */
  117. PG_unevictable, /* Page is "unevictable" */
  118. #ifdef CONFIG_MMU
  119. PG_mlocked, /* Page is vma mlocked */
  120. #endif
  121. #ifdef CONFIG_ARCH_USES_PG_UNCACHED
  122. PG_uncached, /* Page has been mapped as uncached */
  123. #endif
  124. #ifdef CONFIG_MEMORY_FAILURE
  125. PG_hwpoison, /* hardware poisoned page. Don't touch */
  126. #endif
  127. #if defined(CONFIG_PAGE_IDLE_FLAG) && defined(CONFIG_64BIT)
  128. PG_young,
  129. PG_idle,
  130. #endif
  131. #ifdef CONFIG_64BIT
  132. PG_arch_2,
  133. #endif
  134. #ifdef CONFIG_KASAN_HW_TAGS
  135. PG_skip_kasan_poison,
  136. #endif
  137. __NR_PAGEFLAGS,
  138. PG_readahead = PG_reclaim,
  139. /*
  140. * Depending on the way an anonymous folio can be mapped into a page
  141. * table (e.g., single PMD/PUD/CONT of the head page vs. PTE-mapped
  142. * THP), PG_anon_exclusive may be set only for the head page or for
  143. * tail pages of an anonymous folio. For now, we only expect it to be
  144. * set on tail pages for PTE-mapped THP.
  145. */
  146. PG_anon_exclusive = PG_mappedtodisk,
  147. /* Filesystems */
  148. PG_checked = PG_owner_priv_1,
  149. /* SwapBacked */
  150. PG_swapcache = PG_owner_priv_1, /* Swap page: swp_entry_t in private */
  151. /* Two page bits are conscripted by FS-Cache to maintain local caching
  152. * state. These bits are set on pages belonging to the netfs's inodes
  153. * when those inodes are being locally cached.
  154. */
  155. PG_fscache = PG_private_2, /* page backed by cache */
  156. /* XEN */
  157. /* Pinned in Xen as a read-only pagetable page. */
  158. PG_pinned = PG_owner_priv_1,
  159. /* Pinned as part of domain save (see xen_mm_pin_all()). */
  160. PG_savepinned = PG_dirty,
  161. /* Has a grant mapping of another (foreign) domain's page. */
  162. PG_foreign = PG_owner_priv_1,
  163. /* Remapped by swiotlb-xen. */
  164. PG_xen_remapped = PG_owner_priv_1,
  165. /* SLOB */
  166. PG_slob_free = PG_private,
  167. /* Compound pages. Stored in first tail page's flags */
  168. PG_double_map = PG_workingset,
  169. #ifdef CONFIG_MEMORY_FAILURE
  170. /*
  171. * Compound pages. Stored in first tail page's flags.
  172. * Indicates that at least one subpage is hwpoisoned in the
  173. * THP.
  174. */
  175. PG_has_hwpoisoned = PG_error,
  176. #endif
  177. /* non-lru isolated movable page */
  178. PG_isolated = PG_reclaim,
  179. /* Only valid for buddy pages. Used to track pages that are reported */
  180. PG_reported = PG_uptodate,
  181. #ifdef CONFIG_MEMORY_HOTPLUG
  182. /* For self-hosted memmap pages */
  183. PG_vmemmap_self_hosted = PG_owner_priv_1,
  184. #endif
  185. };
  186. #define PAGEFLAGS_MASK ((1UL << NR_PAGEFLAGS) - 1)
  187. #ifndef __GENERATING_BOUNDS_H
  188. #ifdef CONFIG_HUGETLB_PAGE_OPTIMIZE_VMEMMAP
  189. DECLARE_STATIC_KEY_FALSE(hugetlb_optimize_vmemmap_key);
  190. /*
  191. * Return the real head page struct iff the @page is a fake head page, otherwise
  192. * return the @page itself. See Documentation/mm/vmemmap_dedup.rst.
  193. */
  194. static __always_inline const struct page *page_fixed_fake_head(const struct page *page)
  195. {
  196. if (!static_branch_unlikely(&hugetlb_optimize_vmemmap_key))
  197. return page;
  198. /*
  199. * Only addresses aligned with PAGE_SIZE of struct page may be fake head
  200. * struct page. The alignment check aims to avoid access the fields (
  201. * e.g. compound_head) of the @page[1]. It can avoid touch a (possibly)
  202. * cold cacheline in some cases.
  203. */
  204. if (IS_ALIGNED((unsigned long)page, PAGE_SIZE) &&
  205. test_bit(PG_head, &page->flags)) {
  206. /*
  207. * We can safely access the field of the @page[1] with PG_head
  208. * because the @page is a compound page composed with at least
  209. * two contiguous pages.
  210. */
  211. unsigned long head = READ_ONCE(page[1].compound_head);
  212. if (likely(head & 1))
  213. return (const struct page *)(head - 1);
  214. }
  215. return page;
  216. }
  217. #else
  218. static inline const struct page *page_fixed_fake_head(const struct page *page)
  219. {
  220. return page;
  221. }
  222. #endif
  223. static __always_inline int page_is_fake_head(struct page *page)
  224. {
  225. return page_fixed_fake_head(page) != page;
  226. }
  227. static inline unsigned long _compound_head(const struct page *page)
  228. {
  229. unsigned long head = READ_ONCE(page->compound_head);
  230. if (unlikely(head & 1))
  231. return head - 1;
  232. return (unsigned long)page_fixed_fake_head(page);
  233. }
  234. #define compound_head(page) ((typeof(page))_compound_head(page))
  235. /**
  236. * page_folio - Converts from page to folio.
  237. * @p: The page.
  238. *
  239. * Every page is part of a folio. This function cannot be called on a
  240. * NULL pointer.
  241. *
  242. * Context: No reference, nor lock is required on @page. If the caller
  243. * does not hold a reference, this call may race with a folio split, so
  244. * it should re-check the folio still contains this page after gaining
  245. * a reference on the folio.
  246. * Return: The folio which contains this page.
  247. */
  248. #define page_folio(p) (_Generic((p), \
  249. const struct page *: (const struct folio *)_compound_head(p), \
  250. struct page *: (struct folio *)_compound_head(p)))
  251. /**
  252. * folio_page - Return a page from a folio.
  253. * @folio: The folio.
  254. * @n: The page number to return.
  255. *
  256. * @n is relative to the start of the folio. This function does not
  257. * check that the page number lies within @folio; the caller is presumed
  258. * to have a reference to the page.
  259. */
  260. #define folio_page(folio, n) nth_page(&(folio)->page, n)
  261. static __always_inline int PageTail(struct page *page)
  262. {
  263. return READ_ONCE(page->compound_head) & 1 || page_is_fake_head(page);
  264. }
  265. static __always_inline int PageCompound(struct page *page)
  266. {
  267. return test_bit(PG_head, &page->flags) ||
  268. READ_ONCE(page->compound_head) & 1;
  269. }
  270. #define PAGE_POISON_PATTERN -1l
  271. static inline int PagePoisoned(const struct page *page)
  272. {
  273. return READ_ONCE(page->flags) == PAGE_POISON_PATTERN;
  274. }
  275. #ifdef CONFIG_DEBUG_VM
  276. void page_init_poison(struct page *page, size_t size);
  277. #else
  278. static inline void page_init_poison(struct page *page, size_t size)
  279. {
  280. }
  281. #endif
  282. static unsigned long *folio_flags(struct folio *folio, unsigned n)
  283. {
  284. struct page *page = &folio->page;
  285. VM_BUG_ON_PGFLAGS(PageTail(page), page);
  286. VM_BUG_ON_PGFLAGS(n > 0 && !test_bit(PG_head, &page->flags), page);
  287. return &page[n].flags;
  288. }
  289. /*
  290. * Page flags policies wrt compound pages
  291. *
  292. * PF_POISONED_CHECK
  293. * check if this struct page poisoned/uninitialized
  294. *
  295. * PF_ANY:
  296. * the page flag is relevant for small, head and tail pages.
  297. *
  298. * PF_HEAD:
  299. * for compound page all operations related to the page flag applied to
  300. * head page.
  301. *
  302. * PF_ONLY_HEAD:
  303. * for compound page, callers only ever operate on the head page.
  304. *
  305. * PF_NO_TAIL:
  306. * modifications of the page flag must be done on small or head pages,
  307. * checks can be done on tail pages too.
  308. *
  309. * PF_NO_COMPOUND:
  310. * the page flag is not relevant for compound pages.
  311. *
  312. * PF_SECOND:
  313. * the page flag is stored in the first tail page.
  314. */
  315. #define PF_POISONED_CHECK(page) ({ \
  316. VM_BUG_ON_PGFLAGS(PagePoisoned(page), page); \
  317. page; })
  318. #define PF_ANY(page, enforce) PF_POISONED_CHECK(page)
  319. #define PF_HEAD(page, enforce) PF_POISONED_CHECK(compound_head(page))
  320. #define PF_ONLY_HEAD(page, enforce) ({ \
  321. VM_BUG_ON_PGFLAGS(PageTail(page), page); \
  322. PF_POISONED_CHECK(page); })
  323. #define PF_NO_TAIL(page, enforce) ({ \
  324. VM_BUG_ON_PGFLAGS(enforce && PageTail(page), page); \
  325. PF_POISONED_CHECK(compound_head(page)); })
  326. #define PF_NO_COMPOUND(page, enforce) ({ \
  327. VM_BUG_ON_PGFLAGS(enforce && PageCompound(page), page); \
  328. PF_POISONED_CHECK(page); })
  329. #define PF_SECOND(page, enforce) ({ \
  330. VM_BUG_ON_PGFLAGS(!PageHead(page), page); \
  331. PF_POISONED_CHECK(&page[1]); })
  332. /* Which page is the flag stored in */
  333. #define FOLIO_PF_ANY 0
  334. #define FOLIO_PF_HEAD 0
  335. #define FOLIO_PF_ONLY_HEAD 0
  336. #define FOLIO_PF_NO_TAIL 0
  337. #define FOLIO_PF_NO_COMPOUND 0
  338. #define FOLIO_PF_SECOND 1
  339. /*
  340. * Macros to create function definitions for page flags
  341. */
  342. #define TESTPAGEFLAG(uname, lname, policy) \
  343. static __always_inline bool folio_test_##lname(struct folio *folio) \
  344. { return test_bit(PG_##lname, folio_flags(folio, FOLIO_##policy)); } \
  345. static __always_inline int Page##uname(struct page *page) \
  346. { return test_bit(PG_##lname, &policy(page, 0)->flags); }
  347. #define SETPAGEFLAG(uname, lname, policy) \
  348. static __always_inline \
  349. void folio_set_##lname(struct folio *folio) \
  350. { set_bit(PG_##lname, folio_flags(folio, FOLIO_##policy)); } \
  351. static __always_inline void SetPage##uname(struct page *page) \
  352. { set_bit(PG_##lname, &policy(page, 1)->flags); }
  353. #define CLEARPAGEFLAG(uname, lname, policy) \
  354. static __always_inline \
  355. void folio_clear_##lname(struct folio *folio) \
  356. { clear_bit(PG_##lname, folio_flags(folio, FOLIO_##policy)); } \
  357. static __always_inline void ClearPage##uname(struct page *page) \
  358. { clear_bit(PG_##lname, &policy(page, 1)->flags); }
  359. #define __SETPAGEFLAG(uname, lname, policy) \
  360. static __always_inline \
  361. void __folio_set_##lname(struct folio *folio) \
  362. { __set_bit(PG_##lname, folio_flags(folio, FOLIO_##policy)); } \
  363. static __always_inline void __SetPage##uname(struct page *page) \
  364. { __set_bit(PG_##lname, &policy(page, 1)->flags); }
  365. #define __CLEARPAGEFLAG(uname, lname, policy) \
  366. static __always_inline \
  367. void __folio_clear_##lname(struct folio *folio) \
  368. { __clear_bit(PG_##lname, folio_flags(folio, FOLIO_##policy)); } \
  369. static __always_inline void __ClearPage##uname(struct page *page) \
  370. { __clear_bit(PG_##lname, &policy(page, 1)->flags); }
  371. #define TESTSETFLAG(uname, lname, policy) \
  372. static __always_inline \
  373. bool folio_test_set_##lname(struct folio *folio) \
  374. { return test_and_set_bit(PG_##lname, folio_flags(folio, FOLIO_##policy)); } \
  375. static __always_inline int TestSetPage##uname(struct page *page) \
  376. { return test_and_set_bit(PG_##lname, &policy(page, 1)->flags); }
  377. #define TESTCLEARFLAG(uname, lname, policy) \
  378. static __always_inline \
  379. bool folio_test_clear_##lname(struct folio *folio) \
  380. { return test_and_clear_bit(PG_##lname, folio_flags(folio, FOLIO_##policy)); } \
  381. static __always_inline int TestClearPage##uname(struct page *page) \
  382. { return test_and_clear_bit(PG_##lname, &policy(page, 1)->flags); }
  383. #define PAGEFLAG(uname, lname, policy) \
  384. TESTPAGEFLAG(uname, lname, policy) \
  385. SETPAGEFLAG(uname, lname, policy) \
  386. CLEARPAGEFLAG(uname, lname, policy)
  387. #define __PAGEFLAG(uname, lname, policy) \
  388. TESTPAGEFLAG(uname, lname, policy) \
  389. __SETPAGEFLAG(uname, lname, policy) \
  390. __CLEARPAGEFLAG(uname, lname, policy)
  391. #define TESTSCFLAG(uname, lname, policy) \
  392. TESTSETFLAG(uname, lname, policy) \
  393. TESTCLEARFLAG(uname, lname, policy)
  394. #define TESTPAGEFLAG_FALSE(uname, lname) \
  395. static inline bool folio_test_##lname(const struct folio *folio) { return false; } \
  396. static inline int Page##uname(const struct page *page) { return 0; }
  397. #define SETPAGEFLAG_NOOP(uname, lname) \
  398. static inline void folio_set_##lname(struct folio *folio) { } \
  399. static inline void SetPage##uname(struct page *page) { }
  400. #define CLEARPAGEFLAG_NOOP(uname, lname) \
  401. static inline void folio_clear_##lname(struct folio *folio) { } \
  402. static inline void ClearPage##uname(struct page *page) { }
  403. #define __CLEARPAGEFLAG_NOOP(uname, lname) \
  404. static inline void __folio_clear_##lname(struct folio *folio) { } \
  405. static inline void __ClearPage##uname(struct page *page) { }
  406. #define TESTSETFLAG_FALSE(uname, lname) \
  407. static inline bool folio_test_set_##lname(struct folio *folio) \
  408. { return 0; } \
  409. static inline int TestSetPage##uname(struct page *page) { return 0; }
  410. #define TESTCLEARFLAG_FALSE(uname, lname) \
  411. static inline bool folio_test_clear_##lname(struct folio *folio) \
  412. { return 0; } \
  413. static inline int TestClearPage##uname(struct page *page) { return 0; }
  414. #define PAGEFLAG_FALSE(uname, lname) TESTPAGEFLAG_FALSE(uname, lname) \
  415. SETPAGEFLAG_NOOP(uname, lname) CLEARPAGEFLAG_NOOP(uname, lname)
  416. #define TESTSCFLAG_FALSE(uname, lname) \
  417. TESTSETFLAG_FALSE(uname, lname) TESTCLEARFLAG_FALSE(uname, lname)
  418. __PAGEFLAG(Locked, locked, PF_NO_TAIL)
  419. PAGEFLAG(Waiters, waiters, PF_ONLY_HEAD)
  420. PAGEFLAG(Error, error, PF_NO_TAIL) TESTCLEARFLAG(Error, error, PF_NO_TAIL)
  421. PAGEFLAG(Referenced, referenced, PF_HEAD)
  422. TESTCLEARFLAG(Referenced, referenced, PF_HEAD)
  423. __SETPAGEFLAG(Referenced, referenced, PF_HEAD)
  424. PAGEFLAG(Dirty, dirty, PF_HEAD) TESTSCFLAG(Dirty, dirty, PF_HEAD)
  425. __CLEARPAGEFLAG(Dirty, dirty, PF_HEAD)
  426. PAGEFLAG(LRU, lru, PF_HEAD) __CLEARPAGEFLAG(LRU, lru, PF_HEAD)
  427. TESTCLEARFLAG(LRU, lru, PF_HEAD)
  428. PAGEFLAG(Active, active, PF_HEAD) __CLEARPAGEFLAG(Active, active, PF_HEAD)
  429. TESTCLEARFLAG(Active, active, PF_HEAD)
  430. PAGEFLAG(Workingset, workingset, PF_HEAD)
  431. TESTCLEARFLAG(Workingset, workingset, PF_HEAD)
  432. __PAGEFLAG(Slab, slab, PF_NO_TAIL)
  433. __PAGEFLAG(SlobFree, slob_free, PF_NO_TAIL)
  434. PAGEFLAG(Checked, checked, PF_NO_COMPOUND) /* Used by some filesystems */
  435. /* Xen */
  436. PAGEFLAG(Pinned, pinned, PF_NO_COMPOUND)
  437. TESTSCFLAG(Pinned, pinned, PF_NO_COMPOUND)
  438. PAGEFLAG(SavePinned, savepinned, PF_NO_COMPOUND);
  439. PAGEFLAG(Foreign, foreign, PF_NO_COMPOUND);
  440. PAGEFLAG(XenRemapped, xen_remapped, PF_NO_COMPOUND)
  441. TESTCLEARFLAG(XenRemapped, xen_remapped, PF_NO_COMPOUND)
  442. PAGEFLAG(Reserved, reserved, PF_NO_COMPOUND)
  443. __CLEARPAGEFLAG(Reserved, reserved, PF_NO_COMPOUND)
  444. __SETPAGEFLAG(Reserved, reserved, PF_NO_COMPOUND)
  445. PAGEFLAG(SwapBacked, swapbacked, PF_NO_TAIL)
  446. __CLEARPAGEFLAG(SwapBacked, swapbacked, PF_NO_TAIL)
  447. __SETPAGEFLAG(SwapBacked, swapbacked, PF_NO_TAIL)
  448. /*
  449. * Private page markings that may be used by the filesystem that owns the page
  450. * for its own purposes.
  451. * - PG_private and PG_private_2 cause release_folio() and co to be invoked
  452. */
  453. PAGEFLAG(Private, private, PF_ANY)
  454. PAGEFLAG(Private2, private_2, PF_ANY) TESTSCFLAG(Private2, private_2, PF_ANY)
  455. PAGEFLAG(OwnerPriv1, owner_priv_1, PF_ANY)
  456. TESTCLEARFLAG(OwnerPriv1, owner_priv_1, PF_ANY)
  457. /*
  458. * Only test-and-set exist for PG_writeback. The unconditional operators are
  459. * risky: they bypass page accounting.
  460. */
  461. TESTPAGEFLAG(Writeback, writeback, PF_NO_TAIL)
  462. TESTSCFLAG(Writeback, writeback, PF_NO_TAIL)
  463. PAGEFLAG(MappedToDisk, mappedtodisk, PF_NO_TAIL)
  464. /* PG_readahead is only used for reads; PG_reclaim is only for writes */
  465. PAGEFLAG(Reclaim, reclaim, PF_NO_TAIL)
  466. TESTCLEARFLAG(Reclaim, reclaim, PF_NO_TAIL)
  467. PAGEFLAG(Readahead, readahead, PF_NO_COMPOUND)
  468. TESTCLEARFLAG(Readahead, readahead, PF_NO_COMPOUND)
  469. #ifdef CONFIG_HIGHMEM
  470. /*
  471. * Must use a macro here due to header dependency issues. page_zone() is not
  472. * available at this point.
  473. */
  474. #define PageHighMem(__p) is_highmem_idx(page_zonenum(__p))
  475. #else
  476. PAGEFLAG_FALSE(HighMem, highmem)
  477. #endif
  478. #ifdef CONFIG_SWAP
  479. static __always_inline bool folio_test_swapcache(struct folio *folio)
  480. {
  481. return folio_test_swapbacked(folio) &&
  482. test_bit(PG_swapcache, folio_flags(folio, 0));
  483. }
  484. static __always_inline bool PageSwapCache(struct page *page)
  485. {
  486. return folio_test_swapcache(page_folio(page));
  487. }
  488. SETPAGEFLAG(SwapCache, swapcache, PF_NO_TAIL)
  489. CLEARPAGEFLAG(SwapCache, swapcache, PF_NO_TAIL)
  490. #else
  491. PAGEFLAG_FALSE(SwapCache, swapcache)
  492. #endif
  493. PAGEFLAG(Unevictable, unevictable, PF_HEAD)
  494. __CLEARPAGEFLAG(Unevictable, unevictable, PF_HEAD)
  495. TESTCLEARFLAG(Unevictable, unevictable, PF_HEAD)
  496. #ifdef CONFIG_MMU
  497. PAGEFLAG(Mlocked, mlocked, PF_NO_TAIL)
  498. __CLEARPAGEFLAG(Mlocked, mlocked, PF_NO_TAIL)
  499. TESTSCFLAG(Mlocked, mlocked, PF_NO_TAIL)
  500. #else
  501. PAGEFLAG_FALSE(Mlocked, mlocked) __CLEARPAGEFLAG_NOOP(Mlocked, mlocked)
  502. TESTSCFLAG_FALSE(Mlocked, mlocked)
  503. #endif
  504. #ifdef CONFIG_ARCH_USES_PG_UNCACHED
  505. PAGEFLAG(Uncached, uncached, PF_NO_COMPOUND)
  506. #else
  507. PAGEFLAG_FALSE(Uncached, uncached)
  508. #endif
  509. #ifdef CONFIG_MEMORY_FAILURE
  510. PAGEFLAG(HWPoison, hwpoison, PF_ANY)
  511. TESTSCFLAG(HWPoison, hwpoison, PF_ANY)
  512. #define __PG_HWPOISON (1UL << PG_hwpoison)
  513. #define MAGIC_HWPOISON 0x48575053U /* HWPS */
  514. extern void SetPageHWPoisonTakenOff(struct page *page);
  515. extern void ClearPageHWPoisonTakenOff(struct page *page);
  516. extern bool take_page_off_buddy(struct page *page);
  517. extern bool put_page_back_buddy(struct page *page);
  518. #else
  519. PAGEFLAG_FALSE(HWPoison, hwpoison)
  520. #define __PG_HWPOISON 0
  521. #endif
  522. #if defined(CONFIG_PAGE_IDLE_FLAG) && defined(CONFIG_64BIT)
  523. TESTPAGEFLAG(Young, young, PF_ANY)
  524. SETPAGEFLAG(Young, young, PF_ANY)
  525. TESTCLEARFLAG(Young, young, PF_ANY)
  526. PAGEFLAG(Idle, idle, PF_ANY)
  527. #endif
  528. #ifdef CONFIG_KASAN_HW_TAGS
  529. PAGEFLAG(SkipKASanPoison, skip_kasan_poison, PF_HEAD)
  530. #else
  531. PAGEFLAG_FALSE(SkipKASanPoison, skip_kasan_poison)
  532. #endif
  533. /*
  534. * PageReported() is used to track reported free pages within the Buddy
  535. * allocator. We can use the non-atomic version of the test and set
  536. * operations as both should be shielded with the zone lock to prevent
  537. * any possible races on the setting or clearing of the bit.
  538. */
  539. __PAGEFLAG(Reported, reported, PF_NO_COMPOUND)
  540. #ifdef CONFIG_MEMORY_HOTPLUG
  541. PAGEFLAG(VmemmapSelfHosted, vmemmap_self_hosted, PF_ANY)
  542. #else
  543. PAGEFLAG_FALSE(VmemmapSelfHosted, vmemmap_self_hosted)
  544. #endif
  545. /*
  546. * On an anonymous page mapped into a user virtual memory area,
  547. * page->mapping points to its anon_vma, not to a struct address_space;
  548. * with the PAGE_MAPPING_ANON bit set to distinguish it. See rmap.h.
  549. *
  550. * On an anonymous page in a VM_MERGEABLE area, if CONFIG_KSM is enabled,
  551. * the PAGE_MAPPING_MOVABLE bit may be set along with the PAGE_MAPPING_ANON
  552. * bit; and then page->mapping points, not to an anon_vma, but to a private
  553. * structure which KSM associates with that merged page. See ksm.h.
  554. *
  555. * PAGE_MAPPING_KSM without PAGE_MAPPING_ANON is used for non-lru movable
  556. * page and then page->mapping points to a struct movable_operations.
  557. *
  558. * Please note that, confusingly, "page_mapping" refers to the inode
  559. * address_space which maps the page from disk; whereas "page_mapped"
  560. * refers to user virtual address space into which the page is mapped.
  561. *
  562. * For slab pages, since slab reuses the bits in struct page to store its
  563. * internal states, the page->mapping does not exist as such, nor do these
  564. * flags below. So in order to avoid testing non-existent bits, please
  565. * make sure that PageSlab(page) actually evaluates to false before calling
  566. * the following functions (e.g., PageAnon). See mm/slab.h.
  567. */
  568. #define PAGE_MAPPING_ANON 0x1
  569. #define PAGE_MAPPING_MOVABLE 0x2
  570. #define PAGE_MAPPING_KSM (PAGE_MAPPING_ANON | PAGE_MAPPING_MOVABLE)
  571. #define PAGE_MAPPING_FLAGS (PAGE_MAPPING_ANON | PAGE_MAPPING_MOVABLE)
  572. /*
  573. * Different with flags above, this flag is used only for fsdax mode. It
  574. * indicates that this page->mapping is now under reflink case.
  575. */
  576. #define PAGE_MAPPING_DAX_COW 0x1
  577. static __always_inline bool folio_mapping_flags(struct folio *folio)
  578. {
  579. return ((unsigned long)folio->mapping & PAGE_MAPPING_FLAGS) != 0;
  580. }
  581. static __always_inline int PageMappingFlags(struct page *page)
  582. {
  583. return ((unsigned long)page->mapping & PAGE_MAPPING_FLAGS) != 0;
  584. }
  585. static __always_inline bool folio_test_anon(struct folio *folio)
  586. {
  587. return ((unsigned long)folio->mapping & PAGE_MAPPING_ANON) != 0;
  588. }
  589. static __always_inline bool PageAnon(struct page *page)
  590. {
  591. return folio_test_anon(page_folio(page));
  592. }
  593. static __always_inline bool __folio_test_movable(const struct folio *folio)
  594. {
  595. return ((unsigned long)folio->mapping & PAGE_MAPPING_FLAGS) ==
  596. PAGE_MAPPING_MOVABLE;
  597. }
  598. static __always_inline int __PageMovable(struct page *page)
  599. {
  600. return ((unsigned long)page->mapping & PAGE_MAPPING_FLAGS) ==
  601. PAGE_MAPPING_MOVABLE;
  602. }
  603. #ifdef CONFIG_KSM
  604. /*
  605. * A KSM page is one of those write-protected "shared pages" or "merged pages"
  606. * which KSM maps into multiple mms, wherever identical anonymous page content
  607. * is found in VM_MERGEABLE vmas. It's a PageAnon page, pointing not to any
  608. * anon_vma, but to that page's node of the stable tree.
  609. */
  610. static __always_inline bool folio_test_ksm(struct folio *folio)
  611. {
  612. return ((unsigned long)folio->mapping & PAGE_MAPPING_FLAGS) ==
  613. PAGE_MAPPING_KSM;
  614. }
  615. static __always_inline bool PageKsm(struct page *page)
  616. {
  617. return folio_test_ksm(page_folio(page));
  618. }
  619. #else
  620. TESTPAGEFLAG_FALSE(Ksm, ksm)
  621. #endif
  622. u64 stable_page_flags(struct page *page);
  623. /**
  624. * folio_test_uptodate - Is this folio up to date?
  625. * @folio: The folio.
  626. *
  627. * The uptodate flag is set on a folio when every byte in the folio is
  628. * at least as new as the corresponding bytes on storage. Anonymous
  629. * and CoW folios are always uptodate. If the folio is not uptodate,
  630. * some of the bytes in it may be; see the is_partially_uptodate()
  631. * address_space operation.
  632. */
  633. static inline bool folio_test_uptodate(struct folio *folio)
  634. {
  635. bool ret = test_bit(PG_uptodate, folio_flags(folio, 0));
  636. /*
  637. * Must ensure that the data we read out of the folio is loaded
  638. * _after_ we've loaded folio->flags to check the uptodate bit.
  639. * We can skip the barrier if the folio is not uptodate, because
  640. * we wouldn't be reading anything from it.
  641. *
  642. * See folio_mark_uptodate() for the other side of the story.
  643. */
  644. if (ret)
  645. smp_rmb();
  646. return ret;
  647. }
  648. static inline int PageUptodate(struct page *page)
  649. {
  650. return folio_test_uptodate(page_folio(page));
  651. }
  652. static __always_inline void __folio_mark_uptodate(struct folio *folio)
  653. {
  654. smp_wmb();
  655. __set_bit(PG_uptodate, folio_flags(folio, 0));
  656. }
  657. static __always_inline void folio_mark_uptodate(struct folio *folio)
  658. {
  659. /*
  660. * Memory barrier must be issued before setting the PG_uptodate bit,
  661. * so that all previous stores issued in order to bring the folio
  662. * uptodate are actually visible before folio_test_uptodate becomes true.
  663. */
  664. smp_wmb();
  665. set_bit(PG_uptodate, folio_flags(folio, 0));
  666. }
  667. static __always_inline void __SetPageUptodate(struct page *page)
  668. {
  669. __folio_mark_uptodate((struct folio *)page);
  670. }
  671. static __always_inline void SetPageUptodate(struct page *page)
  672. {
  673. folio_mark_uptodate((struct folio *)page);
  674. }
  675. CLEARPAGEFLAG(Uptodate, uptodate, PF_NO_TAIL)
  676. bool __folio_start_writeback(struct folio *folio, bool keep_write);
  677. bool set_page_writeback(struct page *page);
  678. #define folio_start_writeback(folio) \
  679. __folio_start_writeback(folio, false)
  680. #define folio_start_writeback_keepwrite(folio) \
  681. __folio_start_writeback(folio, true)
  682. static inline void set_page_writeback_keepwrite(struct page *page)
  683. {
  684. folio_start_writeback_keepwrite(page_folio(page));
  685. }
  686. static inline bool test_set_page_writeback(struct page *page)
  687. {
  688. return set_page_writeback(page);
  689. }
  690. static __always_inline bool folio_test_head(struct folio *folio)
  691. {
  692. return test_bit(PG_head, folio_flags(folio, FOLIO_PF_ANY));
  693. }
  694. static __always_inline int PageHead(struct page *page)
  695. {
  696. PF_POISONED_CHECK(page);
  697. return test_bit(PG_head, &page->flags) && !page_is_fake_head(page);
  698. }
  699. __SETPAGEFLAG(Head, head, PF_ANY)
  700. __CLEARPAGEFLAG(Head, head, PF_ANY)
  701. CLEARPAGEFLAG(Head, head, PF_ANY)
  702. /**
  703. * folio_test_large() - Does this folio contain more than one page?
  704. * @folio: The folio to test.
  705. *
  706. * Return: True if the folio is larger than one page.
  707. */
  708. static inline bool folio_test_large(struct folio *folio)
  709. {
  710. return folio_test_head(folio);
  711. }
  712. static __always_inline void set_compound_head(struct page *page, struct page *head)
  713. {
  714. WRITE_ONCE(page->compound_head, (unsigned long)head + 1);
  715. }
  716. static __always_inline void clear_compound_head(struct page *page)
  717. {
  718. WRITE_ONCE(page->compound_head, 0);
  719. }
  720. #ifdef CONFIG_TRANSPARENT_HUGEPAGE
  721. static inline void ClearPageCompound(struct page *page)
  722. {
  723. BUG_ON(!PageHead(page));
  724. ClearPageHead(page);
  725. }
  726. #endif
  727. #define PG_head_mask ((1UL << PG_head))
  728. #ifdef CONFIG_HUGETLB_PAGE
  729. int PageHuge(struct page *page);
  730. int PageHeadHuge(struct page *page);
  731. static inline bool folio_test_hugetlb(struct folio *folio)
  732. {
  733. return PageHeadHuge(&folio->page);
  734. }
  735. #else
  736. TESTPAGEFLAG_FALSE(Huge, hugetlb)
  737. TESTPAGEFLAG_FALSE(HeadHuge, headhuge)
  738. #endif
  739. #ifdef CONFIG_TRANSPARENT_HUGEPAGE
  740. /*
  741. * PageHuge() only returns true for hugetlbfs pages, but not for
  742. * normal or transparent huge pages.
  743. *
  744. * PageTransHuge() returns true for both transparent huge and
  745. * hugetlbfs pages, but not normal pages. PageTransHuge() can only be
  746. * called only in the core VM paths where hugetlbfs pages can't exist.
  747. */
  748. static inline int PageTransHuge(struct page *page)
  749. {
  750. VM_BUG_ON_PAGE(PageTail(page), page);
  751. return PageHead(page);
  752. }
  753. static inline bool folio_test_transhuge(struct folio *folio)
  754. {
  755. return folio_test_head(folio);
  756. }
  757. /*
  758. * PageTransCompound returns true for both transparent huge pages
  759. * and hugetlbfs pages, so it should only be called when it's known
  760. * that hugetlbfs pages aren't involved.
  761. */
  762. static inline int PageTransCompound(struct page *page)
  763. {
  764. return PageCompound(page);
  765. }
  766. /*
  767. * PageTransTail returns true for both transparent huge pages
  768. * and hugetlbfs pages, so it should only be called when it's known
  769. * that hugetlbfs pages aren't involved.
  770. */
  771. static inline int PageTransTail(struct page *page)
  772. {
  773. return PageTail(page);
  774. }
  775. /*
  776. * PageDoubleMap indicates that the compound page is mapped with PTEs as well
  777. * as PMDs.
  778. *
  779. * This is required for optimization of rmap operations for THP: we can postpone
  780. * per small page mapcount accounting (and its overhead from atomic operations)
  781. * until the first PMD split.
  782. *
  783. * For the page PageDoubleMap means ->_mapcount in all sub-pages is offset up
  784. * by one. This reference will go away with last compound_mapcount.
  785. *
  786. * See also __split_huge_pmd_locked() and page_remove_anon_compound_rmap().
  787. */
  788. PAGEFLAG(DoubleMap, double_map, PF_SECOND)
  789. TESTSCFLAG(DoubleMap, double_map, PF_SECOND)
  790. #else
  791. TESTPAGEFLAG_FALSE(TransHuge, transhuge)
  792. TESTPAGEFLAG_FALSE(TransCompound, transcompound)
  793. TESTPAGEFLAG_FALSE(TransCompoundMap, transcompoundmap)
  794. TESTPAGEFLAG_FALSE(TransTail, transtail)
  795. PAGEFLAG_FALSE(DoubleMap, double_map)
  796. TESTSCFLAG_FALSE(DoubleMap, double_map)
  797. #endif
  798. #if defined(CONFIG_MEMORY_FAILURE) && defined(CONFIG_TRANSPARENT_HUGEPAGE)
  799. /*
  800. * PageHasHWPoisoned indicates that at least one subpage is hwpoisoned in the
  801. * compound page.
  802. *
  803. * This flag is set by hwpoison handler. Cleared by THP split or free page.
  804. */
  805. PAGEFLAG(HasHWPoisoned, has_hwpoisoned, PF_SECOND)
  806. TESTSCFLAG(HasHWPoisoned, has_hwpoisoned, PF_SECOND)
  807. #else
  808. PAGEFLAG_FALSE(HasHWPoisoned, has_hwpoisoned)
  809. TESTSCFLAG_FALSE(HasHWPoisoned, has_hwpoisoned)
  810. #endif
  811. /*
  812. * Check if a page is currently marked HWPoisoned. Note that this check is
  813. * best effort only and inherently racy: there is no way to synchronize with
  814. * failing hardware.
  815. */
  816. static inline bool is_page_hwpoison(struct page *page)
  817. {
  818. if (PageHWPoison(page))
  819. return true;
  820. return PageHuge(page) && PageHWPoison(compound_head(page));
  821. }
  822. /*
  823. * For pages that are never mapped to userspace (and aren't PageSlab),
  824. * page_type may be used. Because it is initialised to -1, we invert the
  825. * sense of the bit, so __SetPageFoo *clears* the bit used for PageFoo, and
  826. * __ClearPageFoo *sets* the bit used for PageFoo. We reserve a few high and
  827. * low bits so that an underflow or overflow of page_mapcount() won't be
  828. * mistaken for a page type value.
  829. */
  830. #define PAGE_TYPE_BASE 0xf0000000
  831. /* Reserve 0x0000007f to catch underflows of page_mapcount */
  832. #define PAGE_MAPCOUNT_RESERVE -128
  833. #define PG_buddy 0x00000080
  834. #define PG_offline 0x00000100
  835. #define PG_table 0x00000200
  836. #define PG_guard 0x00000400
  837. #define PageType(page, flag) \
  838. ((page->page_type & (PAGE_TYPE_BASE | flag)) == PAGE_TYPE_BASE)
  839. static inline int page_has_type(struct page *page)
  840. {
  841. return (int)page->page_type < PAGE_MAPCOUNT_RESERVE;
  842. }
  843. #define PAGE_TYPE_OPS(uname, lname) \
  844. static __always_inline int Page##uname(struct page *page) \
  845. { \
  846. return PageType(page, PG_##lname); \
  847. } \
  848. static __always_inline void __SetPage##uname(struct page *page) \
  849. { \
  850. VM_BUG_ON_PAGE(!PageType(page, 0), page); \
  851. page->page_type &= ~PG_##lname; \
  852. } \
  853. static __always_inline void __ClearPage##uname(struct page *page) \
  854. { \
  855. VM_BUG_ON_PAGE(!Page##uname(page), page); \
  856. page->page_type |= PG_##lname; \
  857. }
  858. /*
  859. * PageBuddy() indicates that the page is free and in the buddy system
  860. * (see mm/page_alloc.c).
  861. */
  862. PAGE_TYPE_OPS(Buddy, buddy)
  863. /*
  864. * PageOffline() indicates that the page is logically offline although the
  865. * containing section is online. (e.g. inflated in a balloon driver or
  866. * not onlined when onlining the section).
  867. * The content of these pages is effectively stale. Such pages should not
  868. * be touched (read/write/dump/save) except by their owner.
  869. *
  870. * If a driver wants to allow to offline unmovable PageOffline() pages without
  871. * putting them back to the buddy, it can do so via the memory notifier by
  872. * decrementing the reference count in MEM_GOING_OFFLINE and incrementing the
  873. * reference count in MEM_CANCEL_OFFLINE. When offlining, the PageOffline()
  874. * pages (now with a reference count of zero) are treated like free pages,
  875. * allowing the containing memory block to get offlined. A driver that
  876. * relies on this feature is aware that re-onlining the memory block will
  877. * require to re-set the pages PageOffline() and not giving them to the
  878. * buddy via online_page_callback_t.
  879. *
  880. * There are drivers that mark a page PageOffline() and expect there won't be
  881. * any further access to page content. PFN walkers that read content of random
  882. * pages should check PageOffline() and synchronize with such drivers using
  883. * page_offline_freeze()/page_offline_thaw().
  884. */
  885. PAGE_TYPE_OPS(Offline, offline)
  886. extern void page_offline_freeze(void);
  887. extern void page_offline_thaw(void);
  888. extern void page_offline_begin(void);
  889. extern void page_offline_end(void);
  890. /*
  891. * Marks pages in use as page tables.
  892. */
  893. PAGE_TYPE_OPS(Table, table)
  894. /*
  895. * Marks guardpages used with debug_pagealloc.
  896. */
  897. PAGE_TYPE_OPS(Guard, guard)
  898. extern bool is_free_buddy_page(struct page *page);
  899. PAGEFLAG(Isolated, isolated, PF_ANY);
  900. static __always_inline int PageAnonExclusive(struct page *page)
  901. {
  902. VM_BUG_ON_PGFLAGS(!PageAnon(page), page);
  903. VM_BUG_ON_PGFLAGS(PageHuge(page) && !PageHead(page), page);
  904. return test_bit(PG_anon_exclusive, &PF_ANY(page, 1)->flags);
  905. }
  906. static __always_inline void SetPageAnonExclusive(struct page *page)
  907. {
  908. VM_BUG_ON_PGFLAGS(!PageAnon(page) || PageKsm(page), page);
  909. VM_BUG_ON_PGFLAGS(PageHuge(page) && !PageHead(page), page);
  910. set_bit(PG_anon_exclusive, &PF_ANY(page, 1)->flags);
  911. }
  912. static __always_inline void ClearPageAnonExclusive(struct page *page)
  913. {
  914. VM_BUG_ON_PGFLAGS(!PageAnon(page) || PageKsm(page), page);
  915. VM_BUG_ON_PGFLAGS(PageHuge(page) && !PageHead(page), page);
  916. clear_bit(PG_anon_exclusive, &PF_ANY(page, 1)->flags);
  917. }
  918. static __always_inline void __ClearPageAnonExclusive(struct page *page)
  919. {
  920. VM_BUG_ON_PGFLAGS(!PageAnon(page), page);
  921. VM_BUG_ON_PGFLAGS(PageHuge(page) && !PageHead(page), page);
  922. __clear_bit(PG_anon_exclusive, &PF_ANY(page, 1)->flags);
  923. }
  924. #ifdef CONFIG_MMU
  925. #define __PG_MLOCKED (1UL << PG_mlocked)
  926. #else
  927. #define __PG_MLOCKED 0
  928. #endif
  929. /*
  930. * Flags checked when a page is freed. Pages being freed should not have
  931. * these flags set. If they are, there is a problem.
  932. */
  933. #define PAGE_FLAGS_CHECK_AT_FREE \
  934. (1UL << PG_lru | 1UL << PG_locked | \
  935. 1UL << PG_private | 1UL << PG_private_2 | \
  936. 1UL << PG_writeback | 1UL << PG_reserved | \
  937. 1UL << PG_slab | 1UL << PG_active | \
  938. 1UL << PG_unevictable | __PG_MLOCKED | LRU_GEN_MASK)
  939. /*
  940. * Flags checked when a page is prepped for return by the page allocator.
  941. * Pages being prepped should not have these flags set. If they are set,
  942. * there has been a kernel bug or struct page corruption.
  943. *
  944. * __PG_HWPOISON is exceptional because it needs to be kept beyond page's
  945. * alloc-free cycle to prevent from reusing the page.
  946. */
  947. #define PAGE_FLAGS_CHECK_AT_PREP \
  948. ((PAGEFLAGS_MASK & ~__PG_HWPOISON) | LRU_GEN_MASK | LRU_REFS_MASK)
  949. #define PAGE_FLAGS_PRIVATE \
  950. (1UL << PG_private | 1UL << PG_private_2)
  951. /**
  952. * page_has_private - Determine if page has private stuff
  953. * @page: The page to be checked
  954. *
  955. * Determine if a page has private stuff, indicating that release routines
  956. * should be invoked upon it.
  957. */
  958. static inline int page_has_private(struct page *page)
  959. {
  960. return !!(page->flags & PAGE_FLAGS_PRIVATE);
  961. }
  962. static inline bool folio_has_private(struct folio *folio)
  963. {
  964. return page_has_private(&folio->page);
  965. }
  966. #undef PF_ANY
  967. #undef PF_HEAD
  968. #undef PF_ONLY_HEAD
  969. #undef PF_NO_TAIL
  970. #undef PF_NO_COMPOUND
  971. #undef PF_SECOND
  972. #endif /* !__GENERATING_BOUNDS_H */
  973. #endif /* PAGE_FLAGS_H */