blob: 99977ff45b83721eeb6de7fe0c6f7098be93f0d7 [file] [log] [blame]
Rik van Rielb2e18532008-10-18 20:26:30 -07001#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 Riel4f98a2f2008-10-18 20:26:32 -07008 * Returns LRU_FILE if @page is page cache page backed by a regular filesystem,
Rik van Rielb2e18532008-10-18 20:26:30 -07009 * 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 */
17static 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 Riel4f98a2f2008-10-18 20:26:32 -070023 return LRU_FILE;
Rik van Rielb2e18532008-10-18 20:26:30 -070024}
25
Linus Torvalds1da177e2005-04-16 15:20:36 -070026static inline void
Christoph Lameterb69408e2008-10-18 20:26:14 -070027add_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 Hiroyuki08e552c2009-01-07 18:08:01 -080031 mem_cgroup_add_lru_list(page, l);
Christoph Lameterb69408e2008-10-18 20:26:14 -070032}
33
34static inline void
35del_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 Hiroyuki08e552c2009-01-07 18:08:01 -080039 mem_cgroup_del_lru_list(page, l);
Christoph Lameterb69408e2008-10-18 20:26:14 -070040}
41
Johannes Weiner401a8e12009-09-21 17:02:58 -070042/**
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 */
50static 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
Christoph Lameterb69408e2008-10-18 20:26:14 -070057static inline void
Linus Torvalds1da177e2005-04-16 15:20:36 -070058del_page_from_lru(struct zone *zone, struct page *page)
59{
Johannes Weiner401a8e12009-09-21 17:02:58 -070060 enum lru_list l;
Christoph Lameterb69408e2008-10-18 20:26:14 -070061
Linus Torvalds1da177e2005-04-16 15:20:36 -070062 list_del(&page->lru);
Lee Schermerhorn894bc312008-10-18 20:26:39 -070063 if (PageUnevictable(page)) {
64 __ClearPageUnevictable(page);
65 l = LRU_UNEVICTABLE;
66 } else {
Johannes Weiner401a8e12009-09-21 17:02:58 -070067 l = page_lru_base_type(page);
Lee Schermerhorn894bc312008-10-18 20:26:39 -070068 if (PageActive(page)) {
69 __ClearPageActive(page);
70 l += LRU_ACTIVE;
71 }
Linus Torvalds1da177e2005-04-16 15:20:36 -070072 }
Christoph Lameterb69408e2008-10-18 20:26:14 -070073 __dec_zone_state(zone, NR_LRU_BASE + l);
KAMEZAWA Hiroyuki08e552c2009-01-07 18:08:01 -080074 mem_cgroup_del_lru_list(page, l);
Linus Torvalds1da177e2005-04-16 15:20:36 -070075}
Christoph Lameter21eac812006-01-08 01:00:45 -080076
Christoph Lameterb69408e2008-10-18 20:26:14 -070077/**
78 * page_lru - which LRU list should a page be on?
79 * @page: the page to test
80 *
81 * Returns the LRU list a page should be on, as an index
82 * into the array of LRU lists.
83 */
84static inline enum lru_list page_lru(struct page *page)
85{
Johannes Weiner401a8e12009-09-21 17:02:58 -070086 enum lru_list lru;
Christoph Lameterb69408e2008-10-18 20:26:14 -070087
Lee Schermerhorn894bc312008-10-18 20:26:39 -070088 if (PageUnevictable(page))
89 lru = LRU_UNEVICTABLE;
90 else {
Johannes Weiner401a8e12009-09-21 17:02:58 -070091 lru = page_lru_base_type(page);
Lee Schermerhorn894bc312008-10-18 20:26:39 -070092 if (PageActive(page))
93 lru += LRU_ACTIVE;
Lee Schermerhorn894bc312008-10-18 20:26:39 -070094 }
Christoph Lameterb69408e2008-10-18 20:26:14 -070095
96 return lru;
97}
Rik van Rielb2e18532008-10-18 20:26:30 -070098
99#endif