blob: 3ec44e27aa9dbe7b2e0cb26c21c97f8ad9ac97c3 [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 Lameter9223b4192008-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 Lameter9223b4192008-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 *
49 * PG_highmem pages are not permanently mapped into the kernel virtual address
50 * space, they need to be kmapped separately for doing IO on the pages. The
51 * struct page (these bits with information) are always mapped into kernel
52 * address space...
Nick Pigginda6052f2006-09-25 23:31:35 -070053 *
Andi Kleend466f2f2009-09-16 11:50:03 +020054 * PG_hwpoison indicates that a page got corrupted in hardware and contains
55 * data with incorrect ECC bits that triggered a machine check. Accessing is
56 * not safe since it may cause another machine check. Don't touch!
Linus Torvalds1da177e2005-04-16 15:20:36 -070057 */
58
59/*
60 * Don't use the *_dontuse flags. Use the macros. Otherwise you'll break
Andy Whitcroft91fc8ab2006-04-10 22:53:01 -070061 * locked- and dirty-page accounting.
62 *
63 * The page flags field is split into two parts, the main flags area
64 * which extends from the low bits upwards, and the fields area which
65 * extends from the high bits downwards.
66 *
67 * | FIELD | ... | FLAGS |
Christoph Lameter9223b4192008-04-28 02:12:48 -070068 * N-1 ^ 0
69 * (NR_PAGEFLAGS)
Andy Whitcroft91fc8ab2006-04-10 22:53:01 -070070 *
Christoph Lameter9223b4192008-04-28 02:12:48 -070071 * The fields area is reserved for fields mapping zone, node (for NUMA) and
72 * SPARSEMEM section (for variants of SPARSEMEM that require section ids like
73 * SPARSEMEM_EXTREME with !SPARSEMEM_VMEMMAP).
Linus Torvalds1da177e2005-04-16 15:20:36 -070074 */
Christoph Lametere2683182008-04-28 02:12:47 -070075enum pageflags {
76 PG_locked, /* Page is locked. Don't touch. */
77 PG_error,
78 PG_referenced,
79 PG_uptodate,
80 PG_dirty,
81 PG_lru,
82 PG_active,
Linus Torvaldsb91e1302016-12-27 11:40:38 -080083 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 -070084 PG_slab,
85 PG_owner_priv_1, /* Owner use. If pagecache, fs may use*/
Christoph Lametere2683182008-04-28 02:12:47 -070086 PG_arch_1,
87 PG_reserved,
88 PG_private, /* If pagecache, has fs-private data */
David Howells266cf652009-04-03 16:42:36 +010089 PG_private_2, /* If pagecache, has fs aux data */
Christoph Lametere2683182008-04-28 02:12:47 -070090 PG_writeback, /* Page is under writeback */
Christoph Lametere20b8cc2008-04-28 02:12:55 -070091 PG_head, /* A head page */
Christoph Lametere2683182008-04-28 02:12:47 -070092 PG_mappedtodisk, /* Has blocks allocated on-disk */
93 PG_reclaim, /* To be reclaimed asap */
Rik van Rielb2e18532008-10-18 20:26:30 -070094 PG_swapbacked, /* Page is backed by RAM/swap */
Lee Schermerhorn894bc312008-10-18 20:26:39 -070095 PG_unevictable, /* Page is "unevictable" */
Hugh Dickinsaf8e3352009-12-14 17:58:59 -080096#ifdef CONFIG_MMU
Nick Pigginb291f002008-10-18 20:26:44 -070097 PG_mlocked, /* Page is vma mlocked */
Lee Schermerhorn894bc312008-10-18 20:26:39 -070098#endif
Venkatesh Pallipadi46cf98c2009-07-10 09:57:37 -070099#ifdef CONFIG_ARCH_USES_PG_UNCACHED
Christoph Lameter602c4d12008-04-28 02:12:52 -0700100 PG_uncached, /* Page has been mapped as uncached */
Andrew Mortonf886ed42006-06-23 02:03:06 -0700101#endif
Andi Kleend466f2f2009-09-16 11:50:03 +0200102#ifdef CONFIG_MEMORY_FAILURE
103 PG_hwpoison, /* hardware poisoned page. Don't touch */
104#endif
Vladimir Davydov33c3fc72015-09-09 15:35:45 -0700105#if defined(CONFIG_IDLE_PAGE_TRACKING) && defined(CONFIG_64BIT)
106 PG_young,
107 PG_idle,
108#endif
Andy Whitcroft0cad47c2008-07-23 21:27:16 -0700109 __NR_PAGEFLAGS,
110
111 /* Filesystems */
112 PG_checked = PG_owner_priv_1,
113
Nicholas Piggin6326fec2016-12-25 13:00:29 +1000114 /* SwapBacked */
115 PG_swapcache = PG_owner_priv_1, /* Swap page: swp_entry_t in private */
116
David Howells266cf652009-04-03 16:42:36 +0100117 /* Two page bits are conscripted by FS-Cache to maintain local caching
118 * state. These bits are set on pages belonging to the netfs's inodes
119 * when those inodes are being locally cached.
120 */
121 PG_fscache = PG_private_2, /* page backed by cache */
122
Andy Whitcroft0cad47c2008-07-23 21:27:16 -0700123 /* XEN */
Jennifer Herbertd8ac3dd2015-01-05 13:24:09 +0000124 /* Pinned in Xen as a read-only pagetable page. */
Andy Whitcroft0cad47c2008-07-23 21:27:16 -0700125 PG_pinned = PG_owner_priv_1,
Jennifer Herbertd8ac3dd2015-01-05 13:24:09 +0000126 /* Pinned as part of domain save (see xen_mm_pin_all()). */
Andy Whitcroft0cad47c2008-07-23 21:27:16 -0700127 PG_savepinned = PG_dirty,
Jennifer Herbertd8ac3dd2015-01-05 13:24:09 +0000128 /* Has a grant mapping of another (foreign) domain's page. */
129 PG_foreign = PG_owner_priv_1,
Andy Whitcroft8a380822008-07-23 21:27:18 -0700130
Andy Whitcroft9023cb72008-07-23 21:27:19 -0700131 /* SLOB */
Andy Whitcroft9023cb72008-07-23 21:27:19 -0700132 PG_slob_free = PG_private,
Kirill A. Shutemov53f92632016-01-15 16:53:42 -0800133
134 /* Compound pages. Stored in first tail page's flags */
135 PG_double_map = PG_private_2,
Minchan Kimbda807d2016-07-26 15:23:05 -0700136
137 /* non-lru isolated movable page */
138 PG_isolated = PG_reclaim,
Christoph Lametere2683182008-04-28 02:12:47 -0700139};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700140
Christoph Lameter9223b4192008-04-28 02:12:48 -0700141#ifndef __GENERATING_BOUNDS_H
142
Kirill A. Shutemov0e6d31a2016-01-15 16:51:17 -0800143struct page; /* forward declaration */
144
145static inline struct page *compound_head(struct page *page)
146{
147 unsigned long head = READ_ONCE(page->compound_head);
148
149 if (unlikely(head & 1))
150 return (struct page *) (head - 1);
151 return page;
152}
153
Denys Vlasenko4b0f3262016-03-17 14:18:24 -0700154static __always_inline int PageTail(struct page *page)
Kirill A. Shutemov0e6d31a2016-01-15 16:51:17 -0800155{
156 return READ_ONCE(page->compound_head) & 1;
157}
158
Denys Vlasenko4b0f3262016-03-17 14:18:24 -0700159static __always_inline int PageCompound(struct page *page)
Kirill A. Shutemov0e6d31a2016-01-15 16:51:17 -0800160{
161 return test_bit(PG_head, &page->flags) || PageTail(page);
162}
163
Linus Torvalds1da177e2005-04-16 15:20:36 -0700164/*
Kirill A. Shutemov95ad9752016-01-15 16:51:21 -0800165 * Page flags policies wrt compound pages
166 *
167 * PF_ANY:
168 * the page flag is relevant for small, head and tail pages.
169 *
170 * PF_HEAD:
171 * for compound page all operations related to the page flag applied to
172 * head page.
173 *
Nicholas Piggin62906022016-12-25 13:00:30 +1000174 * PF_ONLY_HEAD:
175 * for compound page, callers only ever operate on the head page.
176 *
Kirill A. Shutemov95ad9752016-01-15 16:51:21 -0800177 * PF_NO_TAIL:
178 * modifications of the page flag must be done on small or head pages,
179 * checks can be done on tail pages too.
180 *
181 * PF_NO_COMPOUND:
182 * the page flag is not relevant for compound pages.
183 */
184#define PF_ANY(page, enforce) page
185#define PF_HEAD(page, enforce) compound_head(page)
Nicholas Piggin62906022016-12-25 13:00:30 +1000186#define PF_ONLY_HEAD(page, enforce) ({ \
187 VM_BUG_ON_PGFLAGS(PageTail(page), page); \
188 page;})
Kirill A. Shutemov95ad9752016-01-15 16:51:21 -0800189#define PF_NO_TAIL(page, enforce) ({ \
190 VM_BUG_ON_PGFLAGS(enforce && PageTail(page), page); \
191 compound_head(page);})
Kirill A. Shutemov822cdd112016-01-15 16:52:03 -0800192#define PF_NO_COMPOUND(page, enforce) ({ \
Kirill A. Shutemov95ad9752016-01-15 16:51:21 -0800193 VM_BUG_ON_PGFLAGS(enforce && PageCompound(page), page); \
194 page;})
195
196/*
Christoph Lameterf94a62e2008-04-28 02:12:49 -0700197 * Macros to create function definitions for page flags
198 */
Kirill A. Shutemov95ad9752016-01-15 16:51:21 -0800199#define TESTPAGEFLAG(uname, lname, policy) \
Denys Vlasenko4b0f3262016-03-17 14:18:24 -0700200static __always_inline int Page##uname(struct page *page) \
Kirill A. Shutemov95ad9752016-01-15 16:51:21 -0800201 { return test_bit(PG_##lname, &policy(page, 0)->flags); }
Christoph Lameterf94a62e2008-04-28 02:12:49 -0700202
Kirill A. Shutemov95ad9752016-01-15 16:51:21 -0800203#define SETPAGEFLAG(uname, lname, policy) \
Denys Vlasenko4b0f3262016-03-17 14:18:24 -0700204static __always_inline void SetPage##uname(struct page *page) \
Kirill A. Shutemov95ad9752016-01-15 16:51:21 -0800205 { set_bit(PG_##lname, &policy(page, 1)->flags); }
Christoph Lameterf94a62e2008-04-28 02:12:49 -0700206
Kirill A. Shutemov95ad9752016-01-15 16:51:21 -0800207#define CLEARPAGEFLAG(uname, lname, policy) \
Denys Vlasenko4b0f3262016-03-17 14:18:24 -0700208static __always_inline void ClearPage##uname(struct page *page) \
Kirill A. Shutemov95ad9752016-01-15 16:51:21 -0800209 { clear_bit(PG_##lname, &policy(page, 1)->flags); }
Christoph Lameterf94a62e2008-04-28 02:12:49 -0700210
Kirill A. Shutemov95ad9752016-01-15 16:51:21 -0800211#define __SETPAGEFLAG(uname, lname, policy) \
Denys Vlasenko4b0f3262016-03-17 14:18:24 -0700212static __always_inline void __SetPage##uname(struct page *page) \
Kirill A. Shutemov95ad9752016-01-15 16:51:21 -0800213 { __set_bit(PG_##lname, &policy(page, 1)->flags); }
Christoph Lameterf94a62e2008-04-28 02:12:49 -0700214
Kirill A. Shutemov95ad9752016-01-15 16:51:21 -0800215#define __CLEARPAGEFLAG(uname, lname, policy) \
Denys Vlasenko4b0f3262016-03-17 14:18:24 -0700216static __always_inline void __ClearPage##uname(struct page *page) \
Kirill A. Shutemov95ad9752016-01-15 16:51:21 -0800217 { __clear_bit(PG_##lname, &policy(page, 1)->flags); }
Christoph Lameterf94a62e2008-04-28 02:12:49 -0700218
Kirill A. Shutemov95ad9752016-01-15 16:51:21 -0800219#define TESTSETFLAG(uname, lname, policy) \
Denys Vlasenko4b0f3262016-03-17 14:18:24 -0700220static __always_inline int TestSetPage##uname(struct page *page) \
Kirill A. Shutemov95ad9752016-01-15 16:51:21 -0800221 { return test_and_set_bit(PG_##lname, &policy(page, 1)->flags); }
Christoph Lameterf94a62e2008-04-28 02:12:49 -0700222
Kirill A. Shutemov95ad9752016-01-15 16:51:21 -0800223#define TESTCLEARFLAG(uname, lname, policy) \
Denys Vlasenko4b0f3262016-03-17 14:18:24 -0700224static __always_inline int TestClearPage##uname(struct page *page) \
Kirill A. Shutemov95ad9752016-01-15 16:51:21 -0800225 { return test_and_clear_bit(PG_##lname, &policy(page, 1)->flags); }
Christoph Lameterf94a62e2008-04-28 02:12:49 -0700226
Kirill A. Shutemov95ad9752016-01-15 16:51:21 -0800227#define PAGEFLAG(uname, lname, policy) \
228 TESTPAGEFLAG(uname, lname, policy) \
229 SETPAGEFLAG(uname, lname, policy) \
230 CLEARPAGEFLAG(uname, lname, policy)
Christoph Lameterf94a62e2008-04-28 02:12:49 -0700231
Kirill A. Shutemov95ad9752016-01-15 16:51:21 -0800232#define __PAGEFLAG(uname, lname, policy) \
233 TESTPAGEFLAG(uname, lname, policy) \
234 __SETPAGEFLAG(uname, lname, policy) \
235 __CLEARPAGEFLAG(uname, lname, policy)
Christoph Lameterf94a62e2008-04-28 02:12:49 -0700236
Kirill A. Shutemov95ad9752016-01-15 16:51:21 -0800237#define TESTSCFLAG(uname, lname, policy) \
238 TESTSETFLAG(uname, lname, policy) \
239 TESTCLEARFLAG(uname, lname, policy)
Christoph Lameterf94a62e2008-04-28 02:12:49 -0700240
Johannes Weiner2f3e4422014-08-06 16:05:40 -0700241#define TESTPAGEFLAG_FALSE(uname) \
242static inline int Page##uname(const struct page *page) { return 0; }
243
Lee Schermerhorn8a7a8542008-10-18 20:26:37 -0700244#define SETPAGEFLAG_NOOP(uname) \
245static inline void SetPage##uname(struct page *page) { }
246
247#define CLEARPAGEFLAG_NOOP(uname) \
248static inline void ClearPage##uname(struct page *page) { }
249
250#define __CLEARPAGEFLAG_NOOP(uname) \
251static inline void __ClearPage##uname(struct page *page) { }
252
Johannes Weiner2f3e4422014-08-06 16:05:40 -0700253#define TESTSETFLAG_FALSE(uname) \
254static inline int TestSetPage##uname(struct page *page) { return 0; }
255
Lee Schermerhorn8a7a8542008-10-18 20:26:37 -0700256#define TESTCLEARFLAG_FALSE(uname) \
257static inline int TestClearPage##uname(struct page *page) { return 0; }
258
Johannes Weiner2f3e4422014-08-06 16:05:40 -0700259#define PAGEFLAG_FALSE(uname) TESTPAGEFLAG_FALSE(uname) \
260 SETPAGEFLAG_NOOP(uname) CLEARPAGEFLAG_NOOP(uname)
261
262#define TESTSCFLAG_FALSE(uname) \
263 TESTSETFLAG_FALSE(uname) TESTCLEARFLAG_FALSE(uname)
264
Kirill A. Shutemov48c935a2016-01-15 16:51:24 -0800265__PAGEFLAG(Locked, locked, PF_NO_TAIL)
Nicholas Piggin62906022016-12-25 13:00:30 +1000266PAGEFLAG(Waiters, waiters, PF_ONLY_HEAD) __CLEARPAGEFLAG(Waiters, waiters, PF_ONLY_HEAD)
Kirill A. Shutemovdf8c94d2016-01-15 16:51:28 -0800267PAGEFLAG(Error, error, PF_NO_COMPOUND) TESTCLEARFLAG(Error, error, PF_NO_COMPOUND)
Kirill A. Shutemov8cb38fa2016-01-15 16:51:32 -0800268PAGEFLAG(Referenced, referenced, PF_HEAD)
269 TESTCLEARFLAG(Referenced, referenced, PF_HEAD)
270 __SETPAGEFLAG(Referenced, referenced, PF_HEAD)
Kirill A. Shutemovdf8c94d2016-01-15 16:51:28 -0800271PAGEFLAG(Dirty, dirty, PF_HEAD) TESTSCFLAG(Dirty, dirty, PF_HEAD)
272 __CLEARPAGEFLAG(Dirty, dirty, PF_HEAD)
Kirill A. Shutemov8cb38fa2016-01-15 16:51:32 -0800273PAGEFLAG(LRU, lru, PF_HEAD) __CLEARPAGEFLAG(LRU, lru, PF_HEAD)
274PAGEFLAG(Active, active, PF_HEAD) __CLEARPAGEFLAG(Active, active, PF_HEAD)
275 TESTCLEARFLAG(Active, active, PF_HEAD)
Kirill A. Shutemovdcb351c2016-01-15 16:51:35 -0800276__PAGEFLAG(Slab, slab, PF_NO_TAIL)
277__PAGEFLAG(SlobFree, slob_free, PF_NO_TAIL)
Kirill A. Shutemovdf8c94d2016-01-15 16:51:28 -0800278PAGEFLAG(Checked, checked, PF_NO_COMPOUND) /* Used by some filesystems */
Kirill A. Shutemovc13985f2016-01-15 16:51:39 -0800279
280/* Xen */
281PAGEFLAG(Pinned, pinned, PF_NO_COMPOUND)
282 TESTSCFLAG(Pinned, pinned, PF_NO_COMPOUND)
283PAGEFLAG(SavePinned, savepinned, PF_NO_COMPOUND);
284PAGEFLAG(Foreign, foreign, PF_NO_COMPOUND);
285
Kirill A. Shutemovde09d312016-01-15 16:51:42 -0800286PAGEFLAG(Reserved, reserved, PF_NO_COMPOUND)
287 __CLEARPAGEFLAG(Reserved, reserved, PF_NO_COMPOUND)
Kirill A. Shutemovda5efc42016-01-15 16:51:46 -0800288PAGEFLAG(SwapBacked, swapbacked, PF_NO_TAIL)
289 __CLEARPAGEFLAG(SwapBacked, swapbacked, PF_NO_TAIL)
290 __SETPAGEFLAG(SwapBacked, swapbacked, PF_NO_TAIL)
Christoph Lameter6a1e7f72008-04-28 02:12:50 -0700291
Christoph Lameterf94a62e2008-04-28 02:12:49 -0700292/*
David Howells266cf652009-04-03 16:42:36 +0100293 * Private page markings that may be used by the filesystem that owns the page
294 * for its own purposes.
295 * - PG_private and PG_private_2 cause releasepage() and co to be invoked
296 */
Kirill A. Shutemov95ad9752016-01-15 16:51:21 -0800297PAGEFLAG(Private, private, PF_ANY) __SETPAGEFLAG(Private, private, PF_ANY)
298 __CLEARPAGEFLAG(Private, private, PF_ANY)
299PAGEFLAG(Private2, private_2, PF_ANY) TESTSCFLAG(Private2, private_2, PF_ANY)
300PAGEFLAG(OwnerPriv1, owner_priv_1, PF_ANY)
301 TESTCLEARFLAG(OwnerPriv1, owner_priv_1, PF_ANY)
David Howells266cf652009-04-03 16:42:36 +0100302
303/*
Christoph Lameter6a1e7f72008-04-28 02:12:50 -0700304 * Only test-and-set exist for PG_writeback. The unconditional operators are
305 * risky: they bypass page accounting.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700306 */
Huang Ying225311a2017-09-06 16:22:30 -0700307TESTPAGEFLAG(Writeback, writeback, PF_NO_TAIL)
308 TESTSCFLAG(Writeback, writeback, PF_NO_TAIL)
Kirill A. Shutemove2f0a0d2016-07-26 15:25:59 -0700309PAGEFLAG(MappedToDisk, mappedtodisk, PF_NO_TAIL)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700310
Shaohua Li579f8292014-02-06 12:04:21 -0800311/* PG_readahead is only used for reads; PG_reclaim is only for writes */
Kirill A. Shutemove2f0a0d2016-07-26 15:25:59 -0700312PAGEFLAG(Reclaim, reclaim, PF_NO_TAIL)
313 TESTCLEARFLAG(Reclaim, reclaim, PF_NO_TAIL)
Kirill A. Shutemovdf8c94d2016-01-15 16:51:28 -0800314PAGEFLAG(Readahead, reclaim, PF_NO_COMPOUND)
315 TESTCLEARFLAG(Readahead, reclaim, PF_NO_COMPOUND)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700316
Christoph Lameter6a1e7f72008-04-28 02:12:50 -0700317#ifdef CONFIG_HIGHMEM
318/*
319 * Must use a macro here due to header dependency issues. page_zone() is not
320 * available at this point.
321 */
Vineet Gupta3ca65c12015-11-05 18:48:29 -0800322#define PageHighMem(__p) is_highmem_idx(page_zonenum(__p))
Christoph Lameter6a1e7f72008-04-28 02:12:50 -0700323#else
Christoph Lameterec7cade2008-04-28 02:12:53 -0700324PAGEFLAG_FALSE(HighMem)
Christoph Lameter6a1e7f72008-04-28 02:12:50 -0700325#endif
326
327#ifdef CONFIG_SWAP
Nicholas Piggin6326fec2016-12-25 13:00:29 +1000328static __always_inline int PageSwapCache(struct page *page)
329{
Huang Ying38d8b4e2017-07-06 15:37:18 -0700330#ifdef CONFIG_THP_SWAP
331 page = compound_head(page);
332#endif
Nicholas Piggin6326fec2016-12-25 13:00:29 +1000333 return PageSwapBacked(page) && test_bit(PG_swapcache, &page->flags);
334
335}
Huang Ying38d8b4e2017-07-06 15:37:18 -0700336SETPAGEFLAG(SwapCache, swapcache, PF_NO_TAIL)
337CLEARPAGEFLAG(SwapCache, swapcache, PF_NO_TAIL)
Christoph Lameter6a1e7f72008-04-28 02:12:50 -0700338#else
Christoph Lameterec7cade2008-04-28 02:12:53 -0700339PAGEFLAG_FALSE(SwapCache)
Christoph Lameter6a1e7f72008-04-28 02:12:50 -0700340#endif
341
Kirill A. Shutemov8cb38fa2016-01-15 16:51:32 -0800342PAGEFLAG(Unevictable, unevictable, PF_HEAD)
343 __CLEARPAGEFLAG(Unevictable, unevictable, PF_HEAD)
344 TESTCLEARFLAG(Unevictable, unevictable, PF_HEAD)
Lee Schermerhorn894bc312008-10-18 20:26:39 -0700345
Hugh Dickinsaf8e3352009-12-14 17:58:59 -0800346#ifdef CONFIG_MMU
Kirill A. Shutemove4f87d52016-01-15 16:51:53 -0800347PAGEFLAG(Mlocked, mlocked, PF_NO_TAIL)
348 __CLEARPAGEFLAG(Mlocked, mlocked, PF_NO_TAIL)
349 TESTSCFLAG(Mlocked, mlocked, PF_NO_TAIL)
David Howells33925b22009-03-31 15:23:26 -0700350#else
Johannes Weiner2f3e4422014-08-06 16:05:40 -0700351PAGEFLAG_FALSE(Mlocked) __CLEARPAGEFLAG_NOOP(Mlocked)
Kirill A. Shutemov685eaad2016-01-15 16:52:10 -0800352 TESTSCFLAG_FALSE(Mlocked)
David Howells33925b22009-03-31 15:23:26 -0700353#endif
354
Venkatesh Pallipadi46cf98c2009-07-10 09:57:37 -0700355#ifdef CONFIG_ARCH_USES_PG_UNCACHED
Kirill A. Shutemovb9d41812016-01-15 16:51:56 -0800356PAGEFLAG(Uncached, uncached, PF_NO_COMPOUND)
Christoph Lameter602c4d12008-04-28 02:12:52 -0700357#else
Christoph Lameterec7cade2008-04-28 02:12:53 -0700358PAGEFLAG_FALSE(Uncached)
Christoph Lameter6a1e7f72008-04-28 02:12:50 -0700359#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700360
Andi Kleend466f2f2009-09-16 11:50:03 +0200361#ifdef CONFIG_MEMORY_FAILURE
Kirill A. Shutemov95ad9752016-01-15 16:51:21 -0800362PAGEFLAG(HWPoison, hwpoison, PF_ANY)
363TESTSCFLAG(HWPoison, hwpoison, PF_ANY)
Andi Kleend466f2f2009-09-16 11:50:03 +0200364#define __PG_HWPOISON (1UL << PG_hwpoison)
365#else
366PAGEFLAG_FALSE(HWPoison)
367#define __PG_HWPOISON 0
368#endif
369
Vladimir Davydov33c3fc72015-09-09 15:35:45 -0700370#if defined(CONFIG_IDLE_PAGE_TRACKING) && defined(CONFIG_64BIT)
Kirill A. Shutemov95ad9752016-01-15 16:51:21 -0800371TESTPAGEFLAG(Young, young, PF_ANY)
372SETPAGEFLAG(Young, young, PF_ANY)
373TESTCLEARFLAG(Young, young, PF_ANY)
374PAGEFLAG(Idle, idle, PF_ANY)
Vladimir Davydov33c3fc72015-09-09 15:35:45 -0700375#endif
376
Kirill A. Shutemove8c61582015-04-15 16:13:08 -0700377/*
378 * On an anonymous page mapped into a user virtual memory area,
379 * page->mapping points to its anon_vma, not to a struct address_space;
380 * with the PAGE_MAPPING_ANON bit set to distinguish it. See rmap.h.
381 *
382 * On an anonymous page in a VM_MERGEABLE area, if CONFIG_KSM is enabled,
Minchan Kimbda807d2016-07-26 15:23:05 -0700383 * the PAGE_MAPPING_MOVABLE bit may be set along with the PAGE_MAPPING_ANON
384 * bit; and then page->mapping points, not to an anon_vma, but to a private
Kirill A. Shutemove8c61582015-04-15 16:13:08 -0700385 * structure which KSM associates with that merged page. See ksm.h.
386 *
Minchan Kimbda807d2016-07-26 15:23:05 -0700387 * PAGE_MAPPING_KSM without PAGE_MAPPING_ANON is used for non-lru movable
388 * page and then page->mapping points a struct address_space.
Kirill A. Shutemove8c61582015-04-15 16:13:08 -0700389 *
390 * Please note that, confusingly, "page_mapping" refers to the inode
391 * address_space which maps the page from disk; whereas "page_mapped"
392 * refers to user virtual address space into which the page is mapped.
393 */
Minchan Kimbda807d2016-07-26 15:23:05 -0700394#define PAGE_MAPPING_ANON 0x1
395#define PAGE_MAPPING_MOVABLE 0x2
396#define PAGE_MAPPING_KSM (PAGE_MAPPING_ANON | PAGE_MAPPING_MOVABLE)
397#define PAGE_MAPPING_FLAGS (PAGE_MAPPING_ANON | PAGE_MAPPING_MOVABLE)
Kirill A. Shutemove8c61582015-04-15 16:13:08 -0700398
Minchan Kimbda807d2016-07-26 15:23:05 -0700399static __always_inline int PageMappingFlags(struct page *page)
Mel Gorman17514572016-05-19 17:13:21 -0700400{
Minchan Kimbda807d2016-07-26 15:23:05 -0700401 return ((unsigned long)page->mapping & PAGE_MAPPING_FLAGS) != 0;
Mel Gorman17514572016-05-19 17:13:21 -0700402}
403
Denys Vlasenko4b0f3262016-03-17 14:18:24 -0700404static __always_inline int PageAnon(struct page *page)
Kirill A. Shutemove8c61582015-04-15 16:13:08 -0700405{
Kirill A. Shutemov822cdd112016-01-15 16:52:03 -0800406 page = compound_head(page);
Minchan Kimbda807d2016-07-26 15:23:05 -0700407 return ((unsigned long)page->mapping & PAGE_MAPPING_ANON) != 0;
408}
409
410static __always_inline int __PageMovable(struct page *page)
411{
412 return ((unsigned long)page->mapping & PAGE_MAPPING_FLAGS) ==
413 PAGE_MAPPING_MOVABLE;
Kirill A. Shutemove8c61582015-04-15 16:13:08 -0700414}
415
416#ifdef CONFIG_KSM
417/*
418 * A KSM page is one of those write-protected "shared pages" or "merged pages"
419 * which KSM maps into multiple mms, wherever identical anonymous page content
420 * is found in VM_MERGEABLE vmas. It's a PageAnon page, pointing not to any
421 * anon_vma, but to that page's node of the stable tree.
422 */
Denys Vlasenko4b0f3262016-03-17 14:18:24 -0700423static __always_inline int PageKsm(struct page *page)
Kirill A. Shutemove8c61582015-04-15 16:13:08 -0700424{
Kirill A. Shutemov822cdd112016-01-15 16:52:03 -0800425 page = compound_head(page);
Kirill A. Shutemove8c61582015-04-15 16:13:08 -0700426 return ((unsigned long)page->mapping & PAGE_MAPPING_FLAGS) ==
Minchan Kimbda807d2016-07-26 15:23:05 -0700427 PAGE_MAPPING_KSM;
Kirill A. Shutemove8c61582015-04-15 16:13:08 -0700428}
429#else
430TESTPAGEFLAG_FALSE(Ksm)
431#endif
432
Wu Fengguang1a9b5b72009-12-16 12:19:59 +0100433u64 stable_page_flags(struct page *page);
434
Nick Piggin0ed361d2008-02-04 22:29:34 -0800435static inline int PageUptodate(struct page *page)
436{
Kirill A. Shutemovd2998c42016-01-15 16:52:00 -0800437 int ret;
438 page = compound_head(page);
439 ret = test_bit(PG_uptodate, &(page)->flags);
Nick Piggin0ed361d2008-02-04 22:29:34 -0800440 /*
441 * Must ensure that the data we read out of the page is loaded
442 * _after_ we've loaded page->flags to check for PageUptodate.
443 * We can skip the barrier if the page is not uptodate, because
444 * we wouldn't be reading anything from it.
445 *
446 * See SetPageUptodate() for the other side of the story.
447 */
448 if (ret)
449 smp_rmb();
450
451 return ret;
452}
453
Denys Vlasenko4b0f3262016-03-17 14:18:24 -0700454static __always_inline void __SetPageUptodate(struct page *page)
Nick Piggin0ed361d2008-02-04 22:29:34 -0800455{
Kirill A. Shutemovd2998c42016-01-15 16:52:00 -0800456 VM_BUG_ON_PAGE(PageTail(page), page);
Nick Piggin0ed361d2008-02-04 22:29:34 -0800457 smp_wmb();
Kirill A. Shutemovdf8c94d2016-01-15 16:51:28 -0800458 __set_bit(PG_uptodate, &page->flags);
Nick Piggin0ed361d2008-02-04 22:29:34 -0800459}
460
Denys Vlasenko4b0f3262016-03-17 14:18:24 -0700461static __always_inline void SetPageUptodate(struct page *page)
Heiko Carstens2dcea572006-09-29 01:58:41 -0700462{
Kirill A. Shutemovd2998c42016-01-15 16:52:00 -0800463 VM_BUG_ON_PAGE(PageTail(page), page);
Nick Piggin0ed361d2008-02-04 22:29:34 -0800464 /*
465 * Memory barrier must be issued before setting the PG_uptodate bit,
466 * so that all previous stores issued in order to bring the page
467 * uptodate are actually visible before PageUptodate becomes true.
Nick Piggin0ed361d2008-02-04 22:29:34 -0800468 */
469 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
Kirill A. Shutemovd2998c42016-01-15 16:52:00 -0800473CLEARPAGEFLAG(Uptodate, uptodate, PF_NO_TAIL)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700474
Linus Torvalds1da177e2005-04-16 15:20:36 -0700475int test_clear_page_writeback(struct page *page);
Namjae Jeon1c8349a2014-05-12 08:12:25 -0400476int __test_set_page_writeback(struct page *page, bool keep_write);
477
478#define test_set_page_writeback(page) \
479 __test_set_page_writeback(page, false)
480#define test_set_page_writeback_keepwrite(page) \
481 __test_set_page_writeback(page, true)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700482
Linus Torvalds1da177e2005-04-16 15:20:36 -0700483static inline void set_page_writeback(struct page *page)
484{
485 test_set_page_writeback(page);
486}
487
Namjae Jeon1c8349a2014-05-12 08:12:25 -0400488static inline void set_page_writeback_keepwrite(struct page *page)
489{
490 test_set_page_writeback_keepwrite(page);
491}
492
Kirill A. Shutemov95ad9752016-01-15 16:51:21 -0800493__PAGEFLAG(Head, head, PF_ANY) CLEARPAGEFLAG(Head, head, PF_ANY)
Kirill A. Shutemov1d798ca2015-11-06 16:29:54 -0800494
Denys Vlasenko4b0f3262016-03-17 14:18:24 -0700495static __always_inline void set_compound_head(struct page *page, struct page *head)
Kirill A. Shutemov1d798ca2015-11-06 16:29:54 -0800496{
497 WRITE_ONCE(page->compound_head, (unsigned long)head + 1);
498}
499
Denys Vlasenko4b0f3262016-03-17 14:18:24 -0700500static __always_inline void clear_compound_head(struct page *page)
Kirill A. Shutemov1d798ca2015-11-06 16:29:54 -0800501{
502 WRITE_ONCE(page->compound_head, 0);
503}
504
Andrea Arcangeli4e6af672011-01-13 15:46:44 -0800505#ifdef CONFIG_TRANSPARENT_HUGEPAGE
506static inline void ClearPageCompound(struct page *page)
507{
508 BUG_ON(!PageHead(page));
509 ClearPageHead(page);
510}
511#endif
Petr Tesarikb3acc562014-06-23 13:22:03 -0700512
Yu Zhaod2a1a1f2016-05-20 16:58:16 -0700513#define PG_head_mask ((1UL << PG_head))
Petr Tesarikb3acc562014-06-23 13:22:03 -0700514
Kirill A. Shutemove8c61582015-04-15 16:13:08 -0700515#ifdef CONFIG_HUGETLB_PAGE
516int PageHuge(struct page *page);
517int PageHeadHuge(struct page *page);
Naoya Horiguchi7e1f0492015-04-15 16:14:41 -0700518bool page_huge_active(struct page *page);
Kirill A. Shutemove8c61582015-04-15 16:13:08 -0700519#else
520TESTPAGEFLAG_FALSE(Huge)
521TESTPAGEFLAG_FALSE(HeadHuge)
Naoya Horiguchi7e1f0492015-04-15 16:14:41 -0700522
523static inline bool page_huge_active(struct page *page)
524{
525 return 0;
526}
Kirill A. Shutemove8c61582015-04-15 16:13:08 -0700527#endif
528
Naoya Horiguchi7e1f0492015-04-15 16:14:41 -0700529
Andrea Arcangeli936a5fe2011-01-13 15:46:48 -0800530#ifdef CONFIG_TRANSPARENT_HUGEPAGE
Andrea Arcangeli71e3aac2011-01-13 15:46:52 -0800531/*
532 * PageHuge() only returns true for hugetlbfs pages, but not for
533 * normal or transparent huge pages.
534 *
535 * PageTransHuge() returns true for both transparent huge and
536 * hugetlbfs pages, but not normal pages. PageTransHuge() can only be
537 * called only in the core VM paths where hugetlbfs pages can't exist.
538 */
539static inline int PageTransHuge(struct page *page)
540{
Sasha Levin309381fea2014-01-23 15:52:54 -0800541 VM_BUG_ON_PAGE(PageTail(page), page);
Andrea Arcangeli71e3aac2011-01-13 15:46:52 -0800542 return PageHead(page);
543}
544
Dean Nelson385de352012-03-21 16:34:05 -0700545/*
546 * PageTransCompound returns true for both transparent huge pages
547 * and hugetlbfs pages, so it should only be called when it's known
548 * that hugetlbfs pages aren't involved.
549 */
Andrea Arcangeli936a5fe2011-01-13 15:46:48 -0800550static inline int PageTransCompound(struct page *page)
551{
552 return PageCompound(page);
553}
Andrea Arcangeli71e3aac2011-01-13 15:46:52 -0800554
Dean Nelson385de352012-03-21 16:34:05 -0700555/*
Andrea Arcangeli127393f2016-05-05 16:22:20 -0700556 * PageTransCompoundMap is the same as PageTransCompound, but it also
557 * guarantees the primary MMU has the entire compound page mapped
558 * through pmd_trans_huge, which in turn guarantees the secondary MMUs
559 * can also map the entire compound page. This allows the secondary
560 * MMUs to call get_user_pages() only once for each compound page and
561 * to immediately map the entire compound page with a single secondary
562 * MMU fault. If there will be a pmd split later, the secondary MMUs
563 * will get an update through the MMU notifier invalidation through
564 * split_huge_pmd().
565 *
566 * Unlike PageTransCompound, this is safe to be called only while
567 * split_huge_pmd() cannot run from under us, like if protected by the
568 * MMU notifier, otherwise it may result in page->_mapcount < 0 false
569 * positives.
570 */
571static inline int PageTransCompoundMap(struct page *page)
572{
573 return PageTransCompound(page) && atomic_read(&page->_mapcount) < 0;
574}
575
576/*
Dean Nelson385de352012-03-21 16:34:05 -0700577 * PageTransTail returns true for both transparent huge pages
578 * and hugetlbfs pages, so it should only be called when it's known
579 * that hugetlbfs pages aren't involved.
580 */
581static inline int PageTransTail(struct page *page)
582{
583 return PageTail(page);
584}
585
Kirill A. Shutemov53f92632016-01-15 16:53:42 -0800586/*
587 * PageDoubleMap indicates that the compound page is mapped with PTEs as well
588 * as PMDs.
589 *
590 * This is required for optimization of rmap operations for THP: we can postpone
591 * per small page mapcount accounting (and its overhead from atomic operations)
592 * until the first PMD split.
593 *
594 * For the page PageDoubleMap means ->_mapcount in all sub-pages is offset up
595 * by one. This reference will go away with last compound_mapcount.
596 *
597 * See also __split_huge_pmd_locked() and page_remove_anon_compound_rmap().
598 */
599static inline int PageDoubleMap(struct page *page)
600{
601 return PageHead(page) && test_bit(PG_double_map, &page[1].flags);
602}
603
Kirill A. Shutemov9a73f612016-07-26 15:25:53 -0700604static inline void SetPageDoubleMap(struct page *page)
605{
606 VM_BUG_ON_PAGE(!PageHead(page), page);
607 set_bit(PG_double_map, &page[1].flags);
608}
609
610static inline void ClearPageDoubleMap(struct page *page)
611{
612 VM_BUG_ON_PAGE(!PageHead(page), page);
613 clear_bit(PG_double_map, &page[1].flags);
614}
Kirill A. Shutemov53f92632016-01-15 16:53:42 -0800615static inline int TestSetPageDoubleMap(struct page *page)
616{
617 VM_BUG_ON_PAGE(!PageHead(page), page);
618 return test_and_set_bit(PG_double_map, &page[1].flags);
619}
620
621static inline int TestClearPageDoubleMap(struct page *page)
622{
623 VM_BUG_ON_PAGE(!PageHead(page), page);
624 return test_and_clear_bit(PG_double_map, &page[1].flags);
625}
626
Andrea Arcangeli936a5fe2011-01-13 15:46:48 -0800627#else
Kirill A. Shutemovd8c1bde2016-01-15 16:51:13 -0800628TESTPAGEFLAG_FALSE(TransHuge)
629TESTPAGEFLAG_FALSE(TransCompound)
Andrea Arcangeli127393f2016-05-05 16:22:20 -0700630TESTPAGEFLAG_FALSE(TransCompoundMap)
Kirill A. Shutemovd8c1bde2016-01-15 16:51:13 -0800631TESTPAGEFLAG_FALSE(TransTail)
Kirill A. Shutemov9a73f612016-07-26 15:25:53 -0700632PAGEFLAG_FALSE(DoubleMap)
Kirill A. Shutemov53f92632016-01-15 16:53:42 -0800633 TESTSETFLAG_FALSE(DoubleMap)
634 TESTCLEARFLAG_FALSE(DoubleMap)
Andrea Arcangeli936a5fe2011-01-13 15:46:48 -0800635#endif
636
Mel Gorman072bb0a2012-07-31 16:43:58 -0700637/*
Vladimir Davydov632c0a12016-07-26 15:24:18 -0700638 * For pages that are never mapped to userspace, page->mapcount may be
639 * used for storing extra information about page type. Any value used
640 * for this purpose must be <= -2, but it's better start not too close
641 * to -2 so that an underflow of the page_mapcount() won't be mistaken
642 * for a special page.
643 */
644#define PAGE_MAPCOUNT_OPS(uname, lname) \
645static __always_inline int Page##uname(struct page *page) \
646{ \
647 return atomic_read(&page->_mapcount) == \
648 PAGE_##lname##_MAPCOUNT_VALUE; \
649} \
650static __always_inline void __SetPage##uname(struct page *page) \
651{ \
652 VM_BUG_ON_PAGE(atomic_read(&page->_mapcount) != -1, page); \
653 atomic_set(&page->_mapcount, PAGE_##lname##_MAPCOUNT_VALUE); \
654} \
655static __always_inline void __ClearPage##uname(struct page *page) \
656{ \
657 VM_BUG_ON_PAGE(!Page##uname(page), page); \
658 atomic_set(&page->_mapcount, -1); \
659}
660
661/*
Kirill A. Shutemove8c61582015-04-15 16:13:08 -0700662 * PageBuddy() indicate that the page is free and in the buddy system
663 * (see mm/page_alloc.c).
Kirill A. Shutemove8c61582015-04-15 16:13:08 -0700664 */
Vladimir Davydov632c0a12016-07-26 15:24:18 -0700665#define PAGE_BUDDY_MAPCOUNT_VALUE (-128)
666PAGE_MAPCOUNT_OPS(Buddy, BUDDY)
Kirill A. Shutemove8c61582015-04-15 16:13:08 -0700667
Vladimir Davydov632c0a12016-07-26 15:24:18 -0700668/*
669 * PageBalloon() is set on pages that are on the balloon page list
670 * (see mm/balloon_compaction.c).
671 */
672#define PAGE_BALLOON_MAPCOUNT_VALUE (-256)
673PAGE_MAPCOUNT_OPS(Balloon, BALLOON)
Kirill A. Shutemove8c61582015-04-15 16:13:08 -0700674
Vladimir Davydov49491482016-07-26 15:24:24 -0700675/*
676 * If kmemcg is enabled, the buddy allocator will set PageKmemcg() on
677 * pages allocated with __GFP_ACCOUNT. It gets cleared on page free.
678 */
679#define PAGE_KMEMCG_MAPCOUNT_VALUE (-512)
680PAGE_MAPCOUNT_OPS(Kmemcg, KMEMCG)
681
Naoya Horiguchi832fc1d2016-03-17 14:17:41 -0700682extern bool is_free_buddy_page(struct page *page);
683
Minchan Kimbda807d2016-07-26 15:23:05 -0700684__PAGEFLAG(Isolated, isolated, PF_ANY);
685
Kirill A. Shutemove8c61582015-04-15 16:13:08 -0700686/*
Mel Gorman072bb0a2012-07-31 16:43:58 -0700687 * If network-based swap is enabled, sl*b must keep track of whether pages
688 * were allocated from pfmemalloc reserves.
689 */
690static inline int PageSlabPfmemalloc(struct page *page)
691{
Sasha Levin309381fea2014-01-23 15:52:54 -0800692 VM_BUG_ON_PAGE(!PageSlab(page), page);
Mel Gorman072bb0a2012-07-31 16:43:58 -0700693 return PageActive(page);
694}
695
696static inline void SetPageSlabPfmemalloc(struct page *page)
697{
Sasha Levin309381fea2014-01-23 15:52:54 -0800698 VM_BUG_ON_PAGE(!PageSlab(page), page);
Mel Gorman072bb0a2012-07-31 16:43:58 -0700699 SetPageActive(page);
700}
701
702static inline void __ClearPageSlabPfmemalloc(struct page *page)
703{
Sasha Levin309381fea2014-01-23 15:52:54 -0800704 VM_BUG_ON_PAGE(!PageSlab(page), page);
Mel Gorman072bb0a2012-07-31 16:43:58 -0700705 __ClearPageActive(page);
706}
707
708static inline void ClearPageSlabPfmemalloc(struct page *page)
709{
Sasha Levin309381fea2014-01-23 15:52:54 -0800710 VM_BUG_ON_PAGE(!PageSlab(page), page);
Mel Gorman072bb0a2012-07-31 16:43:58 -0700711 ClearPageActive(page);
712}
713
Hugh Dickinsaf8e3352009-12-14 17:58:59 -0800714#ifdef CONFIG_MMU
Yu Zhaod2a1a1f2016-05-20 16:58:16 -0700715#define __PG_MLOCKED (1UL << PG_mlocked)
David Howells33925b22009-03-31 15:23:26 -0700716#else
Nick Pigginb291f002008-10-18 20:26:44 -0700717#define __PG_MLOCKED 0
Lee Schermerhorn894bc312008-10-18 20:26:39 -0700718#endif
719
Russ Andersondfa7e202008-06-09 11:18:45 -0500720/*
721 * Flags checked when a page is freed. Pages being freed should not have
722 * these flags set. It they are, there is a problem.
723 */
Nicholas Piggin6326fec2016-12-25 13:00:29 +1000724#define PAGE_FLAGS_CHECK_AT_FREE \
725 (1UL << PG_lru | 1UL << PG_locked | \
726 1UL << PG_private | 1UL << PG_private_2 | \
727 1UL << PG_writeback | 1UL << PG_reserved | \
728 1UL << PG_slab | 1UL << PG_active | \
729 1UL << PG_unevictable | __PG_MLOCKED)
Russ Andersondfa7e202008-06-09 11:18:45 -0500730
731/*
732 * Flags checked when a page is prepped for return by the page allocator.
Naoya Horiguchif4c18e62015-08-06 15:47:08 -0700733 * Pages being prepped should not have these flags set. It they are set,
Hugh Dickins79f4b7b2009-01-06 14:40:05 -0800734 * there has been a kernel bug or struct page corruption.
Naoya Horiguchif4c18e62015-08-06 15:47:08 -0700735 *
736 * __PG_HWPOISON is exceptional because it needs to be kept beyond page's
737 * alloc-free cycle to prevent from reusing the page.
Russ Andersondfa7e202008-06-09 11:18:45 -0500738 */
Naoya Horiguchif4c18e62015-08-06 15:47:08 -0700739#define PAGE_FLAGS_CHECK_AT_PREP \
Yu Zhaod2a1a1f2016-05-20 16:58:16 -0700740 (((1UL << NR_PAGEFLAGS) - 1) & ~__PG_HWPOISON)
Russ Andersondfa7e202008-06-09 11:18:45 -0500741
Johannes Weineredcf4742009-09-21 17:02:59 -0700742#define PAGE_FLAGS_PRIVATE \
Yu Zhaod2a1a1f2016-05-20 16:58:16 -0700743 (1UL << PG_private | 1UL << PG_private_2)
David Howells266cf652009-04-03 16:42:36 +0100744/**
745 * page_has_private - Determine if page has private stuff
746 * @page: The page to be checked
747 *
748 * Determine if a page has private stuff, indicating that release routines
749 * should be invoked upon it.
750 */
Johannes Weineredcf4742009-09-21 17:02:59 -0700751static inline int page_has_private(struct page *page)
752{
753 return !!(page->flags & PAGE_FLAGS_PRIVATE);
754}
755
Kirill A. Shutemov95ad9752016-01-15 16:51:21 -0800756#undef PF_ANY
757#undef PF_HEAD
Nicholas Piggin62906022016-12-25 13:00:30 +1000758#undef PF_ONLY_HEAD
Kirill A. Shutemov95ad9752016-01-15 16:51:21 -0800759#undef PF_NO_TAIL
760#undef PF_NO_COMPOUND
Johannes Weineredcf4742009-09-21 17:02:59 -0700761#endif /* !__GENERATING_BOUNDS_H */
David Howells266cf652009-04-03 16:42:36 +0100762
Linus Torvalds1da177e2005-04-16 15:20:36 -0700763#endif /* PAGE_FLAGS_H */