]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/blob - include/linux/mm_inline.h
vmscan: second chance replacement for anonymous pages
[mirror_ubuntu-bionic-kernel.git] / include / linux / mm_inline.h
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 *
8 * Returns LRU_FILE if @page is page cache page backed by a regular filesystem,
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 {
19 if (PageSwapBacked(page))
20 return 0;
21
22 /* The page is page cache backed by a normal filesystem. */
23 return LRU_FILE;
24 }
25
26 static inline void
27 add_page_to_lru_list(struct zone *zone, struct page *page, enum lru_list l)
28 {
29 list_add(&page->lru, &zone->lru[l].list);
30 __inc_zone_state(zone, NR_LRU_BASE + l);
31 }
32
33 static inline void
34 del_page_from_lru_list(struct zone *zone, struct page *page, enum lru_list l)
35 {
36 list_del(&page->lru);
37 __dec_zone_state(zone, NR_LRU_BASE + l);
38 }
39
40 static inline void
41 add_page_to_inactive_anon_list(struct zone *zone, struct page *page)
42 {
43 add_page_to_lru_list(zone, page, LRU_INACTIVE_ANON);
44 }
45
46 static inline void
47 add_page_to_active_anon_list(struct zone *zone, struct page *page)
48 {
49 add_page_to_lru_list(zone, page, LRU_ACTIVE_ANON);
50 }
51
52 static inline void
53 add_page_to_inactive_file_list(struct zone *zone, struct page *page)
54 {
55 add_page_to_lru_list(zone, page, LRU_INACTIVE_FILE);
56 }
57
58 static inline void
59 add_page_to_active_file_list(struct zone *zone, struct page *page)
60 {
61 add_page_to_lru_list(zone, page, LRU_ACTIVE_FILE);
62 }
63
64 static inline void
65 del_page_from_inactive_anon_list(struct zone *zone, struct page *page)
66 {
67 del_page_from_lru_list(zone, page, LRU_INACTIVE_ANON);
68 }
69
70 static inline void
71 del_page_from_active_anon_list(struct zone *zone, struct page *page)
72 {
73 del_page_from_lru_list(zone, page, LRU_ACTIVE_ANON);
74 }
75
76 static inline void
77 del_page_from_inactive_file_list(struct zone *zone, struct page *page)
78 {
79 del_page_from_lru_list(zone, page, LRU_INACTIVE_FILE);
80 }
81
82 static inline void
83 del_page_from_active_file_list(struct zone *zone, struct page *page)
84 {
85 del_page_from_lru_list(zone, page, LRU_INACTIVE_FILE);
86 }
87
88 static inline void
89 del_page_from_lru(struct zone *zone, struct page *page)
90 {
91 enum lru_list l = LRU_BASE;
92
93 list_del(&page->lru);
94 if (PageActive(page)) {
95 __ClearPageActive(page);
96 l += LRU_ACTIVE;
97 }
98 l += page_is_file_cache(page);
99 __dec_zone_state(zone, NR_LRU_BASE + l);
100 }
101
102 /**
103 * page_lru - which LRU list should a page be on?
104 * @page: the page to test
105 *
106 * Returns the LRU list a page should be on, as an index
107 * into the array of LRU lists.
108 */
109 static inline enum lru_list page_lru(struct page *page)
110 {
111 enum lru_list lru = LRU_BASE;
112
113 if (PageActive(page))
114 lru += LRU_ACTIVE;
115 lru += page_is_file_cache(page);
116
117 return lru;
118 }
119
120 /**
121 * inactive_anon_is_low - check if anonymous pages need to be deactivated
122 * @zone: zone to check
123 *
124 * Returns true if the zone does not have enough inactive anon pages,
125 * meaning some active anon pages need to be deactivated.
126 */
127 static inline int inactive_anon_is_low(struct zone *zone)
128 {
129 unsigned long active, inactive;
130
131 active = zone_page_state(zone, NR_ACTIVE_ANON);
132 inactive = zone_page_state(zone, NR_INACTIVE_ANON);
133
134 if (inactive * zone->inactive_ratio < active)
135 return 1;
136
137 return 0;
138 }
139 #endif