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); |
| 31 | } |
| 32 | |
| 33 | static inline void |
| 34 | del_page_from_lru_list(struct zone *zone, struct page *page, enum lru_list l) |
| 35 | { |
| 36 | list_del(&page->lru); |
| 37 | __dec_zone_state(zone, NR_LRU_BASE + l); |
| 38 | } |
| 39 | |
| 40 | static inline void |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 41 | del_page_from_lru(struct zone *zone, struct page *page) |
| 42 | { |
Rik van Riel | 4f98a2f | 2008-10-18 20:26:32 -0700 | [diff] [blame] | 43 | enum lru_list l = LRU_BASE; |
Christoph Lameter | b69408e | 2008-10-18 20:26:14 -0700 | [diff] [blame] | 44 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 45 | list_del(&page->lru); |
Lee Schermerhorn | 894bc31 | 2008-10-18 20:26:39 -0700 | [diff] [blame] | 46 | if (PageUnevictable(page)) { |
| 47 | __ClearPageUnevictable(page); |
| 48 | l = LRU_UNEVICTABLE; |
| 49 | } else { |
| 50 | if (PageActive(page)) { |
| 51 | __ClearPageActive(page); |
| 52 | l += LRU_ACTIVE; |
| 53 | } |
| 54 | l += page_is_file_cache(page); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 55 | } |
Christoph Lameter | b69408e | 2008-10-18 20:26:14 -0700 | [diff] [blame] | 56 | __dec_zone_state(zone, NR_LRU_BASE + l); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 57 | } |
Christoph Lameter | 21eac81 | 2006-01-08 01:00:45 -0800 | [diff] [blame] | 58 | |
Christoph Lameter | b69408e | 2008-10-18 20:26:14 -0700 | [diff] [blame] | 59 | /** |
| 60 | * page_lru - which LRU list should a page be on? |
| 61 | * @page: the page to test |
| 62 | * |
| 63 | * Returns the LRU list a page should be on, as an index |
| 64 | * into the array of LRU lists. |
| 65 | */ |
| 66 | static inline enum lru_list page_lru(struct page *page) |
| 67 | { |
| 68 | enum lru_list lru = LRU_BASE; |
| 69 | |
Lee Schermerhorn | 894bc31 | 2008-10-18 20:26:39 -0700 | [diff] [blame] | 70 | if (PageUnevictable(page)) |
| 71 | lru = LRU_UNEVICTABLE; |
| 72 | else { |
| 73 | if (PageActive(page)) |
| 74 | lru += LRU_ACTIVE; |
| 75 | lru += page_is_file_cache(page); |
| 76 | } |
Christoph Lameter | b69408e | 2008-10-18 20:26:14 -0700 | [diff] [blame] | 77 | |
| 78 | return lru; |
| 79 | } |
Rik van Riel | b2e1853 | 2008-10-18 20:26:30 -0700 | [diff] [blame] | 80 | |
Rik van Riel | 556adec | 2008-10-18 20:26:34 -0700 | [diff] [blame] | 81 | /** |
| 82 | * inactive_anon_is_low - check if anonymous pages need to be deactivated |
| 83 | * @zone: zone to check |
| 84 | * |
| 85 | * Returns true if the zone does not have enough inactive anon pages, |
| 86 | * meaning some active anon pages need to be deactivated. |
| 87 | */ |
| 88 | static inline int inactive_anon_is_low(struct zone *zone) |
| 89 | { |
| 90 | unsigned long active, inactive; |
| 91 | |
| 92 | active = zone_page_state(zone, NR_ACTIVE_ANON); |
| 93 | inactive = zone_page_state(zone, NR_INACTIVE_ANON); |
| 94 | |
| 95 | if (inactive * zone->inactive_ratio < active) |
| 96 | return 1; |
| 97 | |
| 98 | return 0; |
| 99 | } |
Rik van Riel | b2e1853 | 2008-10-18 20:26:30 -0700 | [diff] [blame] | 100 | #endif |