Lines Matching full:page
3 * Macros for manipulating and testing page->flags
18 * Various page->flags bits:
20 * PG_reserved is set for special pages. The "struct page" of such a page
25 * - Pages reserved or allocated early during boot (before the page allocator
27 * initial vmemmap, initial page tables, crashkernel, elfcorehdr, and much
29 * be given to the page allocator.
32 * - The zero page(s)
33 * - Pages not added to the page allocator when onlining a section because
49 * Consequently, PG_reserved for a page mapped into user space can indicate
50 * the zero page, the vDSO, MMIO pages or device memory.
53 * specific data (which is normally at page->private). It can be used by
60 * PG_locked also pins a page in pagecache, and blocks truncation of the file
63 * page_waitqueue(page) is a wait queue of all tasks waiting for the page
66 * PG_swapbacked is set when a page uses swap as a backing storage. This are
71 * PG_referenced, PG_reclaim are used for page reclaim for anonymous and
74 * PG_error is set to indicate that an I/O error occurred on this page.
76 * PG_arch_1 is an architecture specific page state bit. The generic code
77 * guarantees that this bit is cleared for a page when it first is entered into
78 * the page cache.
80 * PG_hwpoison indicates that a page got corrupted in hardware and contains
88 * The page flags field is split into two parts, the main flags area
101 PG_locked, /* Page is locked. Don't touch. */
108 …PG_waiters, /* Page has waiters, check its waitqueue. Must be bit #7 and in the same byte as "PG_…
116 PG_writeback, /* Page is under writeback */
117 PG_head, /* A head page */
120 PG_swapbacked, /* Page is backed by RAM/swap */
121 PG_unevictable, /* Page is "unevictable" */
123 PG_mlocked, /* Page is vma mlocked */
126 PG_uncached, /* Page has been mapped as uncached */
129 PG_hwpoison, /* hardware poisoned page. Don't touch */
146 * Depending on the way an anonymous folio can be mapped into a page
147 * table (e.g., single PMD/PUD/CONT of the head page vs. PTE-mapped
148 * THP), PG_anon_exclusive may be set only for the head page or for
158 PG_swapcache = PG_owner_priv_1, /* Swap page: swp_entry_t in private */
160 /* Two page bits are conscripted by FS-Cache to maintain local caching
164 PG_fscache = PG_private_2, /* page backed by cache */
167 /* Pinned in Xen as a read-only pagetable page. */
171 /* Has a grant mapping of another (foreign) domain's page. */
179 /* Compound pages. Stored in first tail page's flags */
184 * Compound pages. Stored in first tail page's flags.
191 /* non-lru isolated movable page */
211 * Return the real head page struct iff the @page is a fake head page, otherwise
212 * return the @page itself. See Documentation/mm/vmemmap_dedup.rst.
214 static __always_inline const struct page *page_fixed_fake_head(const struct page *page) in page_fixed_fake_head() argument
217 return page; in page_fixed_fake_head()
220 * Only addresses aligned with PAGE_SIZE of struct page may be fake head in page_fixed_fake_head()
221 * struct page. The alignment check aims to avoid access the fields ( in page_fixed_fake_head()
222 * e.g. compound_head) of the @page[1]. It can avoid touch a (possibly) in page_fixed_fake_head()
225 if (IS_ALIGNED((unsigned long)page, PAGE_SIZE) && in page_fixed_fake_head()
226 test_bit(PG_head, &page->flags)) { in page_fixed_fake_head()
228 * We can safely access the field of the @page[1] with PG_head in page_fixed_fake_head()
229 * because the @page is a compound page composed with at least in page_fixed_fake_head()
232 unsigned long head = READ_ONCE(page[1].compound_head); in page_fixed_fake_head()
235 return (const struct page *)(head - 1); in page_fixed_fake_head()
237 return page; in page_fixed_fake_head()
240 static inline const struct page *page_fixed_fake_head(const struct page *page) in page_fixed_fake_head() argument
242 return page; in page_fixed_fake_head()
246 static __always_inline int page_is_fake_head(struct page *page) in page_is_fake_head() argument
248 return page_fixed_fake_head(page) != page; in page_is_fake_head()
251 static inline unsigned long _compound_head(const struct page *page) in _compound_head() argument
253 unsigned long head = READ_ONCE(page->compound_head); in _compound_head()
257 return (unsigned long)page_fixed_fake_head(page); in _compound_head()
260 #define compound_head(page) ((typeof(page))_compound_head(page)) argument
263 * page_folio - Converts from page to folio.
264 * @p: The page.
266 * Every page is part of a folio. This function cannot be called on a
269 * Context: No reference, nor lock is required on @page. If the caller
271 * it should re-check the folio still contains this page after gaining
273 * Return: The folio which contains this page.
276 const struct page *: (const struct folio *)_compound_head(p), \
277 struct page *: (struct folio *)_compound_head(p)))
280 * folio_page - Return a page from a folio.
282 * @n: The page number to return.
285 * check that the page number lies within @folio; the caller is presumed
286 * to have a reference to the page.
288 #define folio_page(folio, n) nth_page(&(folio)->page, n)
290 static __always_inline int PageTail(struct page *page) in PageTail() argument
292 return READ_ONCE(page->compound_head) & 1 || page_is_fake_head(page); in PageTail()
295 static __always_inline int PageCompound(struct page *page) in PageCompound() argument
297 return test_bit(PG_head, &page->flags) || in PageCompound()
298 READ_ONCE(page->compound_head) & 1; in PageCompound()
302 static inline int PagePoisoned(const struct page *page) in PagePoisoned() argument
304 return READ_ONCE(page->flags) == PAGE_POISON_PATTERN; in PagePoisoned()
308 void page_init_poison(struct page *page, size_t size);
310 static inline void page_init_poison(struct page *page, size_t size) in page_init_poison() argument
317 struct page *page = &folio->page; in folio_flags() local
319 VM_BUG_ON_PGFLAGS(PageTail(page), page); in folio_flags()
320 VM_BUG_ON_PGFLAGS(n > 0 && !test_bit(PG_head, &page->flags), page); in folio_flags()
321 return &page[n].flags; in folio_flags()
325 * Page flags policies wrt compound pages
328 * check if this struct page poisoned/uninitialized
331 * the page flag is relevant for small, head and tail pages.
334 * for compound page all operations related to the page flag applied to
335 * head page.
338 * for compound page, callers only ever operate on the head page.
341 * modifications of the page flag must be done on small or head pages,
345 * the page flag is not relevant for compound pages.
348 * the page flag is stored in the first tail page.
350 #define PF_POISONED_CHECK(page) ({ \ argument
351 VM_BUG_ON_PGFLAGS(PagePoisoned(page), page); \
352 page; })
353 #define PF_ANY(page, enforce) PF_POISONED_CHECK(page) argument
354 #define PF_HEAD(page, enforce) PF_POISONED_CHECK(compound_head(page)) argument
355 #define PF_ONLY_HEAD(page, enforce) ({ \ argument
356 VM_BUG_ON_PGFLAGS(PageTail(page), page); \
357 PF_POISONED_CHECK(page); })
358 #define PF_NO_TAIL(page, enforce) ({ \ argument
359 VM_BUG_ON_PGFLAGS(enforce && PageTail(page), page); \
360 PF_POISONED_CHECK(compound_head(page)); })
361 #define PF_NO_COMPOUND(page, enforce) ({ \ argument
362 VM_BUG_ON_PGFLAGS(enforce && PageCompound(page), page); \
363 PF_POISONED_CHECK(page); })
364 #define PF_SECOND(page, enforce) ({ \ argument
365 VM_BUG_ON_PGFLAGS(!PageHead(page), page); \
366 PF_POISONED_CHECK(&page[1]); })
368 /* Which page is the flag stored in */
377 * Macros to create function definitions for page flags
382 static __always_inline int Page##uname(struct page *page) \
383 { return test_bit(PG_##lname, &policy(page, 0)->flags); }
389 static __always_inline void SetPage##uname(struct page *page) \
390 { set_bit(PG_##lname, &policy(page, 1)->flags); }
396 static __always_inline void ClearPage##uname(struct page *page) \
397 { clear_bit(PG_##lname, &policy(page, 1)->flags); }
403 static __always_inline void __SetPage##uname(struct page *page) \
404 { __set_bit(PG_##lname, &policy(page, 1)->flags); }
410 static __always_inline void __ClearPage##uname(struct page *page) \
411 { __clear_bit(PG_##lname, &policy(page, 1)->flags); }
417 static __always_inline int TestSetPage##uname(struct page *page) \
418 { return test_and_set_bit(PG_##lname, &policy(page, 1)->flags); }
424 static __always_inline int TestClearPage##uname(struct page *page) \
425 { return test_and_clear_bit(PG_##lname, &policy(page, 1)->flags); }
443 static inline int Page##uname(const struct page *page) { return 0; }
447 static inline void SetPage##uname(struct page *page) { }
451 static inline void ClearPage##uname(struct page *page) { }
455 static inline void __ClearPage##uname(struct page *page) { }
460 static inline int TestSetPage##uname(struct page *page) { return 0; }
465 static inline int TestClearPage##uname(struct page *page) { return 0; }
507 * Private page markings that may be used by the filesystem that owns the page in PAGEFLAG()
518 * risky: they bypass page accounting. in PAGEFLAG()
547 static __always_inline bool PageSwapCache(struct page *page) in PageSwapCache() argument
549 return folio_test_swapcache(page_folio(page)); in PageSwapCache()
582 extern void SetPageHWPoisonTakenOff(struct page *page);
583 extern void ClearPageHWPoisonTakenOff(struct page *page);
584 extern bool take_page_off_buddy(struct page *page);
585 extern bool put_page_back_buddy(struct page *page);
619 * On an anonymous page mapped into a user virtual memory area, in TESTPAGEFLAG()
620 * page->mapping points to its anon_vma, not to a struct address_space; in TESTPAGEFLAG()
623 * On an anonymous page in a VM_MERGEABLE area, if CONFIG_KSM is enabled, in TESTPAGEFLAG()
625 * bit; and then page->mapping points, not to an anon_vma, but to a private in TESTPAGEFLAG()
626 * structure which KSM associates with that merged page. See ksm.h. in TESTPAGEFLAG()
629 * page and then page->mapping points to a struct movable_operations. in TESTPAGEFLAG()
632 * address_space which maps the page from disk; whereas "page_mapped" in TESTPAGEFLAG()
633 * refers to user virtual address space into which the page is mapped. in TESTPAGEFLAG()
642 * indicates that this page->mapping is now under reflink case. in TESTPAGEFLAG()
651 static __always_inline int PageMappingFlags(struct page *page) in PageMappingFlags() argument
653 return ((unsigned long)page->mapping & PAGE_MAPPING_FLAGS) != 0; in PageMappingFlags()
661 static __always_inline bool PageAnon(struct page *page) in PageAnon() argument
663 return folio_test_anon(page_folio(page)); in PageAnon()
672 static __always_inline int __PageMovable(struct page *page) in __PageMovable() argument
674 return ((unsigned long)page->mapping & PAGE_MAPPING_FLAGS) == in __PageMovable()
680 * A KSM page is one of those write-protected "shared pages" or "merged pages"
681 * which KSM maps into multiple mms, wherever identical anonymous page content
682 * is found in VM_MERGEABLE vmas. It's a PageAnon page, pointing not to any
683 * anon_vma, but to that page's node of the stable tree.
691 static __always_inline bool PageKsm(struct page *page) in PageKsm() argument
693 return folio_test_ksm(page_folio(page)); in PageKsm()
699 u64 stable_page_flags(struct page *page);
728 static inline int PageUptodate(struct page *page) in PageUptodate() argument
730 return folio_test_uptodate(page_folio(page)); in PageUptodate()
750 static __always_inline void __SetPageUptodate(struct page *page) in __SetPageUptodate() argument
752 __folio_mark_uptodate((struct folio *)page); in __SetPageUptodate()
755 static __always_inline void SetPageUptodate(struct page *page) in SetPageUptodate() argument
757 folio_mark_uptodate((struct folio *)page); in SetPageUptodate()
763 bool set_page_writeback(struct page *page);
770 static inline void set_page_writeback_keepwrite(struct page *page) in set_page_writeback_keepwrite() argument
772 folio_start_writeback_keepwrite(page_folio(page)); in set_page_writeback_keepwrite()
775 static inline bool test_set_page_writeback(struct page *page) in test_set_page_writeback() argument
777 return set_page_writeback(page); in test_set_page_writeback()
785 static __always_inline int PageHead(struct page *page) in PageHead() argument
787 PF_POISONED_CHECK(page); in PageHead()
788 return test_bit(PG_head, &page->flags) && !page_is_fake_head(page); in PageHead()
796 * folio_test_large() - Does this folio contain more than one page? in __SETPAGEFLAG()
799 * Return: True if the folio is larger than one page. in __SETPAGEFLAG()
806 static __always_inline void set_compound_head(struct page *page, struct page *head) in set_compound_head() argument
808 WRITE_ONCE(page->compound_head, (unsigned long)head + 1); in set_compound_head()
811 static __always_inline void clear_compound_head(struct page *page) in clear_compound_head() argument
813 WRITE_ONCE(page->compound_head, 0); in clear_compound_head()
817 static inline void ClearPageCompound(struct page *page) in ClearPageCompound() argument
819 BUG_ON(!PageHead(page)); in ClearPageCompound()
820 ClearPageHead(page); in ClearPageCompound()
827 int PageHuge(struct page *page);
828 int PageHeadHuge(struct page *page);
831 return PageHeadHuge(&folio->page); in folio_test_hugetlb()
847 static inline int PageTransHuge(struct page *page) in TESTPAGEFLAG_FALSE()
849 VM_BUG_ON_PAGE(PageTail(page), page); in TESTPAGEFLAG_FALSE()
850 return PageHead(page); in TESTPAGEFLAG_FALSE()
863 static inline int PageTransCompound(struct page *page) in PageTransCompound() argument
865 return PageCompound(page); in PageTransCompound()
873 static inline int PageTransTail(struct page *page) in PageTransTail() argument
875 return PageTail(page); in PageTransTail()
879 * PageDoubleMap indicates that the compound page is mapped with PTEs as well
883 * per small page mapcount accounting (and its overhead from atomic operations)
886 * For the page PageDoubleMap means ->_mapcount in all sub-pages is offset up
905 * compound page. in PAGEFLAG()
907 * This flag is set by hwpoison handler. Cleared by THP split or free page. in PAGEFLAG()
917 * Check if a page is currently marked HWPoisoned. Note that this check is in PAGEFLAG()
921 static inline bool is_page_hwpoison(struct page *page) in PAGEFLAG()
923 if (PageHWPoison(page)) in PAGEFLAG()
925 return PageHuge(page) && PageHWPoison(compound_head(page)); in PAGEFLAG()
934 * mistaken for a page type value.
945 #define PageType(page, flag) \ argument
946 ((page->page_type & (PAGE_TYPE_BASE | flag)) == PAGE_TYPE_BASE)
948 static inline int page_has_type(struct page *page) in page_has_type() argument
950 return (int)page->page_type < PAGE_MAPCOUNT_RESERVE; in page_has_type()
954 static __always_inline int Page##uname(struct page *page) \
956 return PageType(page, PG_##lname); \
958 static __always_inline void __SetPage##uname(struct page *page) \
960 VM_BUG_ON_PAGE(!PageType(page, 0), page); \
961 page->page_type &= ~PG_##lname; \
963 static __always_inline void __ClearPage##uname(struct page *page) \
965 VM_BUG_ON_PAGE(!Page##uname(page), page); \
966 page->page_type |= PG_##lname; \
970 * PageBuddy() indicates that the page is free and in the buddy system
976 * PageOffline() indicates that the page is logically offline although the
992 * There are drivers that mark a page PageOffline() and expect there won't be
993 * any further access to page content. PFN walkers that read content of random
1005 * Marks pages in use as page tables.
1014 extern bool is_free_buddy_page(struct page *page);
1018 static __always_inline int PageAnonExclusive(struct page *page) in PageAnonExclusive() argument
1020 VM_BUG_ON_PGFLAGS(!PageAnon(page), page); in PageAnonExclusive()
1021 VM_BUG_ON_PGFLAGS(PageHuge(page) && !PageHead(page), page); in PageAnonExclusive()
1022 return test_bit(PG_anon_exclusive, &PF_ANY(page, 1)->flags); in PageAnonExclusive()
1025 static __always_inline void SetPageAnonExclusive(struct page *page) in SetPageAnonExclusive() argument
1027 VM_BUG_ON_PGFLAGS(!PageAnon(page) || PageKsm(page), page); in SetPageAnonExclusive()
1028 VM_BUG_ON_PGFLAGS(PageHuge(page) && !PageHead(page), page); in SetPageAnonExclusive()
1029 set_bit(PG_anon_exclusive, &PF_ANY(page, 1)->flags); in SetPageAnonExclusive()
1032 static __always_inline void ClearPageAnonExclusive(struct page *page) in ClearPageAnonExclusive() argument
1034 VM_BUG_ON_PGFLAGS(!PageAnon(page) || PageKsm(page), page); in ClearPageAnonExclusive()
1035 VM_BUG_ON_PGFLAGS(PageHuge(page) && !PageHead(page), page); in ClearPageAnonExclusive()
1036 clear_bit(PG_anon_exclusive, &PF_ANY(page, 1)->flags); in ClearPageAnonExclusive()
1039 static __always_inline void __ClearPageAnonExclusive(struct page *page) in __ClearPageAnonExclusive() argument
1041 VM_BUG_ON_PGFLAGS(!PageAnon(page), page); in __ClearPageAnonExclusive()
1042 VM_BUG_ON_PGFLAGS(PageHuge(page) && !PageHead(page), page); in __ClearPageAnonExclusive()
1043 __clear_bit(PG_anon_exclusive, &PF_ANY(page, 1)->flags); in __ClearPageAnonExclusive()
1053 * Flags checked when a page is freed. Pages being freed should not have
1064 * Flags checked when a page is prepped for return by the page allocator.
1066 * there has been a kernel bug or struct page corruption.
1068 * __PG_HWPOISON is exceptional because it needs to be kept beyond page's
1069 * alloc-free cycle to prevent from reusing the page.
1077 * page_has_private - Determine if page has private stuff
1078 * @page: The page to be checked
1080 * Determine if a page has private stuff, indicating that release routines
1083 static inline int page_has_private(struct page *page) in page_has_private() argument
1085 return !!(page->flags & PAGE_FLAGS_PRIVATE); in page_has_private()
1090 return page_has_private(&folio->page); in folio_has_private()