1 | /* |
---|
2 | * Macros for manipulating and testing page->flags |
---|
3 | */ |
---|
4 | |
---|
5 | #ifndef PAGE_FLAGS_H |
---|
6 | #define PAGE_FLAGS_H |
---|
7 | |
---|
8 | #include <linux/types.h> |
---|
9 | |
---|
10 | /* |
---|
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 | * |
---|
16 | * The PG_private bitflag is set if page->private contains a valid value. |
---|
17 | * |
---|
18 | * During disk I/O, PG_locked is used. This bit is set before I/O and |
---|
19 | * reset when I/O completes. page_waitqueue(page) is a wait queue of all tasks |
---|
20 | * waiting for the I/O on this page to complete. |
---|
21 | * |
---|
22 | * PG_uptodate tells whether the page's contents is valid. When a read |
---|
23 | * completes, the page becomes uptodate, unless a disk I/O error happened. |
---|
24 | * |
---|
25 | * For choosing which pages to swap out, inode pages carry a PG_referenced bit, |
---|
26 | * which is set any time the system accesses that page through the (mapping, |
---|
27 | * index) hash table. This referenced bit, together with the referenced bit |
---|
28 | * in the page tables, is used to manipulate page->age and move the page across |
---|
29 | * the active, inactive_dirty and inactive_clean lists. |
---|
30 | * |
---|
31 | * Note that the referenced bit, the page->lru list_head and the active, |
---|
32 | * inactive_dirty and inactive_clean lists are protected by the |
---|
33 | * zone->lru_lock, and *NOT* by the usual PG_locked bit! |
---|
34 | * |
---|
35 | * PG_error is set to indicate that an I/O error occurred on this page. |
---|
36 | * |
---|
37 | * PG_arch_1 is an architecture specific page state bit. The generic code |
---|
38 | * guarantees that this bit is cleared for a page when it first is entered into |
---|
39 | * the page cache. |
---|
40 | * |
---|
41 | * PG_highmem pages are not permanently mapped into the kernel virtual address |
---|
42 | * space, they need to be kmapped separately for doing IO on the pages. The |
---|
43 | * struct page (these bits with information) are always mapped into kernel |
---|
44 | * address space... |
---|
45 | */ |
---|
46 | |
---|
47 | /* |
---|
48 | * Don't use the *_dontuse flags. Use the macros. Otherwise you'll break |
---|
49 | * locked- and dirty-page accounting. |
---|
50 | * |
---|
51 | * The page flags field is split into two parts, the main flags area |
---|
52 | * which extends from the low bits upwards, and the fields area which |
---|
53 | * extends from the high bits downwards. |
---|
54 | * |
---|
55 | * | FIELD | ... | FLAGS | |
---|
56 | * N-1 ^ 0 |
---|
57 | * (N-FLAGS_RESERVED) |
---|
58 | * |
---|
59 | * The fields area is reserved for fields mapping zone, node and SPARSEMEM |
---|
60 | * section. The boundry between these two areas is defined by |
---|
61 | * FLAGS_RESERVED which defines the width of the fields section |
---|
62 | * (see linux/mmzone.h). New flags must _not_ overlap with this area. |
---|
63 | */ |
---|
64 | #define PG_locked 0 /* Page is locked. Don't touch. */ |
---|
65 | #define PG_error 1 |
---|
66 | #define PG_referenced 2 |
---|
67 | #define PG_uptodate 3 |
---|
68 | |
---|
69 | #define PG_dirty 4 |
---|
70 | #define PG_lru 5 |
---|
71 | #define PG_active 6 |
---|
72 | #define PG_slab 7 /* slab debug (Suparna wants this) */ |
---|
73 | |
---|
74 | #define PG_checked 8 /* kill me in 2.5.<early>. */ |
---|
75 | #define PG_arch_1 9 |
---|
76 | #define PG_reserved 10 |
---|
77 | #define PG_private 11 /* Has something at ->private */ |
---|
78 | |
---|
79 | #define PG_writeback 12 /* Page is under writeback */ |
---|
80 | #define PG_nosave 13 /* Used for system suspend/resume */ |
---|
81 | #define PG_compound 14 /* Part of a compound page */ |
---|
82 | #define PG_swapcache 15 /* Swap page: swp_entry_t in private */ |
---|
83 | |
---|
84 | #define PG_mappedtodisk 16 /* Has blocks allocated on-disk */ |
---|
85 | #define PG_reclaim 17 /* To be reclaimed asap */ |
---|
86 | #define PG_nosave_free 18 /* Free, should not be written */ |
---|
87 | #define PG_buddy 19 /* Page is free, on buddy lists */ |
---|
88 | |
---|
89 | |
---|
90 | #if (BITS_PER_LONG > 32) |
---|
91 | /* |
---|
92 | * 64-bit-only flags build down from bit 31 |
---|
93 | * |
---|
94 | * 32 bit -------------------------------| FIELDS | FLAGS | |
---|
95 | * 64 bit | FIELDS | ?????? FLAGS | |
---|
96 | * 63 32 0 |
---|
97 | */ |
---|
98 | #define PG_uncached 31 /* Page has been mapped as uncached */ |
---|
99 | #endif |
---|
100 | |
---|
101 | #define PG_foreign 20 /* Page is owned by foreign allocator. */ |
---|
102 | |
---|
103 | /* |
---|
104 | * Manipulation of page state flags |
---|
105 | */ |
---|
106 | #define PageLocked(page) \ |
---|
107 | test_bit(PG_locked, &(page)->flags) |
---|
108 | #define SetPageLocked(page) \ |
---|
109 | set_bit(PG_locked, &(page)->flags) |
---|
110 | #define TestSetPageLocked(page) \ |
---|
111 | test_and_set_bit(PG_locked, &(page)->flags) |
---|
112 | #define ClearPageLocked(page) \ |
---|
113 | clear_bit(PG_locked, &(page)->flags) |
---|
114 | #define TestClearPageLocked(page) \ |
---|
115 | test_and_clear_bit(PG_locked, &(page)->flags) |
---|
116 | |
---|
117 | #define PageError(page) test_bit(PG_error, &(page)->flags) |
---|
118 | #define SetPageError(page) set_bit(PG_error, &(page)->flags) |
---|
119 | #define ClearPageError(page) clear_bit(PG_error, &(page)->flags) |
---|
120 | |
---|
121 | #define PageReferenced(page) test_bit(PG_referenced, &(page)->flags) |
---|
122 | #define SetPageReferenced(page) set_bit(PG_referenced, &(page)->flags) |
---|
123 | #define ClearPageReferenced(page) clear_bit(PG_referenced, &(page)->flags) |
---|
124 | #define TestClearPageReferenced(page) test_and_clear_bit(PG_referenced, &(page)->flags) |
---|
125 | |
---|
126 | #define PageUptodate(page) test_bit(PG_uptodate, &(page)->flags) |
---|
127 | #ifdef CONFIG_S390 |
---|
128 | #define SetPageUptodate(_page) \ |
---|
129 | do { \ |
---|
130 | struct page *__page = (_page); \ |
---|
131 | if (!test_and_set_bit(PG_uptodate, &__page->flags)) \ |
---|
132 | page_test_and_clear_dirty(_page); \ |
---|
133 | } while (0) |
---|
134 | #else |
---|
135 | #define SetPageUptodate(page) set_bit(PG_uptodate, &(page)->flags) |
---|
136 | #endif |
---|
137 | #define ClearPageUptodate(page) clear_bit(PG_uptodate, &(page)->flags) |
---|
138 | |
---|
139 | #define PageDirty(page) test_bit(PG_dirty, &(page)->flags) |
---|
140 | #define SetPageDirty(page) set_bit(PG_dirty, &(page)->flags) |
---|
141 | #define TestSetPageDirty(page) test_and_set_bit(PG_dirty, &(page)->flags) |
---|
142 | #define ClearPageDirty(page) clear_bit(PG_dirty, &(page)->flags) |
---|
143 | #define __ClearPageDirty(page) __clear_bit(PG_dirty, &(page)->flags) |
---|
144 | #define TestClearPageDirty(page) test_and_clear_bit(PG_dirty, &(page)->flags) |
---|
145 | |
---|
146 | #define PageLRU(page) test_bit(PG_lru, &(page)->flags) |
---|
147 | #define SetPageLRU(page) set_bit(PG_lru, &(page)->flags) |
---|
148 | #define ClearPageLRU(page) clear_bit(PG_lru, &(page)->flags) |
---|
149 | #define __ClearPageLRU(page) __clear_bit(PG_lru, &(page)->flags) |
---|
150 | |
---|
151 | #define PageActive(page) test_bit(PG_active, &(page)->flags) |
---|
152 | #define SetPageActive(page) set_bit(PG_active, &(page)->flags) |
---|
153 | #define ClearPageActive(page) clear_bit(PG_active, &(page)->flags) |
---|
154 | #define __ClearPageActive(page) __clear_bit(PG_active, &(page)->flags) |
---|
155 | |
---|
156 | #define PageSlab(page) test_bit(PG_slab, &(page)->flags) |
---|
157 | #define __SetPageSlab(page) __set_bit(PG_slab, &(page)->flags) |
---|
158 | #define __ClearPageSlab(page) __clear_bit(PG_slab, &(page)->flags) |
---|
159 | |
---|
160 | #ifdef CONFIG_HIGHMEM |
---|
161 | #define PageHighMem(page) is_highmem(page_zone(page)) |
---|
162 | #else |
---|
163 | #define PageHighMem(page) 0 /* needed to optimize away at compile time */ |
---|
164 | #endif |
---|
165 | |
---|
166 | #define PageChecked(page) test_bit(PG_checked, &(page)->flags) |
---|
167 | #define SetPageChecked(page) set_bit(PG_checked, &(page)->flags) |
---|
168 | #define ClearPageChecked(page) clear_bit(PG_checked, &(page)->flags) |
---|
169 | |
---|
170 | #define PageReserved(page) test_bit(PG_reserved, &(page)->flags) |
---|
171 | #define SetPageReserved(page) set_bit(PG_reserved, &(page)->flags) |
---|
172 | #define ClearPageReserved(page) clear_bit(PG_reserved, &(page)->flags) |
---|
173 | #define __ClearPageReserved(page) __clear_bit(PG_reserved, &(page)->flags) |
---|
174 | |
---|
175 | #define SetPagePrivate(page) set_bit(PG_private, &(page)->flags) |
---|
176 | #define ClearPagePrivate(page) clear_bit(PG_private, &(page)->flags) |
---|
177 | #define PagePrivate(page) test_bit(PG_private, &(page)->flags) |
---|
178 | #define __SetPagePrivate(page) __set_bit(PG_private, &(page)->flags) |
---|
179 | #define __ClearPagePrivate(page) __clear_bit(PG_private, &(page)->flags) |
---|
180 | |
---|
181 | #define PageWriteback(page) test_bit(PG_writeback, &(page)->flags) |
---|
182 | #define SetPageWriteback(page) \ |
---|
183 | do { \ |
---|
184 | if (!test_and_set_bit(PG_writeback, \ |
---|
185 | &(page)->flags)) \ |
---|
186 | inc_zone_page_state(page, NR_WRITEBACK); \ |
---|
187 | } while (0) |
---|
188 | #define TestSetPageWriteback(page) \ |
---|
189 | ({ \ |
---|
190 | int ret; \ |
---|
191 | ret = test_and_set_bit(PG_writeback, \ |
---|
192 | &(page)->flags); \ |
---|
193 | if (!ret) \ |
---|
194 | inc_zone_page_state(page, NR_WRITEBACK); \ |
---|
195 | ret; \ |
---|
196 | }) |
---|
197 | #define ClearPageWriteback(page) \ |
---|
198 | do { \ |
---|
199 | if (test_and_clear_bit(PG_writeback, \ |
---|
200 | &(page)->flags)) \ |
---|
201 | dec_zone_page_state(page, NR_WRITEBACK); \ |
---|
202 | } while (0) |
---|
203 | #define TestClearPageWriteback(page) \ |
---|
204 | ({ \ |
---|
205 | int ret; \ |
---|
206 | ret = test_and_clear_bit(PG_writeback, \ |
---|
207 | &(page)->flags); \ |
---|
208 | if (ret) \ |
---|
209 | dec_zone_page_state(page, NR_WRITEBACK); \ |
---|
210 | ret; \ |
---|
211 | }) |
---|
212 | |
---|
213 | #define PageNosave(page) test_bit(PG_nosave, &(page)->flags) |
---|
214 | #define SetPageNosave(page) set_bit(PG_nosave, &(page)->flags) |
---|
215 | #define TestSetPageNosave(page) test_and_set_bit(PG_nosave, &(page)->flags) |
---|
216 | #define ClearPageNosave(page) clear_bit(PG_nosave, &(page)->flags) |
---|
217 | #define TestClearPageNosave(page) test_and_clear_bit(PG_nosave, &(page)->flags) |
---|
218 | |
---|
219 | #define PageNosaveFree(page) test_bit(PG_nosave_free, &(page)->flags) |
---|
220 | #define SetPageNosaveFree(page) set_bit(PG_nosave_free, &(page)->flags) |
---|
221 | #define ClearPageNosaveFree(page) clear_bit(PG_nosave_free, &(page)->flags) |
---|
222 | |
---|
223 | #define PageBuddy(page) test_bit(PG_buddy, &(page)->flags) |
---|
224 | #define __SetPageBuddy(page) __set_bit(PG_buddy, &(page)->flags) |
---|
225 | #define __ClearPageBuddy(page) __clear_bit(PG_buddy, &(page)->flags) |
---|
226 | |
---|
227 | #define PageMappedToDisk(page) test_bit(PG_mappedtodisk, &(page)->flags) |
---|
228 | #define SetPageMappedToDisk(page) set_bit(PG_mappedtodisk, &(page)->flags) |
---|
229 | #define ClearPageMappedToDisk(page) clear_bit(PG_mappedtodisk, &(page)->flags) |
---|
230 | |
---|
231 | #define PageReclaim(page) test_bit(PG_reclaim, &(page)->flags) |
---|
232 | #define SetPageReclaim(page) set_bit(PG_reclaim, &(page)->flags) |
---|
233 | #define ClearPageReclaim(page) clear_bit(PG_reclaim, &(page)->flags) |
---|
234 | #define TestClearPageReclaim(page) test_and_clear_bit(PG_reclaim, &(page)->flags) |
---|
235 | |
---|
236 | #define PageCompound(page) test_bit(PG_compound, &(page)->flags) |
---|
237 | #define __SetPageCompound(page) __set_bit(PG_compound, &(page)->flags) |
---|
238 | #define __ClearPageCompound(page) __clear_bit(PG_compound, &(page)->flags) |
---|
239 | |
---|
240 | #ifdef CONFIG_SWAP |
---|
241 | #define PageSwapCache(page) test_bit(PG_swapcache, &(page)->flags) |
---|
242 | #define SetPageSwapCache(page) set_bit(PG_swapcache, &(page)->flags) |
---|
243 | #define ClearPageSwapCache(page) clear_bit(PG_swapcache, &(page)->flags) |
---|
244 | #else |
---|
245 | #define PageSwapCache(page) 0 |
---|
246 | #endif |
---|
247 | |
---|
248 | #define PageUncached(page) test_bit(PG_uncached, &(page)->flags) |
---|
249 | #define SetPageUncached(page) set_bit(PG_uncached, &(page)->flags) |
---|
250 | #define ClearPageUncached(page) clear_bit(PG_uncached, &(page)->flags) |
---|
251 | |
---|
252 | #define PageForeign(page) test_bit(PG_foreign, &(page)->flags) |
---|
253 | #define SetPageForeign(page, dtor) do { \ |
---|
254 | set_bit(PG_foreign, &(page)->flags); \ |
---|
255 | (page)->index = (long)(dtor); \ |
---|
256 | } while (0) |
---|
257 | #define ClearPageForeign(page) do { \ |
---|
258 | clear_bit(PG_foreign, &(page)->flags); \ |
---|
259 | (page)->index = 0; \ |
---|
260 | } while (0) |
---|
261 | #define PageForeignDestructor(page) \ |
---|
262 | ( (void (*) (struct page *)) (page)->index )(page) |
---|
263 | |
---|
264 | struct page; /* forward declaration */ |
---|
265 | |
---|
266 | int test_clear_page_dirty(struct page *page); |
---|
267 | int test_clear_page_writeback(struct page *page); |
---|
268 | int test_set_page_writeback(struct page *page); |
---|
269 | |
---|
270 | static inline void clear_page_dirty(struct page *page) |
---|
271 | { |
---|
272 | test_clear_page_dirty(page); |
---|
273 | } |
---|
274 | |
---|
275 | static inline void set_page_writeback(struct page *page) |
---|
276 | { |
---|
277 | test_set_page_writeback(page); |
---|
278 | } |
---|
279 | |
---|
280 | #endif /* PAGE_FLAGS_H */ |
---|