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 | * |
Nick Piggin | da6052f | 2006-09-25 23:31:35 -0700 | [diff] [blame] | 16 | * The PG_private bitflag is set on pagecache pages if they contain filesystem |
| 17 | * specific data (which is normally at page->private). It can be used by |
| 18 | * private allocations for its own usage. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 19 | * |
Nick Piggin | da6052f | 2006-09-25 23:31:35 -0700 | [diff] [blame] | 20 | * During initiation of disk I/O, PG_locked is set. This bit is set before I/O |
| 21 | * and cleared when writeback _starts_ or when read _completes_. PG_writeback |
| 22 | * is set before writeback starts and cleared when it finishes. |
| 23 | * |
| 24 | * PG_locked also pins a page in pagecache, and blocks truncation of the file |
| 25 | * while it is held. |
| 26 | * |
| 27 | * page_waitqueue(page) is a wait queue of all tasks waiting for the page |
| 28 | * to become unlocked. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 29 | * |
| 30 | * PG_uptodate tells whether the page's contents is valid. When a read |
| 31 | * completes, the page becomes uptodate, unless a disk I/O error happened. |
| 32 | * |
Nick Piggin | da6052f | 2006-09-25 23:31:35 -0700 | [diff] [blame] | 33 | * PG_referenced, PG_reclaim are used for page reclaim for anonymous and |
| 34 | * file-backed pagecache (see mm/vmscan.c). |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 35 | * |
| 36 | * PG_error is set to indicate that an I/O error occurred on this page. |
| 37 | * |
| 38 | * PG_arch_1 is an architecture specific page state bit. The generic code |
| 39 | * guarantees that this bit is cleared for a page when it first is entered into |
| 40 | * the page cache. |
| 41 | * |
| 42 | * PG_highmem pages are not permanently mapped into the kernel virtual address |
| 43 | * space, they need to be kmapped separately for doing IO on the pages. The |
| 44 | * struct page (these bits with information) are always mapped into kernel |
| 45 | * address space... |
Nick Piggin | da6052f | 2006-09-25 23:31:35 -0700 | [diff] [blame] | 46 | * |
| 47 | * PG_buddy is set to indicate that the page is free and in the buddy system |
| 48 | * (see mm/page_alloc.c). |
| 49 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 50 | */ |
| 51 | |
| 52 | /* |
| 53 | * 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] | 54 | * locked- and dirty-page accounting. |
| 55 | * |
| 56 | * The page flags field is split into two parts, the main flags area |
| 57 | * which extends from the low bits upwards, and the fields area which |
| 58 | * extends from the high bits downwards. |
| 59 | * |
| 60 | * | FIELD | ... | FLAGS | |
| 61 | * N-1 ^ 0 |
| 62 | * (N-FLAGS_RESERVED) |
| 63 | * |
| 64 | * The fields area is reserved for fields mapping zone, node and SPARSEMEM |
| 65 | * section. The boundry between these two areas is defined by |
| 66 | * FLAGS_RESERVED which defines the width of the fields section |
| 67 | * (see linux/mmzone.h). New flags must _not_ overlap with this area. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 68 | */ |
| 69 | #define PG_locked 0 /* Page is locked. Don't touch. */ |
| 70 | #define PG_error 1 |
| 71 | #define PG_referenced 2 |
| 72 | #define PG_uptodate 3 |
| 73 | |
| 74 | #define PG_dirty 4 |
| 75 | #define PG_lru 5 |
| 76 | #define PG_active 6 |
| 77 | #define PG_slab 7 /* slab debug (Suparna wants this) */ |
| 78 | |
Badari Pulavarty | cbe37d0 | 2005-06-21 17:14:52 -0700 | [diff] [blame] | 79 | #define PG_checked 8 /* kill me in 2.5.<early>. */ |
| 80 | #define PG_arch_1 9 |
| 81 | #define PG_reserved 10 |
Nick Piggin | da6052f | 2006-09-25 23:31:35 -0700 | [diff] [blame] | 82 | #define PG_private 11 /* If pagecache, has fs-private data */ |
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_writeback 12 /* Page is under writeback */ |
| 85 | #define PG_nosave 13 /* Used for system suspend/resume */ |
| 86 | #define PG_compound 14 /* Part of a compound page */ |
| 87 | #define PG_swapcache 15 /* Swap page: swp_entry_t in private */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 88 | |
Badari Pulavarty | cbe37d0 | 2005-06-21 17:14:52 -0700 | [diff] [blame] | 89 | #define PG_mappedtodisk 16 /* Has blocks allocated on-disk */ |
| 90 | #define PG_reclaim 17 /* To be reclaimed asap */ |
Nick Piggin | da6052f | 2006-09-25 23:31:35 -0700 | [diff] [blame] | 91 | #define PG_nosave_free 18 /* Used for system suspend/resume */ |
Nick Piggin | 676165a | 2006-04-10 11:21:48 +1000 | [diff] [blame] | 92 | #define PG_buddy 19 /* Page is free, on buddy lists */ |
| 93 | |
Andrew Morton | f886ed4 | 2006-06-23 02:03:06 -0700 | [diff] [blame] | 94 | |
| 95 | #if (BITS_PER_LONG > 32) |
| 96 | /* |
| 97 | * 64-bit-only flags build down from bit 31 |
| 98 | * |
| 99 | * 32 bit -------------------------------| FIELDS | FLAGS | |
| 100 | * 64 bit | FIELDS | ?????? FLAGS | |
| 101 | * 63 32 0 |
| 102 | */ |
| 103 | #define PG_uncached 31 /* Page has been mapped as uncached */ |
| 104 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 105 | |
| 106 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 107 | * Manipulation of page state flags |
| 108 | */ |
| 109 | #define PageLocked(page) \ |
| 110 | test_bit(PG_locked, &(page)->flags) |
| 111 | #define SetPageLocked(page) \ |
| 112 | set_bit(PG_locked, &(page)->flags) |
| 113 | #define TestSetPageLocked(page) \ |
| 114 | test_and_set_bit(PG_locked, &(page)->flags) |
| 115 | #define ClearPageLocked(page) \ |
| 116 | clear_bit(PG_locked, &(page)->flags) |
| 117 | #define TestClearPageLocked(page) \ |
| 118 | test_and_clear_bit(PG_locked, &(page)->flags) |
| 119 | |
| 120 | #define PageError(page) test_bit(PG_error, &(page)->flags) |
| 121 | #define SetPageError(page) set_bit(PG_error, &(page)->flags) |
| 122 | #define ClearPageError(page) clear_bit(PG_error, &(page)->flags) |
| 123 | |
| 124 | #define PageReferenced(page) test_bit(PG_referenced, &(page)->flags) |
| 125 | #define SetPageReferenced(page) set_bit(PG_referenced, &(page)->flags) |
| 126 | #define ClearPageReferenced(page) clear_bit(PG_referenced, &(page)->flags) |
| 127 | #define TestClearPageReferenced(page) test_and_clear_bit(PG_referenced, &(page)->flags) |
| 128 | |
| 129 | #define PageUptodate(page) test_bit(PG_uptodate, &(page)->flags) |
Christoph Lameter | f6ac235 | 2006-06-30 01:55:32 -0700 | [diff] [blame] | 130 | #ifdef CONFIG_S390 |
Heiko Carstens | 2dcea57 | 2006-09-29 01:58:41 -0700 | [diff] [blame] | 131 | static inline void SetPageUptodate(struct page *page) |
| 132 | { |
| 133 | if (!test_and_set_bit(PG_uptodate, &page->flags)) |
| 134 | page_test_and_clear_dirty(page); |
| 135 | } |
Christoph Lameter | f6ac235 | 2006-06-30 01:55:32 -0700 | [diff] [blame] | 136 | #else |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 137 | #define SetPageUptodate(page) set_bit(PG_uptodate, &(page)->flags) |
| 138 | #endif |
| 139 | #define ClearPageUptodate(page) clear_bit(PG_uptodate, &(page)->flags) |
| 140 | |
| 141 | #define PageDirty(page) test_bit(PG_dirty, &(page)->flags) |
| 142 | #define SetPageDirty(page) set_bit(PG_dirty, &(page)->flags) |
| 143 | #define TestSetPageDirty(page) test_and_set_bit(PG_dirty, &(page)->flags) |
| 144 | #define ClearPageDirty(page) clear_bit(PG_dirty, &(page)->flags) |
Nick Piggin | 242e546 | 2005-09-03 15:54:50 -0700 | [diff] [blame] | 145 | #define __ClearPageDirty(page) __clear_bit(PG_dirty, &(page)->flags) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 146 | #define TestClearPageDirty(page) test_and_clear_bit(PG_dirty, &(page)->flags) |
| 147 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 148 | #define PageLRU(page) test_bit(PG_lru, &(page)->flags) |
Nick Piggin | 8d438f9 | 2006-03-22 00:07:59 -0800 | [diff] [blame] | 149 | #define SetPageLRU(page) set_bit(PG_lru, &(page)->flags) |
| 150 | #define ClearPageLRU(page) clear_bit(PG_lru, &(page)->flags) |
Nick Piggin | 6745391 | 2006-03-22 00:08:00 -0800 | [diff] [blame] | 151 | #define __ClearPageLRU(page) __clear_bit(PG_lru, &(page)->flags) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 152 | |
| 153 | #define PageActive(page) test_bit(PG_active, &(page)->flags) |
| 154 | #define SetPageActive(page) set_bit(PG_active, &(page)->flags) |
| 155 | #define ClearPageActive(page) clear_bit(PG_active, &(page)->flags) |
Nick Piggin | 6745391 | 2006-03-22 00:08:00 -0800 | [diff] [blame] | 156 | #define __ClearPageActive(page) __clear_bit(PG_active, &(page)->flags) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 157 | |
| 158 | #define PageSlab(page) test_bit(PG_slab, &(page)->flags) |
Nick Piggin | f205b2f | 2006-03-22 00:08:02 -0800 | [diff] [blame] | 159 | #define __SetPageSlab(page) __set_bit(PG_slab, &(page)->flags) |
| 160 | #define __ClearPageSlab(page) __clear_bit(PG_slab, &(page)->flags) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 161 | |
| 162 | #ifdef CONFIG_HIGHMEM |
Badari Pulavarty | cbe37d0 | 2005-06-21 17:14:52 -0700 | [diff] [blame] | 163 | #define PageHighMem(page) is_highmem(page_zone(page)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 164 | #else |
| 165 | #define PageHighMem(page) 0 /* needed to optimize away at compile time */ |
| 166 | #endif |
| 167 | |
| 168 | #define PageChecked(page) test_bit(PG_checked, &(page)->flags) |
| 169 | #define SetPageChecked(page) set_bit(PG_checked, &(page)->flags) |
| 170 | #define ClearPageChecked(page) clear_bit(PG_checked, &(page)->flags) |
| 171 | |
| 172 | #define PageReserved(page) test_bit(PG_reserved, &(page)->flags) |
| 173 | #define SetPageReserved(page) set_bit(PG_reserved, &(page)->flags) |
| 174 | #define ClearPageReserved(page) clear_bit(PG_reserved, &(page)->flags) |
| 175 | #define __ClearPageReserved(page) __clear_bit(PG_reserved, &(page)->flags) |
| 176 | |
| 177 | #define SetPagePrivate(page) set_bit(PG_private, &(page)->flags) |
| 178 | #define ClearPagePrivate(page) clear_bit(PG_private, &(page)->flags) |
| 179 | #define PagePrivate(page) test_bit(PG_private, &(page)->flags) |
| 180 | #define __SetPagePrivate(page) __set_bit(PG_private, &(page)->flags) |
| 181 | #define __ClearPagePrivate(page) __clear_bit(PG_private, &(page)->flags) |
| 182 | |
| 183 | #define PageWriteback(page) test_bit(PG_writeback, &(page)->flags) |
| 184 | #define SetPageWriteback(page) \ |
| 185 | do { \ |
| 186 | if (!test_and_set_bit(PG_writeback, \ |
| 187 | &(page)->flags)) \ |
Christoph Lameter | ce866b3 | 2006-06-30 01:55:40 -0700 | [diff] [blame] | 188 | inc_zone_page_state(page, NR_WRITEBACK); \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 189 | } while (0) |
| 190 | #define TestSetPageWriteback(page) \ |
| 191 | ({ \ |
| 192 | int ret; \ |
| 193 | ret = test_and_set_bit(PG_writeback, \ |
| 194 | &(page)->flags); \ |
| 195 | if (!ret) \ |
Christoph Lameter | ce866b3 | 2006-06-30 01:55:40 -0700 | [diff] [blame] | 196 | inc_zone_page_state(page, NR_WRITEBACK); \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 197 | ret; \ |
| 198 | }) |
| 199 | #define ClearPageWriteback(page) \ |
| 200 | do { \ |
| 201 | if (test_and_clear_bit(PG_writeback, \ |
| 202 | &(page)->flags)) \ |
Christoph Lameter | ce866b3 | 2006-06-30 01:55:40 -0700 | [diff] [blame] | 203 | dec_zone_page_state(page, NR_WRITEBACK); \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 204 | } while (0) |
| 205 | #define TestClearPageWriteback(page) \ |
| 206 | ({ \ |
| 207 | int ret; \ |
| 208 | ret = test_and_clear_bit(PG_writeback, \ |
| 209 | &(page)->flags); \ |
| 210 | if (ret) \ |
Christoph Lameter | ce866b3 | 2006-06-30 01:55:40 -0700 | [diff] [blame] | 211 | dec_zone_page_state(page, NR_WRITEBACK); \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 212 | ret; \ |
| 213 | }) |
| 214 | |
| 215 | #define PageNosave(page) test_bit(PG_nosave, &(page)->flags) |
| 216 | #define SetPageNosave(page) set_bit(PG_nosave, &(page)->flags) |
| 217 | #define TestSetPageNosave(page) test_and_set_bit(PG_nosave, &(page)->flags) |
| 218 | #define ClearPageNosave(page) clear_bit(PG_nosave, &(page)->flags) |
| 219 | #define TestClearPageNosave(page) test_and_clear_bit(PG_nosave, &(page)->flags) |
| 220 | |
| 221 | #define PageNosaveFree(page) test_bit(PG_nosave_free, &(page)->flags) |
| 222 | #define SetPageNosaveFree(page) set_bit(PG_nosave_free, &(page)->flags) |
| 223 | #define ClearPageNosaveFree(page) clear_bit(PG_nosave_free, &(page)->flags) |
| 224 | |
Nick Piggin | 676165a | 2006-04-10 11:21:48 +1000 | [diff] [blame] | 225 | #define PageBuddy(page) test_bit(PG_buddy, &(page)->flags) |
| 226 | #define __SetPageBuddy(page) __set_bit(PG_buddy, &(page)->flags) |
| 227 | #define __ClearPageBuddy(page) __clear_bit(PG_buddy, &(page)->flags) |
| 228 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 229 | #define PageMappedToDisk(page) test_bit(PG_mappedtodisk, &(page)->flags) |
| 230 | #define SetPageMappedToDisk(page) set_bit(PG_mappedtodisk, &(page)->flags) |
| 231 | #define ClearPageMappedToDisk(page) clear_bit(PG_mappedtodisk, &(page)->flags) |
| 232 | |
| 233 | #define PageReclaim(page) test_bit(PG_reclaim, &(page)->flags) |
| 234 | #define SetPageReclaim(page) set_bit(PG_reclaim, &(page)->flags) |
| 235 | #define ClearPageReclaim(page) clear_bit(PG_reclaim, &(page)->flags) |
| 236 | #define TestClearPageReclaim(page) test_and_clear_bit(PG_reclaim, &(page)->flags) |
| 237 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 238 | #define PageCompound(page) test_bit(PG_compound, &(page)->flags) |
Nick Piggin | 5e9dace | 2006-03-22 00:08:01 -0800 | [diff] [blame] | 239 | #define __SetPageCompound(page) __set_bit(PG_compound, &(page)->flags) |
| 240 | #define __ClearPageCompound(page) __clear_bit(PG_compound, &(page)->flags) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 241 | |
| 242 | #ifdef CONFIG_SWAP |
| 243 | #define PageSwapCache(page) test_bit(PG_swapcache, &(page)->flags) |
| 244 | #define SetPageSwapCache(page) set_bit(PG_swapcache, &(page)->flags) |
| 245 | #define ClearPageSwapCache(page) clear_bit(PG_swapcache, &(page)->flags) |
| 246 | #else |
| 247 | #define PageSwapCache(page) 0 |
| 248 | #endif |
| 249 | |
| 250 | #define PageUncached(page) test_bit(PG_uncached, &(page)->flags) |
| 251 | #define SetPageUncached(page) set_bit(PG_uncached, &(page)->flags) |
| 252 | #define ClearPageUncached(page) clear_bit(PG_uncached, &(page)->flags) |
| 253 | |
| 254 | struct page; /* forward declaration */ |
| 255 | |
| 256 | int test_clear_page_dirty(struct page *page); |
| 257 | int test_clear_page_writeback(struct page *page); |
| 258 | int test_set_page_writeback(struct page *page); |
| 259 | |
| 260 | static inline void clear_page_dirty(struct page *page) |
| 261 | { |
| 262 | test_clear_page_dirty(page); |
| 263 | } |
| 264 | |
| 265 | static inline void set_page_writeback(struct page *page) |
| 266 | { |
| 267 | test_set_page_writeback(page); |
| 268 | } |
| 269 | |
| 270 | #endif /* PAGE_FLAGS_H */ |