Commit | Line | Data |
---|---|---|
b2e18538 RR |
1 | #ifndef LINUX_MM_INLINE_H |
2 | #define LINUX_MM_INLINE_H | |
3 | ||
2c888cfb RR |
4 | #include <linux/huge_mm.h> |
5 | ||
b2e18538 RR |
6 | /** |
7 | * page_is_file_cache - should the page be on a file LRU or anon LRU? | |
8 | * @page: the page to test | |
9 | * | |
6c0b1351 | 10 | * Returns 1 if @page is page cache page backed by a regular filesystem, |
b2e18538 RR |
11 | * or 0 if @page is anonymous, tmpfs or otherwise ram or swap backed. |
12 | * Used by functions that manipulate the LRU lists, to sort a page | |
13 | * onto the right LRU list. | |
14 | * | |
15 | * We would like to get this info without a page flag, but the state | |
16 | * needs to survive until the page is last deleted from the LRU, which | |
17 | * could be as far down as __page_cache_release. | |
18 | */ | |
19 | static inline int page_is_file_cache(struct page *page) | |
20 | { | |
6c0b1351 | 21 | return !PageSwapBacked(page); |
b2e18538 RR |
22 | } |
23 | ||
b69408e8 | 24 | static inline void |
71e3aac0 AA |
25 | __add_page_to_lru_list(struct zone *zone, struct page *page, enum lru_list l, |
26 | struct list_head *head) | |
b69408e8 | 27 | { |
71e3aac0 | 28 | list_add(&page->lru, head); |
2c888cfb | 29 | __mod_zone_page_state(zone, NR_LRU_BASE + l, hpage_nr_pages(page)); |
08e552c6 | 30 | mem_cgroup_add_lru_list(page, l); |
b69408e8 CL |
31 | } |
32 | ||
71e3aac0 AA |
33 | static inline void |
34 | add_page_to_lru_list(struct zone *zone, struct page *page, enum lru_list l) | |
35 | { | |
36 | __add_page_to_lru_list(zone, page, l, &zone->lru[l].list); | |
37 | } | |
38 | ||
b69408e8 CL |
39 | static inline void |
40 | del_page_from_lru_list(struct zone *zone, struct page *page, enum lru_list l) | |
41 | { | |
42 | list_del(&page->lru); | |
2c888cfb | 43 | __mod_zone_page_state(zone, NR_LRU_BASE + l, -hpage_nr_pages(page)); |
08e552c6 | 44 | mem_cgroup_del_lru_list(page, l); |
b69408e8 CL |
45 | } |
46 | ||
401a8e1c JW |
47 | /** |
48 | * page_lru_base_type - which LRU list type should a page be on? | |
49 | * @page: the page to test | |
50 | * | |
51 | * Used for LRU list index arithmetic. | |
52 | * | |
53 | * Returns the base LRU type - file or anon - @page should be on. | |
54 | */ | |
55 | static inline enum lru_list page_lru_base_type(struct page *page) | |
56 | { | |
57 | if (page_is_file_cache(page)) | |
58 | return LRU_INACTIVE_FILE; | |
59 | return LRU_INACTIVE_ANON; | |
60 | } | |
61 | ||
1da177e4 LT |
62 | static inline void |
63 | del_page_from_lru(struct zone *zone, struct page *page) | |
64 | { | |
401a8e1c | 65 | enum lru_list l; |
b69408e8 | 66 | |
1da177e4 | 67 | list_del(&page->lru); |
894bc310 LS |
68 | if (PageUnevictable(page)) { |
69 | __ClearPageUnevictable(page); | |
70 | l = LRU_UNEVICTABLE; | |
71 | } else { | |
401a8e1c | 72 | l = page_lru_base_type(page); |
894bc310 LS |
73 | if (PageActive(page)) { |
74 | __ClearPageActive(page); | |
75 | l += LRU_ACTIVE; | |
76 | } | |
1da177e4 | 77 | } |
2c888cfb | 78 | __mod_zone_page_state(zone, NR_LRU_BASE + l, -hpage_nr_pages(page)); |
08e552c6 | 79 | mem_cgroup_del_lru_list(page, l); |
1da177e4 | 80 | } |
21eac81f | 81 | |
b69408e8 CL |
82 | /** |
83 | * page_lru - which LRU list should a page be on? | |
84 | * @page: the page to test | |
85 | * | |
86 | * Returns the LRU list a page should be on, as an index | |
87 | * into the array of LRU lists. | |
88 | */ | |
89 | static inline enum lru_list page_lru(struct page *page) | |
90 | { | |
401a8e1c | 91 | enum lru_list lru; |
b69408e8 | 92 | |
894bc310 LS |
93 | if (PageUnevictable(page)) |
94 | lru = LRU_UNEVICTABLE; | |
95 | else { | |
401a8e1c | 96 | lru = page_lru_base_type(page); |
894bc310 LS |
97 | if (PageActive(page)) |
98 | lru += LRU_ACTIVE; | |
894bc310 | 99 | } |
b69408e8 CL |
100 | |
101 | return lru; | |
102 | } | |
b2e18538 RR |
103 | |
104 | #endif |