]>
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 | 22 | static inline void |
71e3aac0 AA |
23 | __add_page_to_lru_list(struct zone *zone, struct page *page, enum lru_list l, |
24 | struct list_head *head) | |
b69408e8 | 25 | { |
71e3aac0 | 26 | list_add(&page->lru, head); |
b69408e8 | 27 | __inc_zone_state(zone, NR_LRU_BASE + l); |
08e552c6 | 28 | mem_cgroup_add_lru_list(page, l); |
b69408e8 CL |
29 | } |
30 | ||
71e3aac0 AA |
31 | static inline void |
32 | add_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 | ||
b69408e8 CL |
37 | static inline void |
38 | del_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); | |
08e552c6 | 42 | mem_cgroup_del_lru_list(page, l); |
b69408e8 CL |
43 | } |
44 | ||
401a8e1c JW |
45 | /** |
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 | */ | |
53 | static 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 | ||
1da177e4 LT |
60 | static inline void |
61 | del_page_from_lru(struct zone *zone, struct page *page) | |
62 | { | |
401a8e1c | 63 | enum lru_list l; |
b69408e8 | 64 | |
1da177e4 | 65 | list_del(&page->lru); |
894bc310 LS |
66 | if (PageUnevictable(page)) { |
67 | __ClearPageUnevictable(page); | |
68 | l = LRU_UNEVICTABLE; | |
69 | } else { | |
401a8e1c | 70 | l = page_lru_base_type(page); |
894bc310 LS |
71 | if (PageActive(page)) { |
72 | __ClearPageActive(page); | |
73 | l += LRU_ACTIVE; | |
74 | } | |
1da177e4 | 75 | } |
b69408e8 | 76 | __dec_zone_state(zone, NR_LRU_BASE + l); |
08e552c6 | 77 | mem_cgroup_del_lru_list(page, l); |
1da177e4 | 78 | } |
21eac81f | 79 | |
b69408e8 CL |
80 | /** |
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 | */ | |
87 | static inline enum lru_list page_lru(struct page *page) | |
88 | { | |
401a8e1c | 89 | enum lru_list lru; |
b69408e8 | 90 | |
894bc310 LS |
91 | if (PageUnevictable(page)) |
92 | lru = LRU_UNEVICTABLE; | |
93 | else { | |
401a8e1c | 94 | lru = page_lru_base_type(page); |
894bc310 LS |
95 | if (PageActive(page)) |
96 | lru += LRU_ACTIVE; | |
894bc310 | 97 | } |
b69408e8 CL |
98 | |
99 | return lru; | |
100 | } | |
b2e18538 RR |
101 | |
102 | #endif |