]> git.proxmox.com Git - mirror_ubuntu-eoan-kernel.git/blob - include/linux/mm_inline.h
thp: transparent hugepage core
[mirror_ubuntu-eoan-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 1 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 return !PageSwapBacked(page);
20 }
21
22 static inline void
23 __add_page_to_lru_list(struct zone *zone, struct page *page, enum lru_list l,
24 struct list_head *head)
25 {
26 list_add(&page->lru, head);
27 __inc_zone_state(zone, NR_LRU_BASE + l);
28 mem_cgroup_add_lru_list(page, l);
29 }
30
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
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);
42 mem_cgroup_del_lru_list(page, l);
43 }
44
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
60 static inline void
61 del_page_from_lru(struct zone *zone, struct page *page)
62 {
63 enum lru_list l;
64
65 list_del(&page->lru);
66 if (PageUnevictable(page)) {
67 __ClearPageUnevictable(page);
68 l = LRU_UNEVICTABLE;
69 } else {
70 l = page_lru_base_type(page);
71 if (PageActive(page)) {
72 __ClearPageActive(page);
73 l += LRU_ACTIVE;
74 }
75 }
76 __dec_zone_state(zone, NR_LRU_BASE + l);
77 mem_cgroup_del_lru_list(page, l);
78 }
79
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 {
89 enum lru_list lru;
90
91 if (PageUnevictable(page))
92 lru = LRU_UNEVICTABLE;
93 else {
94 lru = page_lru_base_type(page);
95 if (PageActive(page))
96 lru += LRU_ACTIVE;
97 }
98
99 return lru;
100 }
101
102 #endif