mm: introduce page_lru_base_type()
[pandora-kernel.git] / include / linux / mm_inline.h
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  *
8  * Returns LRU_FILE if @page is page cache page backed by a regular filesystem,
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. */
23         return LRU_FILE;
24 }
25
26 static inline void
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         mem_cgroup_add_lru_list(page, l);
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);
39         mem_cgroup_del_lru_list(page, l);
40 }
41
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
57 static inline void
58 del_page_from_lru(struct zone *zone, struct page *page)
59 {
60         enum lru_list l;
61
62         list_del(&page->lru);
63         if (PageUnevictable(page)) {
64                 __ClearPageUnevictable(page);
65                 l = LRU_UNEVICTABLE;
66         } else {
67                 l = page_lru_base_type(page);
68                 if (PageActive(page)) {
69                         __ClearPageActive(page);
70                         l += LRU_ACTIVE;
71                 }
72         }
73         __dec_zone_state(zone, NR_LRU_BASE + l);
74         mem_cgroup_del_lru_list(page, l);
75 }
76
77 /**
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  */
84 static inline enum lru_list page_lru(struct page *page)
85 {
86         enum lru_list lru;
87
88         if (PageUnevictable(page))
89                 lru = LRU_UNEVICTABLE;
90         else {
91                 lru = page_lru_base_type(page);
92                 if (PageActive(page))
93                         lru += LRU_ACTIVE;
94         }
95
96         return lru;
97 }
98
99 #endif