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 | * |
Johannes Weiner | 6c0b135 | 2009-09-21 17:02:59 -0700 | [diff] [blame] | 8 | * Returns 1 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 | { |
Johannes Weiner | 6c0b135 | 2009-09-21 17:02:59 -0700 | [diff] [blame] | 19 | return !PageSwapBacked(page); |
Rik van Riel | b2e1853 | 2008-10-18 20:26:30 -0700 | [diff] [blame] | 20 | } |
| 21 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 22 | static inline void |
Andrea Arcangeli | 71e3aac | 2011-01-13 15:46:52 -0800 | [diff] [blame^] | 23 | __add_page_to_lru_list(struct zone *zone, struct page *page, enum lru_list l, |
| 24 | struct list_head *head) |
Christoph Lameter | b69408e | 2008-10-18 20:26:14 -0700 | [diff] [blame] | 25 | { |
Andrea Arcangeli | 71e3aac | 2011-01-13 15:46:52 -0800 | [diff] [blame^] | 26 | list_add(&page->lru, head); |
Christoph Lameter | b69408e | 2008-10-18 20:26:14 -0700 | [diff] [blame] | 27 | __inc_zone_state(zone, NR_LRU_BASE + l); |
KAMEZAWA Hiroyuki | 08e552c | 2009-01-07 18:08:01 -0800 | [diff] [blame] | 28 | mem_cgroup_add_lru_list(page, l); |
Christoph Lameter | b69408e | 2008-10-18 20:26:14 -0700 | [diff] [blame] | 29 | } |
| 30 | |
| 31 | static inline void |
Andrea Arcangeli | 71e3aac | 2011-01-13 15:46:52 -0800 | [diff] [blame^] | 32 | add_page_to_lru_list(struct zone *zone, struct page *page, enum lru_list l) |
| 33 | { |
| 34 | __add_page_to_lru_list(zone, page, l, &zone->lru[l].list); |
| 35 | } |
| 36 | |
| 37 | static inline void |
Christoph Lameter | b69408e | 2008-10-18 20:26:14 -0700 | [diff] [blame] | 38 | del_page_from_lru_list(struct zone *zone, struct page *page, enum lru_list l) |
| 39 | { |
| 40 | list_del(&page->lru); |
| 41 | __dec_zone_state(zone, NR_LRU_BASE + l); |
KAMEZAWA Hiroyuki | 08e552c | 2009-01-07 18:08:01 -0800 | [diff] [blame] | 42 | mem_cgroup_del_lru_list(page, l); |
Christoph Lameter | b69408e | 2008-10-18 20:26:14 -0700 | [diff] [blame] | 43 | } |
| 44 | |
Johannes Weiner | 401a8e1 | 2009-09-21 17:02:58 -0700 | [diff] [blame] | 45 | /** |
| 46 | * page_lru_base_type - which LRU list type should a page be on? |
| 47 | * @page: the page to test |
| 48 | * |
| 49 | * Used for LRU list index arithmetic. |
| 50 | * |
| 51 | * Returns the base LRU type - file or anon - @page should be on. |
| 52 | */ |
| 53 | static inline enum lru_list page_lru_base_type(struct page *page) |
| 54 | { |
| 55 | if (page_is_file_cache(page)) |
| 56 | return LRU_INACTIVE_FILE; |
| 57 | return LRU_INACTIVE_ANON; |
| 58 | } |
| 59 | |
Christoph Lameter | b69408e | 2008-10-18 20:26:14 -0700 | [diff] [blame] | 60 | static inline void |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 61 | del_page_from_lru(struct zone *zone, struct page *page) |
| 62 | { |
Johannes Weiner | 401a8e1 | 2009-09-21 17:02:58 -0700 | [diff] [blame] | 63 | enum lru_list l; |
Christoph Lameter | b69408e | 2008-10-18 20:26:14 -0700 | [diff] [blame] | 64 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 65 | list_del(&page->lru); |
Lee Schermerhorn | 894bc31 | 2008-10-18 20:26:39 -0700 | [diff] [blame] | 66 | if (PageUnevictable(page)) { |
| 67 | __ClearPageUnevictable(page); |
| 68 | l = LRU_UNEVICTABLE; |
| 69 | } else { |
Johannes Weiner | 401a8e1 | 2009-09-21 17:02:58 -0700 | [diff] [blame] | 70 | l = page_lru_base_type(page); |
Lee Schermerhorn | 894bc31 | 2008-10-18 20:26:39 -0700 | [diff] [blame] | 71 | if (PageActive(page)) { |
| 72 | __ClearPageActive(page); |
| 73 | l += LRU_ACTIVE; |
| 74 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 75 | } |
Christoph Lameter | b69408e | 2008-10-18 20:26:14 -0700 | [diff] [blame] | 76 | __dec_zone_state(zone, NR_LRU_BASE + l); |
KAMEZAWA Hiroyuki | 08e552c | 2009-01-07 18:08:01 -0800 | [diff] [blame] | 77 | mem_cgroup_del_lru_list(page, l); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 78 | } |
Christoph Lameter | 21eac81 | 2006-01-08 01:00:45 -0800 | [diff] [blame] | 79 | |
Christoph Lameter | b69408e | 2008-10-18 20:26:14 -0700 | [diff] [blame] | 80 | /** |
| 81 | * page_lru - which LRU list should a page be on? |
| 82 | * @page: the page to test |
| 83 | * |
| 84 | * Returns the LRU list a page should be on, as an index |
| 85 | * into the array of LRU lists. |
| 86 | */ |
| 87 | static inline enum lru_list page_lru(struct page *page) |
| 88 | { |
Johannes Weiner | 401a8e1 | 2009-09-21 17:02:58 -0700 | [diff] [blame] | 89 | enum lru_list lru; |
Christoph Lameter | b69408e | 2008-10-18 20:26:14 -0700 | [diff] [blame] | 90 | |
Lee Schermerhorn | 894bc31 | 2008-10-18 20:26:39 -0700 | [diff] [blame] | 91 | if (PageUnevictable(page)) |
| 92 | lru = LRU_UNEVICTABLE; |
| 93 | else { |
Johannes Weiner | 401a8e1 | 2009-09-21 17:02:58 -0700 | [diff] [blame] | 94 | lru = page_lru_base_type(page); |
Lee Schermerhorn | 894bc31 | 2008-10-18 20:26:39 -0700 | [diff] [blame] | 95 | if (PageActive(page)) |
| 96 | lru += LRU_ACTIVE; |
Lee Schermerhorn | 894bc31 | 2008-10-18 20:26:39 -0700 | [diff] [blame] | 97 | } |
Christoph Lameter | b69408e | 2008-10-18 20:26:14 -0700 | [diff] [blame] | 98 | |
| 99 | return lru; |
| 100 | } |
Rik van Riel | b2e1853 | 2008-10-18 20:26:30 -0700 | [diff] [blame] | 101 | |
| 102 | #endif |