2 * Macros for manipulating and testing page->flags
8 #include <linux/percpu.h>
9 #include <linux/cache.h>
10 #include <asm/pgtable.h>
13 * Various page->flags bits:
15 * PG_reserved is set for special pages, which can never be swapped out. Some
16 * of them might not even exist (eg empty_bad_page)...
18 * The PG_private bitflag is set if page->private contains a valid value.
20 * During disk I/O, PG_locked is used. This bit is set before I/O and
21 * reset when I/O completes. page_waitqueue(page) is a wait queue of all tasks
22 * waiting for the I/O on this page to complete.
24 * PG_uptodate tells whether the page's contents is valid. When a read
25 * completes, the page becomes uptodate, unless a disk I/O error happened.
27 * For choosing which pages to swap out, inode pages carry a PG_referenced bit,
28 * which is set any time the system accesses that page through the (mapping,
29 * index) hash table. This referenced bit, together with the referenced bit
30 * in the page tables, is used to manipulate page->age and move the page across
31 * the active, inactive_dirty and inactive_clean lists.
33 * Note that the referenced bit, the page->lru list_head and the active,
34 * inactive_dirty and inactive_clean lists are protected by the
35 * zone->lru_lock, and *NOT* by the usual PG_locked bit!
37 * PG_error is set to indicate that an I/O error occurred on this page.
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
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
50 * Don't use the *_dontuse flags. Use the macros. Otherwise you'll break
51 * locked- and dirty-page accounting. The top eight bits of page->flags are
52 * used for page->zone, so putting flag bits there doesn't work.
54 #define PG_locked 0 /* Page is locked. Don't touch. */
56 #define PG_referenced 2
62 #define PG_slab 7 /* slab debug (Suparna wants this) */
65 #define PG_checked 9 /* kill me in 2.5.<early>. */
67 #define PG_reserved 11
69 #define PG_private 12 /* Has something at ->private */
70 #define PG_writeback 13 /* Page is under writeback */
71 #define PG_nosave 14 /* Used for system suspend/resume */
72 #define PG_compound 15 /* Part of a compound page */
74 #define PG_swapcache 16 /* Swap page: swp_entry_t in private */
75 #define PG_mappedtodisk 17 /* Has blocks allocated on-disk */
76 #define PG_reclaim 18 /* To be reclaimed asap */
79 * Global page accounting. One instance per CPU. Only unsigned longs are
83 unsigned long nr_dirty; /* Dirty writeable pages */
84 unsigned long nr_writeback; /* Pages under writeback */
85 unsigned long nr_unstable; /* NFS unstable pages */
86 unsigned long nr_page_table_pages;/* Pages used for pagetables */
87 unsigned long nr_mapped; /* mapped into pagetables */
88 unsigned long nr_slab; /* In slab */
89 #define GET_PAGE_STATE_LAST nr_slab
92 * The below are zeroed by get_page_state(). Use get_full_page_state()
93 * to add up all these.
95 unsigned long pgpgin; /* Disk reads */
96 unsigned long pgpgout; /* Disk writes */
97 unsigned long pswpin; /* swap reads */
98 unsigned long pswpout; /* swap writes */
99 unsigned long pgalloc_high; /* page allocations */
101 unsigned long pgalloc_normal;
102 unsigned long pgalloc_dma;
103 unsigned long pgfree; /* page freeings */
104 unsigned long pgactivate; /* pages moved inactive->active */
105 unsigned long pgdeactivate; /* pages moved active->inactive */
107 unsigned long pgfault; /* faults (major+minor) */
108 unsigned long pgmajfault; /* faults (major only) */
109 unsigned long pgrefill_high; /* inspected in refill_inactive_zone */
110 unsigned long pgrefill_normal;
111 unsigned long pgrefill_dma;
113 unsigned long pgsteal_high; /* total highmem pages reclaimed */
114 unsigned long pgsteal_normal;
115 unsigned long pgsteal_dma;
116 unsigned long pgscan_kswapd_high;/* total highmem pages scanned */
117 unsigned long pgscan_kswapd_normal;
119 unsigned long pgscan_kswapd_dma;
120 unsigned long pgscan_direct_high;/* total highmem pages scanned */
121 unsigned long pgscan_direct_normal;
122 unsigned long pgscan_direct_dma;
123 unsigned long pginodesteal; /* pages reclaimed via inode freeing */
125 unsigned long slabs_scanned; /* slab objects scanned */
126 unsigned long kswapd_steal; /* pages reclaimed by kswapd */
127 unsigned long kswapd_inodesteal;/* reclaimed via kswapd inode freeing */
128 unsigned long pageoutrun; /* kswapd's calls to page reclaim */
129 unsigned long allocstall; /* direct reclaim calls */
131 unsigned long pgrotated; /* pages rotated to tail of the LRU */
134 DECLARE_PER_CPU(struct page_state, page_states);
136 extern void get_page_state(struct page_state *ret);
137 extern void get_full_page_state(struct page_state *ret);
138 extern unsigned long __read_page_state(unsigned offset);
140 #define read_page_state(member) \
141 __read_page_state(offsetof(struct page_state, member))
143 #define mod_page_state(member, delta) \
145 unsigned long flags; \
146 local_irq_save(flags); \
147 __get_cpu_var(page_states).member += (delta); \
148 local_irq_restore(flags); \
152 #define inc_page_state(member) mod_page_state(member, 1UL)
153 #define dec_page_state(member) mod_page_state(member, 0UL - 1)
154 #define add_page_state(member,delta) mod_page_state(member, (delta))
155 #define sub_page_state(member,delta) mod_page_state(member, 0UL - (delta))
157 #define mod_page_state_zone(zone, member, delta) \
159 unsigned long flags; \
160 local_irq_save(flags); \
161 if (is_highmem(zone)) \
162 __get_cpu_var(page_states).member##_high += (delta);\
163 else if (is_normal(zone)) \
164 __get_cpu_var(page_states).member##_normal += (delta);\
166 __get_cpu_var(page_states).member##_dma += (delta);\
167 local_irq_restore(flags); \
171 * Manipulation of page state flags
173 #define PageLocked(page) \
174 test_bit(PG_locked, &(page)->flags)
175 #define SetPageLocked(page) \
176 set_bit(PG_locked, &(page)->flags)
177 #define TestSetPageLocked(page) \
178 test_and_set_bit(PG_locked, &(page)->flags)
179 #define ClearPageLocked(page) \
180 clear_bit(PG_locked, &(page)->flags)
181 #define TestClearPageLocked(page) \
182 test_and_clear_bit(PG_locked, &(page)->flags)
184 #define PageError(page) test_bit(PG_error, &(page)->flags)
185 #define SetPageError(page) set_bit(PG_error, &(page)->flags)
186 #define ClearPageError(page) clear_bit(PG_error, &(page)->flags)
188 #define PageReferenced(page) test_bit(PG_referenced, &(page)->flags)
189 #define SetPageReferenced(page) set_bit(PG_referenced, &(page)->flags)
190 #define ClearPageReferenced(page) clear_bit(PG_referenced, &(page)->flags)
191 #define TestClearPageReferenced(page) test_and_clear_bit(PG_referenced, &(page)->flags)
193 #define PageUptodate(page) test_bit(PG_uptodate, &(page)->flags)
194 #ifndef SetPageUptodate
195 #define SetPageUptodate(page) set_bit(PG_uptodate, &(page)->flags)
197 #define ClearPageUptodate(page) clear_bit(PG_uptodate, &(page)->flags)
199 #define PageDirty(page) test_bit(PG_dirty, &(page)->flags)
200 #define SetPageDirty(page) set_bit(PG_dirty, &(page)->flags)
201 #define TestSetPageDirty(page) test_and_set_bit(PG_dirty, &(page)->flags)
202 #define ClearPageDirty(page) clear_bit(PG_dirty, &(page)->flags)
203 #define TestClearPageDirty(page) test_and_clear_bit(PG_dirty, &(page)->flags)
205 #define SetPageLRU(page) set_bit(PG_lru, &(page)->flags)
206 #define PageLRU(page) test_bit(PG_lru, &(page)->flags)
207 #define TestSetPageLRU(page) test_and_set_bit(PG_lru, &(page)->flags)
208 #define TestClearPageLRU(page) test_and_clear_bit(PG_lru, &(page)->flags)
210 #define PageActive(page) test_bit(PG_active, &(page)->flags)
211 #define SetPageActive(page) set_bit(PG_active, &(page)->flags)
212 #define ClearPageActive(page) clear_bit(PG_active, &(page)->flags)
213 #define TestClearPageActive(page) test_and_clear_bit(PG_active, &(page)->flags)
214 #define TestSetPageActive(page) test_and_set_bit(PG_active, &(page)->flags)
216 #define PageSlab(page) test_bit(PG_slab, &(page)->flags)
217 #define SetPageSlab(page) set_bit(PG_slab, &(page)->flags)
218 #define ClearPageSlab(page) clear_bit(PG_slab, &(page)->flags)
219 #define TestClearPageSlab(page) test_and_clear_bit(PG_slab, &(page)->flags)
220 #define TestSetPageSlab(page) test_and_set_bit(PG_slab, &(page)->flags)
222 #ifdef CONFIG_HIGHMEM
223 #define PageHighMem(page) test_bit(PG_highmem, &(page)->flags)
225 #define PageHighMem(page) 0 /* needed to optimize away at compile time */
228 #define PageChecked(page) test_bit(PG_checked, &(page)->flags)
229 #define SetPageChecked(page) set_bit(PG_checked, &(page)->flags)
230 #define ClearPageChecked(page) clear_bit(PG_checked, &(page)->flags)
232 #define PageReserved(page) test_bit(PG_reserved, &(page)->flags)
233 #define SetPageReserved(page) set_bit(PG_reserved, &(page)->flags)
234 #define ClearPageReserved(page) clear_bit(PG_reserved, &(page)->flags)
235 #define __ClearPageReserved(page) __clear_bit(PG_reserved, &(page)->flags)
237 #define SetPagePrivate(page) set_bit(PG_private, &(page)->flags)
238 #define ClearPagePrivate(page) clear_bit(PG_private, &(page)->flags)
239 #define PagePrivate(page) test_bit(PG_private, &(page)->flags)
241 #define PageWriteback(page) test_bit(PG_writeback, &(page)->flags)
242 #define SetPageWriteback(page) \
244 if (!test_and_set_bit(PG_writeback, \
246 inc_page_state(nr_writeback); \
248 #define TestSetPageWriteback(page) \
251 ret = test_and_set_bit(PG_writeback, \
254 inc_page_state(nr_writeback); \
257 #define ClearPageWriteback(page) \
259 if (test_and_clear_bit(PG_writeback, \
261 dec_page_state(nr_writeback); \
263 #define TestClearPageWriteback(page) \
266 ret = test_and_clear_bit(PG_writeback, \
269 dec_page_state(nr_writeback); \
273 #define PageNosave(page) test_bit(PG_nosave, &(page)->flags)
274 #define SetPageNosave(page) set_bit(PG_nosave, &(page)->flags)
275 #define TestSetPageNosave(page) test_and_set_bit(PG_nosave, &(page)->flags)
276 #define ClearPageNosave(page) clear_bit(PG_nosave, &(page)->flags)
277 #define TestClearPageNosave(page) test_and_clear_bit(PG_nosave, &(page)->flags)
279 #define PageMappedToDisk(page) test_bit(PG_mappedtodisk, &(page)->flags)
280 #define SetPageMappedToDisk(page) set_bit(PG_mappedtodisk, &(page)->flags)
281 #define ClearPageMappedToDisk(page) clear_bit(PG_mappedtodisk, &(page)->flags)
283 #define PageReclaim(page) test_bit(PG_reclaim, &(page)->flags)
284 #define SetPageReclaim(page) set_bit(PG_reclaim, &(page)->flags)
285 #define ClearPageReclaim(page) clear_bit(PG_reclaim, &(page)->flags)
286 #define TestClearPageReclaim(page) test_and_clear_bit(PG_reclaim, &(page)->flags)
288 #define PageCompound(page) test_bit(PG_compound, &(page)->flags)
289 #define SetPageCompound(page) set_bit(PG_compound, &(page)->flags)
290 #define ClearPageCompound(page) clear_bit(PG_compound, &(page)->flags)
293 #define PageSwapCache(page) test_bit(PG_swapcache, &(page)->flags)
294 #define SetPageSwapCache(page) set_bit(PG_swapcache, &(page)->flags)
295 #define ClearPageSwapCache(page) clear_bit(PG_swapcache, &(page)->flags)
297 #define PageSwapCache(page) 0
300 struct page; /* forward declaration */
302 int test_clear_page_dirty(struct page *page);
303 int __clear_page_dirty(struct page *page);
304 int test_clear_page_writeback(struct page *page);
305 int test_set_page_writeback(struct page *page);
307 static inline void clear_page_dirty(struct page *page)
309 test_clear_page_dirty(page);
312 static inline void set_page_writeback(struct page *page)
314 test_set_page_writeback(page);
317 #endif /* PAGE_FLAGS_H */