2 * Macros for manipulating and testing page->flags
8 #include <linux/types.h>
11 * Various page->flags bits:
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)...
16 * The PG_private bitflag is set if page->private contains a valid value.
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.
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.
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.
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!
35 * PG_error is set to indicate that an I/O error occurred on this page.
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
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
48 * Don't use the *_dontuse flags. Use the macros. Otherwise you'll break
49 * locked- and dirty-page accounting.
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.
55 * | FIELD | ... | FLAGS |
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.
64 #define PG_locked 0 /* Page is locked. Don't touch. */
66 #define PG_referenced 2
72 #define PG_slab 7 /* slab debug (Suparna wants this) */
74 #define PG_checked 8 /* kill me in 2.5.<early>. */
76 #define PG_reserved 10
77 #define PG_private 11 /* Has something at ->private */
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 */
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 */
90 #if (BITS_PER_LONG > 32)
92 * 64-bit-only flags build down from bit 31
94 * 32 bit -------------------------------| FIELDS | FLAGS |
95 * 64 bit | FIELDS | ?????? FLAGS |
98 #define PG_uncached 31 /* Page has been mapped as uncached */
102 * Manipulation of page state flags
104 #define PageLocked(page) \
105 test_bit(PG_locked, &(page)->flags)
106 #define SetPageLocked(page) \
107 set_bit(PG_locked, &(page)->flags)
108 #define TestSetPageLocked(page) \
109 test_and_set_bit(PG_locked, &(page)->flags)
110 #define ClearPageLocked(page) \
111 clear_bit(PG_locked, &(page)->flags)
112 #define TestClearPageLocked(page) \
113 test_and_clear_bit(PG_locked, &(page)->flags)
115 #define PageError(page) test_bit(PG_error, &(page)->flags)
116 #define SetPageError(page) set_bit(PG_error, &(page)->flags)
117 #define ClearPageError(page) clear_bit(PG_error, &(page)->flags)
119 #define PageReferenced(page) test_bit(PG_referenced, &(page)->flags)
120 #define SetPageReferenced(page) set_bit(PG_referenced, &(page)->flags)
121 #define ClearPageReferenced(page) clear_bit(PG_referenced, &(page)->flags)
122 #define TestClearPageReferenced(page) test_and_clear_bit(PG_referenced, &(page)->flags)
124 #define PageUptodate(page) test_bit(PG_uptodate, &(page)->flags)
126 #define SetPageUptodate(_page) \
128 struct page *__page = (_page); \
129 if (!test_and_set_bit(PG_uptodate, &__page->flags)) \
130 page_test_and_clear_dirty(_page); \
133 #define SetPageUptodate(page) set_bit(PG_uptodate, &(page)->flags)
135 #define ClearPageUptodate(page) clear_bit(PG_uptodate, &(page)->flags)
137 #define PageDirty(page) test_bit(PG_dirty, &(page)->flags)
138 #define SetPageDirty(page) set_bit(PG_dirty, &(page)->flags)
139 #define TestSetPageDirty(page) test_and_set_bit(PG_dirty, &(page)->flags)
140 #define ClearPageDirty(page) clear_bit(PG_dirty, &(page)->flags)
141 #define __ClearPageDirty(page) __clear_bit(PG_dirty, &(page)->flags)
142 #define TestClearPageDirty(page) test_and_clear_bit(PG_dirty, &(page)->flags)
144 #define PageLRU(page) test_bit(PG_lru, &(page)->flags)
145 #define SetPageLRU(page) set_bit(PG_lru, &(page)->flags)
146 #define ClearPageLRU(page) clear_bit(PG_lru, &(page)->flags)
147 #define __ClearPageLRU(page) __clear_bit(PG_lru, &(page)->flags)
149 #define PageActive(page) test_bit(PG_active, &(page)->flags)
150 #define SetPageActive(page) set_bit(PG_active, &(page)->flags)
151 #define ClearPageActive(page) clear_bit(PG_active, &(page)->flags)
152 #define __ClearPageActive(page) __clear_bit(PG_active, &(page)->flags)
154 #define PageSlab(page) test_bit(PG_slab, &(page)->flags)
155 #define __SetPageSlab(page) __set_bit(PG_slab, &(page)->flags)
156 #define __ClearPageSlab(page) __clear_bit(PG_slab, &(page)->flags)
158 #ifdef CONFIG_HIGHMEM
159 #define PageHighMem(page) is_highmem(page_zone(page))
161 #define PageHighMem(page) 0 /* needed to optimize away at compile time */
164 #define PageChecked(page) test_bit(PG_checked, &(page)->flags)
165 #define SetPageChecked(page) set_bit(PG_checked, &(page)->flags)
166 #define ClearPageChecked(page) clear_bit(PG_checked, &(page)->flags)
168 #define PageReserved(page) test_bit(PG_reserved, &(page)->flags)
169 #define SetPageReserved(page) set_bit(PG_reserved, &(page)->flags)
170 #define ClearPageReserved(page) clear_bit(PG_reserved, &(page)->flags)
171 #define __ClearPageReserved(page) __clear_bit(PG_reserved, &(page)->flags)
173 #define SetPagePrivate(page) set_bit(PG_private, &(page)->flags)
174 #define ClearPagePrivate(page) clear_bit(PG_private, &(page)->flags)
175 #define PagePrivate(page) test_bit(PG_private, &(page)->flags)
176 #define __SetPagePrivate(page) __set_bit(PG_private, &(page)->flags)
177 #define __ClearPagePrivate(page) __clear_bit(PG_private, &(page)->flags)
179 #define PageWriteback(page) test_bit(PG_writeback, &(page)->flags)
180 #define SetPageWriteback(page) \
182 if (!test_and_set_bit(PG_writeback, \
184 inc_zone_page_state(page, NR_WRITEBACK); \
186 #define TestSetPageWriteback(page) \
189 ret = test_and_set_bit(PG_writeback, \
192 inc_zone_page_state(page, NR_WRITEBACK); \
195 #define ClearPageWriteback(page) \
197 if (test_and_clear_bit(PG_writeback, \
199 dec_zone_page_state(page, NR_WRITEBACK); \
201 #define TestClearPageWriteback(page) \
204 ret = test_and_clear_bit(PG_writeback, \
207 dec_zone_page_state(page, NR_WRITEBACK); \
211 #define PageNosave(page) test_bit(PG_nosave, &(page)->flags)
212 #define SetPageNosave(page) set_bit(PG_nosave, &(page)->flags)
213 #define TestSetPageNosave(page) test_and_set_bit(PG_nosave, &(page)->flags)
214 #define ClearPageNosave(page) clear_bit(PG_nosave, &(page)->flags)
215 #define TestClearPageNosave(page) test_and_clear_bit(PG_nosave, &(page)->flags)
217 #define PageNosaveFree(page) test_bit(PG_nosave_free, &(page)->flags)
218 #define SetPageNosaveFree(page) set_bit(PG_nosave_free, &(page)->flags)
219 #define ClearPageNosaveFree(page) clear_bit(PG_nosave_free, &(page)->flags)
221 #define PageBuddy(page) test_bit(PG_buddy, &(page)->flags)
222 #define __SetPageBuddy(page) __set_bit(PG_buddy, &(page)->flags)
223 #define __ClearPageBuddy(page) __clear_bit(PG_buddy, &(page)->flags)
225 #define PageMappedToDisk(page) test_bit(PG_mappedtodisk, &(page)->flags)
226 #define SetPageMappedToDisk(page) set_bit(PG_mappedtodisk, &(page)->flags)
227 #define ClearPageMappedToDisk(page) clear_bit(PG_mappedtodisk, &(page)->flags)
229 #define PageReclaim(page) test_bit(PG_reclaim, &(page)->flags)
230 #define SetPageReclaim(page) set_bit(PG_reclaim, &(page)->flags)
231 #define ClearPageReclaim(page) clear_bit(PG_reclaim, &(page)->flags)
232 #define TestClearPageReclaim(page) test_and_clear_bit(PG_reclaim, &(page)->flags)
234 #define PageCompound(page) test_bit(PG_compound, &(page)->flags)
235 #define __SetPageCompound(page) __set_bit(PG_compound, &(page)->flags)
236 #define __ClearPageCompound(page) __clear_bit(PG_compound, &(page)->flags)
239 #define PageSwapCache(page) test_bit(PG_swapcache, &(page)->flags)
240 #define SetPageSwapCache(page) set_bit(PG_swapcache, &(page)->flags)
241 #define ClearPageSwapCache(page) clear_bit(PG_swapcache, &(page)->flags)
243 #define PageSwapCache(page) 0
246 #define PageUncached(page) test_bit(PG_uncached, &(page)->flags)
247 #define SetPageUncached(page) set_bit(PG_uncached, &(page)->flags)
248 #define ClearPageUncached(page) clear_bit(PG_uncached, &(page)->flags)
250 struct page; /* forward declaration */
252 int test_clear_page_dirty(struct page *page);
253 int test_clear_page_writeback(struct page *page);
254 int test_set_page_writeback(struct page *page);
256 static inline void clear_page_dirty(struct page *page)
258 test_clear_page_dirty(page);
261 static inline void set_page_writeback(struct page *page)
263 test_set_page_writeback(page);
266 #endif /* PAGE_FLAGS_H */