blob: 67d7697fd019107f03766206fa6dd4159430aa6a [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);
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
40static inline void
Rik van Riel4f98a2f2008-10-18 20:26:32 -070041add_page_to_inactive_anon_list(struct zone *zone, struct page *page)
Linus Torvalds1da177e2005-04-16 15:20:36 -070042{
Rik van Riel4f98a2f2008-10-18 20:26:32 -070043 add_page_to_lru_list(zone, page, LRU_INACTIVE_ANON);
Linus Torvalds1da177e2005-04-16 15:20:36 -070044}
45
46static inline void
Rik van Riel4f98a2f2008-10-18 20:26:32 -070047add_page_to_active_anon_list(struct zone *zone, struct page *page)
Linus Torvalds1da177e2005-04-16 15:20:36 -070048{
Rik van Riel4f98a2f2008-10-18 20:26:32 -070049 add_page_to_lru_list(zone, page, LRU_ACTIVE_ANON);
Linus Torvalds1da177e2005-04-16 15:20:36 -070050}
51
52static inline void
Rik van Riel4f98a2f2008-10-18 20:26:32 -070053add_page_to_inactive_file_list(struct zone *zone, struct page *page)
Linus Torvalds1da177e2005-04-16 15:20:36 -070054{
Rik van Riel4f98a2f2008-10-18 20:26:32 -070055 add_page_to_lru_list(zone, page, LRU_INACTIVE_FILE);
Linus Torvalds1da177e2005-04-16 15:20:36 -070056}
57
58static inline void
Rik van Riel4f98a2f2008-10-18 20:26:32 -070059add_page_to_active_file_list(struct zone *zone, struct page *page)
Linus Torvalds1da177e2005-04-16 15:20:36 -070060{
Rik van Riel4f98a2f2008-10-18 20:26:32 -070061 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);
Linus Torvalds1da177e2005-04-16 15:20:36 -070086}
87
88static inline void
89del_page_from_lru(struct zone *zone, struct page *page)
90{
Rik van Riel4f98a2f2008-10-18 20:26:32 -070091 enum lru_list l = LRU_BASE;
Christoph Lameterb69408e2008-10-18 20:26:14 -070092
Linus Torvalds1da177e2005-04-16 15:20:36 -070093 list_del(&page->lru);
Lee Schermerhorn894bc312008-10-18 20:26:39 -070094 if (PageUnevictable(page)) {
95 __ClearPageUnevictable(page);
96 l = LRU_UNEVICTABLE;
97 } else {
98 if (PageActive(page)) {
99 __ClearPageActive(page);
100 l += LRU_ACTIVE;
101 }
102 l += page_is_file_cache(page);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700103 }
Christoph Lameterb69408e2008-10-18 20:26:14 -0700104 __dec_zone_state(zone, NR_LRU_BASE + l);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700105}
Christoph Lameter21eac812006-01-08 01:00:45 -0800106
Christoph Lameterb69408e2008-10-18 20:26:14 -0700107/**
108 * page_lru - which LRU list should a page be on?
109 * @page: the page to test
110 *
111 * Returns the LRU list a page should be on, as an index
112 * into the array of LRU lists.
113 */
114static inline enum lru_list page_lru(struct page *page)
115{
116 enum lru_list lru = LRU_BASE;
117
Lee Schermerhorn894bc312008-10-18 20:26:39 -0700118 if (PageUnevictable(page))
119 lru = LRU_UNEVICTABLE;
120 else {
121 if (PageActive(page))
122 lru += LRU_ACTIVE;
123 lru += page_is_file_cache(page);
124 }
Christoph Lameterb69408e2008-10-18 20:26:14 -0700125
126 return lru;
127}
Rik van Rielb2e18532008-10-18 20:26:30 -0700128
Rik van Riel556adec2008-10-18 20:26:34 -0700129/**
130 * inactive_anon_is_low - check if anonymous pages need to be deactivated
131 * @zone: zone to check
132 *
133 * Returns true if the zone does not have enough inactive anon pages,
134 * meaning some active anon pages need to be deactivated.
135 */
136static inline int inactive_anon_is_low(struct zone *zone)
137{
138 unsigned long active, inactive;
139
140 active = zone_page_state(zone, NR_ACTIVE_ANON);
141 inactive = zone_page_state(zone, NR_INACTIVE_ANON);
142
143 if (inactive * zone->inactive_ratio < active)
144 return 1;
145
146 return 0;
147}
Rik van Rielb2e18532008-10-18 20:26:30 -0700148#endif