Files
kernel/include/linux/mm_inline.h
T

108 lines
2.9 KiB
C
Raw Normal View History

/* SPDX-License-Identifier: GPL-2.0 */
2008-10-18 20:26:30 -07:00
#ifndef LINUX_MM_INLINE_H
#define LINUX_MM_INLINE_H
#include <linux/huge_mm.h>
#include <linux/swap.h>
2008-10-18 20:26:30 -07:00
/**
2020-04-06 20:04:41 -07:00
* page_is_file_lru - should the page be on a file LRU or anon LRU?
2008-10-18 20:26:30 -07:00
* @page: the page to test
*
2020-04-06 20:04:41 -07:00
* Returns 1 if @page is a regular filesystem backed page cache page or a lazily
* freed anonymous page (e.g. via MADV_FREE). Returns 0 if @page is a normal
* anonymous page, a tmpfs page or otherwise ram or swap backed page. Used by
* functions that manipulate the LRU lists, to sort a page onto the right LRU
* list.
2008-10-18 20:26:30 -07:00
*
* We would like to get this info without a page flag, but the state
* needs to survive until the page is last deleted from the LRU, which
* could be as far down as __page_cache_release.
*/
2020-04-06 20:04:41 -07:00
static inline int page_is_file_lru(struct page *page)
2008-10-18 20:26:30 -07:00
{
return !PageSwapBacked(page);
2008-10-18 20:26:30 -07:00
}
static __always_inline void update_lru_size(struct lruvec *lruvec,
2016-07-28 15:45:31 -07:00
enum lru_list lru, enum zone_type zid,
int nr_pages)
{
2016-07-28 15:45:31 -07:00
struct pglist_data *pgdat = lruvec_pgdat(lruvec);
__mod_lruvec_state(lruvec, NR_LRU_BASE + lru, nr_pages);
2016-07-28 15:47:26 -07:00
__mod_zone_page_state(&pgdat->node_zones[zid],
NR_ZONE_LRU_BASE + lru, nr_pages);
#ifdef CONFIG_MEMCG
mem_cgroup_update_lru_size(lruvec, lru, zid, nr_pages);
#endif
}
/**
* __clear_page_lru_flags - clear page lru flags before releasing a page
* @page: the page that was on lru and now has a zero reference
*/
static __always_inline void __clear_page_lru_flags(struct page *page)
2005-04-16 15:20:36 -07:00
{
2021-02-24 12:08:32 -08:00
VM_BUG_ON_PAGE(!PageLRU(page), page);
__ClearPageLRU(page);
/* this shouldn't happen, so leave the flags to bad_page() */
if (PageActive(page) && PageUnevictable(page))
return;
__ClearPageActive(page);
__ClearPageUnevictable(page);
2005-04-16 15:20:36 -07:00
}
2006-01-08 01:00:45 -08:00
/**
* page_lru - which LRU list should a page be on?
* @page: the page to test
*
* Returns the LRU list a page should be on, as an index
* into the array of LRU lists.
*/
static __always_inline enum lru_list page_lru(struct page *page)
{
2009-09-21 17:02:58 -07:00
enum lru_list lru;
2021-02-24 12:08:32 -08:00
VM_BUG_ON_PAGE(PageActive(page) && PageUnevictable(page), page);
2008-10-18 20:26:39 -07:00
if (PageUnevictable(page))
return LRU_UNEVICTABLE;
lru = page_is_file_lru(page) ? LRU_INACTIVE_FILE : LRU_INACTIVE_ANON;
if (PageActive(page))
lru += LRU_ACTIVE;
return lru;
}
static __always_inline void add_page_to_lru_list(struct page *page,
struct lruvec *lruvec)
{
enum lru_list lru = page_lru(page);
update_lru_size(lruvec, lru, page_zonenum(page), thp_nr_pages(page));
list_add(&page->lru, &lruvec->lists[lru]);
}
static __always_inline void add_page_to_lru_list_tail(struct page *page,
struct lruvec *lruvec)
{
enum lru_list lru = page_lru(page);
update_lru_size(lruvec, lru, page_zonenum(page), thp_nr_pages(page));
list_add_tail(&page->lru, &lruvec->lists[lru]);
}
static __always_inline void del_page_from_lru_list(struct page *page,
struct lruvec *lruvec)
{
list_del(&page->lru);
update_lru_size(lruvec, page_lru(page), page_zonenum(page),
-thp_nr_pages(page));
}
2008-10-18 20:26:30 -07:00
#endif