Commit | Line | Data |
---|---|---|
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 | * | |
6c0b1351 | 8 | * Returns 1 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 | */ | |
17 | static inline int page_is_file_cache(struct page *page) | |
18 | { | |
6c0b1351 | 19 | return !PageSwapBacked(page); |
b2e18538 RR |
20 | } |
21 | ||
b69408e8 CL |
22 | static inline void |
23 | add_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); | |
08e552c6 | 27 | mem_cgroup_add_lru_list(page, l); |
b69408e8 CL |
28 | } |
29 | ||
30 | static inline void | |
31 | del_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); | |
08e552c6 | 35 | mem_cgroup_del_lru_list(page, l); |
b69408e8 CL |
36 | } |
37 | ||
401a8e1c JW |
38 | /** |
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 | */ | |
46 | static 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 | ||
1da177e4 LT |
53 | static inline void |
54 | del_page_from_lru(struct zone *zone, struct page *page) | |
55 | { | |
401a8e1c | 56 | enum lru_list l; |
b69408e8 | 57 | |
1da177e4 | 58 | list_del(&page->lru); |
894bc310 LS |
59 | if (PageUnevictable(page)) { |
60 | __ClearPageUnevictable(page); | |
61 | l = LRU_UNEVICTABLE; | |
62 | } else { | |
401a8e1c | 63 | l = page_lru_base_type(page); |
894bc310 LS |
64 | if (PageActive(page)) { |
65 | __ClearPageActive(page); | |
66 | l += LRU_ACTIVE; | |
67 | } | |
1da177e4 | 68 | } |
b69408e8 | 69 | __dec_zone_state(zone, NR_LRU_BASE + l); |
08e552c6 | 70 | mem_cgroup_del_lru_list(page, l); |
1da177e4 | 71 | } |
21eac81f | 72 | |
b69408e8 CL |
73 | /** |
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 | */ | |
80 | static inline enum lru_list page_lru(struct page *page) | |
81 | { | |
401a8e1c | 82 | enum lru_list lru; |
b69408e8 | 83 | |
894bc310 LS |
84 | if (PageUnevictable(page)) |
85 | lru = LRU_UNEVICTABLE; | |
86 | else { | |
401a8e1c | 87 | lru = page_lru_base_type(page); |
894bc310 LS |
88 | if (PageActive(page)) |
89 | lru += LRU_ACTIVE; | |
894bc310 | 90 | } |
b69408e8 CL |
91 | |
92 | return lru; | |
93 | } | |
b2e18538 RR |
94 | |
95 | #endif |