blob: a1e143634946f08128737148f53358550b356ec8 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * Macros for manipulating and testing page->flags
3 */
4
5#ifndef PAGE_FLAGS_H
6#define PAGE_FLAGS_H
7
Andrew Mortonf886ed42006-06-23 02:03:06 -07008#include <linux/types.h>
9
Linus Torvalds1da177e2005-04-16 15:20:36 -070010/*
11 * Various page->flags bits:
12 *
13 * PG_reserved is set for special pages, which can never be swapped out. Some
14 * of them might not even exist (eg empty_bad_page)...
15 *
Nick Pigginda6052f2006-09-25 23:31:35 -070016 * The PG_private bitflag is set on pagecache pages if they contain filesystem
17 * specific data (which is normally at page->private). It can be used by
18 * private allocations for its own usage.
Linus Torvalds1da177e2005-04-16 15:20:36 -070019 *
Nick Pigginda6052f2006-09-25 23:31:35 -070020 * During initiation of disk I/O, PG_locked is set. This bit is set before I/O
21 * and cleared when writeback _starts_ or when read _completes_. PG_writeback
22 * is set before writeback starts and cleared when it finishes.
23 *
24 * PG_locked also pins a page in pagecache, and blocks truncation of the file
25 * while it is held.
26 *
27 * page_waitqueue(page) is a wait queue of all tasks waiting for the page
28 * to become unlocked.
Linus Torvalds1da177e2005-04-16 15:20:36 -070029 *
30 * PG_uptodate tells whether the page's contents is valid. When a read
31 * completes, the page becomes uptodate, unless a disk I/O error happened.
32 *
Nick Pigginda6052f2006-09-25 23:31:35 -070033 * PG_referenced, PG_reclaim are used for page reclaim for anonymous and
34 * file-backed pagecache (see mm/vmscan.c).
Linus Torvalds1da177e2005-04-16 15:20:36 -070035 *
36 * PG_error is set to indicate that an I/O error occurred on this page.
37 *
38 * PG_arch_1 is an architecture specific page state bit. The generic code
39 * guarantees that this bit is cleared for a page when it first is entered into
40 * the page cache.
41 *
42 * PG_highmem pages are not permanently mapped into the kernel virtual address
43 * space, they need to be kmapped separately for doing IO on the pages. The
44 * struct page (these bits with information) are always mapped into kernel
45 * address space...
Nick Pigginda6052f2006-09-25 23:31:35 -070046 *
47 * PG_buddy is set to indicate that the page is free and in the buddy system
48 * (see mm/page_alloc.c).
49 *
Linus Torvalds1da177e2005-04-16 15:20:36 -070050 */
51
52/*
53 * Don't use the *_dontuse flags. Use the macros. Otherwise you'll break
Andy Whitcroft91fc8ab2006-04-10 22:53:01 -070054 * locked- and dirty-page accounting.
55 *
56 * The page flags field is split into two parts, the main flags area
57 * which extends from the low bits upwards, and the fields area which
58 * extends from the high bits downwards.
59 *
60 * | FIELD | ... | FLAGS |
61 * N-1 ^ 0
62 * (N-FLAGS_RESERVED)
63 *
64 * The fields area is reserved for fields mapping zone, node and SPARSEMEM
65 * section. The boundry between these two areas is defined by
66 * FLAGS_RESERVED which defines the width of the fields section
67 * (see linux/mmzone.h). New flags must _not_ overlap with this area.
Linus Torvalds1da177e2005-04-16 15:20:36 -070068 */
69#define PG_locked 0 /* Page is locked. Don't touch. */
70#define PG_error 1
71#define PG_referenced 2
72#define PG_uptodate 3
73
74#define PG_dirty 4
75#define PG_lru 5
76#define PG_active 6
77#define PG_slab 7 /* slab debug (Suparna wants this) */
78
Nick Piggin5409bae2007-02-28 20:12:27 -080079#define PG_owner_priv_1 8 /* Owner use. If pagecache, fs may use*/
Badari Pulavartycbe37d02005-06-21 17:14:52 -070080#define PG_arch_1 9
81#define PG_reserved 10
Nick Pigginda6052f2006-09-25 23:31:35 -070082#define PG_private 11 /* If pagecache, has fs-private data */
Linus Torvalds1da177e2005-04-16 15:20:36 -070083
Badari Pulavartycbe37d02005-06-21 17:14:52 -070084#define PG_writeback 12 /* Page is under writeback */
85#define PG_nosave 13 /* Used for system suspend/resume */
86#define PG_compound 14 /* Part of a compound page */
87#define PG_swapcache 15 /* Swap page: swp_entry_t in private */
Linus Torvalds1da177e2005-04-16 15:20:36 -070088
Badari Pulavartycbe37d02005-06-21 17:14:52 -070089#define PG_mappedtodisk 16 /* Has blocks allocated on-disk */
90#define PG_reclaim 17 /* To be reclaimed asap */
Nick Pigginda6052f2006-09-25 23:31:35 -070091#define PG_nosave_free 18 /* Used for system suspend/resume */
Nick Piggin676165a2006-04-10 11:21:48 +100092#define PG_buddy 19 /* Page is free, on buddy lists */
93
Nick Piggin5409bae2007-02-28 20:12:27 -080094/* PG_owner_priv_1 users should have descriptive aliases */
95#define PG_checked PG_owner_priv_1 /* Used by some filesystems */
Andrew Mortonf886ed42006-06-23 02:03:06 -070096
Christoph Lameterd85f3382007-05-06 14:49:39 -070097/*
98 * Marks tail portion of a compound page. We currently do not reclaim
99 * compound pages so we can reuse a flag only used for reclaim here.
100 */
101#define PG_tail PG_reclaim
102
Andrew Mortonf886ed42006-06-23 02:03:06 -0700103#if (BITS_PER_LONG > 32)
104/*
105 * 64-bit-only flags build down from bit 31
106 *
107 * 32 bit -------------------------------| FIELDS | FLAGS |
108 * 64 bit | FIELDS | ?????? FLAGS |
109 * 63 32 0
110 */
111#define PG_uncached 31 /* Page has been mapped as uncached */
112#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700113
114/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700115 * Manipulation of page state flags
116 */
117#define PageLocked(page) \
118 test_bit(PG_locked, &(page)->flags)
119#define SetPageLocked(page) \
120 set_bit(PG_locked, &(page)->flags)
121#define TestSetPageLocked(page) \
122 test_and_set_bit(PG_locked, &(page)->flags)
123#define ClearPageLocked(page) \
124 clear_bit(PG_locked, &(page)->flags)
125#define TestClearPageLocked(page) \
126 test_and_clear_bit(PG_locked, &(page)->flags)
127
128#define PageError(page) test_bit(PG_error, &(page)->flags)
129#define SetPageError(page) set_bit(PG_error, &(page)->flags)
130#define ClearPageError(page) clear_bit(PG_error, &(page)->flags)
131
132#define PageReferenced(page) test_bit(PG_referenced, &(page)->flags)
133#define SetPageReferenced(page) set_bit(PG_referenced, &(page)->flags)
134#define ClearPageReferenced(page) clear_bit(PG_referenced, &(page)->flags)
135#define TestClearPageReferenced(page) test_and_clear_bit(PG_referenced, &(page)->flags)
136
137#define PageUptodate(page) test_bit(PG_uptodate, &(page)->flags)
Christoph Lameterf6ac2352006-06-30 01:55:32 -0700138#ifdef CONFIG_S390
Heiko Carstens2dcea572006-09-29 01:58:41 -0700139static inline void SetPageUptodate(struct page *page)
140{
141 if (!test_and_set_bit(PG_uptodate, &page->flags))
Martin Schwidefsky6c210482007-04-27 16:01:57 +0200142 page_clear_dirty(page);
Heiko Carstens2dcea572006-09-29 01:58:41 -0700143}
Christoph Lameterf6ac2352006-06-30 01:55:32 -0700144#else
Linus Torvalds1da177e2005-04-16 15:20:36 -0700145#define SetPageUptodate(page) set_bit(PG_uptodate, &(page)->flags)
146#endif
147#define ClearPageUptodate(page) clear_bit(PG_uptodate, &(page)->flags)
148
149#define PageDirty(page) test_bit(PG_dirty, &(page)->flags)
150#define SetPageDirty(page) set_bit(PG_dirty, &(page)->flags)
151#define TestSetPageDirty(page) test_and_set_bit(PG_dirty, &(page)->flags)
152#define ClearPageDirty(page) clear_bit(PG_dirty, &(page)->flags)
Nick Piggin242e5462005-09-03 15:54:50 -0700153#define __ClearPageDirty(page) __clear_bit(PG_dirty, &(page)->flags)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700154#define TestClearPageDirty(page) test_and_clear_bit(PG_dirty, &(page)->flags)
155
Linus Torvalds1da177e2005-04-16 15:20:36 -0700156#define PageLRU(page) test_bit(PG_lru, &(page)->flags)
Nick Piggin8d438f92006-03-22 00:07:59 -0800157#define SetPageLRU(page) set_bit(PG_lru, &(page)->flags)
158#define ClearPageLRU(page) clear_bit(PG_lru, &(page)->flags)
Nick Piggin67453912006-03-22 00:08:00 -0800159#define __ClearPageLRU(page) __clear_bit(PG_lru, &(page)->flags)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700160
161#define PageActive(page) test_bit(PG_active, &(page)->flags)
162#define SetPageActive(page) set_bit(PG_active, &(page)->flags)
163#define ClearPageActive(page) clear_bit(PG_active, &(page)->flags)
Nick Piggin67453912006-03-22 00:08:00 -0800164#define __ClearPageActive(page) __clear_bit(PG_active, &(page)->flags)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700165
166#define PageSlab(page) test_bit(PG_slab, &(page)->flags)
Nick Pigginf205b2f2006-03-22 00:08:02 -0800167#define __SetPageSlab(page) __set_bit(PG_slab, &(page)->flags)
168#define __ClearPageSlab(page) __clear_bit(PG_slab, &(page)->flags)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700169
170#ifdef CONFIG_HIGHMEM
Badari Pulavartycbe37d02005-06-21 17:14:52 -0700171#define PageHighMem(page) is_highmem(page_zone(page))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700172#else
173#define PageHighMem(page) 0 /* needed to optimize away at compile time */
174#endif
175
176#define PageChecked(page) test_bit(PG_checked, &(page)->flags)
177#define SetPageChecked(page) set_bit(PG_checked, &(page)->flags)
178#define ClearPageChecked(page) clear_bit(PG_checked, &(page)->flags)
179
180#define PageReserved(page) test_bit(PG_reserved, &(page)->flags)
181#define SetPageReserved(page) set_bit(PG_reserved, &(page)->flags)
182#define ClearPageReserved(page) clear_bit(PG_reserved, &(page)->flags)
183#define __ClearPageReserved(page) __clear_bit(PG_reserved, &(page)->flags)
184
185#define SetPagePrivate(page) set_bit(PG_private, &(page)->flags)
186#define ClearPagePrivate(page) clear_bit(PG_private, &(page)->flags)
187#define PagePrivate(page) test_bit(PG_private, &(page)->flags)
188#define __SetPagePrivate(page) __set_bit(PG_private, &(page)->flags)
189#define __ClearPagePrivate(page) __clear_bit(PG_private, &(page)->flags)
190
191#define PageWriteback(page) test_bit(PG_writeback, &(page)->flags)
192#define SetPageWriteback(page) \
193 do { \
194 if (!test_and_set_bit(PG_writeback, \
195 &(page)->flags)) \
Christoph Lameterce866b32006-06-30 01:55:40 -0700196 inc_zone_page_state(page, NR_WRITEBACK); \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700197 } while (0)
198#define TestSetPageWriteback(page) \
199 ({ \
200 int ret; \
201 ret = test_and_set_bit(PG_writeback, \
202 &(page)->flags); \
203 if (!ret) \
Christoph Lameterce866b32006-06-30 01:55:40 -0700204 inc_zone_page_state(page, NR_WRITEBACK); \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700205 ret; \
206 })
207#define ClearPageWriteback(page) \
208 do { \
209 if (test_and_clear_bit(PG_writeback, \
210 &(page)->flags)) \
Christoph Lameterce866b32006-06-30 01:55:40 -0700211 dec_zone_page_state(page, NR_WRITEBACK); \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700212 } while (0)
213#define TestClearPageWriteback(page) \
214 ({ \
215 int ret; \
216 ret = test_and_clear_bit(PG_writeback, \
217 &(page)->flags); \
218 if (ret) \
Christoph Lameterce866b32006-06-30 01:55:40 -0700219 dec_zone_page_state(page, NR_WRITEBACK); \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700220 ret; \
221 })
222
223#define PageNosave(page) test_bit(PG_nosave, &(page)->flags)
224#define SetPageNosave(page) set_bit(PG_nosave, &(page)->flags)
225#define TestSetPageNosave(page) test_and_set_bit(PG_nosave, &(page)->flags)
226#define ClearPageNosave(page) clear_bit(PG_nosave, &(page)->flags)
227#define TestClearPageNosave(page) test_and_clear_bit(PG_nosave, &(page)->flags)
228
229#define PageNosaveFree(page) test_bit(PG_nosave_free, &(page)->flags)
230#define SetPageNosaveFree(page) set_bit(PG_nosave_free, &(page)->flags)
231#define ClearPageNosaveFree(page) clear_bit(PG_nosave_free, &(page)->flags)
232
Nick Piggin676165a2006-04-10 11:21:48 +1000233#define PageBuddy(page) test_bit(PG_buddy, &(page)->flags)
234#define __SetPageBuddy(page) __set_bit(PG_buddy, &(page)->flags)
235#define __ClearPageBuddy(page) __clear_bit(PG_buddy, &(page)->flags)
236
Linus Torvalds1da177e2005-04-16 15:20:36 -0700237#define PageMappedToDisk(page) test_bit(PG_mappedtodisk, &(page)->flags)
238#define SetPageMappedToDisk(page) set_bit(PG_mappedtodisk, &(page)->flags)
239#define ClearPageMappedToDisk(page) clear_bit(PG_mappedtodisk, &(page)->flags)
240
241#define PageReclaim(page) test_bit(PG_reclaim, &(page)->flags)
242#define SetPageReclaim(page) set_bit(PG_reclaim, &(page)->flags)
243#define ClearPageReclaim(page) clear_bit(PG_reclaim, &(page)->flags)
244#define TestClearPageReclaim(page) test_and_clear_bit(PG_reclaim, &(page)->flags)
245
Linus Torvalds1da177e2005-04-16 15:20:36 -0700246#define PageCompound(page) test_bit(PG_compound, &(page)->flags)
Nick Piggin5e9dace2006-03-22 00:08:01 -0800247#define __SetPageCompound(page) __set_bit(PG_compound, &(page)->flags)
248#define __ClearPageCompound(page) __clear_bit(PG_compound, &(page)->flags)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700249
Christoph Lameterd85f3382007-05-06 14:49:39 -0700250/*
251 * Note: PG_tail is an alias of another page flag. The result of PageTail()
252 * is only valid if PageCompound(page) is true.
253 */
254#define PageTail(page) test_bit(PG_tail, &(page)->flags)
255#define __SetPageTail(page) __set_bit(PG_tail, &(page)->flags)
256#define __ClearPageTail(page) __clear_bit(PG_tail, &(page)->flags)
257
Linus Torvalds1da177e2005-04-16 15:20:36 -0700258#ifdef CONFIG_SWAP
259#define PageSwapCache(page) test_bit(PG_swapcache, &(page)->flags)
260#define SetPageSwapCache(page) set_bit(PG_swapcache, &(page)->flags)
261#define ClearPageSwapCache(page) clear_bit(PG_swapcache, &(page)->flags)
262#else
263#define PageSwapCache(page) 0
264#endif
265
266#define PageUncached(page) test_bit(PG_uncached, &(page)->flags)
267#define SetPageUncached(page) set_bit(PG_uncached, &(page)->flags)
268#define ClearPageUncached(page) clear_bit(PG_uncached, &(page)->flags)
269
270struct page; /* forward declaration */
271
Linus Torvaldsfba25912006-12-20 13:46:42 -0800272extern void cancel_dirty_page(struct page *page, unsigned int account_size);
273
Linus Torvalds1da177e2005-04-16 15:20:36 -0700274int test_clear_page_writeback(struct page *page);
275int test_set_page_writeback(struct page *page);
276
Linus Torvalds1da177e2005-04-16 15:20:36 -0700277static inline void set_page_writeback(struct page *page)
278{
279 test_set_page_writeback(page);
280}
281
282#endif /* PAGE_FLAGS_H */