Rik van Riel | b2e1853 | 2008-10-18 20:26:30 -0700 | [diff] [blame] | 1 | #ifndef LINUX_MM_INLINE_H |
| 2 | #define LINUX_MM_INLINE_H |
| 3 | |
| 4 | /** |
| 5 | * page_is_file_cache - should the page be on a file LRU or anon LRU? |
| 6 | * @page: the page to test |
| 7 | * |
Rik van Riel | 4f98a2f | 2008-10-18 20:26:32 -0700 | [diff] [blame] | 8 | * Returns LRU_FILE if @page is page cache page backed by a regular filesystem, |
Rik van Riel | b2e1853 | 2008-10-18 20:26:30 -0700 | [diff] [blame] | 9 | * or 0 if @page is anonymous, tmpfs or otherwise ram or swap backed. |
| 10 | * Used by functions that manipulate the LRU lists, to sort a page |
| 11 | * onto the right LRU list. |
| 12 | * |
| 13 | * We would like to get this info without a page flag, but the state |
| 14 | * needs to survive until the page is last deleted from the LRU, which |
| 15 | * could be as far down as __page_cache_release. |
| 16 | */ |
| 17 | static inline int page_is_file_cache(struct page *page) |
| 18 | { |
| 19 | if (PageSwapBacked(page)) |
| 20 | return 0; |
| 21 | |
| 22 | /* The page is page cache backed by a normal filesystem. */ |
Rik van Riel | 4f98a2f | 2008-10-18 20:26:32 -0700 | [diff] [blame] | 23 | return LRU_FILE; |
Rik van Riel | b2e1853 | 2008-10-18 20:26:30 -0700 | [diff] [blame] | 24 | } |
| 25 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 26 | static inline void |
Christoph Lameter | b69408e | 2008-10-18 20:26:14 -0700 | [diff] [blame] | 27 | add_page_to_lru_list(struct zone *zone, struct page *page, enum lru_list l) |
| 28 | { |
| 29 | list_add(&page->lru, &zone->lru[l].list); |
| 30 | __inc_zone_state(zone, NR_LRU_BASE + l); |
KAMEZAWA Hiroyuki | 08e552c | 2009-01-07 18:08:01 -0800 | [diff] [blame] | 31 | mem_cgroup_add_lru_list(page, l); |
Christoph Lameter | b69408e | 2008-10-18 20:26:14 -0700 | [diff] [blame] | 32 | } |
| 33 | |
| 34 | static inline void |
| 35 | del_page_from_lru_list(struct zone *zone, struct page *page, enum lru_list l) |
| 36 | { |
| 37 | list_del(&page->lru); |
| 38 | __dec_zone_state(zone, NR_LRU_BASE + l); |
KAMEZAWA Hiroyuki | 08e552c | 2009-01-07 18:08:01 -0800 | [diff] [blame] | 39 | mem_cgroup_del_lru_list(page, l); |
Christoph Lameter | b69408e | 2008-10-18 20:26:14 -0700 | [diff] [blame] | 40 | } |
| 41 | |
| 42 | static inline void |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 43 | del_page_from_lru(struct zone *zone, struct page *page) |
| 44 | { |
Rik van Riel | 4f98a2f | 2008-10-18 20:26:32 -0700 | [diff] [blame] | 45 | enum lru_list l = LRU_BASE; |
Christoph Lameter | b69408e | 2008-10-18 20:26:14 -0700 | [diff] [blame] | 46 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 47 | list_del(&page->lru); |
Lee Schermerhorn | 894bc31 | 2008-10-18 20:26:39 -0700 | [diff] [blame] | 48 | if (PageUnevictable(page)) { |
| 49 | __ClearPageUnevictable(page); |
| 50 | l = LRU_UNEVICTABLE; |
| 51 | } else { |
| 52 | if (PageActive(page)) { |
| 53 | __ClearPageActive(page); |
| 54 | l += LRU_ACTIVE; |
| 55 | } |
| 56 | l += page_is_file_cache(page); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 57 | } |
Christoph Lameter | b69408e | 2008-10-18 20:26:14 -0700 | [diff] [blame] | 58 | __dec_zone_state(zone, NR_LRU_BASE + l); |
KAMEZAWA Hiroyuki | 08e552c | 2009-01-07 18:08:01 -0800 | [diff] [blame] | 59 | mem_cgroup_del_lru_list(page, l); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 60 | } |
Christoph Lameter | 21eac81 | 2006-01-08 01:00:45 -0800 | [diff] [blame] | 61 | |
Christoph Lameter | b69408e | 2008-10-18 20:26:14 -0700 | [diff] [blame] | 62 | /** |
| 63 | * page_lru - which LRU list should a page be on? |
| 64 | * @page: the page to test |
| 65 | * |
| 66 | * Returns the LRU list a page should be on, as an index |
| 67 | * into the array of LRU lists. |
| 68 | */ |
| 69 | static inline enum lru_list page_lru(struct page *page) |
| 70 | { |
| 71 | enum lru_list lru = LRU_BASE; |
| 72 | |
Lee Schermerhorn | 894bc31 | 2008-10-18 20:26:39 -0700 | [diff] [blame] | 73 | if (PageUnevictable(page)) |
| 74 | lru = LRU_UNEVICTABLE; |
| 75 | else { |
| 76 | if (PageActive(page)) |
| 77 | lru += LRU_ACTIVE; |
| 78 | lru += page_is_file_cache(page); |
| 79 | } |
Christoph Lameter | b69408e | 2008-10-18 20:26:14 -0700 | [diff] [blame] | 80 | |
| 81 | return lru; |
| 82 | } |
Rik van Riel | b2e1853 | 2008-10-18 20:26:30 -0700 | [diff] [blame] | 83 | |
| 84 | #endif |