blob: 650f31eabdb1ac3a1b24f5ee7f67008237d8e542 [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
Andrea Arcangeli71e3aac2011-01-13 15:46:52 -080023__add_page_to_lru_list(struct zone *zone, struct page *page, enum lru_list l,
24 struct list_head *head)
Christoph Lameterb69408e2008-10-18 20:26:14 -070025{
Andrea Arcangeli71e3aac2011-01-13 15:46:52 -080026 list_add(&page->lru, head);
Christoph Lameterb69408e2008-10-18 20:26:14 -070027 __inc_zone_state(zone, NR_LRU_BASE + l);
KAMEZAWA Hiroyuki08e552c2009-01-07 18:08:01 -080028 mem_cgroup_add_lru_list(page, l);
Christoph Lameterb69408e2008-10-18 20:26:14 -070029}
30
31static inline void
Andrea Arcangeli71e3aac2011-01-13 15:46:52 -080032add_page_to_lru_list(struct zone *zone, struct page *page, enum lru_list l)
33{
34 __add_page_to_lru_list(zone, page, l, &zone->lru[l].list);
35}
36
37static inline void
Christoph Lameterb69408e2008-10-18 20:26:14 -070038del_page_from_lru_list(struct zone *zone, struct page *page, enum lru_list l)
39{
40 list_del(&page->lru);
41 __dec_zone_state(zone, NR_LRU_BASE + l);
KAMEZAWA Hiroyuki08e552c2009-01-07 18:08:01 -080042 mem_cgroup_del_lru_list(page, l);
Christoph Lameterb69408e2008-10-18 20:26:14 -070043}
44
Johannes Weiner401a8e12009-09-21 17:02:58 -070045/**
46 * page_lru_base_type - which LRU list type should a page be on?
47 * @page: the page to test
48 *
49 * Used for LRU list index arithmetic.
50 *
51 * Returns the base LRU type - file or anon - @page should be on.
52 */
53static inline enum lru_list page_lru_base_type(struct page *page)
54{
55 if (page_is_file_cache(page))
56 return LRU_INACTIVE_FILE;
57 return LRU_INACTIVE_ANON;
58}
59
Christoph Lameterb69408e2008-10-18 20:26:14 -070060static inline void
Linus Torvalds1da177e2005-04-16 15:20:36 -070061del_page_from_lru(struct zone *zone, struct page *page)
62{
Johannes Weiner401a8e12009-09-21 17:02:58 -070063 enum lru_list l;
Christoph Lameterb69408e2008-10-18 20:26:14 -070064
Linus Torvalds1da177e2005-04-16 15:20:36 -070065 list_del(&page->lru);
Lee Schermerhorn894bc312008-10-18 20:26:39 -070066 if (PageUnevictable(page)) {
67 __ClearPageUnevictable(page);
68 l = LRU_UNEVICTABLE;
69 } else {
Johannes Weiner401a8e12009-09-21 17:02:58 -070070 l = page_lru_base_type(page);
Lee Schermerhorn894bc312008-10-18 20:26:39 -070071 if (PageActive(page)) {
72 __ClearPageActive(page);
73 l += LRU_ACTIVE;
74 }
Linus Torvalds1da177e2005-04-16 15:20:36 -070075 }
Christoph Lameterb69408e2008-10-18 20:26:14 -070076 __dec_zone_state(zone, NR_LRU_BASE + l);
KAMEZAWA Hiroyuki08e552c2009-01-07 18:08:01 -080077 mem_cgroup_del_lru_list(page, l);
Linus Torvalds1da177e2005-04-16 15:20:36 -070078}
Christoph Lameter21eac812006-01-08 01:00:45 -080079
Christoph Lameterb69408e2008-10-18 20:26:14 -070080/**
81 * page_lru - which LRU list should a page be on?
82 * @page: the page to test
83 *
84 * Returns the LRU list a page should be on, as an index
85 * into the array of LRU lists.
86 */
87static inline enum lru_list page_lru(struct page *page)
88{
Johannes Weiner401a8e12009-09-21 17:02:58 -070089 enum lru_list lru;
Christoph Lameterb69408e2008-10-18 20:26:14 -070090
Lee Schermerhorn894bc312008-10-18 20:26:39 -070091 if (PageUnevictable(page))
92 lru = LRU_UNEVICTABLE;
93 else {
Johannes Weiner401a8e12009-09-21 17:02:58 -070094 lru = page_lru_base_type(page);
Lee Schermerhorn894bc312008-10-18 20:26:39 -070095 if (PageActive(page))
96 lru += LRU_ACTIVE;
Lee Schermerhorn894bc312008-10-18 20:26:39 -070097 }
Christoph Lameterb69408e2008-10-18 20:26:14 -070098
99 return lru;
100}
Rik van Rielb2e18532008-10-18 20:26:30 -0700101
102#endif