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 | |
Rik van Riel | 2c888cf | 2011-01-13 15:47:13 -0800 | [diff] [blame] | 4 | #include <linux/huge_mm.h> |
| 5 | |
Rik van Riel | b2e1853 | 2008-10-18 20:26:30 -0700 | [diff] [blame] | 6 | /** |
| 7 | * page_is_file_cache - should the page be on a file LRU or anon LRU? |
| 8 | * @page: the page to test |
| 9 | * |
Johannes Weiner | 6c0b135 | 2009-09-21 17:02:59 -0700 | [diff] [blame] | 10 | * 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] | 11 | * or 0 if @page is anonymous, tmpfs or otherwise ram or swap backed. |
| 12 | * Used by functions that manipulate the LRU lists, to sort a page |
| 13 | * onto the right LRU list. |
| 14 | * |
| 15 | * We would like to get this info without a page flag, but the state |
| 16 | * needs to survive until the page is last deleted from the LRU, which |
| 17 | * could be as far down as __page_cache_release. |
| 18 | */ |
| 19 | static inline int page_is_file_cache(struct page *page) |
| 20 | { |
Johannes Weiner | 6c0b135 | 2009-09-21 17:02:59 -0700 | [diff] [blame] | 21 | return !PageSwapBacked(page); |
Rik van Riel | b2e1853 | 2008-10-18 20:26:30 -0700 | [diff] [blame] | 22 | } |
| 23 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 24 | static inline void |
Hugh Dickins | 4111304 | 2012-01-12 17:20:01 -0800 | [diff] [blame] | 25 | add_page_to_lru_list(struct zone *zone, struct page *page, enum lru_list lru) |
Andrea Arcangeli | 71e3aac | 2011-01-13 15:46:52 -0800 | [diff] [blame] | 26 | { |
Johannes Weiner | 925b767 | 2012-01-12 17:18:15 -0800 | [diff] [blame] | 27 | struct lruvec *lruvec; |
| 28 | |
Hugh Dickins | 4111304 | 2012-01-12 17:20:01 -0800 | [diff] [blame] | 29 | lruvec = mem_cgroup_lru_add_list(zone, page, lru); |
| 30 | list_add(&page->lru, &lruvec->lists[lru]); |
| 31 | __mod_zone_page_state(zone, NR_LRU_BASE + lru, hpage_nr_pages(page)); |
Andrea Arcangeli | 71e3aac | 2011-01-13 15:46:52 -0800 | [diff] [blame] | 32 | } |
| 33 | |
| 34 | static inline void |
Hugh Dickins | 4111304 | 2012-01-12 17:20:01 -0800 | [diff] [blame] | 35 | del_page_from_lru_list(struct zone *zone, struct page *page, enum lru_list lru) |
Christoph Lameter | b69408e | 2008-10-18 20:26:14 -0700 | [diff] [blame] | 36 | { |
Hugh Dickins | 4111304 | 2012-01-12 17:20:01 -0800 | [diff] [blame] | 37 | mem_cgroup_lru_del_list(page, lru); |
Christoph Lameter | b69408e | 2008-10-18 20:26:14 -0700 | [diff] [blame] | 38 | list_del(&page->lru); |
Hugh Dickins | 4111304 | 2012-01-12 17:20:01 -0800 | [diff] [blame] | 39 | __mod_zone_page_state(zone, NR_LRU_BASE + lru, -hpage_nr_pages(page)); |
Christoph Lameter | b69408e | 2008-10-18 20:26:14 -0700 | [diff] [blame] | 40 | } |
| 41 | |
Johannes Weiner | 401a8e1 | 2009-09-21 17:02:58 -0700 | [diff] [blame] | 42 | /** |
| 43 | * page_lru_base_type - which LRU list type should a page be on? |
| 44 | * @page: the page to test |
| 45 | * |
| 46 | * Used for LRU list index arithmetic. |
| 47 | * |
| 48 | * Returns the base LRU type - file or anon - @page should be on. |
| 49 | */ |
| 50 | static inline enum lru_list page_lru_base_type(struct page *page) |
| 51 | { |
| 52 | if (page_is_file_cache(page)) |
| 53 | return LRU_INACTIVE_FILE; |
| 54 | return LRU_INACTIVE_ANON; |
| 55 | } |
| 56 | |
Hugh Dickins | 1c1c53d | 2012-01-12 17:20:04 -0800 | [diff] [blame] | 57 | /** |
| 58 | * page_off_lru - which LRU list was page on? clearing its lru flags. |
| 59 | * @page: the page to test |
| 60 | * |
| 61 | * Returns the LRU list a page was on, as an index into the array of LRU |
| 62 | * lists; and clears its Unevictable or Active flags, ready for freeing. |
| 63 | */ |
| 64 | static inline enum lru_list page_off_lru(struct page *page) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 65 | { |
Hugh Dickins | 4111304 | 2012-01-12 17:20:01 -0800 | [diff] [blame] | 66 | enum lru_list lru; |
Christoph Lameter | b69408e | 2008-10-18 20:26:14 -0700 | [diff] [blame] | 67 | |
Lee Schermerhorn | 894bc31 | 2008-10-18 20:26:39 -0700 | [diff] [blame] | 68 | if (PageUnevictable(page)) { |
| 69 | __ClearPageUnevictable(page); |
Hugh Dickins | 4111304 | 2012-01-12 17:20:01 -0800 | [diff] [blame] | 70 | lru = LRU_UNEVICTABLE; |
Lee Schermerhorn | 894bc31 | 2008-10-18 20:26:39 -0700 | [diff] [blame] | 71 | } else { |
Hugh Dickins | 4111304 | 2012-01-12 17:20:01 -0800 | [diff] [blame] | 72 | lru = page_lru_base_type(page); |
Lee Schermerhorn | 894bc31 | 2008-10-18 20:26:39 -0700 | [diff] [blame] | 73 | if (PageActive(page)) { |
| 74 | __ClearPageActive(page); |
Hugh Dickins | 4111304 | 2012-01-12 17:20:01 -0800 | [diff] [blame] | 75 | lru += LRU_ACTIVE; |
Lee Schermerhorn | 894bc31 | 2008-10-18 20:26:39 -0700 | [diff] [blame] | 76 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 77 | } |
Hugh Dickins | 1c1c53d | 2012-01-12 17:20:04 -0800 | [diff] [blame] | 78 | return lru; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 79 | } |
Christoph Lameter | 21eac81 | 2006-01-08 01:00:45 -0800 | [diff] [blame] | 80 | |
Christoph Lameter | b69408e | 2008-10-18 20:26:14 -0700 | [diff] [blame] | 81 | /** |
| 82 | * page_lru - which LRU list should a page be on? |
| 83 | * @page: the page to test |
| 84 | * |
| 85 | * Returns the LRU list a page should be on, as an index |
| 86 | * into the array of LRU lists. |
| 87 | */ |
| 88 | static inline enum lru_list page_lru(struct page *page) |
| 89 | { |
Johannes Weiner | 401a8e1 | 2009-09-21 17:02:58 -0700 | [diff] [blame] | 90 | enum lru_list lru; |
Christoph Lameter | b69408e | 2008-10-18 20:26:14 -0700 | [diff] [blame] | 91 | |
Lee Schermerhorn | 894bc31 | 2008-10-18 20:26:39 -0700 | [diff] [blame] | 92 | if (PageUnevictable(page)) |
| 93 | lru = LRU_UNEVICTABLE; |
| 94 | else { |
Johannes Weiner | 401a8e1 | 2009-09-21 17:02:58 -0700 | [diff] [blame] | 95 | lru = page_lru_base_type(page); |
Lee Schermerhorn | 894bc31 | 2008-10-18 20:26:39 -0700 | [diff] [blame] | 96 | if (PageActive(page)) |
| 97 | lru += LRU_ACTIVE; |
Lee Schermerhorn | 894bc31 | 2008-10-18 20:26:39 -0700 | [diff] [blame] | 98 | } |
Christoph Lameter | b69408e | 2008-10-18 20:26:14 -0700 | [diff] [blame] | 99 | return lru; |
| 100 | } |
Rik van Riel | b2e1853 | 2008-10-18 20:26:30 -0700 | [diff] [blame] | 101 | |
| 102 | #endif |