]>
Commit | Line | Data |
---|---|---|
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> |
6d777953 | 9 | #include <linux/mm_types.h> |
f886ed44 | 10 | |
1da177e4 LT |
11 | /* |
12 | * Various page->flags bits: | |
13 | * | |
14 | * PG_reserved is set for special pages, which can never be swapped out. Some | |
15 | * of them might not even exist (eg empty_bad_page)... | |
16 | * | |
da6052f7 NP |
17 | * The PG_private bitflag is set on pagecache pages if they contain filesystem |
18 | * specific data (which is normally at page->private). It can be used by | |
19 | * private allocations for its own usage. | |
1da177e4 | 20 | * |
da6052f7 NP |
21 | * During initiation of disk I/O, PG_locked is set. This bit is set before I/O |
22 | * and cleared when writeback _starts_ or when read _completes_. PG_writeback | |
23 | * is set before writeback starts and cleared when it finishes. | |
24 | * | |
25 | * PG_locked also pins a page in pagecache, and blocks truncation of the file | |
26 | * while it is held. | |
27 | * | |
28 | * page_waitqueue(page) is a wait queue of all tasks waiting for the page | |
29 | * to become unlocked. | |
1da177e4 LT |
30 | * |
31 | * PG_uptodate tells whether the page's contents is valid. When a read | |
32 | * completes, the page becomes uptodate, unless a disk I/O error happened. | |
33 | * | |
da6052f7 NP |
34 | * PG_referenced, PG_reclaim are used for page reclaim for anonymous and |
35 | * file-backed pagecache (see mm/vmscan.c). | |
1da177e4 LT |
36 | * |
37 | * PG_error is set to indicate that an I/O error occurred on this page. | |
38 | * | |
39 | * PG_arch_1 is an architecture specific page state bit. The generic code | |
40 | * guarantees that this bit is cleared for a page when it first is entered into | |
41 | * the page cache. | |
42 | * | |
43 | * PG_highmem pages are not permanently mapped into the kernel virtual address | |
44 | * space, they need to be kmapped separately for doing IO on the pages. The | |
45 | * struct page (these bits with information) are always mapped into kernel | |
46 | * address space... | |
da6052f7 NP |
47 | * |
48 | * PG_buddy is set to indicate that the page is free and in the buddy system | |
49 | * (see mm/page_alloc.c). | |
50 | * | |
1da177e4 LT |
51 | */ |
52 | ||
53 | /* | |
54 | * Don't use the *_dontuse flags. Use the macros. Otherwise you'll break | |
91fc8ab3 AW |
55 | * locked- and dirty-page accounting. |
56 | * | |
57 | * The page flags field is split into two parts, the main flags area | |
58 | * which extends from the low bits upwards, and the fields area which | |
59 | * extends from the high bits downwards. | |
60 | * | |
61 | * | FIELD | ... | FLAGS | | |
62 | * N-1 ^ 0 | |
63 | * (N-FLAGS_RESERVED) | |
64 | * | |
65 | * The fields area is reserved for fields mapping zone, node and SPARSEMEM | |
66 | * section. The boundry between these two areas is defined by | |
67 | * FLAGS_RESERVED which defines the width of the fields section | |
68 | * (see linux/mmzone.h). New flags must _not_ overlap with this area. | |
1da177e4 LT |
69 | */ |
70 | #define PG_locked 0 /* Page is locked. Don't touch. */ | |
71 | #define PG_error 1 | |
72 | #define PG_referenced 2 | |
73 | #define PG_uptodate 3 | |
74 | ||
75 | #define PG_dirty 4 | |
76 | #define PG_lru 5 | |
77 | #define PG_active 6 | |
78 | #define PG_slab 7 /* slab debug (Suparna wants this) */ | |
79 | ||
5409bae0 | 80 | #define PG_owner_priv_1 8 /* Owner use. If pagecache, fs may use*/ |
cbe37d09 BP |
81 | #define PG_arch_1 9 |
82 | #define PG_reserved 10 | |
da6052f7 | 83 | #define PG_private 11 /* If pagecache, has fs-private data */ |
cbe37d09 BP |
84 | |
85 | #define PG_writeback 12 /* Page is under writeback */ | |
cbe37d09 BP |
86 | #define PG_compound 14 /* Part of a compound page */ |
87 | #define PG_swapcache 15 /* Swap page: swp_entry_t in private */ | |
88 | ||
89 | #define PG_mappedtodisk 16 /* Has blocks allocated on-disk */ | |
90 | #define PG_reclaim 17 /* To be reclaimed asap */ | |
676165a8 NP |
91 | #define PG_buddy 19 /* Page is free, on buddy lists */ |
92 | ||
5409bae0 NP |
93 | /* PG_owner_priv_1 users should have descriptive aliases */ |
94 | #define PG_checked PG_owner_priv_1 /* Used by some filesystems */ | |
f886ed44 AM |
95 | |
96 | #if (BITS_PER_LONG > 32) | |
97 | /* | |
98 | * 64-bit-only flags build down from bit 31 | |
99 | * | |
100 | * 32 bit -------------------------------| FIELDS | FLAGS | | |
101 | * 64 bit | FIELDS | ?????? FLAGS | | |
102 | * 63 32 0 | |
103 | */ | |
104 | #define PG_uncached 31 /* Page has been mapped as uncached */ | |
105 | #endif | |
1da177e4 | 106 | |
1da177e4 LT |
107 | /* |
108 | * Manipulation of page state flags | |
109 | */ | |
110 | #define PageLocked(page) \ | |
111 | test_bit(PG_locked, &(page)->flags) | |
112 | #define SetPageLocked(page) \ | |
113 | set_bit(PG_locked, &(page)->flags) | |
114 | #define TestSetPageLocked(page) \ | |
115 | test_and_set_bit(PG_locked, &(page)->flags) | |
116 | #define ClearPageLocked(page) \ | |
117 | clear_bit(PG_locked, &(page)->flags) | |
118 | #define TestClearPageLocked(page) \ | |
119 | test_and_clear_bit(PG_locked, &(page)->flags) | |
120 | ||
121 | #define PageError(page) test_bit(PG_error, &(page)->flags) | |
122 | #define SetPageError(page) set_bit(PG_error, &(page)->flags) | |
123 | #define ClearPageError(page) clear_bit(PG_error, &(page)->flags) | |
124 | ||
125 | #define PageReferenced(page) test_bit(PG_referenced, &(page)->flags) | |
126 | #define SetPageReferenced(page) set_bit(PG_referenced, &(page)->flags) | |
127 | #define ClearPageReferenced(page) clear_bit(PG_referenced, &(page)->flags) | |
128 | #define TestClearPageReferenced(page) test_and_clear_bit(PG_referenced, &(page)->flags) | |
129 | ||
130 | #define PageUptodate(page) test_bit(PG_uptodate, &(page)->flags) | |
f6ac2354 | 131 | #ifdef CONFIG_S390 |
2dcea57a HC |
132 | static inline void SetPageUptodate(struct page *page) |
133 | { | |
134 | if (!test_and_set_bit(PG_uptodate, &page->flags)) | |
6c210482 | 135 | page_clear_dirty(page); |
2dcea57a | 136 | } |
f6ac2354 | 137 | #else |
1da177e4 LT |
138 | #define SetPageUptodate(page) set_bit(PG_uptodate, &(page)->flags) |
139 | #endif | |
140 | #define ClearPageUptodate(page) clear_bit(PG_uptodate, &(page)->flags) | |
141 | ||
142 | #define PageDirty(page) test_bit(PG_dirty, &(page)->flags) | |
143 | #define SetPageDirty(page) set_bit(PG_dirty, &(page)->flags) | |
144 | #define TestSetPageDirty(page) test_and_set_bit(PG_dirty, &(page)->flags) | |
145 | #define ClearPageDirty(page) clear_bit(PG_dirty, &(page)->flags) | |
242e5468 | 146 | #define __ClearPageDirty(page) __clear_bit(PG_dirty, &(page)->flags) |
1da177e4 LT |
147 | #define TestClearPageDirty(page) test_and_clear_bit(PG_dirty, &(page)->flags) |
148 | ||
1da177e4 | 149 | #define PageLRU(page) test_bit(PG_lru, &(page)->flags) |
8d438f96 NP |
150 | #define SetPageLRU(page) set_bit(PG_lru, &(page)->flags) |
151 | #define ClearPageLRU(page) clear_bit(PG_lru, &(page)->flags) | |
67453911 | 152 | #define __ClearPageLRU(page) __clear_bit(PG_lru, &(page)->flags) |
1da177e4 LT |
153 | |
154 | #define PageActive(page) test_bit(PG_active, &(page)->flags) | |
155 | #define SetPageActive(page) set_bit(PG_active, &(page)->flags) | |
156 | #define ClearPageActive(page) clear_bit(PG_active, &(page)->flags) | |
67453911 | 157 | #define __ClearPageActive(page) __clear_bit(PG_active, &(page)->flags) |
1da177e4 LT |
158 | |
159 | #define PageSlab(page) test_bit(PG_slab, &(page)->flags) | |
f205b2fe NP |
160 | #define __SetPageSlab(page) __set_bit(PG_slab, &(page)->flags) |
161 | #define __ClearPageSlab(page) __clear_bit(PG_slab, &(page)->flags) | |
1da177e4 LT |
162 | |
163 | #ifdef CONFIG_HIGHMEM | |
cbe37d09 | 164 | #define PageHighMem(page) is_highmem(page_zone(page)) |
1da177e4 LT |
165 | #else |
166 | #define PageHighMem(page) 0 /* needed to optimize away at compile time */ | |
167 | #endif | |
168 | ||
169 | #define PageChecked(page) test_bit(PG_checked, &(page)->flags) | |
170 | #define SetPageChecked(page) set_bit(PG_checked, &(page)->flags) | |
171 | #define ClearPageChecked(page) clear_bit(PG_checked, &(page)->flags) | |
172 | ||
173 | #define PageReserved(page) test_bit(PG_reserved, &(page)->flags) | |
174 | #define SetPageReserved(page) set_bit(PG_reserved, &(page)->flags) | |
175 | #define ClearPageReserved(page) clear_bit(PG_reserved, &(page)->flags) | |
176 | #define __ClearPageReserved(page) __clear_bit(PG_reserved, &(page)->flags) | |
177 | ||
178 | #define SetPagePrivate(page) set_bit(PG_private, &(page)->flags) | |
179 | #define ClearPagePrivate(page) clear_bit(PG_private, &(page)->flags) | |
180 | #define PagePrivate(page) test_bit(PG_private, &(page)->flags) | |
181 | #define __SetPagePrivate(page) __set_bit(PG_private, &(page)->flags) | |
182 | #define __ClearPagePrivate(page) __clear_bit(PG_private, &(page)->flags) | |
183 | ||
184 | #define PageWriteback(page) test_bit(PG_writeback, &(page)->flags) | |
185 | #define SetPageWriteback(page) \ | |
186 | do { \ | |
187 | if (!test_and_set_bit(PG_writeback, \ | |
188 | &(page)->flags)) \ | |
ce866b34 | 189 | inc_zone_page_state(page, NR_WRITEBACK); \ |
1da177e4 LT |
190 | } while (0) |
191 | #define TestSetPageWriteback(page) \ | |
192 | ({ \ | |
193 | int ret; \ | |
194 | ret = test_and_set_bit(PG_writeback, \ | |
195 | &(page)->flags); \ | |
196 | if (!ret) \ | |
ce866b34 | 197 | inc_zone_page_state(page, NR_WRITEBACK); \ |
1da177e4 LT |
198 | ret; \ |
199 | }) | |
200 | #define ClearPageWriteback(page) \ | |
201 | do { \ | |
202 | if (test_and_clear_bit(PG_writeback, \ | |
203 | &(page)->flags)) \ | |
ce866b34 | 204 | dec_zone_page_state(page, NR_WRITEBACK); \ |
1da177e4 LT |
205 | } while (0) |
206 | #define TestClearPageWriteback(page) \ | |
207 | ({ \ | |
208 | int ret; \ | |
209 | ret = test_and_clear_bit(PG_writeback, \ | |
210 | &(page)->flags); \ | |
211 | if (ret) \ | |
ce866b34 | 212 | dec_zone_page_state(page, NR_WRITEBACK); \ |
1da177e4 LT |
213 | ret; \ |
214 | }) | |
215 | ||
676165a8 NP |
216 | #define PageBuddy(page) test_bit(PG_buddy, &(page)->flags) |
217 | #define __SetPageBuddy(page) __set_bit(PG_buddy, &(page)->flags) | |
218 | #define __ClearPageBuddy(page) __clear_bit(PG_buddy, &(page)->flags) | |
219 | ||
1da177e4 LT |
220 | #define PageMappedToDisk(page) test_bit(PG_mappedtodisk, &(page)->flags) |
221 | #define SetPageMappedToDisk(page) set_bit(PG_mappedtodisk, &(page)->flags) | |
222 | #define ClearPageMappedToDisk(page) clear_bit(PG_mappedtodisk, &(page)->flags) | |
223 | ||
224 | #define PageReclaim(page) test_bit(PG_reclaim, &(page)->flags) | |
225 | #define SetPageReclaim(page) set_bit(PG_reclaim, &(page)->flags) | |
226 | #define ClearPageReclaim(page) clear_bit(PG_reclaim, &(page)->flags) | |
227 | #define TestClearPageReclaim(page) test_and_clear_bit(PG_reclaim, &(page)->flags) | |
228 | ||
1da177e4 | 229 | #define PageCompound(page) test_bit(PG_compound, &(page)->flags) |
5e9dace8 NP |
230 | #define __SetPageCompound(page) __set_bit(PG_compound, &(page)->flags) |
231 | #define __ClearPageCompound(page) __clear_bit(PG_compound, &(page)->flags) | |
1da177e4 | 232 | |
d85f3385 | 233 | /* |
6d777953 CL |
234 | * PG_reclaim is used in combination with PG_compound to mark the |
235 | * head and tail of a compound page | |
236 | * | |
237 | * PG_compound & PG_reclaim => Tail page | |
238 | * PG_compound & ~PG_reclaim => Head page | |
d85f3385 | 239 | */ |
6d777953 CL |
240 | |
241 | #define PG_head_tail_mask ((1L << PG_compound) | (1L << PG_reclaim)) | |
242 | ||
243 | #define PageTail(page) ((page->flags & PG_head_tail_mask) \ | |
244 | == PG_head_tail_mask) | |
245 | ||
246 | static inline void __SetPageTail(struct page *page) | |
247 | { | |
248 | page->flags |= PG_head_tail_mask; | |
249 | } | |
250 | ||
251 | static inline void __ClearPageTail(struct page *page) | |
252 | { | |
253 | page->flags &= ~PG_head_tail_mask; | |
254 | } | |
255 | ||
256 | #define PageHead(page) ((page->flags & PG_head_tail_mask) \ | |
257 | == (1L << PG_compound)) | |
258 | #define __SetPageHead(page) __SetPageCompound(page) | |
259 | #define __ClearPageHead(page) __ClearPageCompound(page) | |
d85f3385 | 260 | |
1da177e4 LT |
261 | #ifdef CONFIG_SWAP |
262 | #define PageSwapCache(page) test_bit(PG_swapcache, &(page)->flags) | |
263 | #define SetPageSwapCache(page) set_bit(PG_swapcache, &(page)->flags) | |
264 | #define ClearPageSwapCache(page) clear_bit(PG_swapcache, &(page)->flags) | |
265 | #else | |
266 | #define PageSwapCache(page) 0 | |
267 | #endif | |
268 | ||
269 | #define PageUncached(page) test_bit(PG_uncached, &(page)->flags) | |
270 | #define SetPageUncached(page) set_bit(PG_uncached, &(page)->flags) | |
271 | #define ClearPageUncached(page) clear_bit(PG_uncached, &(page)->flags) | |
272 | ||
273 | struct page; /* forward declaration */ | |
274 | ||
fba2591b LT |
275 | extern void cancel_dirty_page(struct page *page, unsigned int account_size); |
276 | ||
1da177e4 LT |
277 | int test_clear_page_writeback(struct page *page); |
278 | int test_set_page_writeback(struct page *page); | |
279 | ||
1da177e4 LT |
280 | static inline void set_page_writeback(struct page *page) |
281 | { | |
282 | test_set_page_writeback(page); | |
283 | } | |
284 | ||
285 | #endif /* PAGE_FLAGS_H */ |