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 | ||
fa9add64 HD |
24 | static __always_inline void add_page_to_lru_list(struct page *page, |
25 | struct lruvec *lruvec, enum lru_list lru) | |
71e3aac0 | 26 | { |
fa9add64 HD |
27 | int nr_pages = hpage_nr_pages(page); |
28 | mem_cgroup_update_lru_size(lruvec, lru, nr_pages); | |
4111304d | 29 | list_add(&page->lru, &lruvec->lists[lru]); |
fa9add64 | 30 | __mod_zone_page_state(lruvec_zone(lruvec), NR_LRU_BASE + lru, nr_pages); |
71e3aac0 AA |
31 | } |
32 | ||
fa9add64 HD |
33 | static __always_inline void del_page_from_lru_list(struct page *page, |
34 | struct lruvec *lruvec, enum lru_list lru) | |
b69408e8 | 35 | { |
fa9add64 HD |
36 | int nr_pages = hpage_nr_pages(page); |
37 | mem_cgroup_update_lru_size(lruvec, lru, -nr_pages); | |
b69408e8 | 38 | list_del(&page->lru); |
fa9add64 | 39 | __mod_zone_page_state(lruvec_zone(lruvec), NR_LRU_BASE + lru, -nr_pages); |
b69408e8 CL |
40 | } |
41 | ||
401a8e1c JW |
42 | /** |
43 | * page_lru_base_type - which LRU list type should a page be on? | |
44 | * @page: the page to test | |
45 | * | |
46 | * Used for LRU list index arithmetic. | |
47 | * | |
48 | * Returns the base LRU type - file or anon - @page should be on. | |
49 | */ | |
50 | static inline enum lru_list page_lru_base_type(struct page *page) | |
51 | { | |
52 | if (page_is_file_cache(page)) | |
53 | return LRU_INACTIVE_FILE; | |
54 | return LRU_INACTIVE_ANON; | |
55 | } | |
56 | ||
1c1c53d4 HD |
57 | /** |
58 | * page_off_lru - which LRU list was page on? clearing its lru flags. | |
59 | * @page: the page to test | |
60 | * | |
61 | * Returns the LRU list a page was on, as an index into the array of LRU | |
62 | * lists; and clears its Unevictable or Active flags, ready for freeing. | |
63 | */ | |
014483bc | 64 | static __always_inline enum lru_list page_off_lru(struct page *page) |
1da177e4 | 65 | { |
4111304d | 66 | enum lru_list lru; |
b69408e8 | 67 | |
894bc310 LS |
68 | if (PageUnevictable(page)) { |
69 | __ClearPageUnevictable(page); | |
4111304d | 70 | lru = LRU_UNEVICTABLE; |
894bc310 | 71 | } else { |
4111304d | 72 | lru = page_lru_base_type(page); |
894bc310 LS |
73 | if (PageActive(page)) { |
74 | __ClearPageActive(page); | |
4111304d | 75 | lru += LRU_ACTIVE; |
894bc310 | 76 | } |
1da177e4 | 77 | } |
1c1c53d4 | 78 | return lru; |
1da177e4 | 79 | } |
21eac81f | 80 | |
b69408e8 CL |
81 | /** |
82 | * page_lru - which LRU list should a page be on? | |
83 | * @page: the page to test | |
84 | * | |
85 | * Returns the LRU list a page should be on, as an index | |
86 | * into the array of LRU lists. | |
87 | */ | |
014483bc | 88 | static __always_inline enum lru_list page_lru(struct page *page) |
b69408e8 | 89 | { |
401a8e1c | 90 | enum lru_list lru; |
b69408e8 | 91 | |
894bc310 LS |
92 | if (PageUnevictable(page)) |
93 | lru = LRU_UNEVICTABLE; | |
94 | else { | |
401a8e1c | 95 | lru = page_lru_base_type(page); |
894bc310 LS |
96 | if (PageActive(page)) |
97 | lru += LRU_ACTIVE; | |
894bc310 | 98 | } |
b69408e8 CL |
99 | return lru; |
100 | } | |
b2e18538 RR |
101 | |
102 | #endif |