blob: 74bee8cecf4ce864322157d3e93defe200ec0173 [file] [log] [blame]
Greg Kroah-Hartmanb2441312017-11-01 15:07:57 +01001/* SPDX-License-Identifier: GPL-2.0 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002/*
3 * Macros for manipulating and testing page->flags
4 */
5
6#ifndef PAGE_FLAGS_H
7#define PAGE_FLAGS_H
8
Andrew Mortonf886ed42006-06-23 02:03:06 -07009#include <linux/types.h>
Paul Gortmaker187f1882011-11-23 20:12:59 -050010#include <linux/bug.h>
Mel Gorman072bb0a2012-07-31 16:43:58 -070011#include <linux/mmdebug.h>
Christoph Lameter9223b412008-04-28 02:12:48 -070012#ifndef __GENERATING_BOUNDS_H
Christoph Lameter6d777952007-05-06 14:49:40 -070013#include <linux/mm_types.h>
Sam Ravnborg01fc0ac2009-04-19 21:57:19 +020014#include <generated/bounds.h>
Christoph Lameter9223b412008-04-28 02:12:48 -070015#endif /* !__GENERATING_BOUNDS_H */
Andrew Mortonf886ed42006-06-23 02:03:06 -070016
Linus Torvalds1da177e2005-04-16 15:20:36 -070017/*
18 * Various page->flags bits:
19 *
20 * PG_reserved is set for special pages, which can never be swapped out. Some
Michal Hocko87458082017-11-15 17:34:22 -080021 * of them might not even exist...
Linus Torvalds1da177e2005-04-16 15:20:36 -070022 *
Nick Pigginda6052f2006-09-25 23:31:35 -070023 * The PG_private bitflag is set on pagecache pages if they contain filesystem
24 * specific data (which is normally at page->private). It can be used by
25 * private allocations for its own usage.
Linus Torvalds1da177e2005-04-16 15:20:36 -070026 *
Nick Pigginda6052f2006-09-25 23:31:35 -070027 * During initiation of disk I/O, PG_locked is set. This bit is set before I/O
28 * and cleared when writeback _starts_ or when read _completes_. PG_writeback
29 * is set before writeback starts and cleared when it finishes.
30 *
31 * PG_locked also pins a page in pagecache, and blocks truncation of the file
32 * while it is held.
33 *
34 * page_waitqueue(page) is a wait queue of all tasks waiting for the page
35 * to become unlocked.
Linus Torvalds1da177e2005-04-16 15:20:36 -070036 *
37 * PG_uptodate tells whether the page's contents is valid. When a read
38 * completes, the page becomes uptodate, unless a disk I/O error happened.
39 *
Nick Pigginda6052f2006-09-25 23:31:35 -070040 * PG_referenced, PG_reclaim are used for page reclaim for anonymous and
41 * file-backed pagecache (see mm/vmscan.c).
Linus Torvalds1da177e2005-04-16 15:20:36 -070042 *
43 * PG_error is set to indicate that an I/O error occurred on this page.
44 *
45 * PG_arch_1 is an architecture specific page state bit. The generic code
46 * guarantees that this bit is cleared for a page when it first is entered into
47 * the page cache.
48 *
Andi Kleend466f2f2009-09-16 11:50:03 +020049 * PG_hwpoison indicates that a page got corrupted in hardware and contains
50 * data with incorrect ECC bits that triggered a machine check. Accessing is
51 * not safe since it may cause another machine check. Don't touch!
Linus Torvalds1da177e2005-04-16 15:20:36 -070052 */
53
54/*
55 * Don't use the *_dontuse flags. Use the macros. Otherwise you'll break
Andy Whitcroft91fc8ab2006-04-10 22:53:01 -070056 * locked- and dirty-page accounting.
57 *
58 * The page flags field is split into two parts, the main flags area
59 * which extends from the low bits upwards, and the fields area which
60 * extends from the high bits downwards.
61 *
62 * | FIELD | ... | FLAGS |
Christoph Lameter9223b412008-04-28 02:12:48 -070063 * N-1 ^ 0
64 * (NR_PAGEFLAGS)
Andy Whitcroft91fc8ab2006-04-10 22:53:01 -070065 *
Christoph Lameter9223b412008-04-28 02:12:48 -070066 * The fields area is reserved for fields mapping zone, node (for NUMA) and
67 * SPARSEMEM section (for variants of SPARSEMEM that require section ids like
68 * SPARSEMEM_EXTREME with !SPARSEMEM_VMEMMAP).
Linus Torvalds1da177e2005-04-16 15:20:36 -070069 */
Christoph Lametere2683182008-04-28 02:12:47 -070070enum pageflags {
71 PG_locked, /* Page is locked. Don't touch. */
72 PG_error,
73 PG_referenced,
74 PG_uptodate,
75 PG_dirty,
76 PG_lru,
77 PG_active,
Linus Torvaldsb91e1302016-12-27 11:40:38 -080078 PG_waiters, /* Page has waiters, check its waitqueue. Must be bit #7 and in the same byte as "PG_locked" */
Christoph Lametere2683182008-04-28 02:12:47 -070079 PG_slab,
80 PG_owner_priv_1, /* Owner use. If pagecache, fs may use*/
Christoph Lametere2683182008-04-28 02:12:47 -070081 PG_arch_1,
82 PG_reserved,
83 PG_private, /* If pagecache, has fs-private data */
David Howells266cf652009-04-03 16:42:36 +010084 PG_private_2, /* If pagecache, has fs aux data */
Christoph Lametere2683182008-04-28 02:12:47 -070085 PG_writeback, /* Page is under writeback */
Christoph Lametere20b8cc2008-04-28 02:12:55 -070086 PG_head, /* A head page */
Christoph Lametere2683182008-04-28 02:12:47 -070087 PG_mappedtodisk, /* Has blocks allocated on-disk */
88 PG_reclaim, /* To be reclaimed asap */
Rik van Rielb2e18532008-10-18 20:26:30 -070089 PG_swapbacked, /* Page is backed by RAM/swap */
Lee Schermerhorn894bc312008-10-18 20:26:39 -070090 PG_unevictable, /* Page is "unevictable" */
Hugh Dickinsaf8e3352009-12-14 17:58:59 -080091#ifdef CONFIG_MMU
Nick Pigginb291f002008-10-18 20:26:44 -070092 PG_mlocked, /* Page is vma mlocked */
Lee Schermerhorn894bc312008-10-18 20:26:39 -070093#endif
Venkatesh Pallipadi46cf98c2009-07-10 09:57:37 -070094#ifdef CONFIG_ARCH_USES_PG_UNCACHED
Christoph Lameter602c4d12008-04-28 02:12:52 -070095 PG_uncached, /* Page has been mapped as uncached */
Andrew Mortonf886ed42006-06-23 02:03:06 -070096#endif
Andi Kleend466f2f2009-09-16 11:50:03 +020097#ifdef CONFIG_MEMORY_FAILURE
98 PG_hwpoison, /* hardware poisoned page. Don't touch */
99#endif
Vladimir Davydov33c3fc72015-09-09 15:35:45 -0700100#if defined(CONFIG_IDLE_PAGE_TRACKING) && defined(CONFIG_64BIT)
101 PG_young,
102 PG_idle,
103#endif
Andy Whitcroft0cad47c2008-07-23 21:27:16 -0700104 __NR_PAGEFLAGS,
105
106 /* Filesystems */
107 PG_checked = PG_owner_priv_1,
108
Nicholas Piggin6326fec2016-12-25 13:00:29 +1000109 /* SwapBacked */
110 PG_swapcache = PG_owner_priv_1, /* Swap page: swp_entry_t in private */
111
David Howells266cf652009-04-03 16:42:36 +0100112 /* Two page bits are conscripted by FS-Cache to maintain local caching
113 * state. These bits are set on pages belonging to the netfs's inodes
114 * when those inodes are being locally cached.
115 */
116 PG_fscache = PG_private_2, /* page backed by cache */
117
Andy Whitcroft0cad47c2008-07-23 21:27:16 -0700118 /* XEN */
Jennifer Herbertd8ac3dd2015-01-05 13:24:09 +0000119 /* Pinned in Xen as a read-only pagetable page. */
Andy Whitcroft0cad47c2008-07-23 21:27:16 -0700120 PG_pinned = PG_owner_priv_1,
Jennifer Herbertd8ac3dd2015-01-05 13:24:09 +0000121 /* Pinned as part of domain save (see xen_mm_pin_all()). */
Andy Whitcroft0cad47c2008-07-23 21:27:16 -0700122 PG_savepinned = PG_dirty,
Jennifer Herbertd8ac3dd2015-01-05 13:24:09 +0000123 /* Has a grant mapping of another (foreign) domain's page. */
124 PG_foreign = PG_owner_priv_1,
Andy Whitcroft8a380822008-07-23 21:27:18 -0700125
Andy Whitcroft9023cb72008-07-23 21:27:19 -0700126 /* SLOB */
Andy Whitcroft9023cb72008-07-23 21:27:19 -0700127 PG_slob_free = PG_private,
Kirill A. Shutemov53f92632016-01-15 16:53:42 -0800128
129 /* Compound pages. Stored in first tail page's flags */
130 PG_double_map = PG_private_2,
Minchan Kimbda807d2016-07-26 15:23:05 -0700131
132 /* non-lru isolated movable page */
133 PG_isolated = PG_reclaim,
Christoph Lametere2683182008-04-28 02:12:47 -0700134};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700135
Christoph Lameter9223b412008-04-28 02:12:48 -0700136#ifndef __GENERATING_BOUNDS_H
137
Kirill A. Shutemov0e6d31a2016-01-15 16:51:17 -0800138struct page; /* forward declaration */
139
140static inline struct page *compound_head(struct page *page)
141{
142 unsigned long head = READ_ONCE(page->compound_head);
143
144 if (unlikely(head & 1))
145 return (struct page *) (head - 1);
146 return page;
147}
148
Denys Vlasenko4b0f3262016-03-17 14:18:24 -0700149static __always_inline int PageTail(struct page *page)
Kirill A. Shutemov0e6d31a2016-01-15 16:51:17 -0800150{
151 return READ_ONCE(page->compound_head) & 1;
152}
153
Denys Vlasenko4b0f3262016-03-17 14:18:24 -0700154static __always_inline int PageCompound(struct page *page)
Kirill A. Shutemov0e6d31a2016-01-15 16:51:17 -0800155{
156 return test_bit(PG_head, &page->flags) || PageTail(page);
157}
158
Pavel Tatashinf165b372018-04-05 16:22:47 -0700159#define PAGE_POISON_PATTERN -1l
160static inline int PagePoisoned(const struct page *page)
161{
162 return page->flags == PAGE_POISON_PATTERN;
163}
164
Linus Torvalds1da177e2005-04-16 15:20:36 -0700165/*
Kirill A. Shutemov95ad9752016-01-15 16:51:21 -0800166 * Page flags policies wrt compound pages
167 *
Pavel Tatashinf165b372018-04-05 16:22:47 -0700168 * PF_POISONED_CHECK
169 * check if this struct page poisoned/uninitialized
170 *
Kirill A. Shutemov95ad9752016-01-15 16:51:21 -0800171 * PF_ANY:
172 * the page flag is relevant for small, head and tail pages.
173 *
174 * PF_HEAD:
175 * for compound page all operations related to the page flag applied to
176 * head page.
177 *
Nicholas Piggin62906022016-12-25 13:00:30 +1000178 * PF_ONLY_HEAD:
179 * for compound page, callers only ever operate on the head page.
180 *
Kirill A. Shutemov95ad9752016-01-15 16:51:21 -0800181 * PF_NO_TAIL:
182 * modifications of the page flag must be done on small or head pages,
183 * checks can be done on tail pages too.
184 *
185 * PF_NO_COMPOUND:
186 * the page flag is not relevant for compound pages.
187 */
Pavel Tatashinf165b372018-04-05 16:22:47 -0700188#define PF_POISONED_CHECK(page) ({ \
189 VM_BUG_ON_PGFLAGS(PagePoisoned(page), page); \
190 page; })
191#define PF_ANY(page, enforce) PF_POISONED_CHECK(page)
192#define PF_HEAD(page, enforce) PF_POISONED_CHECK(compound_head(page))
Nicholas Piggin62906022016-12-25 13:00:30 +1000193#define PF_ONLY_HEAD(page, enforce) ({ \
194 VM_BUG_ON_PGFLAGS(PageTail(page), page); \
Pavel Tatashinf165b372018-04-05 16:22:47 -0700195 PF_POISONED_CHECK(page); })
Kirill A. Shutemov95ad9752016-01-15 16:51:21 -0800196#define PF_NO_TAIL(page, enforce) ({ \
197 VM_BUG_ON_PGFLAGS(enforce && PageTail(page), page); \
Pavel Tatashinf165b372018-04-05 16:22:47 -0700198 PF_POISONED_CHECK(compound_head(page)); })
Kirill A. Shutemov822cdd112016-01-15 16:52:03 -0800199#define PF_NO_COMPOUND(page, enforce) ({ \
Kirill A. Shutemov95ad9752016-01-15 16:51:21 -0800200 VM_BUG_ON_PGFLAGS(enforce && PageCompound(page), page); \
Pavel Tatashinf165b372018-04-05 16:22:47 -0700201 PF_POISONED_CHECK(page); })
Kirill A. Shutemov95ad9752016-01-15 16:51:21 -0800202
203/*
Christoph Lameterf94a62e2008-04-28 02:12:49 -0700204 * Macros to create function definitions for page flags
205 */
Kirill A. Shutemov95ad9752016-01-15 16:51:21 -0800206#define TESTPAGEFLAG(uname, lname, policy) \
Denys Vlasenko4b0f3262016-03-17 14:18:24 -0700207static __always_inline int Page##uname(struct page *page) \
Kirill A. Shutemov95ad9752016-01-15 16:51:21 -0800208 { return test_bit(PG_##lname, &policy(page, 0)->flags); }
Christoph Lameterf94a62e2008-04-28 02:12:49 -0700209
Kirill A. Shutemov95ad9752016-01-15 16:51:21 -0800210#define SETPAGEFLAG(uname, lname, policy) \
Denys Vlasenko4b0f3262016-03-17 14:18:24 -0700211static __always_inline void SetPage##uname(struct page *page) \
Kirill A. Shutemov95ad9752016-01-15 16:51:21 -0800212 { set_bit(PG_##lname, &policy(page, 1)->flags); }
Christoph Lameterf94a62e2008-04-28 02:12:49 -0700213
Kirill A. Shutemov95ad9752016-01-15 16:51:21 -0800214#define CLEARPAGEFLAG(uname, lname, policy) \
Denys Vlasenko4b0f3262016-03-17 14:18:24 -0700215static __always_inline void ClearPage##uname(struct page *page) \
Kirill A. Shutemov95ad9752016-01-15 16:51:21 -0800216 { clear_bit(PG_##lname, &policy(page, 1)->flags); }
Christoph Lameterf94a62e2008-04-28 02:12:49 -0700217
Kirill A. Shutemov95ad9752016-01-15 16:51:21 -0800218#define __SETPAGEFLAG(uname, lname, policy) \
Denys Vlasenko4b0f3262016-03-17 14:18:24 -0700219static __always_inline void __SetPage##uname(struct page *page) \
Kirill A. Shutemov95ad9752016-01-15 16:51:21 -0800220 { __set_bit(PG_##lname, &policy(page, 1)->flags); }
Christoph Lameterf94a62e2008-04-28 02:12:49 -0700221
Kirill A. Shutemov95ad9752016-01-15 16:51:21 -0800222#define __CLEARPAGEFLAG(uname, lname, policy) \
Denys Vlasenko4b0f3262016-03-17 14:18:24 -0700223static __always_inline void __ClearPage##uname(struct page *page) \
Kirill A. Shutemov95ad9752016-01-15 16:51:21 -0800224 { __clear_bit(PG_##lname, &policy(page, 1)->flags); }
Christoph Lameterf94a62e2008-04-28 02:12:49 -0700225
Kirill A. Shutemov95ad9752016-01-15 16:51:21 -0800226#define TESTSETFLAG(uname, lname, policy) \
Denys Vlasenko4b0f3262016-03-17 14:18:24 -0700227static __always_inline int TestSetPage##uname(struct page *page) \
Kirill A. Shutemov95ad9752016-01-15 16:51:21 -0800228 { return test_and_set_bit(PG_##lname, &policy(page, 1)->flags); }
Christoph Lameterf94a62e2008-04-28 02:12:49 -0700229
Kirill A. Shutemov95ad9752016-01-15 16:51:21 -0800230#define TESTCLEARFLAG(uname, lname, policy) \
Denys Vlasenko4b0f3262016-03-17 14:18:24 -0700231static __always_inline int TestClearPage##uname(struct page *page) \
Kirill A. Shutemov95ad9752016-01-15 16:51:21 -0800232 { return test_and_clear_bit(PG_##lname, &policy(page, 1)->flags); }
Christoph Lameterf94a62e2008-04-28 02:12:49 -0700233
Kirill A. Shutemov95ad9752016-01-15 16:51:21 -0800234#define PAGEFLAG(uname, lname, policy) \
235 TESTPAGEFLAG(uname, lname, policy) \
236 SETPAGEFLAG(uname, lname, policy) \
237 CLEARPAGEFLAG(uname, lname, policy)
Christoph Lameterf94a62e2008-04-28 02:12:49 -0700238
Kirill A. Shutemov95ad9752016-01-15 16:51:21 -0800239#define __PAGEFLAG(uname, lname, policy) \
240 TESTPAGEFLAG(uname, lname, policy) \
241 __SETPAGEFLAG(uname, lname, policy) \
242 __CLEARPAGEFLAG(uname, lname, policy)
Christoph Lameterf94a62e2008-04-28 02:12:49 -0700243
Kirill A. Shutemov95ad9752016-01-15 16:51:21 -0800244#define TESTSCFLAG(uname, lname, policy) \
245 TESTSETFLAG(uname, lname, policy) \
246 TESTCLEARFLAG(uname, lname, policy)
Christoph Lameterf94a62e2008-04-28 02:12:49 -0700247
Johannes Weiner2f3e4422014-08-06 16:05:40 -0700248#define TESTPAGEFLAG_FALSE(uname) \
249static inline int Page##uname(const struct page *page) { return 0; }
250
Lee Schermerhorn8a7a8542008-10-18 20:26:37 -0700251#define SETPAGEFLAG_NOOP(uname) \
252static inline void SetPage##uname(struct page *page) { }
253
254#define CLEARPAGEFLAG_NOOP(uname) \
255static inline void ClearPage##uname(struct page *page) { }
256
257#define __CLEARPAGEFLAG_NOOP(uname) \
258static inline void __ClearPage##uname(struct page *page) { }
259
Johannes Weiner2f3e4422014-08-06 16:05:40 -0700260#define TESTSETFLAG_FALSE(uname) \
261static inline int TestSetPage##uname(struct page *page) { return 0; }
262
Lee Schermerhorn8a7a8542008-10-18 20:26:37 -0700263#define TESTCLEARFLAG_FALSE(uname) \
264static inline int TestClearPage##uname(struct page *page) { return 0; }
265
Johannes Weiner2f3e4422014-08-06 16:05:40 -0700266#define PAGEFLAG_FALSE(uname) TESTPAGEFLAG_FALSE(uname) \
267 SETPAGEFLAG_NOOP(uname) CLEARPAGEFLAG_NOOP(uname)
268
269#define TESTSCFLAG_FALSE(uname) \
270 TESTSETFLAG_FALSE(uname) TESTCLEARFLAG_FALSE(uname)
271
Kirill A. Shutemov48c935a2016-01-15 16:51:24 -0800272__PAGEFLAG(Locked, locked, PF_NO_TAIL)
Nicholas Piggin62906022016-12-25 13:00:30 +1000273PAGEFLAG(Waiters, waiters, PF_ONLY_HEAD) __CLEARPAGEFLAG(Waiters, waiters, PF_ONLY_HEAD)
Kirill A. Shutemovdf8c94d2016-01-15 16:51:28 -0800274PAGEFLAG(Error, error, PF_NO_COMPOUND) TESTCLEARFLAG(Error, error, PF_NO_COMPOUND)
Kirill A. Shutemov8cb38fa2016-01-15 16:51:32 -0800275PAGEFLAG(Referenced, referenced, PF_HEAD)
276 TESTCLEARFLAG(Referenced, referenced, PF_HEAD)
277 __SETPAGEFLAG(Referenced, referenced, PF_HEAD)
Kirill A. Shutemovdf8c94d2016-01-15 16:51:28 -0800278PAGEFLAG(Dirty, dirty, PF_HEAD) TESTSCFLAG(Dirty, dirty, PF_HEAD)
279 __CLEARPAGEFLAG(Dirty, dirty, PF_HEAD)
Kirill A. Shutemov8cb38fa2016-01-15 16:51:32 -0800280PAGEFLAG(LRU, lru, PF_HEAD) __CLEARPAGEFLAG(LRU, lru, PF_HEAD)
281PAGEFLAG(Active, active, PF_HEAD) __CLEARPAGEFLAG(Active, active, PF_HEAD)
282 TESTCLEARFLAG(Active, active, PF_HEAD)
Kirill A. Shutemovdcb351c2016-01-15 16:51:35 -0800283__PAGEFLAG(Slab, slab, PF_NO_TAIL)
284__PAGEFLAG(SlobFree, slob_free, PF_NO_TAIL)
Kirill A. Shutemovdf8c94d2016-01-15 16:51:28 -0800285PAGEFLAG(Checked, checked, PF_NO_COMPOUND) /* Used by some filesystems */
Kirill A. Shutemovc13985f2016-01-15 16:51:39 -0800286
287/* Xen */
288PAGEFLAG(Pinned, pinned, PF_NO_COMPOUND)
289 TESTSCFLAG(Pinned, pinned, PF_NO_COMPOUND)
290PAGEFLAG(SavePinned, savepinned, PF_NO_COMPOUND);
291PAGEFLAG(Foreign, foreign, PF_NO_COMPOUND);
292
Kirill A. Shutemovde09d312016-01-15 16:51:42 -0800293PAGEFLAG(Reserved, reserved, PF_NO_COMPOUND)
294 __CLEARPAGEFLAG(Reserved, reserved, PF_NO_COMPOUND)
Kirill A. Shutemovda5efc42016-01-15 16:51:46 -0800295PAGEFLAG(SwapBacked, swapbacked, PF_NO_TAIL)
296 __CLEARPAGEFLAG(SwapBacked, swapbacked, PF_NO_TAIL)
297 __SETPAGEFLAG(SwapBacked, swapbacked, PF_NO_TAIL)
Christoph Lameter6a1e7f72008-04-28 02:12:50 -0700298
Christoph Lameterf94a62e2008-04-28 02:12:49 -0700299/*
David Howells266cf652009-04-03 16:42:36 +0100300 * Private page markings that may be used by the filesystem that owns the page
301 * for its own purposes.
302 * - PG_private and PG_private_2 cause releasepage() and co to be invoked
303 */
Kirill A. Shutemov95ad9752016-01-15 16:51:21 -0800304PAGEFLAG(Private, private, PF_ANY) __SETPAGEFLAG(Private, private, PF_ANY)
305 __CLEARPAGEFLAG(Private, private, PF_ANY)
306PAGEFLAG(Private2, private_2, PF_ANY) TESTSCFLAG(Private2, private_2, PF_ANY)
307PAGEFLAG(OwnerPriv1, owner_priv_1, PF_ANY)
308 TESTCLEARFLAG(OwnerPriv1, owner_priv_1, PF_ANY)
David Howells266cf652009-04-03 16:42:36 +0100309
310/*
Christoph Lameter6a1e7f72008-04-28 02:12:50 -0700311 * Only test-and-set exist for PG_writeback. The unconditional operators are
312 * risky: they bypass page accounting.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700313 */
Huang Ying225311a2017-09-06 16:22:30 -0700314TESTPAGEFLAG(Writeback, writeback, PF_NO_TAIL)
315 TESTSCFLAG(Writeback, writeback, PF_NO_TAIL)
Kirill A. Shutemove2f0a0d2016-07-26 15:25:59 -0700316PAGEFLAG(MappedToDisk, mappedtodisk, PF_NO_TAIL)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700317
Shaohua Li579f8292014-02-06 12:04:21 -0800318/* PG_readahead is only used for reads; PG_reclaim is only for writes */
Kirill A. Shutemove2f0a0d2016-07-26 15:25:59 -0700319PAGEFLAG(Reclaim, reclaim, PF_NO_TAIL)
320 TESTCLEARFLAG(Reclaim, reclaim, PF_NO_TAIL)
Kirill A. Shutemovdf8c94d2016-01-15 16:51:28 -0800321PAGEFLAG(Readahead, reclaim, PF_NO_COMPOUND)
322 TESTCLEARFLAG(Readahead, reclaim, PF_NO_COMPOUND)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700323
Christoph Lameter6a1e7f72008-04-28 02:12:50 -0700324#ifdef CONFIG_HIGHMEM
325/*
326 * Must use a macro here due to header dependency issues. page_zone() is not
327 * available at this point.
328 */
Vineet Gupta3ca65c12015-11-05 18:48:29 -0800329#define PageHighMem(__p) is_highmem_idx(page_zonenum(__p))
Christoph Lameter6a1e7f72008-04-28 02:12:50 -0700330#else
Christoph Lameterec7cade2008-04-28 02:12:53 -0700331PAGEFLAG_FALSE(HighMem)
Christoph Lameter6a1e7f72008-04-28 02:12:50 -0700332#endif
333
334#ifdef CONFIG_SWAP
Nicholas Piggin6326fec2016-12-25 13:00:29 +1000335static __always_inline int PageSwapCache(struct page *page)
336{
Huang Ying38d8b4e2017-07-06 15:37:18 -0700337#ifdef CONFIG_THP_SWAP
338 page = compound_head(page);
339#endif
Nicholas Piggin6326fec2016-12-25 13:00:29 +1000340 return PageSwapBacked(page) && test_bit(PG_swapcache, &page->flags);
341
342}
Huang Ying38d8b4e2017-07-06 15:37:18 -0700343SETPAGEFLAG(SwapCache, swapcache, PF_NO_TAIL)
344CLEARPAGEFLAG(SwapCache, swapcache, PF_NO_TAIL)
Christoph Lameter6a1e7f72008-04-28 02:12:50 -0700345#else
Christoph Lameterec7cade2008-04-28 02:12:53 -0700346PAGEFLAG_FALSE(SwapCache)
Christoph Lameter6a1e7f72008-04-28 02:12:50 -0700347#endif
348
Kirill A. Shutemov8cb38fa2016-01-15 16:51:32 -0800349PAGEFLAG(Unevictable, unevictable, PF_HEAD)
350 __CLEARPAGEFLAG(Unevictable, unevictable, PF_HEAD)
351 TESTCLEARFLAG(Unevictable, unevictable, PF_HEAD)
Lee Schermerhorn894bc312008-10-18 20:26:39 -0700352
Hugh Dickinsaf8e3352009-12-14 17:58:59 -0800353#ifdef CONFIG_MMU
Kirill A. Shutemove4f87d52016-01-15 16:51:53 -0800354PAGEFLAG(Mlocked, mlocked, PF_NO_TAIL)
355 __CLEARPAGEFLAG(Mlocked, mlocked, PF_NO_TAIL)
356 TESTSCFLAG(Mlocked, mlocked, PF_NO_TAIL)
David Howells33925b22009-03-31 15:23:26 -0700357#else
Johannes Weiner2f3e4422014-08-06 16:05:40 -0700358PAGEFLAG_FALSE(Mlocked) __CLEARPAGEFLAG_NOOP(Mlocked)
Kirill A. Shutemov685eaad2016-01-15 16:52:10 -0800359 TESTSCFLAG_FALSE(Mlocked)
David Howells33925b22009-03-31 15:23:26 -0700360#endif
361
Venkatesh Pallipadi46cf98c2009-07-10 09:57:37 -0700362#ifdef CONFIG_ARCH_USES_PG_UNCACHED
Kirill A. Shutemovb9d41812016-01-15 16:51:56 -0800363PAGEFLAG(Uncached, uncached, PF_NO_COMPOUND)
Christoph Lameter602c4d12008-04-28 02:12:52 -0700364#else
Christoph Lameterec7cade2008-04-28 02:12:53 -0700365PAGEFLAG_FALSE(Uncached)
Christoph Lameter6a1e7f72008-04-28 02:12:50 -0700366#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700367
Andi Kleend466f2f2009-09-16 11:50:03 +0200368#ifdef CONFIG_MEMORY_FAILURE
Kirill A. Shutemov95ad9752016-01-15 16:51:21 -0800369PAGEFLAG(HWPoison, hwpoison, PF_ANY)
370TESTSCFLAG(HWPoison, hwpoison, PF_ANY)
Andi Kleend466f2f2009-09-16 11:50:03 +0200371#define __PG_HWPOISON (1UL << PG_hwpoison)
Naoya Horiguchid4ae9912018-08-23 17:00:42 -0700372extern bool set_hwpoison_free_buddy_page(struct page *page);
Andi Kleend466f2f2009-09-16 11:50:03 +0200373#else
374PAGEFLAG_FALSE(HWPoison)
Naoya Horiguchid4ae9912018-08-23 17:00:42 -0700375static inline bool set_hwpoison_free_buddy_page(struct page *page)
376{
377 return 0;
378}
Andi Kleend466f2f2009-09-16 11:50:03 +0200379#define __PG_HWPOISON 0
380#endif
381
Vladimir Davydov33c3fc72015-09-09 15:35:45 -0700382#if defined(CONFIG_IDLE_PAGE_TRACKING) && defined(CONFIG_64BIT)
Kirill A. Shutemov95ad9752016-01-15 16:51:21 -0800383TESTPAGEFLAG(Young, young, PF_ANY)
384SETPAGEFLAG(Young, young, PF_ANY)
385TESTCLEARFLAG(Young, young, PF_ANY)
386PAGEFLAG(Idle, idle, PF_ANY)
Vladimir Davydov33c3fc72015-09-09 15:35:45 -0700387#endif
388
Kirill A. Shutemove8c61582015-04-15 16:13:08 -0700389/*
390 * On an anonymous page mapped into a user virtual memory area,
391 * page->mapping points to its anon_vma, not to a struct address_space;
392 * with the PAGE_MAPPING_ANON bit set to distinguish it. See rmap.h.
393 *
394 * On an anonymous page in a VM_MERGEABLE area, if CONFIG_KSM is enabled,
Minchan Kimbda807d2016-07-26 15:23:05 -0700395 * the PAGE_MAPPING_MOVABLE bit may be set along with the PAGE_MAPPING_ANON
396 * bit; and then page->mapping points, not to an anon_vma, but to a private
Kirill A. Shutemove8c61582015-04-15 16:13:08 -0700397 * structure which KSM associates with that merged page. See ksm.h.
398 *
Minchan Kimbda807d2016-07-26 15:23:05 -0700399 * PAGE_MAPPING_KSM without PAGE_MAPPING_ANON is used for non-lru movable
400 * page and then page->mapping points a struct address_space.
Kirill A. Shutemove8c61582015-04-15 16:13:08 -0700401 *
402 * Please note that, confusingly, "page_mapping" refers to the inode
403 * address_space which maps the page from disk; whereas "page_mapped"
404 * refers to user virtual address space into which the page is mapped.
405 */
Minchan Kimbda807d2016-07-26 15:23:05 -0700406#define PAGE_MAPPING_ANON 0x1
407#define PAGE_MAPPING_MOVABLE 0x2
408#define PAGE_MAPPING_KSM (PAGE_MAPPING_ANON | PAGE_MAPPING_MOVABLE)
409#define PAGE_MAPPING_FLAGS (PAGE_MAPPING_ANON | PAGE_MAPPING_MOVABLE)
Kirill A. Shutemove8c61582015-04-15 16:13:08 -0700410
Minchan Kimbda807d2016-07-26 15:23:05 -0700411static __always_inline int PageMappingFlags(struct page *page)
Mel Gorman17514572016-05-19 17:13:21 -0700412{
Minchan Kimbda807d2016-07-26 15:23:05 -0700413 return ((unsigned long)page->mapping & PAGE_MAPPING_FLAGS) != 0;
Mel Gorman17514572016-05-19 17:13:21 -0700414}
415
Denys Vlasenko4b0f3262016-03-17 14:18:24 -0700416static __always_inline int PageAnon(struct page *page)
Kirill A. Shutemove8c61582015-04-15 16:13:08 -0700417{
Kirill A. Shutemov822cdd112016-01-15 16:52:03 -0800418 page = compound_head(page);
Minchan Kimbda807d2016-07-26 15:23:05 -0700419 return ((unsigned long)page->mapping & PAGE_MAPPING_ANON) != 0;
420}
421
422static __always_inline int __PageMovable(struct page *page)
423{
424 return ((unsigned long)page->mapping & PAGE_MAPPING_FLAGS) ==
425 PAGE_MAPPING_MOVABLE;
Kirill A. Shutemove8c61582015-04-15 16:13:08 -0700426}
427
428#ifdef CONFIG_KSM
429/*
430 * A KSM page is one of those write-protected "shared pages" or "merged pages"
431 * which KSM maps into multiple mms, wherever identical anonymous page content
432 * is found in VM_MERGEABLE vmas. It's a PageAnon page, pointing not to any
433 * anon_vma, but to that page's node of the stable tree.
434 */
Denys Vlasenko4b0f3262016-03-17 14:18:24 -0700435static __always_inline int PageKsm(struct page *page)
Kirill A. Shutemove8c61582015-04-15 16:13:08 -0700436{
Kirill A. Shutemov822cdd112016-01-15 16:52:03 -0800437 page = compound_head(page);
Kirill A. Shutemove8c61582015-04-15 16:13:08 -0700438 return ((unsigned long)page->mapping & PAGE_MAPPING_FLAGS) ==
Minchan Kimbda807d2016-07-26 15:23:05 -0700439 PAGE_MAPPING_KSM;
Kirill A. Shutemove8c61582015-04-15 16:13:08 -0700440}
441#else
442TESTPAGEFLAG_FALSE(Ksm)
443#endif
444
Wu Fengguang1a9b5b72009-12-16 12:19:59 +0100445u64 stable_page_flags(struct page *page);
446
Nick Piggin0ed361d2008-02-04 22:29:34 -0800447static inline int PageUptodate(struct page *page)
448{
Kirill A. Shutemovd2998c42016-01-15 16:52:00 -0800449 int ret;
450 page = compound_head(page);
451 ret = test_bit(PG_uptodate, &(page)->flags);
Nick Piggin0ed361d2008-02-04 22:29:34 -0800452 /*
453 * Must ensure that the data we read out of the page is loaded
454 * _after_ we've loaded page->flags to check for PageUptodate.
455 * We can skip the barrier if the page is not uptodate, because
456 * we wouldn't be reading anything from it.
457 *
458 * See SetPageUptodate() for the other side of the story.
459 */
460 if (ret)
461 smp_rmb();
462
463 return ret;
464}
465
Denys Vlasenko4b0f3262016-03-17 14:18:24 -0700466static __always_inline void __SetPageUptodate(struct page *page)
Nick Piggin0ed361d2008-02-04 22:29:34 -0800467{
Kirill A. Shutemovd2998c42016-01-15 16:52:00 -0800468 VM_BUG_ON_PAGE(PageTail(page), page);
Nick Piggin0ed361d2008-02-04 22:29:34 -0800469 smp_wmb();
Kirill A. Shutemovdf8c94d2016-01-15 16:51:28 -0800470 __set_bit(PG_uptodate, &page->flags);
Nick Piggin0ed361d2008-02-04 22:29:34 -0800471}
472
Denys Vlasenko4b0f3262016-03-17 14:18:24 -0700473static __always_inline void SetPageUptodate(struct page *page)
Heiko Carstens2dcea572006-09-29 01:58:41 -0700474{
Kirill A. Shutemovd2998c42016-01-15 16:52:00 -0800475 VM_BUG_ON_PAGE(PageTail(page), page);
Nick Piggin0ed361d2008-02-04 22:29:34 -0800476 /*
477 * Memory barrier must be issued before setting the PG_uptodate bit,
478 * so that all previous stores issued in order to bring the page
479 * uptodate are actually visible before PageUptodate becomes true.
Nick Piggin0ed361d2008-02-04 22:29:34 -0800480 */
481 smp_wmb();
Kirill A. Shutemovdf8c94d2016-01-15 16:51:28 -0800482 set_bit(PG_uptodate, &page->flags);
Nick Piggin0ed361d2008-02-04 22:29:34 -0800483}
484
Kirill A. Shutemovd2998c42016-01-15 16:52:00 -0800485CLEARPAGEFLAG(Uptodate, uptodate, PF_NO_TAIL)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700486
Linus Torvalds1da177e2005-04-16 15:20:36 -0700487int test_clear_page_writeback(struct page *page);
Namjae Jeon1c8349a2014-05-12 08:12:25 -0400488int __test_set_page_writeback(struct page *page, bool keep_write);
489
490#define test_set_page_writeback(page) \
491 __test_set_page_writeback(page, false)
492#define test_set_page_writeback_keepwrite(page) \
493 __test_set_page_writeback(page, true)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700494
Linus Torvalds1da177e2005-04-16 15:20:36 -0700495static inline void set_page_writeback(struct page *page)
496{
497 test_set_page_writeback(page);
498}
499
Namjae Jeon1c8349a2014-05-12 08:12:25 -0400500static inline void set_page_writeback_keepwrite(struct page *page)
501{
502 test_set_page_writeback_keepwrite(page);
503}
504
Kirill A. Shutemov95ad9752016-01-15 16:51:21 -0800505__PAGEFLAG(Head, head, PF_ANY) CLEARPAGEFLAG(Head, head, PF_ANY)
Kirill A. Shutemov1d798ca2015-11-06 16:29:54 -0800506
Denys Vlasenko4b0f3262016-03-17 14:18:24 -0700507static __always_inline void set_compound_head(struct page *page, struct page *head)
Kirill A. Shutemov1d798ca2015-11-06 16:29:54 -0800508{
509 WRITE_ONCE(page->compound_head, (unsigned long)head + 1);
510}
511
Denys Vlasenko4b0f3262016-03-17 14:18:24 -0700512static __always_inline void clear_compound_head(struct page *page)
Kirill A. Shutemov1d798ca2015-11-06 16:29:54 -0800513{
514 WRITE_ONCE(page->compound_head, 0);
515}
516
Andrea Arcangeli4e6af672011-01-13 15:46:44 -0800517#ifdef CONFIG_TRANSPARENT_HUGEPAGE
518static inline void ClearPageCompound(struct page *page)
519{
520 BUG_ON(!PageHead(page));
521 ClearPageHead(page);
522}
523#endif
Petr Tesarikb3acc562014-06-23 13:22:03 -0700524
Yu Zhaod2a1a1f2016-05-20 16:58:16 -0700525#define PG_head_mask ((1UL << PG_head))
Petr Tesarikb3acc562014-06-23 13:22:03 -0700526
Kirill A. Shutemove8c61582015-04-15 16:13:08 -0700527#ifdef CONFIG_HUGETLB_PAGE
528int PageHuge(struct page *page);
529int PageHeadHuge(struct page *page);
Naoya Horiguchi7e1f0492015-04-15 16:14:41 -0700530bool page_huge_active(struct page *page);
Kirill A. Shutemove8c61582015-04-15 16:13:08 -0700531#else
532TESTPAGEFLAG_FALSE(Huge)
533TESTPAGEFLAG_FALSE(HeadHuge)
Naoya Horiguchi7e1f0492015-04-15 16:14:41 -0700534
535static inline bool page_huge_active(struct page *page)
536{
537 return 0;
538}
Kirill A. Shutemove8c61582015-04-15 16:13:08 -0700539#endif
540
Naoya Horiguchi7e1f0492015-04-15 16:14:41 -0700541
Andrea Arcangeli936a5fe2011-01-13 15:46:48 -0800542#ifdef CONFIG_TRANSPARENT_HUGEPAGE
Andrea Arcangeli71e3aac2011-01-13 15:46:52 -0800543/*
544 * PageHuge() only returns true for hugetlbfs pages, but not for
545 * normal or transparent huge pages.
546 *
547 * PageTransHuge() returns true for both transparent huge and
548 * hugetlbfs pages, but not normal pages. PageTransHuge() can only be
549 * called only in the core VM paths where hugetlbfs pages can't exist.
550 */
551static inline int PageTransHuge(struct page *page)
552{
Sasha Levin309381fea2014-01-23 15:52:54 -0800553 VM_BUG_ON_PAGE(PageTail(page), page);
Andrea Arcangeli71e3aac2011-01-13 15:46:52 -0800554 return PageHead(page);
555}
556
Dean Nelson385de352012-03-21 16:34:05 -0700557/*
558 * PageTransCompound returns true for both transparent huge pages
559 * and hugetlbfs pages, so it should only be called when it's known
560 * that hugetlbfs pages aren't involved.
561 */
Andrea Arcangeli936a5fe2011-01-13 15:46:48 -0800562static inline int PageTransCompound(struct page *page)
563{
564 return PageCompound(page);
565}
Andrea Arcangeli71e3aac2011-01-13 15:46:52 -0800566
Dean Nelson385de352012-03-21 16:34:05 -0700567/*
Andrea Arcangeli127393f2016-05-05 16:22:20 -0700568 * PageTransCompoundMap is the same as PageTransCompound, but it also
569 * guarantees the primary MMU has the entire compound page mapped
570 * through pmd_trans_huge, which in turn guarantees the secondary MMUs
571 * can also map the entire compound page. This allows the secondary
572 * MMUs to call get_user_pages() only once for each compound page and
573 * to immediately map the entire compound page with a single secondary
574 * MMU fault. If there will be a pmd split later, the secondary MMUs
575 * will get an update through the MMU notifier invalidation through
576 * split_huge_pmd().
577 *
578 * Unlike PageTransCompound, this is safe to be called only while
579 * split_huge_pmd() cannot run from under us, like if protected by the
580 * MMU notifier, otherwise it may result in page->_mapcount < 0 false
581 * positives.
582 */
583static inline int PageTransCompoundMap(struct page *page)
584{
585 return PageTransCompound(page) && atomic_read(&page->_mapcount) < 0;
586}
587
588/*
Dean Nelson385de352012-03-21 16:34:05 -0700589 * PageTransTail returns true for both transparent huge pages
590 * and hugetlbfs pages, so it should only be called when it's known
591 * that hugetlbfs pages aren't involved.
592 */
593static inline int PageTransTail(struct page *page)
594{
595 return PageTail(page);
596}
597
Kirill A. Shutemov53f92632016-01-15 16:53:42 -0800598/*
599 * PageDoubleMap indicates that the compound page is mapped with PTEs as well
600 * as PMDs.
601 *
602 * This is required for optimization of rmap operations for THP: we can postpone
603 * per small page mapcount accounting (and its overhead from atomic operations)
604 * until the first PMD split.
605 *
606 * For the page PageDoubleMap means ->_mapcount in all sub-pages is offset up
607 * by one. This reference will go away with last compound_mapcount.
608 *
609 * See also __split_huge_pmd_locked() and page_remove_anon_compound_rmap().
610 */
611static inline int PageDoubleMap(struct page *page)
612{
613 return PageHead(page) && test_bit(PG_double_map, &page[1].flags);
614}
615
Kirill A. Shutemov9a73f612016-07-26 15:25:53 -0700616static inline void SetPageDoubleMap(struct page *page)
617{
618 VM_BUG_ON_PAGE(!PageHead(page), page);
619 set_bit(PG_double_map, &page[1].flags);
620}
621
622static inline void ClearPageDoubleMap(struct page *page)
623{
624 VM_BUG_ON_PAGE(!PageHead(page), page);
625 clear_bit(PG_double_map, &page[1].flags);
626}
Kirill A. Shutemov53f92632016-01-15 16:53:42 -0800627static inline int TestSetPageDoubleMap(struct page *page)
628{
629 VM_BUG_ON_PAGE(!PageHead(page), page);
630 return test_and_set_bit(PG_double_map, &page[1].flags);
631}
632
633static inline int TestClearPageDoubleMap(struct page *page)
634{
635 VM_BUG_ON_PAGE(!PageHead(page), page);
636 return test_and_clear_bit(PG_double_map, &page[1].flags);
637}
638
Andrea Arcangeli936a5fe2011-01-13 15:46:48 -0800639#else
Kirill A. Shutemovd8c1bde2016-01-15 16:51:13 -0800640TESTPAGEFLAG_FALSE(TransHuge)
641TESTPAGEFLAG_FALSE(TransCompound)
Andrea Arcangeli127393f2016-05-05 16:22:20 -0700642TESTPAGEFLAG_FALSE(TransCompoundMap)
Kirill A. Shutemovd8c1bde2016-01-15 16:51:13 -0800643TESTPAGEFLAG_FALSE(TransTail)
Kirill A. Shutemov9a73f612016-07-26 15:25:53 -0700644PAGEFLAG_FALSE(DoubleMap)
Kirill A. Shutemov53f92632016-01-15 16:53:42 -0800645 TESTSETFLAG_FALSE(DoubleMap)
646 TESTCLEARFLAG_FALSE(DoubleMap)
Andrea Arcangeli936a5fe2011-01-13 15:46:48 -0800647#endif
648
Mel Gorman072bb0a2012-07-31 16:43:58 -0700649/*
Matthew Wilcox6e292b92018-06-07 17:08:18 -0700650 * For pages that are never mapped to userspace (and aren't PageSlab),
651 * page_type may be used. Because it is initialised to -1, we invert the
652 * sense of the bit, so __SetPageFoo *clears* the bit used for PageFoo, and
653 * __ClearPageFoo *sets* the bit used for PageFoo. We reserve a few high and
654 * low bits so that an underflow or overflow of page_mapcount() won't be
655 * mistaken for a page type value.
Vladimir Davydov632c0a12016-07-26 15:24:18 -0700656 */
Matthew Wilcox6e292b92018-06-07 17:08:18 -0700657
658#define PAGE_TYPE_BASE 0xf0000000
659/* Reserve 0x0000007f to catch underflows of page_mapcount */
660#define PG_buddy 0x00000080
661#define PG_balloon 0x00000100
662#define PG_kmemcg 0x00000200
Matthew Wilcox1d40a5e2018-06-07 17:08:23 -0700663#define PG_table 0x00000400
Matthew Wilcox6e292b92018-06-07 17:08:18 -0700664
665#define PageType(page, flag) \
666 ((page->page_type & (PAGE_TYPE_BASE | flag)) == PAGE_TYPE_BASE)
667
668#define PAGE_TYPE_OPS(uname, lname) \
Vladimir Davydov632c0a12016-07-26 15:24:18 -0700669static __always_inline int Page##uname(struct page *page) \
670{ \
Matthew Wilcox6e292b92018-06-07 17:08:18 -0700671 return PageType(page, PG_##lname); \
Vladimir Davydov632c0a12016-07-26 15:24:18 -0700672} \
673static __always_inline void __SetPage##uname(struct page *page) \
674{ \
Matthew Wilcox6e292b92018-06-07 17:08:18 -0700675 VM_BUG_ON_PAGE(!PageType(page, 0), page); \
676 page->page_type &= ~PG_##lname; \
Vladimir Davydov632c0a12016-07-26 15:24:18 -0700677} \
678static __always_inline void __ClearPage##uname(struct page *page) \
679{ \
680 VM_BUG_ON_PAGE(!Page##uname(page), page); \
Matthew Wilcox6e292b92018-06-07 17:08:18 -0700681 page->page_type |= PG_##lname; \
Vladimir Davydov632c0a12016-07-26 15:24:18 -0700682}
683
684/*
Matthew Wilcox6e292b92018-06-07 17:08:18 -0700685 * PageBuddy() indicates that the page is free and in the buddy system
Kirill A. Shutemove8c61582015-04-15 16:13:08 -0700686 * (see mm/page_alloc.c).
Kirill A. Shutemove8c61582015-04-15 16:13:08 -0700687 */
Matthew Wilcox6e292b92018-06-07 17:08:18 -0700688PAGE_TYPE_OPS(Buddy, buddy)
Kirill A. Shutemove8c61582015-04-15 16:13:08 -0700689
Vladimir Davydov632c0a12016-07-26 15:24:18 -0700690/*
Matthew Wilcox6e292b92018-06-07 17:08:18 -0700691 * PageBalloon() is true for pages that are on the balloon page list
Vladimir Davydov632c0a12016-07-26 15:24:18 -0700692 * (see mm/balloon_compaction.c).
693 */
Matthew Wilcox6e292b92018-06-07 17:08:18 -0700694PAGE_TYPE_OPS(Balloon, balloon)
Kirill A. Shutemove8c61582015-04-15 16:13:08 -0700695
Vladimir Davydov49491482016-07-26 15:24:24 -0700696/*
697 * If kmemcg is enabled, the buddy allocator will set PageKmemcg() on
698 * pages allocated with __GFP_ACCOUNT. It gets cleared on page free.
699 */
Matthew Wilcox6e292b92018-06-07 17:08:18 -0700700PAGE_TYPE_OPS(Kmemcg, kmemcg)
Vladimir Davydov49491482016-07-26 15:24:24 -0700701
Matthew Wilcox1d40a5e2018-06-07 17:08:23 -0700702/*
703 * Marks pages in use as page tables.
704 */
705PAGE_TYPE_OPS(Table, table)
706
Naoya Horiguchi832fc1d2016-03-17 14:17:41 -0700707extern bool is_free_buddy_page(struct page *page);
708
Minchan Kimbda807d2016-07-26 15:23:05 -0700709__PAGEFLAG(Isolated, isolated, PF_ANY);
710
Kirill A. Shutemove8c61582015-04-15 16:13:08 -0700711/*
Mel Gorman072bb0a2012-07-31 16:43:58 -0700712 * If network-based swap is enabled, sl*b must keep track of whether pages
713 * were allocated from pfmemalloc reserves.
714 */
715static inline int PageSlabPfmemalloc(struct page *page)
716{
Sasha Levin309381fea2014-01-23 15:52:54 -0800717 VM_BUG_ON_PAGE(!PageSlab(page), page);
Mel Gorman072bb0a2012-07-31 16:43:58 -0700718 return PageActive(page);
719}
720
721static inline void SetPageSlabPfmemalloc(struct page *page)
722{
Sasha Levin309381fea2014-01-23 15:52:54 -0800723 VM_BUG_ON_PAGE(!PageSlab(page), page);
Mel Gorman072bb0a2012-07-31 16:43:58 -0700724 SetPageActive(page);
725}
726
727static inline void __ClearPageSlabPfmemalloc(struct page *page)
728{
Sasha Levin309381fea2014-01-23 15:52:54 -0800729 VM_BUG_ON_PAGE(!PageSlab(page), page);
Mel Gorman072bb0a2012-07-31 16:43:58 -0700730 __ClearPageActive(page);
731}
732
733static inline void ClearPageSlabPfmemalloc(struct page *page)
734{
Sasha Levin309381fea2014-01-23 15:52:54 -0800735 VM_BUG_ON_PAGE(!PageSlab(page), page);
Mel Gorman072bb0a2012-07-31 16:43:58 -0700736 ClearPageActive(page);
737}
738
Hugh Dickinsaf8e3352009-12-14 17:58:59 -0800739#ifdef CONFIG_MMU
Yu Zhaod2a1a1f2016-05-20 16:58:16 -0700740#define __PG_MLOCKED (1UL << PG_mlocked)
David Howells33925b22009-03-31 15:23:26 -0700741#else
Nick Pigginb291f002008-10-18 20:26:44 -0700742#define __PG_MLOCKED 0
Lee Schermerhorn894bc312008-10-18 20:26:39 -0700743#endif
744
Russ Andersondfa7e202008-06-09 11:18:45 -0500745/*
746 * Flags checked when a page is freed. Pages being freed should not have
747 * these flags set. It they are, there is a problem.
748 */
Nicholas Piggin6326fec2016-12-25 13:00:29 +1000749#define PAGE_FLAGS_CHECK_AT_FREE \
750 (1UL << PG_lru | 1UL << PG_locked | \
751 1UL << PG_private | 1UL << PG_private_2 | \
752 1UL << PG_writeback | 1UL << PG_reserved | \
753 1UL << PG_slab | 1UL << PG_active | \
754 1UL << PG_unevictable | __PG_MLOCKED)
Russ Andersondfa7e202008-06-09 11:18:45 -0500755
756/*
757 * Flags checked when a page is prepped for return by the page allocator.
Naoya Horiguchif4c18e62015-08-06 15:47:08 -0700758 * Pages being prepped should not have these flags set. It they are set,
Hugh Dickins79f4b7b2009-01-06 14:40:05 -0800759 * there has been a kernel bug or struct page corruption.
Naoya Horiguchif4c18e62015-08-06 15:47:08 -0700760 *
761 * __PG_HWPOISON is exceptional because it needs to be kept beyond page's
762 * alloc-free cycle to prevent from reusing the page.
Russ Andersondfa7e202008-06-09 11:18:45 -0500763 */
Naoya Horiguchif4c18e62015-08-06 15:47:08 -0700764#define PAGE_FLAGS_CHECK_AT_PREP \
Yu Zhaod2a1a1f2016-05-20 16:58:16 -0700765 (((1UL << NR_PAGEFLAGS) - 1) & ~__PG_HWPOISON)
Russ Andersondfa7e202008-06-09 11:18:45 -0500766
Johannes Weineredcf4742009-09-21 17:02:59 -0700767#define PAGE_FLAGS_PRIVATE \
Yu Zhaod2a1a1f2016-05-20 16:58:16 -0700768 (1UL << PG_private | 1UL << PG_private_2)
David Howells266cf652009-04-03 16:42:36 +0100769/**
770 * page_has_private - Determine if page has private stuff
771 * @page: The page to be checked
772 *
773 * Determine if a page has private stuff, indicating that release routines
774 * should be invoked upon it.
775 */
Johannes Weineredcf4742009-09-21 17:02:59 -0700776static inline int page_has_private(struct page *page)
777{
778 return !!(page->flags & PAGE_FLAGS_PRIVATE);
779}
780
Kirill A. Shutemov95ad9752016-01-15 16:51:21 -0800781#undef PF_ANY
782#undef PF_HEAD
Nicholas Piggin62906022016-12-25 13:00:30 +1000783#undef PF_ONLY_HEAD
Kirill A. Shutemov95ad9752016-01-15 16:51:21 -0800784#undef PF_NO_TAIL
785#undef PF_NO_COMPOUND
Johannes Weineredcf4742009-09-21 17:02:59 -0700786#endif /* !__GENERATING_BOUNDS_H */
David Howells266cf652009-04-03 16:42:36 +0100787
Linus Torvalds1da177e2005-04-16 15:20:36 -0700788#endif /* PAGE_FLAGS_H */