]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/blame - include/linux/page-flags.h
page-flags: move code around
[mirror_ubuntu-bionic-kernel.git] / include / linux / page-flags.h
CommitLineData
1da177e4
LT
1/*
2 * Macros for manipulating and testing page->flags
3 */
4
5#ifndef PAGE_FLAGS_H
6#define PAGE_FLAGS_H
7
f886ed44 8#include <linux/types.h>
187f1882 9#include <linux/bug.h>
072bb0aa 10#include <linux/mmdebug.h>
9223b419 11#ifndef __GENERATING_BOUNDS_H
6d777953 12#include <linux/mm_types.h>
01fc0ac1 13#include <generated/bounds.h>
9223b419 14#endif /* !__GENERATING_BOUNDS_H */
f886ed44 15
1da177e4
LT
16/*
17 * Various page->flags bits:
18 *
19 * PG_reserved is set for special pages, which can never be swapped out. Some
20 * of them might not even exist (eg empty_bad_page)...
21 *
da6052f7
NP
22 * The PG_private bitflag is set on pagecache pages if they contain filesystem
23 * specific data (which is normally at page->private). It can be used by
24 * private allocations for its own usage.
1da177e4 25 *
da6052f7
NP
26 * During initiation of disk I/O, PG_locked is set. This bit is set before I/O
27 * and cleared when writeback _starts_ or when read _completes_. PG_writeback
28 * is set before writeback starts and cleared when it finishes.
29 *
30 * PG_locked also pins a page in pagecache, and blocks truncation of the file
31 * while it is held.
32 *
33 * page_waitqueue(page) is a wait queue of all tasks waiting for the page
34 * to become unlocked.
1da177e4
LT
35 *
36 * PG_uptodate tells whether the page's contents is valid. When a read
37 * completes, the page becomes uptodate, unless a disk I/O error happened.
38 *
da6052f7
NP
39 * PG_referenced, PG_reclaim are used for page reclaim for anonymous and
40 * file-backed pagecache (see mm/vmscan.c).
1da177e4
LT
41 *
42 * PG_error is set to indicate that an I/O error occurred on this page.
43 *
44 * PG_arch_1 is an architecture specific page state bit. The generic code
45 * guarantees that this bit is cleared for a page when it first is entered into
46 * the page cache.
47 *
48 * PG_highmem pages are not permanently mapped into the kernel virtual address
49 * space, they need to be kmapped separately for doing IO on the pages. The
50 * struct page (these bits with information) are always mapped into kernel
51 * address space...
da6052f7 52 *
d466f2fc
AK
53 * PG_hwpoison indicates that a page got corrupted in hardware and contains
54 * data with incorrect ECC bits that triggered a machine check. Accessing is
55 * not safe since it may cause another machine check. Don't touch!
1da177e4
LT
56 */
57
58/*
59 * Don't use the *_dontuse flags. Use the macros. Otherwise you'll break
91fc8ab3
AW
60 * locked- and dirty-page accounting.
61 *
62 * The page flags field is split into two parts, the main flags area
63 * which extends from the low bits upwards, and the fields area which
64 * extends from the high bits downwards.
65 *
66 * | FIELD | ... | FLAGS |
9223b419
CL
67 * N-1 ^ 0
68 * (NR_PAGEFLAGS)
91fc8ab3 69 *
9223b419
CL
70 * The fields area is reserved for fields mapping zone, node (for NUMA) and
71 * SPARSEMEM section (for variants of SPARSEMEM that require section ids like
72 * SPARSEMEM_EXTREME with !SPARSEMEM_VMEMMAP).
1da177e4 73 */
e2683181
CL
74enum pageflags {
75 PG_locked, /* Page is locked. Don't touch. */
76 PG_error,
77 PG_referenced,
78 PG_uptodate,
79 PG_dirty,
80 PG_lru,
81 PG_active,
82 PG_slab,
83 PG_owner_priv_1, /* Owner use. If pagecache, fs may use*/
e2683181
CL
84 PG_arch_1,
85 PG_reserved,
86 PG_private, /* If pagecache, has fs-private data */
266cf658 87 PG_private_2, /* If pagecache, has fs aux data */
e2683181 88 PG_writeback, /* Page is under writeback */
e20b8cca 89 PG_head, /* A head page */
e2683181
CL
90 PG_swapcache, /* Swap page: swp_entry_t in private */
91 PG_mappedtodisk, /* Has blocks allocated on-disk */
92 PG_reclaim, /* To be reclaimed asap */
b2e18538 93 PG_swapbacked, /* Page is backed by RAM/swap */
894bc310 94 PG_unevictable, /* Page is "unevictable" */
af8e3354 95#ifdef CONFIG_MMU
b291f000 96 PG_mlocked, /* Page is vma mlocked */
894bc310 97#endif
46cf98cd 98#ifdef CONFIG_ARCH_USES_PG_UNCACHED
602c4d11 99 PG_uncached, /* Page has been mapped as uncached */
d466f2fc
AK
100#endif
101#ifdef CONFIG_MEMORY_FAILURE
102 PG_hwpoison, /* hardware poisoned page. Don't touch */
e9da73d6
AA
103#endif
104#ifdef CONFIG_TRANSPARENT_HUGEPAGE
105 PG_compound_lock,
33c3fc71
VD
106#endif
107#if defined(CONFIG_IDLE_PAGE_TRACKING) && defined(CONFIG_64BIT)
108 PG_young,
109 PG_idle,
f886ed44 110#endif
0cad47cf
AW
111 __NR_PAGEFLAGS,
112
113 /* Filesystems */
114 PG_checked = PG_owner_priv_1,
115
266cf658
DH
116 /* Two page bits are conscripted by FS-Cache to maintain local caching
117 * state. These bits are set on pages belonging to the netfs's inodes
118 * when those inodes are being locally cached.
119 */
120 PG_fscache = PG_private_2, /* page backed by cache */
121
0cad47cf 122 /* XEN */
d8ac3dd4 123 /* Pinned in Xen as a read-only pagetable page. */
0cad47cf 124 PG_pinned = PG_owner_priv_1,
d8ac3dd4 125 /* Pinned as part of domain save (see xen_mm_pin_all()). */
0cad47cf 126 PG_savepinned = PG_dirty,
d8ac3dd4
JH
127 /* Has a grant mapping of another (foreign) domain's page. */
128 PG_foreign = PG_owner_priv_1,
8a38082d 129
9023cb7e 130 /* SLOB */
9023cb7e 131 PG_slob_free = PG_private,
e2683181 132};
1da177e4 133
9223b419
CL
134#ifndef __GENERATING_BOUNDS_H
135
0e6d31a7
KS
136struct page; /* forward declaration */
137
138static inline struct page *compound_head(struct page *page)
139{
140 unsigned long head = READ_ONCE(page->compound_head);
141
142 if (unlikely(head & 1))
143 return (struct page *) (head - 1);
144 return page;
145}
146
147static inline int PageTail(struct page *page)
148{
149 return READ_ONCE(page->compound_head) & 1;
150}
151
152static inline int PageCompound(struct page *page)
153{
154 return test_bit(PG_head, &page->flags) || PageTail(page);
155}
156
f94a62e9
CL
157/*
158 * Macros to create function definitions for page flags
159 */
160#define TESTPAGEFLAG(uname, lname) \
67db392d 161static inline int Page##uname(const struct page *page) \
f94a62e9
CL
162 { return test_bit(PG_##lname, &page->flags); }
163
164#define SETPAGEFLAG(uname, lname) \
165static inline void SetPage##uname(struct page *page) \
166 { set_bit(PG_##lname, &page->flags); }
167
168#define CLEARPAGEFLAG(uname, lname) \
169static inline void ClearPage##uname(struct page *page) \
170 { clear_bit(PG_##lname, &page->flags); }
171
172#define __SETPAGEFLAG(uname, lname) \
173static inline void __SetPage##uname(struct page *page) \
174 { __set_bit(PG_##lname, &page->flags); }
175
176#define __CLEARPAGEFLAG(uname, lname) \
177static inline void __ClearPage##uname(struct page *page) \
178 { __clear_bit(PG_##lname, &page->flags); }
179
180#define TESTSETFLAG(uname, lname) \
181static inline int TestSetPage##uname(struct page *page) \
182 { return test_and_set_bit(PG_##lname, &page->flags); }
183
184#define TESTCLEARFLAG(uname, lname) \
185static inline int TestClearPage##uname(struct page *page) \
186 { return test_and_clear_bit(PG_##lname, &page->flags); }
187
451ea25d
JW
188#define __TESTCLEARFLAG(uname, lname) \
189static inline int __TestClearPage##uname(struct page *page) \
190 { return __test_and_clear_bit(PG_##lname, &page->flags); }
f94a62e9
CL
191
192#define PAGEFLAG(uname, lname) TESTPAGEFLAG(uname, lname) \
193 SETPAGEFLAG(uname, lname) CLEARPAGEFLAG(uname, lname)
194
195#define __PAGEFLAG(uname, lname) TESTPAGEFLAG(uname, lname) \
196 __SETPAGEFLAG(uname, lname) __CLEARPAGEFLAG(uname, lname)
197
198#define TESTSCFLAG(uname, lname) \
199 TESTSETFLAG(uname, lname) TESTCLEARFLAG(uname, lname)
200
2f3e442c
JW
201#define TESTPAGEFLAG_FALSE(uname) \
202static inline int Page##uname(const struct page *page) { return 0; }
203
8a7a8544
LS
204#define SETPAGEFLAG_NOOP(uname) \
205static inline void SetPage##uname(struct page *page) { }
206
207#define CLEARPAGEFLAG_NOOP(uname) \
208static inline void ClearPage##uname(struct page *page) { }
209
210#define __CLEARPAGEFLAG_NOOP(uname) \
211static inline void __ClearPage##uname(struct page *page) { }
212
2f3e442c
JW
213#define TESTSETFLAG_FALSE(uname) \
214static inline int TestSetPage##uname(struct page *page) { return 0; }
215
8a7a8544
LS
216#define TESTCLEARFLAG_FALSE(uname) \
217static inline int TestClearPage##uname(struct page *page) { return 0; }
218
451ea25d
JW
219#define __TESTCLEARFLAG_FALSE(uname) \
220static inline int __TestClearPage##uname(struct page *page) { return 0; }
221
2f3e442c
JW
222#define PAGEFLAG_FALSE(uname) TESTPAGEFLAG_FALSE(uname) \
223 SETPAGEFLAG_NOOP(uname) CLEARPAGEFLAG_NOOP(uname)
224
225#define TESTSCFLAG_FALSE(uname) \
226 TESTSETFLAG_FALSE(uname) TESTCLEARFLAG_FALSE(uname)
227
6a1e7f77 228
cb240452 229TESTPAGEFLAG(Locked, locked)
212260aa 230PAGEFLAG(Error, error) TESTCLEARFLAG(Error, error)
6a1e7f77 231PAGEFLAG(Referenced, referenced) TESTCLEARFLAG(Referenced, referenced)
2457aec6 232 __SETPAGEFLAG(Referenced, referenced)
6a1e7f77
CL
233PAGEFLAG(Dirty, dirty) TESTSCFLAG(Dirty, dirty) __CLEARPAGEFLAG(Dirty, dirty)
234PAGEFLAG(LRU, lru) __CLEARPAGEFLAG(LRU, lru)
235PAGEFLAG(Active, active) __CLEARPAGEFLAG(Active, active)
894bc310 236 TESTCLEARFLAG(Active, active)
6a1e7f77 237__PAGEFLAG(Slab, slab)
0cad47cf
AW
238PAGEFLAG(Checked, checked) /* Used by some filesystems */
239PAGEFLAG(Pinned, pinned) TESTSCFLAG(Pinned, pinned) /* Xen */
240PAGEFLAG(SavePinned, savepinned); /* Xen */
d8ac3dd4 241PAGEFLAG(Foreign, foreign); /* Xen */
6a1e7f77 242PAGEFLAG(Reserved, reserved) __CLEARPAGEFLAG(Reserved, reserved)
b2e18538 243PAGEFLAG(SwapBacked, swapbacked) __CLEARPAGEFLAG(SwapBacked, swapbacked)
07a42788 244 __SETPAGEFLAG(SwapBacked, swapbacked)
6a1e7f77 245
9023cb7e
AW
246__PAGEFLAG(SlobFree, slob_free)
247
266cf658
DH
248/*
249 * Private page markings that may be used by the filesystem that owns the page
250 * for its own purposes.
251 * - PG_private and PG_private_2 cause releasepage() and co to be invoked
252 */
253PAGEFLAG(Private, private) __SETPAGEFLAG(Private, private)
254 __CLEARPAGEFLAG(Private, private)
255PAGEFLAG(Private2, private_2) TESTSCFLAG(Private2, private_2)
256PAGEFLAG(OwnerPriv1, owner_priv_1) TESTCLEARFLAG(OwnerPriv1, owner_priv_1)
257
6a1e7f77
CL
258/*
259 * Only test-and-set exist for PG_writeback. The unconditional operators are
260 * risky: they bypass page accounting.
261 */
262TESTPAGEFLAG(Writeback, writeback) TESTSCFLAG(Writeback, writeback)
6a1e7f77
CL
263PAGEFLAG(MappedToDisk, mappedtodisk)
264
579f8290 265/* PG_readahead is only used for reads; PG_reclaim is only for writes */
6a1e7f77 266PAGEFLAG(Reclaim, reclaim) TESTCLEARFLAG(Reclaim, reclaim)
579f8290 267PAGEFLAG(Readahead, reclaim) TESTCLEARFLAG(Readahead, reclaim)
6a1e7f77
CL
268
269#ifdef CONFIG_HIGHMEM
1da177e4 270/*
6a1e7f77
CL
271 * Must use a macro here due to header dependency issues. page_zone() is not
272 * available at this point.
1da177e4 273 */
3ca65c19 274#define PageHighMem(__p) is_highmem_idx(page_zonenum(__p))
6a1e7f77 275#else
ec7cade8 276PAGEFLAG_FALSE(HighMem)
6a1e7f77
CL
277#endif
278
279#ifdef CONFIG_SWAP
280PAGEFLAG(SwapCache, swapcache)
281#else
ec7cade8 282PAGEFLAG_FALSE(SwapCache)
6a1e7f77
CL
283#endif
284
894bc310
LS
285PAGEFLAG(Unevictable, unevictable) __CLEARPAGEFLAG(Unevictable, unevictable)
286 TESTCLEARFLAG(Unevictable, unevictable)
b291f000 287
af8e3354 288#ifdef CONFIG_MMU
b291f000 289PAGEFLAG(Mlocked, mlocked) __CLEARPAGEFLAG(Mlocked, mlocked)
451ea25d 290 TESTSCFLAG(Mlocked, mlocked) __TESTCLEARFLAG(Mlocked, mlocked)
894bc310 291#else
2f3e442c
JW
292PAGEFLAG_FALSE(Mlocked) __CLEARPAGEFLAG_NOOP(Mlocked)
293 TESTSCFLAG_FALSE(Mlocked) __TESTCLEARFLAG_FALSE(Mlocked)
894bc310
LS
294#endif
295
46cf98cd 296#ifdef CONFIG_ARCH_USES_PG_UNCACHED
6a1e7f77 297PAGEFLAG(Uncached, uncached)
602c4d11 298#else
ec7cade8 299PAGEFLAG_FALSE(Uncached)
6a1e7f77 300#endif
1da177e4 301
d466f2fc
AK
302#ifdef CONFIG_MEMORY_FAILURE
303PAGEFLAG(HWPoison, hwpoison)
847ce401 304TESTSCFLAG(HWPoison, hwpoison)
d466f2fc
AK
305#define __PG_HWPOISON (1UL << PG_hwpoison)
306#else
307PAGEFLAG_FALSE(HWPoison)
308#define __PG_HWPOISON 0
309#endif
310
33c3fc71
VD
311#if defined(CONFIG_IDLE_PAGE_TRACKING) && defined(CONFIG_64BIT)
312TESTPAGEFLAG(Young, young)
313SETPAGEFLAG(Young, young)
314TESTCLEARFLAG(Young, young)
315PAGEFLAG(Idle, idle)
316#endif
317
e8c6158f
KS
318/*
319 * On an anonymous page mapped into a user virtual memory area,
320 * page->mapping points to its anon_vma, not to a struct address_space;
321 * with the PAGE_MAPPING_ANON bit set to distinguish it. See rmap.h.
322 *
323 * On an anonymous page in a VM_MERGEABLE area, if CONFIG_KSM is enabled,
324 * the PAGE_MAPPING_KSM bit may be set along with the PAGE_MAPPING_ANON bit;
325 * and then page->mapping points, not to an anon_vma, but to a private
326 * structure which KSM associates with that merged page. See ksm.h.
327 *
328 * PAGE_MAPPING_KSM without PAGE_MAPPING_ANON is currently never used.
329 *
330 * Please note that, confusingly, "page_mapping" refers to the inode
331 * address_space which maps the page from disk; whereas "page_mapped"
332 * refers to user virtual address space into which the page is mapped.
333 */
334#define PAGE_MAPPING_ANON 1
335#define PAGE_MAPPING_KSM 2
336#define PAGE_MAPPING_FLAGS (PAGE_MAPPING_ANON | PAGE_MAPPING_KSM)
337
338static inline int PageAnon(struct page *page)
339{
340 return ((unsigned long)page->mapping & PAGE_MAPPING_ANON) != 0;
341}
342
343#ifdef CONFIG_KSM
344/*
345 * A KSM page is one of those write-protected "shared pages" or "merged pages"
346 * which KSM maps into multiple mms, wherever identical anonymous page content
347 * is found in VM_MERGEABLE vmas. It's a PageAnon page, pointing not to any
348 * anon_vma, but to that page's node of the stable tree.
349 */
350static inline int PageKsm(struct page *page)
351{
352 return ((unsigned long)page->mapping & PAGE_MAPPING_FLAGS) ==
353 (PAGE_MAPPING_ANON | PAGE_MAPPING_KSM);
354}
355#else
356TESTPAGEFLAG_FALSE(Ksm)
357#endif
358
1a9b5b7f
WF
359u64 stable_page_flags(struct page *page);
360
0ed361de
NP
361static inline int PageUptodate(struct page *page)
362{
363 int ret = test_bit(PG_uptodate, &(page)->flags);
364
365 /*
366 * Must ensure that the data we read out of the page is loaded
367 * _after_ we've loaded page->flags to check for PageUptodate.
368 * We can skip the barrier if the page is not uptodate, because
369 * we wouldn't be reading anything from it.
370 *
371 * See SetPageUptodate() for the other side of the story.
372 */
373 if (ret)
374 smp_rmb();
375
376 return ret;
377}
378
379static inline void __SetPageUptodate(struct page *page)
380{
381 smp_wmb();
382 __set_bit(PG_uptodate, &(page)->flags);
0ed361de
NP
383}
384
2dcea57a
HC
385static inline void SetPageUptodate(struct page *page)
386{
0ed361de
NP
387 /*
388 * Memory barrier must be issued before setting the PG_uptodate bit,
389 * so that all previous stores issued in order to bring the page
390 * uptodate are actually visible before PageUptodate becomes true.
0ed361de
NP
391 */
392 smp_wmb();
393 set_bit(PG_uptodate, &(page)->flags);
0ed361de
NP
394}
395
6a1e7f77 396CLEARPAGEFLAG(Uptodate, uptodate)
1da177e4 397
6a1e7f77 398int test_clear_page_writeback(struct page *page);
1c8349a1
NJ
399int __test_set_page_writeback(struct page *page, bool keep_write);
400
401#define test_set_page_writeback(page) \
402 __test_set_page_writeback(page, false)
403#define test_set_page_writeback_keepwrite(page) \
404 __test_set_page_writeback(page, true)
1da177e4 405
6a1e7f77
CL
406static inline void set_page_writeback(struct page *page)
407{
408 test_set_page_writeback(page);
409}
1da177e4 410
1c8349a1
NJ
411static inline void set_page_writeback_keepwrite(struct page *page)
412{
413 test_set_page_writeback_keepwrite(page);
414}
415
4e6af67e 416__PAGEFLAG(Head, head) CLEARPAGEFLAG(Head, head)
e20b8cca 417
1d798ca3 418static inline void set_compound_head(struct page *page, struct page *head)
ad4b3fb7 419{
1d798ca3 420 WRITE_ONCE(page->compound_head, (unsigned long)head + 1);
ad4b3fb7
CD
421}
422
1d798ca3 423static inline void clear_compound_head(struct page *page)
6a1e7f77 424{
1d798ca3 425 WRITE_ONCE(page->compound_head, 0);
6a1e7f77 426}
6d777953 427
4e6af67e
AA
428#ifdef CONFIG_TRANSPARENT_HUGEPAGE
429static inline void ClearPageCompound(struct page *page)
430{
1d798ca3
KS
431 BUG_ON(!PageHead(page));
432 ClearPageHead(page);
4e6af67e
AA
433}
434#endif
435
1d798ca3 436#define PG_head_mask ((1L << PG_head))
dfa7e20c 437
e8c6158f
KS
438#ifdef CONFIG_HUGETLB_PAGE
439int PageHuge(struct page *page);
440int PageHeadHuge(struct page *page);
7e1f049e 441bool page_huge_active(struct page *page);
e8c6158f
KS
442#else
443TESTPAGEFLAG_FALSE(Huge)
444TESTPAGEFLAG_FALSE(HeadHuge)
7e1f049e
NH
445
446static inline bool page_huge_active(struct page *page)
447{
448 return 0;
449}
e8c6158f
KS
450#endif
451
7e1f049e 452
936a5fe6 453#ifdef CONFIG_TRANSPARENT_HUGEPAGE
71e3aac0
AA
454/*
455 * PageHuge() only returns true for hugetlbfs pages, but not for
456 * normal or transparent huge pages.
457 *
458 * PageTransHuge() returns true for both transparent huge and
459 * hugetlbfs pages, but not normal pages. PageTransHuge() can only be
460 * called only in the core VM paths where hugetlbfs pages can't exist.
461 */
462static inline int PageTransHuge(struct page *page)
463{
309381fe 464 VM_BUG_ON_PAGE(PageTail(page), page);
71e3aac0
AA
465 return PageHead(page);
466}
467
385de357
DN
468/*
469 * PageTransCompound returns true for both transparent huge pages
470 * and hugetlbfs pages, so it should only be called when it's known
471 * that hugetlbfs pages aren't involved.
472 */
936a5fe6
AA
473static inline int PageTransCompound(struct page *page)
474{
475 return PageCompound(page);
476}
71e3aac0 477
385de357
DN
478/*
479 * PageTransTail returns true for both transparent huge pages
480 * and hugetlbfs pages, so it should only be called when it's known
481 * that hugetlbfs pages aren't involved.
482 */
483static inline int PageTransTail(struct page *page)
484{
485 return PageTail(page);
486}
487
936a5fe6 488#else
d8c1bdeb
KS
489TESTPAGEFLAG_FALSE(TransHuge)
490TESTPAGEFLAG_FALSE(TransCompound)
491TESTPAGEFLAG_FALSE(TransTail)
936a5fe6
AA
492#endif
493
e8c6158f
KS
494/*
495 * PageBuddy() indicate that the page is free and in the buddy system
496 * (see mm/page_alloc.c).
497 *
498 * PAGE_BUDDY_MAPCOUNT_VALUE must be <= -2 but better not too close to
499 * -2 so that an underflow of the page_mapcount() won't be mistaken
500 * for a genuine PAGE_BUDDY_MAPCOUNT_VALUE. -128 can be created very
501 * efficiently by most CPU architectures.
502 */
503#define PAGE_BUDDY_MAPCOUNT_VALUE (-128)
504
505static inline int PageBuddy(struct page *page)
506{
507 return atomic_read(&page->_mapcount) == PAGE_BUDDY_MAPCOUNT_VALUE;
508}
509
510static inline void __SetPageBuddy(struct page *page)
511{
512 VM_BUG_ON_PAGE(atomic_read(&page->_mapcount) != -1, page);
513 atomic_set(&page->_mapcount, PAGE_BUDDY_MAPCOUNT_VALUE);
514}
515
516static inline void __ClearPageBuddy(struct page *page)
517{
518 VM_BUG_ON_PAGE(!PageBuddy(page), page);
519 atomic_set(&page->_mapcount, -1);
520}
521
522#define PAGE_BALLOON_MAPCOUNT_VALUE (-256)
523
524static inline int PageBalloon(struct page *page)
525{
526 return atomic_read(&page->_mapcount) == PAGE_BALLOON_MAPCOUNT_VALUE;
527}
528
529static inline void __SetPageBalloon(struct page *page)
530{
531 VM_BUG_ON_PAGE(atomic_read(&page->_mapcount) != -1, page);
532 atomic_set(&page->_mapcount, PAGE_BALLOON_MAPCOUNT_VALUE);
533}
534
535static inline void __ClearPageBalloon(struct page *page)
536{
537 VM_BUG_ON_PAGE(!PageBalloon(page), page);
538 atomic_set(&page->_mapcount, -1);
539}
540
072bb0aa
MG
541/*
542 * If network-based swap is enabled, sl*b must keep track of whether pages
543 * were allocated from pfmemalloc reserves.
544 */
545static inline int PageSlabPfmemalloc(struct page *page)
546{
309381fe 547 VM_BUG_ON_PAGE(!PageSlab(page), page);
072bb0aa
MG
548 return PageActive(page);
549}
550
551static inline void SetPageSlabPfmemalloc(struct page *page)
552{
309381fe 553 VM_BUG_ON_PAGE(!PageSlab(page), page);
072bb0aa
MG
554 SetPageActive(page);
555}
556
557static inline void __ClearPageSlabPfmemalloc(struct page *page)
558{
309381fe 559 VM_BUG_ON_PAGE(!PageSlab(page), page);
072bb0aa
MG
560 __ClearPageActive(page);
561}
562
563static inline void ClearPageSlabPfmemalloc(struct page *page)
564{
309381fe 565 VM_BUG_ON_PAGE(!PageSlab(page), page);
072bb0aa
MG
566 ClearPageActive(page);
567}
568
af8e3354 569#ifdef CONFIG_MMU
33925b25
DH
570#define __PG_MLOCKED (1 << PG_mlocked)
571#else
b291f000 572#define __PG_MLOCKED 0
894bc310
LS
573#endif
574
e9da73d6
AA
575#ifdef CONFIG_TRANSPARENT_HUGEPAGE
576#define __PG_COMPOUND_LOCK (1 << PG_compound_lock)
577#else
578#define __PG_COMPOUND_LOCK 0
579#endif
580
dfa7e20c
RA
581/*
582 * Flags checked when a page is freed. Pages being freed should not have
583 * these flags set. It they are, there is a problem.
584 */
79f4b7bf 585#define PAGE_FLAGS_CHECK_AT_FREE \
266cf658
DH
586 (1 << PG_lru | 1 << PG_locked | \
587 1 << PG_private | 1 << PG_private_2 | \
5f24ce5f 588 1 << PG_writeback | 1 << PG_reserved | \
266cf658 589 1 << PG_slab | 1 << PG_swapcache | 1 << PG_active | \
f4c18e6f 590 1 << PG_unevictable | __PG_MLOCKED | \
e9da73d6 591 __PG_COMPOUND_LOCK)
dfa7e20c
RA
592
593/*
594 * Flags checked when a page is prepped for return by the page allocator.
f4c18e6f 595 * Pages being prepped should not have these flags set. It they are set,
79f4b7bf 596 * there has been a kernel bug or struct page corruption.
f4c18e6f
NH
597 *
598 * __PG_HWPOISON is exceptional because it needs to be kept beyond page's
599 * alloc-free cycle to prevent from reusing the page.
dfa7e20c 600 */
f4c18e6f
NH
601#define PAGE_FLAGS_CHECK_AT_PREP \
602 (((1 << NR_PAGEFLAGS) - 1) & ~__PG_HWPOISON)
dfa7e20c 603
edcf4748
JW
604#define PAGE_FLAGS_PRIVATE \
605 (1 << PG_private | 1 << PG_private_2)
266cf658
DH
606/**
607 * page_has_private - Determine if page has private stuff
608 * @page: The page to be checked
609 *
610 * Determine if a page has private stuff, indicating that release routines
611 * should be invoked upon it.
612 */
edcf4748
JW
613static inline int page_has_private(struct page *page)
614{
615 return !!(page->flags & PAGE_FLAGS_PRIVATE);
616}
617
618#endif /* !__GENERATING_BOUNDS_H */
266cf658 619
1da177e4 620#endif /* PAGE_FLAGS_H */