[PATCH] ppc64: Add PTRACE_{GET|SET}VRREGS
[linux-2.6] / include / linux / page-flags.h
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/percpu.h>
9 #include <linux/cache.h>
10 #include <asm/pgtable.h>
11
12 /*
13  * Various page->flags bits:
14  *
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)...
17  *
18  * The PG_private bitflag is set if page->private contains a valid value.
19  *
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.
23  *
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.
26  *
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.
32  *
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!
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...
47  */
48
49 /*
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.
53  */
54 #define PG_locked                0      /* Page is locked. Don't touch. */
55 #define PG_error                 1
56 #define PG_referenced            2
57 #define PG_uptodate              3
58
59 #define PG_dirty                 4
60 #define PG_lru                   5
61 #define PG_active                6
62 #define PG_slab                  7      /* slab debug (Suparna wants this) */
63
64 #define PG_checked               8      /* kill me in 2.5.<early>. */
65 #define PG_arch_1                9
66 #define PG_reserved             10
67 #define PG_private              11      /* Has something at ->private */
68
69 #define PG_writeback            12      /* Page is under writeback */
70 #define PG_nosave               13      /* Used for system suspend/resume */
71 #define PG_compound             14      /* Part of a compound page */
72 #define PG_swapcache            15      /* Swap page: swp_entry_t in private */
73
74 #define PG_mappedtodisk         16      /* Has blocks allocated on-disk */
75 #define PG_reclaim              17      /* To be reclaimed asap */
76 #define PG_nosave_free          18      /* Free, should not be written */
77 #define PG_uncached             19      /* Page has been mapped as uncached */
78
79 /*
80  * Global page accounting.  One instance per CPU.  Only unsigned longs are
81  * allowed.
82  */
83 struct page_state {
84         unsigned long nr_dirty;         /* Dirty writeable pages */
85         unsigned long nr_writeback;     /* Pages under writeback */
86         unsigned long nr_unstable;      /* NFS unstable pages */
87         unsigned long nr_page_table_pages;/* Pages used for pagetables */
88         unsigned long nr_mapped;        /* mapped into pagetables */
89         unsigned long nr_slab;          /* In slab */
90 #define GET_PAGE_STATE_LAST nr_slab
91
92         /*
93          * The below are zeroed by get_page_state().  Use get_full_page_state()
94          * to add up all these.
95          */
96         unsigned long pgpgin;           /* Disk reads */
97         unsigned long pgpgout;          /* Disk writes */
98         unsigned long pswpin;           /* swap reads */
99         unsigned long pswpout;          /* swap writes */
100         unsigned long pgalloc_high;     /* page allocations */
101
102         unsigned long pgalloc_normal;
103         unsigned long pgalloc_dma;
104         unsigned long pgfree;           /* page freeings */
105         unsigned long pgactivate;       /* pages moved inactive->active */
106         unsigned long pgdeactivate;     /* pages moved active->inactive */
107
108         unsigned long pgfault;          /* faults (major+minor) */
109         unsigned long pgmajfault;       /* faults (major only) */
110         unsigned long pgrefill_high;    /* inspected in refill_inactive_zone */
111         unsigned long pgrefill_normal;
112         unsigned long pgrefill_dma;
113
114         unsigned long pgsteal_high;     /* total highmem pages reclaimed */
115         unsigned long pgsteal_normal;
116         unsigned long pgsteal_dma;
117         unsigned long pgscan_kswapd_high;/* total highmem pages scanned */
118         unsigned long pgscan_kswapd_normal;
119
120         unsigned long pgscan_kswapd_dma;
121         unsigned long pgscan_direct_high;/* total highmem pages scanned */
122         unsigned long pgscan_direct_normal;
123         unsigned long pgscan_direct_dma;
124         unsigned long pginodesteal;     /* pages reclaimed via inode freeing */
125
126         unsigned long slabs_scanned;    /* slab objects scanned */
127         unsigned long kswapd_steal;     /* pages reclaimed by kswapd */
128         unsigned long kswapd_inodesteal;/* reclaimed via kswapd inode freeing */
129         unsigned long pageoutrun;       /* kswapd's calls to page reclaim */
130         unsigned long allocstall;       /* direct reclaim calls */
131
132         unsigned long pgrotated;        /* pages rotated to tail of the LRU */
133         unsigned long nr_bounce;        /* pages for bounce buffers */
134 };
135
136 extern void get_page_state(struct page_state *ret);
137 extern void get_page_state_node(struct page_state *ret, int node);
138 extern void get_full_page_state(struct page_state *ret);
139 extern unsigned long __read_page_state(unsigned long offset);
140 extern void __mod_page_state(unsigned long offset, unsigned long delta);
141
142 #define read_page_state(member) \
143         __read_page_state(offsetof(struct page_state, member))
144
145 #define mod_page_state(member, delta)   \
146         __mod_page_state(offsetof(struct page_state, member), (delta))
147
148 #define inc_page_state(member)  mod_page_state(member, 1UL)
149 #define dec_page_state(member)  mod_page_state(member, 0UL - 1)
150 #define add_page_state(member,delta) mod_page_state(member, (delta))
151 #define sub_page_state(member,delta) mod_page_state(member, 0UL - (delta))
152
153 #define mod_page_state_zone(zone, member, delta)                                \
154         do {                                                                    \
155                 unsigned offset;                                                \
156                 if (is_highmem(zone))                                           \
157                         offset = offsetof(struct page_state, member##_high);    \
158                 else if (is_normal(zone))                                       \
159                         offset = offsetof(struct page_state, member##_normal);  \
160                 else                                                            \
161                         offset = offsetof(struct page_state, member##_dma);     \
162                 __mod_page_state(offset, (delta));                              \
163         } while (0)
164
165 /*
166  * Manipulation of page state flags
167  */
168 #define PageLocked(page)                \
169                 test_bit(PG_locked, &(page)->flags)
170 #define SetPageLocked(page)             \
171                 set_bit(PG_locked, &(page)->flags)
172 #define TestSetPageLocked(page)         \
173                 test_and_set_bit(PG_locked, &(page)->flags)
174 #define ClearPageLocked(page)           \
175                 clear_bit(PG_locked, &(page)->flags)
176 #define TestClearPageLocked(page)       \
177                 test_and_clear_bit(PG_locked, &(page)->flags)
178
179 #define PageError(page)         test_bit(PG_error, &(page)->flags)
180 #define SetPageError(page)      set_bit(PG_error, &(page)->flags)
181 #define ClearPageError(page)    clear_bit(PG_error, &(page)->flags)
182
183 #define PageReferenced(page)    test_bit(PG_referenced, &(page)->flags)
184 #define SetPageReferenced(page) set_bit(PG_referenced, &(page)->flags)
185 #define ClearPageReferenced(page)       clear_bit(PG_referenced, &(page)->flags)
186 #define TestClearPageReferenced(page) test_and_clear_bit(PG_referenced, &(page)->flags)
187
188 #define PageUptodate(page)      test_bit(PG_uptodate, &(page)->flags)
189 #ifndef SetPageUptodate
190 #define SetPageUptodate(page)   set_bit(PG_uptodate, &(page)->flags)
191 #endif
192 #define ClearPageUptodate(page) clear_bit(PG_uptodate, &(page)->flags)
193
194 #define PageDirty(page)         test_bit(PG_dirty, &(page)->flags)
195 #define SetPageDirty(page)      set_bit(PG_dirty, &(page)->flags)
196 #define TestSetPageDirty(page)  test_and_set_bit(PG_dirty, &(page)->flags)
197 #define ClearPageDirty(page)    clear_bit(PG_dirty, &(page)->flags)
198 #define __ClearPageDirty(page)  __clear_bit(PG_dirty, &(page)->flags)
199 #define TestClearPageDirty(page) test_and_clear_bit(PG_dirty, &(page)->flags)
200
201 #define SetPageLRU(page)        set_bit(PG_lru, &(page)->flags)
202 #define PageLRU(page)           test_bit(PG_lru, &(page)->flags)
203 #define TestSetPageLRU(page)    test_and_set_bit(PG_lru, &(page)->flags)
204 #define TestClearPageLRU(page)  test_and_clear_bit(PG_lru, &(page)->flags)
205
206 #define PageActive(page)        test_bit(PG_active, &(page)->flags)
207 #define SetPageActive(page)     set_bit(PG_active, &(page)->flags)
208 #define ClearPageActive(page)   clear_bit(PG_active, &(page)->flags)
209 #define TestClearPageActive(page) test_and_clear_bit(PG_active, &(page)->flags)
210 #define TestSetPageActive(page) test_and_set_bit(PG_active, &(page)->flags)
211
212 #define PageSlab(page)          test_bit(PG_slab, &(page)->flags)
213 #define SetPageSlab(page)       set_bit(PG_slab, &(page)->flags)
214 #define ClearPageSlab(page)     clear_bit(PG_slab, &(page)->flags)
215 #define TestClearPageSlab(page) test_and_clear_bit(PG_slab, &(page)->flags)
216 #define TestSetPageSlab(page)   test_and_set_bit(PG_slab, &(page)->flags)
217
218 #ifdef CONFIG_HIGHMEM
219 #define PageHighMem(page)       is_highmem(page_zone(page))
220 #else
221 #define PageHighMem(page)       0 /* needed to optimize away at compile time */
222 #endif
223
224 #define PageChecked(page)       test_bit(PG_checked, &(page)->flags)
225 #define SetPageChecked(page)    set_bit(PG_checked, &(page)->flags)
226 #define ClearPageChecked(page)  clear_bit(PG_checked, &(page)->flags)
227
228 #define PageReserved(page)      test_bit(PG_reserved, &(page)->flags)
229 #define SetPageReserved(page)   set_bit(PG_reserved, &(page)->flags)
230 #define ClearPageReserved(page) clear_bit(PG_reserved, &(page)->flags)
231 #define __ClearPageReserved(page)       __clear_bit(PG_reserved, &(page)->flags)
232
233 #define SetPagePrivate(page)    set_bit(PG_private, &(page)->flags)
234 #define ClearPagePrivate(page)  clear_bit(PG_private, &(page)->flags)
235 #define PagePrivate(page)       test_bit(PG_private, &(page)->flags)
236 #define __SetPagePrivate(page)  __set_bit(PG_private, &(page)->flags)
237 #define __ClearPagePrivate(page) __clear_bit(PG_private, &(page)->flags)
238
239 #define PageWriteback(page)     test_bit(PG_writeback, &(page)->flags)
240 #define SetPageWriteback(page)                                          \
241         do {                                                            \
242                 if (!test_and_set_bit(PG_writeback,                     \
243                                 &(page)->flags))                        \
244                         inc_page_state(nr_writeback);                   \
245         } while (0)
246 #define TestSetPageWriteback(page)                                      \
247         ({                                                              \
248                 int ret;                                                \
249                 ret = test_and_set_bit(PG_writeback,                    \
250                                         &(page)->flags);                \
251                 if (!ret)                                               \
252                         inc_page_state(nr_writeback);                   \
253                 ret;                                                    \
254         })
255 #define ClearPageWriteback(page)                                        \
256         do {                                                            \
257                 if (test_and_clear_bit(PG_writeback,                    \
258                                 &(page)->flags))                        \
259                         dec_page_state(nr_writeback);                   \
260         } while (0)
261 #define TestClearPageWriteback(page)                                    \
262         ({                                                              \
263                 int ret;                                                \
264                 ret = test_and_clear_bit(PG_writeback,                  \
265                                 &(page)->flags);                        \
266                 if (ret)                                                \
267                         dec_page_state(nr_writeback);                   \
268                 ret;                                                    \
269         })
270
271 #define PageNosave(page)        test_bit(PG_nosave, &(page)->flags)
272 #define SetPageNosave(page)     set_bit(PG_nosave, &(page)->flags)
273 #define TestSetPageNosave(page) test_and_set_bit(PG_nosave, &(page)->flags)
274 #define ClearPageNosave(page)           clear_bit(PG_nosave, &(page)->flags)
275 #define TestClearPageNosave(page)       test_and_clear_bit(PG_nosave, &(page)->flags)
276
277 #define PageNosaveFree(page)    test_bit(PG_nosave_free, &(page)->flags)
278 #define SetPageNosaveFree(page) set_bit(PG_nosave_free, &(page)->flags)
279 #define ClearPageNosaveFree(page)               clear_bit(PG_nosave_free, &(page)->flags)
280
281 #define PageMappedToDisk(page)  test_bit(PG_mappedtodisk, &(page)->flags)
282 #define SetPageMappedToDisk(page) set_bit(PG_mappedtodisk, &(page)->flags)
283 #define ClearPageMappedToDisk(page) clear_bit(PG_mappedtodisk, &(page)->flags)
284
285 #define PageReclaim(page)       test_bit(PG_reclaim, &(page)->flags)
286 #define SetPageReclaim(page)    set_bit(PG_reclaim, &(page)->flags)
287 #define ClearPageReclaim(page)  clear_bit(PG_reclaim, &(page)->flags)
288 #define TestClearPageReclaim(page) test_and_clear_bit(PG_reclaim, &(page)->flags)
289
290 #ifdef CONFIG_HUGETLB_PAGE
291 #define PageCompound(page)      test_bit(PG_compound, &(page)->flags)
292 #else
293 #define PageCompound(page)      0
294 #endif
295 #define SetPageCompound(page)   set_bit(PG_compound, &(page)->flags)
296 #define ClearPageCompound(page) clear_bit(PG_compound, &(page)->flags)
297
298 #ifdef CONFIG_SWAP
299 #define PageSwapCache(page)     test_bit(PG_swapcache, &(page)->flags)
300 #define SetPageSwapCache(page)  set_bit(PG_swapcache, &(page)->flags)
301 #define ClearPageSwapCache(page) clear_bit(PG_swapcache, &(page)->flags)
302 #else
303 #define PageSwapCache(page)     0
304 #endif
305
306 #define PageUncached(page)      test_bit(PG_uncached, &(page)->flags)
307 #define SetPageUncached(page)   set_bit(PG_uncached, &(page)->flags)
308 #define ClearPageUncached(page) clear_bit(PG_uncached, &(page)->flags)
309
310 struct page;    /* forward declaration */
311
312 int test_clear_page_dirty(struct page *page);
313 int test_clear_page_writeback(struct page *page);
314 int test_set_page_writeback(struct page *page);
315
316 static inline void clear_page_dirty(struct page *page)
317 {
318         test_clear_page_dirty(page);
319 }
320
321 static inline void set_page_writeback(struct page *page)
322 {
323         test_set_page_writeback(page);
324 }
325
326 #endif  /* PAGE_FLAGS_H */