vmscan: split LRU lists into anon & file sets
[linux-2.6-block.git] / include / linux / mm_inline.h
CommitLineData
b2e18538
RR
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 *
4f98a2fe 8 * Returns LRU_FILE if @page is page cache page backed by a regular filesystem,
b2e18538
RR
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 */
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. */
4f98a2fe 23 return LRU_FILE;
b2e18538
RR
24}
25
b69408e8
CL
26static inline void
27add_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
33static inline void
34del_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
1da177e4 40static inline void
4f98a2fe 41add_page_to_inactive_anon_list(struct zone *zone, struct page *page)
1da177e4 42{
4f98a2fe 43 add_page_to_lru_list(zone, page, LRU_INACTIVE_ANON);
1da177e4
LT
44}
45
46static inline void
4f98a2fe 47add_page_to_active_anon_list(struct zone *zone, struct page *page)
1da177e4 48{
4f98a2fe 49 add_page_to_lru_list(zone, page, LRU_ACTIVE_ANON);
1da177e4
LT
50}
51
52static inline void
4f98a2fe 53add_page_to_inactive_file_list(struct zone *zone, struct page *page)
1da177e4 54{
4f98a2fe 55 add_page_to_lru_list(zone, page, LRU_INACTIVE_FILE);
1da177e4
LT
56}
57
58static inline void
4f98a2fe 59add_page_to_active_file_list(struct zone *zone, struct page *page)
1da177e4 60{
4f98a2fe
RR
61 add_page_to_lru_list(zone, page, LRU_ACTIVE_FILE);
62}
63
64static inline void
65del_page_from_inactive_anon_list(struct zone *zone, struct page *page)
66{
67 del_page_from_lru_list(zone, page, LRU_INACTIVE_ANON);
68}
69
70static inline void
71del_page_from_active_anon_list(struct zone *zone, struct page *page)
72{
73 del_page_from_lru_list(zone, page, LRU_ACTIVE_ANON);
74}
75
76static inline void
77del_page_from_inactive_file_list(struct zone *zone, struct page *page)
78{
79 del_page_from_lru_list(zone, page, LRU_INACTIVE_FILE);
80}
81
82static inline void
83del_page_from_active_file_list(struct zone *zone, struct page *page)
84{
85 del_page_from_lru_list(zone, page, LRU_INACTIVE_FILE);
1da177e4
LT
86}
87
88static inline void
89del_page_from_lru(struct zone *zone, struct page *page)
90{
4f98a2fe 91 enum lru_list l = LRU_BASE;
b69408e8 92
1da177e4
LT
93 list_del(&page->lru);
94 if (PageActive(page)) {
67453911 95 __ClearPageActive(page);
4f98a2fe 96 l += LRU_ACTIVE;
1da177e4 97 }
4f98a2fe 98 l += page_is_file_cache(page);
b69408e8 99 __dec_zone_state(zone, NR_LRU_BASE + l);
1da177e4 100}
21eac81f 101
b69408e8
CL
102/**
103 * page_lru - which LRU list should a page be on?
104 * @page: the page to test
105 *
106 * Returns the LRU list a page should be on, as an index
107 * into the array of LRU lists.
108 */
109static inline enum lru_list page_lru(struct page *page)
110{
111 enum lru_list lru = LRU_BASE;
112
113 if (PageActive(page))
114 lru += LRU_ACTIVE;
4f98a2fe 115 lru += page_is_file_cache(page);
b69408e8
CL
116
117 return lru;
118}
b2e18538
RR
119
120#endif