| 1 | /* SPDX-License-Identifier: GPL-2.0 */ |
| 2 | /* |
| 3 | * Macros for manipulating and testing page->flags |
| 4 | */ |
| 5 | |
| 6 | #ifndef PAGE_FLAGS_H |
| 7 | #define PAGE_FLAGS_H |
| 8 | |
| 9 | #include <linux/types.h> |
| 10 | #include <linux/bug.h> |
| 11 | #include <linux/mmdebug.h> |
| 12 | #ifndef __GENERATING_BOUNDS_H |
| 13 | #include <linux/mm_types.h> |
| 14 | #include <generated/bounds.h> |
| 15 | #endif /* !__GENERATING_BOUNDS_H */ |
| 16 | |
| 17 | /* |
| 18 | * Various page->flags bits: |
| 19 | * |
| 20 | * PG_reserved is set for special pages. The "struct page" of such a page |
| 21 | * should in general not be touched (e.g. set dirty) except by its owner. |
| 22 | * Pages marked as PG_reserved include: |
| 23 | * - Pages part of the kernel image (including vDSO) and similar (e.g. BIOS, |
| 24 | * initrd, HW tables) |
| 25 | * - Pages reserved or allocated early during boot (before the page allocator |
| 26 | * was initialized). This includes (depending on the architecture) the |
| 27 | * initial vmemmap, initial page tables, crashkernel, elfcorehdr, and much |
| 28 | * much more. Once (if ever) freed, PG_reserved is cleared and they will |
| 29 | * be given to the page allocator. |
| 30 | * - Pages falling into physical memory gaps - not IORESOURCE_SYSRAM. Trying |
| 31 | * to read/write these pages might end badly. Don't touch! |
| 32 | * - The zero page(s) |
| 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 | * - MCA pages on ia64 |
| 39 | * - Pages holding CPU notes for POWER Firmware Assisted Dump |
| 40 | * - Device memory (e.g. PMEM, DAX, HMM) |
| 41 | * Some PG_reserved pages will be excluded from the hibernation image. |
| 42 | * PG_reserved does in general not hinder anybody from dumping or swapping |
| 43 | * and is no longer required for remap_pfn_range(). ioremap might require it. |
| 44 | * Consequently, PG_reserved for a page mapped into user space can indicate |
| 45 | * the zero page, the vDSO, MMIO pages or device memory. |
| 46 | * |
| 47 | * The PG_private bitflag is set on pagecache pages if they contain filesystem |
| 48 | * specific data (which is normally at page->private). It can be used by |
| 49 | * private allocations for its own usage. |
| 50 | * |
| 51 | * During initiation of disk I/O, PG_locked is set. This bit is set before I/O |
| 52 | * and cleared when writeback _starts_ or when read _completes_. PG_writeback |
| 53 | * is set before writeback starts and cleared when it finishes. |
| 54 | * |
| 55 | * PG_locked also pins a page in pagecache, and blocks truncation of the file |
| 56 | * while it is held. |
| 57 | * |
| 58 | * page_waitqueue(page) is a wait queue of all tasks waiting for the page |
| 59 | * to become unlocked. |
| 60 | * |
| 61 | * PG_swapbacked is set when a page uses swap as a backing storage. This are |
| 62 | * usually PageAnon or shmem pages but please note that even anonymous pages |
| 63 | * might lose their PG_swapbacked flag when they simply can be dropped (e.g. as |
| 64 | * a result of MADV_FREE). |
| 65 | * |
| 66 | * PG_referenced, PG_reclaim are used for page reclaim for anonymous and |
| 67 | * file-backed pagecache (see mm/vmscan.c). |
| 68 | * |
| 69 | * PG_arch_1 is an architecture specific page state bit. The generic code |
| 70 | * guarantees that this bit is cleared for a page when it first is entered into |
| 71 | * the page cache. |
| 72 | * |
| 73 | * PG_hwpoison indicates that a page got corrupted in hardware and contains |
| 74 | * data with incorrect ECC bits that triggered a machine check. Accessing is |
| 75 | * not safe since it may cause another machine check. Don't touch! |
| 76 | */ |
| 77 | |
| 78 | /* |
| 79 | * Don't use the pageflags directly. Use the PageFoo macros. |
| 80 | * |
| 81 | * The page flags field is split into two parts, the main flags area |
| 82 | * which extends from the low bits upwards, and the fields area which |
| 83 | * extends from the high bits downwards. |
| 84 | * |
| 85 | * | FIELD | ... | FLAGS | |
| 86 | * N-1 ^ 0 |
| 87 | * (NR_PAGEFLAGS) |
| 88 | * |
| 89 | * The fields area is reserved for fields mapping zone, node (for NUMA) and |
| 90 | * SPARSEMEM section (for variants of SPARSEMEM that require section ids like |
| 91 | * SPARSEMEM_EXTREME with !SPARSEMEM_VMEMMAP). |
| 92 | */ |
| 93 | enum pageflags { |
| 94 | PG_locked, /* Page is locked. Don't touch. */ |
| 95 | PG_writeback, /* Page is under writeback */ |
| 96 | PG_referenced, |
| 97 | PG_uptodate, |
| 98 | PG_dirty, |
| 99 | PG_lru, |
| 100 | PG_head, /* Must be in bit 6 */ |
| 101 | PG_waiters, /* Page has waiters, check its waitqueue. Must be bit #7 and in the same byte as "PG_locked" */ |
| 102 | PG_active, |
| 103 | PG_workingset, |
| 104 | PG_owner_priv_1, /* Owner use. If pagecache, fs may use */ |
| 105 | PG_owner_2, /* Owner use. If pagecache, fs may use */ |
| 106 | PG_arch_1, |
| 107 | PG_reserved, |
| 108 | PG_private, /* If pagecache, has fs-private data */ |
| 109 | PG_private_2, /* If pagecache, has fs aux data */ |
| 110 | PG_reclaim, /* To be reclaimed asap */ |
| 111 | PG_swapbacked, /* Page is backed by RAM/swap */ |
| 112 | PG_unevictable, /* Page is "unevictable" */ |
| 113 | PG_dropbehind, /* drop pages on IO completion */ |
| 114 | #ifdef CONFIG_MMU |
| 115 | PG_mlocked, /* Page is vma mlocked */ |
| 116 | #endif |
| 117 | #ifdef CONFIG_MEMORY_FAILURE |
| 118 | PG_hwpoison, /* hardware poisoned page. Don't touch */ |
| 119 | #endif |
| 120 | #if defined(CONFIG_PAGE_IDLE_FLAG) && defined(CONFIG_64BIT) |
| 121 | PG_young, |
| 122 | PG_idle, |
| 123 | #endif |
| 124 | #ifdef CONFIG_ARCH_USES_PG_ARCH_2 |
| 125 | PG_arch_2, |
| 126 | #endif |
| 127 | #ifdef CONFIG_ARCH_USES_PG_ARCH_3 |
| 128 | PG_arch_3, |
| 129 | #endif |
| 130 | __NR_PAGEFLAGS, |
| 131 | |
| 132 | PG_readahead = PG_reclaim, |
| 133 | |
| 134 | /* Anonymous memory (and shmem) */ |
| 135 | PG_swapcache = PG_owner_priv_1, /* Swap page: swp_entry_t in private */ |
| 136 | /* Some filesystems */ |
| 137 | PG_checked = PG_owner_priv_1, |
| 138 | |
| 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_owner_2, |
| 147 | |
| 148 | /* |
| 149 | * Set if all buffer heads in the folio are mapped. |
| 150 | * Filesystems which do not use BHs can use it for their own purpose. |
| 151 | */ |
| 152 | PG_mappedtodisk = PG_owner_2, |
| 153 | |
| 154 | /* Two page bits are conscripted by FS-Cache to maintain local caching |
| 155 | * state. These bits are set on pages belonging to the netfs's inodes |
| 156 | * when those inodes are being locally cached. |
| 157 | */ |
| 158 | PG_fscache = PG_private_2, /* page backed by cache */ |
| 159 | |
| 160 | /* XEN */ |
| 161 | /* Pinned in Xen as a read-only pagetable page. */ |
| 162 | PG_pinned = PG_owner_priv_1, |
| 163 | /* Pinned as part of domain save (see xen_mm_pin_all()). */ |
| 164 | PG_savepinned = PG_dirty, |
| 165 | /* Has a grant mapping of another (foreign) domain's page. */ |
| 166 | PG_foreign = PG_owner_priv_1, |
| 167 | /* Remapped by swiotlb-xen. */ |
| 168 | PG_xen_remapped = PG_owner_priv_1, |
| 169 | |
| 170 | #ifdef CONFIG_MIGRATION |
| 171 | /* movable_ops page that is isolated for migration */ |
| 172 | PG_movable_ops_isolated = PG_reclaim, |
| 173 | /* this is a movable_ops page (for selected typed pages only) */ |
| 174 | PG_movable_ops = PG_uptodate, |
| 175 | #endif |
| 176 | |
| 177 | /* Only valid for buddy pages. Used to track pages that are reported */ |
| 178 | PG_reported = PG_uptodate, |
| 179 | |
| 180 | #ifdef CONFIG_MEMORY_HOTPLUG |
| 181 | /* For self-hosted memmap pages */ |
| 182 | PG_vmemmap_self_hosted = PG_owner_priv_1, |
| 183 | #endif |
| 184 | |
| 185 | /* |
| 186 | * Flags only valid for compound pages. Stored in first tail page's |
| 187 | * flags word. Cannot use the first 8 flags or any flag marked as |
| 188 | * PF_ANY. |
| 189 | */ |
| 190 | |
| 191 | /* At least one page in this folio has the hwpoison flag set */ |
| 192 | PG_has_hwpoisoned = PG_active, |
| 193 | PG_large_rmappable = PG_workingset, /* anon or file-backed */ |
| 194 | PG_partially_mapped = PG_reclaim, /* was identified to be partially mapped */ |
| 195 | }; |
| 196 | |
| 197 | #define PAGEFLAGS_MASK ((1UL << NR_PAGEFLAGS) - 1) |
| 198 | |
| 199 | #ifndef __GENERATING_BOUNDS_H |
| 200 | |
| 201 | #ifdef CONFIG_HUGETLB_PAGE_OPTIMIZE_VMEMMAP |
| 202 | DECLARE_STATIC_KEY_FALSE(hugetlb_optimize_vmemmap_key); |
| 203 | |
| 204 | /* |
| 205 | * Return the real head page struct iff the @page is a fake head page, otherwise |
| 206 | * return the @page itself. See Documentation/mm/vmemmap_dedup.rst. |
| 207 | */ |
| 208 | static __always_inline const struct page *page_fixed_fake_head(const struct page *page) |
| 209 | { |
| 210 | if (!static_branch_unlikely(&hugetlb_optimize_vmemmap_key)) |
| 211 | return page; |
| 212 | |
| 213 | /* |
| 214 | * Only addresses aligned with PAGE_SIZE of struct page may be fake head |
| 215 | * struct page. The alignment check aims to avoid access the fields ( |
| 216 | * e.g. compound_head) of the @page[1]. It can avoid touch a (possibly) |
| 217 | * cold cacheline in some cases. |
| 218 | */ |
| 219 | if (IS_ALIGNED((unsigned long)page, PAGE_SIZE) && |
| 220 | test_bit(PG_head, &page->flags.f)) { |
| 221 | /* |
| 222 | * We can safely access the field of the @page[1] with PG_head |
| 223 | * because the @page is a compound page composed with at least |
| 224 | * two contiguous pages. |
| 225 | */ |
| 226 | unsigned long head = READ_ONCE(page[1].compound_head); |
| 227 | |
| 228 | if (likely(head & 1)) |
| 229 | return (const struct page *)(head - 1); |
| 230 | } |
| 231 | return page; |
| 232 | } |
| 233 | |
| 234 | static __always_inline bool page_count_writable(const struct page *page, int u) |
| 235 | { |
| 236 | if (!static_branch_unlikely(&hugetlb_optimize_vmemmap_key)) |
| 237 | return true; |
| 238 | |
| 239 | /* |
| 240 | * The refcount check is ordered before the fake-head check to prevent |
| 241 | * the following race: |
| 242 | * CPU 1 (HVO) CPU 2 (speculative PFN walker) |
| 243 | * |
| 244 | * page_ref_freeze() |
| 245 | * synchronize_rcu() |
| 246 | * rcu_read_lock() |
| 247 | * page_is_fake_head() is false |
| 248 | * vmemmap_remap_pte() |
| 249 | * XXX: struct page[] becomes r/o |
| 250 | * |
| 251 | * page_ref_unfreeze() |
| 252 | * page_ref_count() is not zero |
| 253 | * |
| 254 | * atomic_add_unless(&page->_refcount) |
| 255 | * XXX: try to modify r/o struct page[] |
| 256 | * |
| 257 | * The refcount check also prevents modification attempts to other (r/o) |
| 258 | * tail pages that are not fake heads. |
| 259 | */ |
| 260 | if (atomic_read_acquire(v: &page->_refcount) == u) |
| 261 | return false; |
| 262 | |
| 263 | return page_fixed_fake_head(page) == page; |
| 264 | } |
| 265 | #else |
| 266 | static inline const struct page *page_fixed_fake_head(const struct page *page) |
| 267 | { |
| 268 | return page; |
| 269 | } |
| 270 | |
| 271 | static inline bool page_count_writable(const struct page *page, int u) |
| 272 | { |
| 273 | return true; |
| 274 | } |
| 275 | #endif |
| 276 | |
| 277 | static __always_inline int page_is_fake_head(const struct page *page) |
| 278 | { |
| 279 | return page_fixed_fake_head(page) != page; |
| 280 | } |
| 281 | |
| 282 | static __always_inline unsigned long _compound_head(const struct page *page) |
| 283 | { |
| 284 | unsigned long head = READ_ONCE(page->compound_head); |
| 285 | |
| 286 | if (unlikely(head & 1)) |
| 287 | return head - 1; |
| 288 | return (unsigned long)page_fixed_fake_head(page); |
| 289 | } |
| 290 | |
| 291 | #define compound_head(page) ((typeof(page))_compound_head(page)) |
| 292 | |
| 293 | /** |
| 294 | * page_folio - Converts from page to folio. |
| 295 | * @p: The page. |
| 296 | * |
| 297 | * Every page is part of a folio. This function cannot be called on a |
| 298 | * NULL pointer. |
| 299 | * |
| 300 | * Context: No reference, nor lock is required on @page. If the caller |
| 301 | * does not hold a reference, this call may race with a folio split, so |
| 302 | * it should re-check the folio still contains this page after gaining |
| 303 | * a reference on the folio. |
| 304 | * Return: The folio which contains this page. |
| 305 | */ |
| 306 | #define page_folio(p) (_Generic((p), \ |
| 307 | const struct page *: (const struct folio *)_compound_head(p), \ |
| 308 | struct page *: (struct folio *)_compound_head(p))) |
| 309 | |
| 310 | /** |
| 311 | * folio_page - Return a page from a folio. |
| 312 | * @folio: The folio. |
| 313 | * @n: The page number to return. |
| 314 | * |
| 315 | * @n is relative to the start of the folio. This function does not |
| 316 | * check that the page number lies within @folio; the caller is presumed |
| 317 | * to have a reference to the page. |
| 318 | */ |
| 319 | #define folio_page(folio, n) (&(folio)->page + (n)) |
| 320 | |
| 321 | static __always_inline int PageTail(const struct page *page) |
| 322 | { |
| 323 | return READ_ONCE(page->compound_head) & 1 || page_is_fake_head(page); |
| 324 | } |
| 325 | |
| 326 | static __always_inline int PageCompound(const struct page *page) |
| 327 | { |
| 328 | return test_bit(PG_head, &page->flags.f) || |
| 329 | READ_ONCE(page->compound_head) & 1; |
| 330 | } |
| 331 | |
| 332 | #define PAGE_POISON_PATTERN -1l |
| 333 | static inline int PagePoisoned(const struct page *page) |
| 334 | { |
| 335 | return READ_ONCE(page->flags.f) == PAGE_POISON_PATTERN; |
| 336 | } |
| 337 | |
| 338 | #ifdef CONFIG_DEBUG_VM |
| 339 | void page_init_poison(struct page *page, size_t size); |
| 340 | #else |
| 341 | static inline void page_init_poison(struct page *page, size_t size) |
| 342 | { |
| 343 | } |
| 344 | #endif |
| 345 | |
| 346 | static const unsigned long *const_folio_flags(const struct folio *folio, |
| 347 | unsigned n) |
| 348 | { |
| 349 | const struct page *page = &folio->page; |
| 350 | |
| 351 | VM_BUG_ON_PGFLAGS(page->compound_head & 1, page); |
| 352 | VM_BUG_ON_PGFLAGS(n > 0 && !test_bit(PG_head, &page->flags.f), page); |
| 353 | return &page[n].flags.f; |
| 354 | } |
| 355 | |
| 356 | static unsigned long *folio_flags(struct folio *folio, unsigned n) |
| 357 | { |
| 358 | struct page *page = &folio->page; |
| 359 | |
| 360 | VM_BUG_ON_PGFLAGS(page->compound_head & 1, page); |
| 361 | VM_BUG_ON_PGFLAGS(n > 0 && !test_bit(PG_head, &page->flags.f), page); |
| 362 | return &page[n].flags.f; |
| 363 | } |
| 364 | |
| 365 | /* |
| 366 | * Page flags policies wrt compound pages |
| 367 | * |
| 368 | * PF_POISONED_CHECK |
| 369 | * check if this struct page poisoned/uninitialized |
| 370 | * |
| 371 | * PF_ANY: |
| 372 | * the page flag is relevant for small, head and tail pages. |
| 373 | * |
| 374 | * PF_HEAD: |
| 375 | * for compound page all operations related to the page flag applied to |
| 376 | * head page. |
| 377 | * |
| 378 | * PF_NO_TAIL: |
| 379 | * modifications of the page flag must be done on small or head pages, |
| 380 | * checks can be done on tail pages too. |
| 381 | * |
| 382 | * PF_NO_COMPOUND: |
| 383 | * the page flag is not relevant for compound pages. |
| 384 | * |
| 385 | * PF_SECOND: |
| 386 | * the page flag is stored in the first tail page. |
| 387 | */ |
| 388 | #define PF_POISONED_CHECK(page) ({ \ |
| 389 | VM_BUG_ON_PGFLAGS(PagePoisoned(page), page); \ |
| 390 | page; }) |
| 391 | #define PF_ANY(page, enforce) PF_POISONED_CHECK(page) |
| 392 | #define PF_HEAD(page, enforce) PF_POISONED_CHECK(compound_head(page)) |
| 393 | #define PF_NO_TAIL(page, enforce) ({ \ |
| 394 | VM_BUG_ON_PGFLAGS(enforce && PageTail(page), page); \ |
| 395 | PF_POISONED_CHECK(compound_head(page)); }) |
| 396 | #define PF_NO_COMPOUND(page, enforce) ({ \ |
| 397 | VM_BUG_ON_PGFLAGS(enforce && PageCompound(page), page); \ |
| 398 | PF_POISONED_CHECK(page); }) |
| 399 | #define PF_SECOND(page, enforce) ({ \ |
| 400 | VM_BUG_ON_PGFLAGS(!PageHead(page), page); \ |
| 401 | PF_POISONED_CHECK(&page[1]); }) |
| 402 | |
| 403 | /* Which page is the flag stored in */ |
| 404 | #define FOLIO_PF_ANY 0 |
| 405 | #define FOLIO_PF_HEAD 0 |
| 406 | #define FOLIO_PF_NO_TAIL 0 |
| 407 | #define FOLIO_PF_NO_COMPOUND 0 |
| 408 | #define FOLIO_PF_SECOND 1 |
| 409 | |
| 410 | #define FOLIO_HEAD_PAGE 0 |
| 411 | #define FOLIO_SECOND_PAGE 1 |
| 412 | |
| 413 | /* |
| 414 | * Macros to create function definitions for page flags |
| 415 | */ |
| 416 | #define FOLIO_TEST_FLAG(name, page) \ |
| 417 | static __always_inline bool folio_test_##name(const struct folio *folio) \ |
| 418 | { return test_bit(PG_##name, const_folio_flags(folio, page)); } |
| 419 | |
| 420 | #define FOLIO_SET_FLAG(name, page) \ |
| 421 | static __always_inline void folio_set_##name(struct folio *folio) \ |
| 422 | { set_bit(PG_##name, folio_flags(folio, page)); } |
| 423 | |
| 424 | #define FOLIO_CLEAR_FLAG(name, page) \ |
| 425 | static __always_inline void folio_clear_##name(struct folio *folio) \ |
| 426 | { clear_bit(PG_##name, folio_flags(folio, page)); } |
| 427 | |
| 428 | #define __FOLIO_SET_FLAG(name, page) \ |
| 429 | static __always_inline void __folio_set_##name(struct folio *folio) \ |
| 430 | { __set_bit(PG_##name, folio_flags(folio, page)); } |
| 431 | |
| 432 | #define __FOLIO_CLEAR_FLAG(name, page) \ |
| 433 | static __always_inline void __folio_clear_##name(struct folio *folio) \ |
| 434 | { __clear_bit(PG_##name, folio_flags(folio, page)); } |
| 435 | |
| 436 | #define FOLIO_TEST_SET_FLAG(name, page) \ |
| 437 | static __always_inline bool folio_test_set_##name(struct folio *folio) \ |
| 438 | { return test_and_set_bit(PG_##name, folio_flags(folio, page)); } |
| 439 | |
| 440 | #define FOLIO_TEST_CLEAR_FLAG(name, page) \ |
| 441 | static __always_inline bool folio_test_clear_##name(struct folio *folio) \ |
| 442 | { return test_and_clear_bit(PG_##name, folio_flags(folio, page)); } |
| 443 | |
| 444 | #define FOLIO_FLAG(name, page) \ |
| 445 | FOLIO_TEST_FLAG(name, page) \ |
| 446 | FOLIO_SET_FLAG(name, page) \ |
| 447 | FOLIO_CLEAR_FLAG(name, page) |
| 448 | |
| 449 | #define TESTPAGEFLAG(uname, lname, policy) \ |
| 450 | FOLIO_TEST_FLAG(lname, FOLIO_##policy) \ |
| 451 | static __always_inline int Page##uname(const struct page *page) \ |
| 452 | { return test_bit(PG_##lname, &policy(page, 0)->flags.f); } |
| 453 | |
| 454 | #define SETPAGEFLAG(uname, lname, policy) \ |
| 455 | FOLIO_SET_FLAG(lname, FOLIO_##policy) \ |
| 456 | static __always_inline void SetPage##uname(struct page *page) \ |
| 457 | { set_bit(PG_##lname, &policy(page, 1)->flags.f); } |
| 458 | |
| 459 | #define CLEARPAGEFLAG(uname, lname, policy) \ |
| 460 | FOLIO_CLEAR_FLAG(lname, FOLIO_##policy) \ |
| 461 | static __always_inline void ClearPage##uname(struct page *page) \ |
| 462 | { clear_bit(PG_##lname, &policy(page, 1)->flags.f); } |
| 463 | |
| 464 | #define __SETPAGEFLAG(uname, lname, policy) \ |
| 465 | __FOLIO_SET_FLAG(lname, FOLIO_##policy) \ |
| 466 | static __always_inline void __SetPage##uname(struct page *page) \ |
| 467 | { __set_bit(PG_##lname, &policy(page, 1)->flags.f); } |
| 468 | |
| 469 | #define __CLEARPAGEFLAG(uname, lname, policy) \ |
| 470 | __FOLIO_CLEAR_FLAG(lname, FOLIO_##policy) \ |
| 471 | static __always_inline void __ClearPage##uname(struct page *page) \ |
| 472 | { __clear_bit(PG_##lname, &policy(page, 1)->flags.f); } |
| 473 | |
| 474 | #define TESTSETFLAG(uname, lname, policy) \ |
| 475 | FOLIO_TEST_SET_FLAG(lname, FOLIO_##policy) \ |
| 476 | static __always_inline int TestSetPage##uname(struct page *page) \ |
| 477 | { return test_and_set_bit(PG_##lname, &policy(page, 1)->flags.f); } |
| 478 | |
| 479 | #define TESTCLEARFLAG(uname, lname, policy) \ |
| 480 | FOLIO_TEST_CLEAR_FLAG(lname, FOLIO_##policy) \ |
| 481 | static __always_inline int TestClearPage##uname(struct page *page) \ |
| 482 | { return test_and_clear_bit(PG_##lname, &policy(page, 1)->flags.f); } |
| 483 | |
| 484 | #define PAGEFLAG(uname, lname, policy) \ |
| 485 | TESTPAGEFLAG(uname, lname, policy) \ |
| 486 | SETPAGEFLAG(uname, lname, policy) \ |
| 487 | CLEARPAGEFLAG(uname, lname, policy) |
| 488 | |
| 489 | #define __PAGEFLAG(uname, lname, policy) \ |
| 490 | TESTPAGEFLAG(uname, lname, policy) \ |
| 491 | __SETPAGEFLAG(uname, lname, policy) \ |
| 492 | __CLEARPAGEFLAG(uname, lname, policy) |
| 493 | |
| 494 | #define TESTSCFLAG(uname, lname, policy) \ |
| 495 | TESTSETFLAG(uname, lname, policy) \ |
| 496 | TESTCLEARFLAG(uname, lname, policy) |
| 497 | |
| 498 | #define FOLIO_TEST_FLAG_FALSE(name) \ |
| 499 | static inline bool folio_test_##name(const struct folio *folio) \ |
| 500 | { return false; } |
| 501 | #define FOLIO_SET_FLAG_NOOP(name) \ |
| 502 | static inline void folio_set_##name(struct folio *folio) { } |
| 503 | #define FOLIO_CLEAR_FLAG_NOOP(name) \ |
| 504 | static inline void folio_clear_##name(struct folio *folio) { } |
| 505 | #define __FOLIO_SET_FLAG_NOOP(name) \ |
| 506 | static inline void __folio_set_##name(struct folio *folio) { } |
| 507 | #define __FOLIO_CLEAR_FLAG_NOOP(name) \ |
| 508 | static inline void __folio_clear_##name(struct folio *folio) { } |
| 509 | #define FOLIO_TEST_SET_FLAG_FALSE(name) \ |
| 510 | static inline bool folio_test_set_##name(struct folio *folio) \ |
| 511 | { return false; } |
| 512 | #define FOLIO_TEST_CLEAR_FLAG_FALSE(name) \ |
| 513 | static inline bool folio_test_clear_##name(struct folio *folio) \ |
| 514 | { return false; } |
| 515 | |
| 516 | #define FOLIO_FLAG_FALSE(name) \ |
| 517 | FOLIO_TEST_FLAG_FALSE(name) \ |
| 518 | FOLIO_SET_FLAG_NOOP(name) \ |
| 519 | FOLIO_CLEAR_FLAG_NOOP(name) |
| 520 | |
| 521 | #define TESTPAGEFLAG_FALSE(uname, lname) \ |
| 522 | FOLIO_TEST_FLAG_FALSE(lname) \ |
| 523 | static inline int Page##uname(const struct page *page) { return 0; } |
| 524 | |
| 525 | #define SETPAGEFLAG_NOOP(uname, lname) \ |
| 526 | FOLIO_SET_FLAG_NOOP(lname) \ |
| 527 | static inline void SetPage##uname(struct page *page) { } |
| 528 | |
| 529 | #define CLEARPAGEFLAG_NOOP(uname, lname) \ |
| 530 | FOLIO_CLEAR_FLAG_NOOP(lname) \ |
| 531 | static inline void ClearPage##uname(struct page *page) { } |
| 532 | |
| 533 | #define __CLEARPAGEFLAG_NOOP(uname, lname) \ |
| 534 | __FOLIO_CLEAR_FLAG_NOOP(lname) \ |
| 535 | static inline void __ClearPage##uname(struct page *page) { } |
| 536 | |
| 537 | #define TESTSETFLAG_FALSE(uname, lname) \ |
| 538 | FOLIO_TEST_SET_FLAG_FALSE(lname) \ |
| 539 | static inline int TestSetPage##uname(struct page *page) { return 0; } |
| 540 | |
| 541 | #define TESTCLEARFLAG_FALSE(uname, lname) \ |
| 542 | FOLIO_TEST_CLEAR_FLAG_FALSE(lname) \ |
| 543 | static inline int TestClearPage##uname(struct page *page) { return 0; } |
| 544 | |
| 545 | #define PAGEFLAG_FALSE(uname, lname) TESTPAGEFLAG_FALSE(uname, lname) \ |
| 546 | SETPAGEFLAG_NOOP(uname, lname) CLEARPAGEFLAG_NOOP(uname, lname) |
| 547 | |
| 548 | #define TESTSCFLAG_FALSE(uname, lname) \ |
| 549 | TESTSETFLAG_FALSE(uname, lname) TESTCLEARFLAG_FALSE(uname, lname) |
| 550 | |
| 551 | __PAGEFLAG(Locked, locked, PF_NO_TAIL) |
| 552 | FOLIO_FLAG(waiters, FOLIO_HEAD_PAGE) |
| 553 | FOLIO_FLAG(referenced, FOLIO_HEAD_PAGE) |
| 554 | FOLIO_TEST_CLEAR_FLAG(referenced, FOLIO_HEAD_PAGE) |
| 555 | __FOLIO_SET_FLAG(referenced, FOLIO_HEAD_PAGE) |
| 556 | PAGEFLAG(Dirty, dirty, PF_HEAD) TESTSCFLAG(Dirty, dirty, PF_HEAD) |
| 557 | __CLEARPAGEFLAG(Dirty, dirty, PF_HEAD) |
| 558 | PAGEFLAG(LRU, lru, PF_HEAD) __CLEARPAGEFLAG(LRU, lru, PF_HEAD) |
| 559 | TESTCLEARFLAG(LRU, lru, PF_HEAD) |
| 560 | FOLIO_FLAG(active, FOLIO_HEAD_PAGE) |
| 561 | __FOLIO_CLEAR_FLAG(active, FOLIO_HEAD_PAGE) |
| 562 | FOLIO_TEST_CLEAR_FLAG(active, FOLIO_HEAD_PAGE) |
| 563 | PAGEFLAG(Workingset, workingset, PF_HEAD) |
| 564 | TESTCLEARFLAG(Workingset, workingset, PF_HEAD) |
| 565 | PAGEFLAG(Checked, checked, PF_NO_COMPOUND) /* Used by some filesystems */ |
| 566 | |
| 567 | /* Xen */ |
| 568 | PAGEFLAG(Pinned, pinned, PF_NO_COMPOUND) |
| 569 | TESTSCFLAG(Pinned, pinned, PF_NO_COMPOUND) |
| 570 | PAGEFLAG(SavePinned, savepinned, PF_NO_COMPOUND); |
| 571 | PAGEFLAG(Foreign, foreign, PF_NO_COMPOUND); |
| 572 | PAGEFLAG(XenRemapped, xen_remapped, PF_NO_COMPOUND) |
| 573 | TESTCLEARFLAG(XenRemapped, xen_remapped, PF_NO_COMPOUND) |
| 574 | |
| 575 | PAGEFLAG(Reserved, reserved, PF_NO_COMPOUND) |
| 576 | __CLEARPAGEFLAG(Reserved, reserved, PF_NO_COMPOUND) |
| 577 | __SETPAGEFLAG(Reserved, reserved, PF_NO_COMPOUND) |
| 578 | FOLIO_FLAG(swapbacked, FOLIO_HEAD_PAGE) |
| 579 | __FOLIO_CLEAR_FLAG(swapbacked, FOLIO_HEAD_PAGE) |
| 580 | __FOLIO_SET_FLAG(swapbacked, FOLIO_HEAD_PAGE) |
| 581 | |
| 582 | /* |
| 583 | * Private page markings that may be used by the filesystem that owns the page |
| 584 | * for its own purposes. |
| 585 | * - PG_private and PG_private_2 cause release_folio() and co to be invoked |
| 586 | */ |
| 587 | PAGEFLAG(Private, private, PF_ANY) |
| 588 | FOLIO_FLAG(private_2, FOLIO_HEAD_PAGE) |
| 589 | |
| 590 | /* owner_2 can be set on tail pages for anon memory */ |
| 591 | FOLIO_FLAG(owner_2, FOLIO_HEAD_PAGE) |
| 592 | |
| 593 | /* |
| 594 | * Only test-and-set exist for PG_writeback. The unconditional operators are |
| 595 | * risky: they bypass page accounting. |
| 596 | */ |
| 597 | TESTPAGEFLAG(Writeback, writeback, PF_NO_TAIL) |
| 598 | TESTSCFLAG(Writeback, writeback, PF_NO_TAIL) |
| 599 | FOLIO_FLAG(mappedtodisk, FOLIO_HEAD_PAGE) |
| 600 | |
| 601 | /* PG_readahead is only used for reads; PG_reclaim is only for writes */ |
| 602 | You are visitor 01402520 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |
|---|