blob: 8835b877b8dbefdd57bf8ba4b52fcc25b47662ff [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 *
Johannes Weiner6c0b1352009-09-21 17:02:59 -07008 * Returns 1 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{
Johannes Weiner6c0b1352009-09-21 17:02:59 -070019 return !PageSwapBacked(page);
Rik van Rielb2e18532008-10-18 20:26:30 -070020}
21
Linus Torvalds1da177e2005-04-16 15:20:36 -070022static inline void
Christoph Lameterb69408e2008-10-18 20:26:14 -070023add_page_to_lru_list(struct zone *zone, struct page *page, enum lru_list l)
24{
25 list_add(&page->lru, &zone->lru[l].list);
26 __inc_zone_state(zone, NR_LRU_BASE + l);
KAMEZAWA Hiroyuki08e552c2009-01-07 18:08:01 -080027 mem_cgroup_add_lru_list(page, l);
Christoph Lameterb69408e2008-10-18 20:26:14 -070028}
29
30static inline void
31del_page_from_lru_list(struct zone *zone, struct page *page, enum lru_list l)
32{
33 list_del(&page->lru);
34 __dec_zone_state(zone, NR_LRU_BASE + l);
KAMEZAWA Hiroyuki08e552c2009-01-07 18:08:01 -080035 mem_cgroup_del_lru_list(page, l);
Christoph Lameterb69408e2008-10-18 20:26:14 -070036}
37
Johannes Weiner401a8e12009-09-21 17:02:58 -070038/**
39 * page_lru_base_type - which LRU list type should a page be on?
40 * @page: the page to test
41 *
42 * Used for LRU list index arithmetic.
43 *
44 * Returns the base LRU type - file or anon - @page should be on.
45 */
46static inline enum lru_list page_lru_base_type(struct page *page)
47{
48 if (page_is_file_cache(page))
49 return LRU_INACTIVE_FILE;
50 return LRU_INACTIVE_ANON;
51}
52
Christoph Lameterb69408e2008-10-18 20:26:14 -070053static inline void
Linus Torvalds1da177e2005-04-16 15:20:36 -070054del_page_from_lru(struct zone *zone, struct page *page)
55{
Johannes Weiner401a8e12009-09-21 17:02:58 -070056 enum lru_list l;
Christoph Lameterb69408e2008-10-18 20:26:14 -070057
Linus Torvalds1da177e2005-04-16 15:20:36 -070058 list_del(&page->lru);
Lee Schermerhorn894bc312008-10-18 20:26:39 -070059 if (PageUnevictable(page)) {
60 __ClearPageUnevictable(page);
61 l = LRU_UNEVICTABLE;
62 } else {
Johannes Weiner401a8e12009-09-21 17:02:58 -070063 l = page_lru_base_type(page);
Lee Schermerhorn894bc312008-10-18 20:26:39 -070064 if (PageActive(page)) {
65 __ClearPageActive(page);
66 l += LRU_ACTIVE;
67 }
Linus Torvalds1da177e2005-04-16 15:20:36 -070068 }
Christoph Lameterb69408e2008-10-18 20:26:14 -070069 __dec_zone_state(zone, NR_LRU_BASE + l);
KAMEZAWA Hiroyuki08e552c2009-01-07 18:08:01 -080070 mem_cgroup_del_lru_list(page, l);
Linus Torvalds1da177e2005-04-16 15:20:36 -070071}
Christoph Lameter21eac812006-01-08 01:00:45 -080072
Christoph Lameterb69408e2008-10-18 20:26:14 -070073/**
74 * page_lru - which LRU list should a page be on?
75 * @page: the page to test
76 *
77 * Returns the LRU list a page should be on, as an index
78 * into the array of LRU lists.
79 */
80static inline enum lru_list page_lru(struct page *page)
81{
Johannes Weiner401a8e12009-09-21 17:02:58 -070082 enum lru_list lru;
Christoph Lameterb69408e2008-10-18 20:26:14 -070083
Lee Schermerhorn894bc312008-10-18 20:26:39 -070084 if (PageUnevictable(page))
85 lru = LRU_UNEVICTABLE;
86 else {
Johannes Weiner401a8e12009-09-21 17:02:58 -070087 lru = page_lru_base_type(page);
Lee Schermerhorn894bc312008-10-18 20:26:39 -070088 if (PageActive(page))
89 lru += LRU_ACTIVE;
Lee Schermerhorn894bc312008-10-18 20:26:39 -070090 }
Christoph Lameterb69408e2008-10-18 20:26:14 -070091
92 return lru;
93}
Rik van Rielb2e18532008-10-18 20:26:30 -070094
95#endif