1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef LINUX_MM_INLINE_H
3 #define LINUX_MM_INLINE_H
5 #include <linux/huge_mm.h>
6 #include <linux/swap.h>
9 * page_is_file_lru - should the page be on a file LRU or anon LRU?
10 * @page: the page to test
12 * Returns 1 if @page is a regular filesystem backed page cache page or a lazily
13 * freed anonymous page (e.g. via MADV_FREE). Returns 0 if @page is a normal
14 * anonymous page, a tmpfs page or otherwise ram or swap backed page. Used by
15 * functions that manipulate the LRU lists, to sort a page onto the right LRU
18 * We would like to get this info without a page flag, but the state
19 * needs to survive until the page is last deleted from the LRU, which
20 * could be as far down as __page_cache_release.
22 static inline int page_is_file_lru(struct page *page)
24 return !PageSwapBacked(page);
27 static __always_inline void __update_lru_size(struct lruvec *lruvec,
28 enum lru_list lru, enum zone_type zid,
31 struct pglist_data *pgdat = lruvec_pgdat(lruvec);
33 __mod_lruvec_state(lruvec, NR_LRU_BASE + lru, nr_pages);
34 __mod_zone_page_state(&pgdat->node_zones[zid],
35 NR_ZONE_LRU_BASE + lru, nr_pages);
38 static __always_inline void update_lru_size(struct lruvec *lruvec,
39 enum lru_list lru, enum zone_type zid,
42 __update_lru_size(lruvec, lru, zid, nr_pages);
44 mem_cgroup_update_lru_size(lruvec, lru, zid, nr_pages);
49 * page_lru_base_type - which LRU list type should a page be on?
50 * @page: the page to test
52 * Used for LRU list index arithmetic.
54 * Returns the base LRU type - file or anon - @page should be on.
56 static inline enum lru_list page_lru_base_type(struct page *page)
58 if (page_is_file_lru(page))
59 return LRU_INACTIVE_FILE;
60 return LRU_INACTIVE_ANON;
64 * __clear_page_lru_flags - clear page lru flags before releasing a page
65 * @page: the page that was on lru and now has a zero reference
67 static __always_inline void __clear_page_lru_flags(struct page *page)
69 VM_BUG_ON_PAGE(!PageLRU(page), page);
73 /* this shouldn't happen, so leave the flags to bad_page() */
74 if (PageActive(page) && PageUnevictable(page))
77 __ClearPageActive(page);
78 __ClearPageUnevictable(page);
82 * page_lru - which LRU list should a page be on?
83 * @page: the page to test
85 * Returns the LRU list a page should be on, as an index
86 * into the array of LRU lists.
88 static __always_inline enum lru_list page_lru(struct page *page)
92 VM_BUG_ON_PAGE(PageActive(page) && PageUnevictable(page), page);
94 if (PageUnevictable(page))
95 lru = LRU_UNEVICTABLE;
97 lru = page_lru_base_type(page);
104 static __always_inline void add_page_to_lru_list(struct page *page,
105 struct lruvec *lruvec)
107 enum lru_list lru = page_lru(page);
109 update_lru_size(lruvec, lru, page_zonenum(page), thp_nr_pages(page));
110 list_add(&page->lru, &lruvec->lists[lru]);
113 static __always_inline void add_page_to_lru_list_tail(struct page *page,
114 struct lruvec *lruvec)
116 enum lru_list lru = page_lru(page);
118 update_lru_size(lruvec, lru, page_zonenum(page), thp_nr_pages(page));
119 list_add_tail(&page->lru, &lruvec->lists[lru]);
122 static __always_inline void del_page_from_lru_list(struct page *page,
123 struct lruvec *lruvec)
125 list_del(&page->lru);
126 update_lru_size(lruvec, page_lru(page), page_zonenum(page),
127 -thp_nr_pages(page));