Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Macros for manipulating and testing page->flags |
| 3 | */ |
| 4 | |
| 5 | #ifndef PAGE_FLAGS_H |
| 6 | #define PAGE_FLAGS_H |
| 7 | |
Andrew Morton | f886ed4 | 2006-06-23 02:03:06 -0700 | [diff] [blame] | 8 | #include <linux/types.h> |
| 9 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 |
Andy Whitcroft | 91fc8ab | 2006-04-10 22:53:01 -0700 | [diff] [blame] | 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. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 | |
Badari Pulavarty | cbe37d0 | 2005-06-21 17:14:52 -0700 | [diff] [blame] | 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 */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 78 | |
Badari Pulavarty | cbe37d0 | 2005-06-21 17:14:52 -0700 | [diff] [blame] | 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 */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 83 | |
Badari Pulavarty | cbe37d0 | 2005-06-21 17:14:52 -0700 | [diff] [blame] | 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 */ |
Nick Piggin | 676165a | 2006-04-10 11:21:48 +1000 | [diff] [blame] | 87 | #define PG_buddy 19 /* Page is free, on buddy lists */ |
| 88 | |
Andrew Morton | f886ed4 | 2006-06-23 02:03:06 -0700 | [diff] [blame] | 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 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 100 | |
| 101 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 102 | * Manipulation of page state flags |
| 103 | */ |
| 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) |
| 114 | |
| 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) |
| 118 | |
| 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) |
| 123 | |
| 124 | #define PageUptodate(page) test_bit(PG_uptodate, &(page)->flags) |
Christoph Lameter | f6ac235 | 2006-06-30 01:55:32 -0700 | [diff] [blame] | 125 | #ifdef CONFIG_S390 |
| 126 | #define SetPageUptodate(_page) \ |
| 127 | do { \ |
| 128 | struct page *__page = (_page); \ |
| 129 | if (!test_and_set_bit(PG_uptodate, &__page->flags)) \ |
| 130 | page_test_and_clear_dirty(_page); \ |
| 131 | } while (0) |
| 132 | #else |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 133 | #define SetPageUptodate(page) set_bit(PG_uptodate, &(page)->flags) |
| 134 | #endif |
| 135 | #define ClearPageUptodate(page) clear_bit(PG_uptodate, &(page)->flags) |
| 136 | |
| 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) |
Nick Piggin | 242e546 | 2005-09-03 15:54:50 -0700 | [diff] [blame] | 141 | #define __ClearPageDirty(page) __clear_bit(PG_dirty, &(page)->flags) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 142 | #define TestClearPageDirty(page) test_and_clear_bit(PG_dirty, &(page)->flags) |
| 143 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 144 | #define PageLRU(page) test_bit(PG_lru, &(page)->flags) |
Nick Piggin | 8d438f9 | 2006-03-22 00:07:59 -0800 | [diff] [blame] | 145 | #define SetPageLRU(page) set_bit(PG_lru, &(page)->flags) |
| 146 | #define ClearPageLRU(page) clear_bit(PG_lru, &(page)->flags) |
Nick Piggin | 6745391 | 2006-03-22 00:08:00 -0800 | [diff] [blame] | 147 | #define __ClearPageLRU(page) __clear_bit(PG_lru, &(page)->flags) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 148 | |
| 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) |
Nick Piggin | 6745391 | 2006-03-22 00:08:00 -0800 | [diff] [blame] | 152 | #define __ClearPageActive(page) __clear_bit(PG_active, &(page)->flags) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 153 | |
| 154 | #define PageSlab(page) test_bit(PG_slab, &(page)->flags) |
Nick Piggin | f205b2f | 2006-03-22 00:08:02 -0800 | [diff] [blame] | 155 | #define __SetPageSlab(page) __set_bit(PG_slab, &(page)->flags) |
| 156 | #define __ClearPageSlab(page) __clear_bit(PG_slab, &(page)->flags) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 157 | |
| 158 | #ifdef CONFIG_HIGHMEM |
Badari Pulavarty | cbe37d0 | 2005-06-21 17:14:52 -0700 | [diff] [blame] | 159 | #define PageHighMem(page) is_highmem(page_zone(page)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 160 | #else |
| 161 | #define PageHighMem(page) 0 /* needed to optimize away at compile time */ |
| 162 | #endif |
| 163 | |
| 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) |
| 167 | |
| 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) |
| 172 | |
| 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) |
| 178 | |
| 179 | #define PageWriteback(page) test_bit(PG_writeback, &(page)->flags) |
| 180 | #define SetPageWriteback(page) \ |
| 181 | do { \ |
| 182 | if (!test_and_set_bit(PG_writeback, \ |
| 183 | &(page)->flags)) \ |
Christoph Lameter | ce866b3 | 2006-06-30 01:55:40 -0700 | [diff] [blame] | 184 | inc_zone_page_state(page, NR_WRITEBACK); \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 185 | } while (0) |
| 186 | #define TestSetPageWriteback(page) \ |
| 187 | ({ \ |
| 188 | int ret; \ |
| 189 | ret = test_and_set_bit(PG_writeback, \ |
| 190 | &(page)->flags); \ |
| 191 | if (!ret) \ |
Christoph Lameter | ce866b3 | 2006-06-30 01:55:40 -0700 | [diff] [blame] | 192 | inc_zone_page_state(page, NR_WRITEBACK); \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 193 | ret; \ |
| 194 | }) |
| 195 | #define ClearPageWriteback(page) \ |
| 196 | do { \ |
| 197 | if (test_and_clear_bit(PG_writeback, \ |
| 198 | &(page)->flags)) \ |
Christoph Lameter | ce866b3 | 2006-06-30 01:55:40 -0700 | [diff] [blame] | 199 | dec_zone_page_state(page, NR_WRITEBACK); \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 200 | } while (0) |
| 201 | #define TestClearPageWriteback(page) \ |
| 202 | ({ \ |
| 203 | int ret; \ |
| 204 | ret = test_and_clear_bit(PG_writeback, \ |
| 205 | &(page)->flags); \ |
| 206 | if (ret) \ |
Christoph Lameter | ce866b3 | 2006-06-30 01:55:40 -0700 | [diff] [blame] | 207 | dec_zone_page_state(page, NR_WRITEBACK); \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 208 | ret; \ |
| 209 | }) |
| 210 | |
| 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) |
| 216 | |
| 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) |
| 220 | |
Nick Piggin | 676165a | 2006-04-10 11:21:48 +1000 | [diff] [blame] | 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) |
| 224 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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) |
| 228 | |
| 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) |
| 233 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 234 | #define PageCompound(page) test_bit(PG_compound, &(page)->flags) |
Nick Piggin | 5e9dace | 2006-03-22 00:08:01 -0800 | [diff] [blame] | 235 | #define __SetPageCompound(page) __set_bit(PG_compound, &(page)->flags) |
| 236 | #define __ClearPageCompound(page) __clear_bit(PG_compound, &(page)->flags) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 237 | |
| 238 | #ifdef CONFIG_SWAP |
| 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) |
| 242 | #else |
| 243 | #define PageSwapCache(page) 0 |
| 244 | #endif |
| 245 | |
| 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) |
| 249 | |
| 250 | struct page; /* forward declaration */ |
| 251 | |
| 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); |
| 255 | |
| 256 | static inline void clear_page_dirty(struct page *page) |
| 257 | { |
| 258 | test_clear_page_dirty(page); |
| 259 | } |
| 260 | |
| 261 | static inline void set_page_writeback(struct page *page) |
| 262 | { |
| 263 | test_set_page_writeback(page); |
| 264 | } |
| 265 | |
| 266 | #endif /* PAGE_FLAGS_H */ |