Commit 401a8e1c authored by Johannes Weiner's avatar Johannes Weiner Committed by Linus Torvalds

mm: introduce page_lru_base_type()

Instead of abusing page_is_file_cache() for LRU list index arithmetic, add
another helper with a more appropriate name and convert the non-boolean
users of page_is_file_cache() accordingly.

This new helper gives the LRU base type a page is supposed to live on,
inactive anon or inactive file.

[hugh.dickins@tiscali.co.uk: convert del_page_from_lru() also]
Signed-off-by: default avatarJohannes Weiner <hannes@cmpxchg.org>
Reviewed-by: default avatarRik van Riel <riel@redhat.com>
Cc: Minchan Kim <minchan.kim@gmail.com>
Reviewed-by: default avatarKOSAKI Motohiro <kosaki.motohiro@jp.fujitsu.com>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent b7c46d15
...@@ -39,21 +39,36 @@ del_page_from_lru_list(struct zone *zone, struct page *page, enum lru_list l) ...@@ -39,21 +39,36 @@ del_page_from_lru_list(struct zone *zone, struct page *page, enum lru_list l)
mem_cgroup_del_lru_list(page, l); mem_cgroup_del_lru_list(page, l);
} }
/**
* page_lru_base_type - which LRU list type should a page be on?
* @page: the page to test
*
* Used for LRU list index arithmetic.
*
* Returns the base LRU type - file or anon - @page should be on.
*/
static inline enum lru_list page_lru_base_type(struct page *page)
{
if (page_is_file_cache(page))
return LRU_INACTIVE_FILE;
return LRU_INACTIVE_ANON;
}
static inline void static inline void
del_page_from_lru(struct zone *zone, struct page *page) del_page_from_lru(struct zone *zone, struct page *page)
{ {
enum lru_list l = LRU_BASE; enum lru_list l;
list_del(&page->lru); list_del(&page->lru);
if (PageUnevictable(page)) { if (PageUnevictable(page)) {
__ClearPageUnevictable(page); __ClearPageUnevictable(page);
l = LRU_UNEVICTABLE; l = LRU_UNEVICTABLE;
} else { } else {
l = page_lru_base_type(page);
if (PageActive(page)) { if (PageActive(page)) {
__ClearPageActive(page); __ClearPageActive(page);
l += LRU_ACTIVE; l += LRU_ACTIVE;
} }
l += page_is_file_cache(page);
} }
__dec_zone_state(zone, NR_LRU_BASE + l); __dec_zone_state(zone, NR_LRU_BASE + l);
mem_cgroup_del_lru_list(page, l); mem_cgroup_del_lru_list(page, l);
...@@ -68,14 +83,14 @@ del_page_from_lru(struct zone *zone, struct page *page) ...@@ -68,14 +83,14 @@ del_page_from_lru(struct zone *zone, struct page *page)
*/ */
static inline enum lru_list page_lru(struct page *page) static inline enum lru_list page_lru(struct page *page)
{ {
enum lru_list lru = LRU_BASE; enum lru_list lru;
if (PageUnevictable(page)) if (PageUnevictable(page))
lru = LRU_UNEVICTABLE; lru = LRU_UNEVICTABLE;
else { else {
lru = page_lru_base_type(page);
if (PageActive(page)) if (PageActive(page))
lru += LRU_ACTIVE; lru += LRU_ACTIVE;
lru += page_is_file_cache(page);
} }
return lru; return lru;
......
...@@ -118,7 +118,7 @@ static void pagevec_move_tail(struct pagevec *pvec) ...@@ -118,7 +118,7 @@ static void pagevec_move_tail(struct pagevec *pvec)
spin_lock(&zone->lru_lock); spin_lock(&zone->lru_lock);
} }
if (PageLRU(page) && !PageActive(page) && !PageUnevictable(page)) { if (PageLRU(page) && !PageActive(page) && !PageUnevictable(page)) {
int lru = page_is_file_cache(page); int lru = page_lru_base_type(page);
list_move_tail(&page->lru, &zone->lru[lru].list); list_move_tail(&page->lru, &zone->lru[lru].list);
pgmoved++; pgmoved++;
} }
...@@ -181,7 +181,7 @@ void activate_page(struct page *page) ...@@ -181,7 +181,7 @@ void activate_page(struct page *page)
spin_lock_irq(&zone->lru_lock); spin_lock_irq(&zone->lru_lock);
if (PageLRU(page) && !PageActive(page) && !PageUnevictable(page)) { if (PageLRU(page) && !PageActive(page) && !PageUnevictable(page)) {
int file = page_is_file_cache(page); int file = page_is_file_cache(page);
int lru = LRU_BASE + file; int lru = page_lru_base_type(page);
del_page_from_lru_list(zone, page, lru); del_page_from_lru_list(zone, page, lru);
SetPageActive(page); SetPageActive(page);
......
...@@ -531,7 +531,7 @@ void putback_lru_page(struct page *page) ...@@ -531,7 +531,7 @@ void putback_lru_page(struct page *page)
* unevictable page on [in]active list. * unevictable page on [in]active list.
* We know how to handle that. * We know how to handle that.
*/ */
lru = active + page_is_file_cache(page); lru = active + page_lru_base_type(page);
lru_cache_add_lru(page, lru); lru_cache_add_lru(page, lru);
} else { } else {
/* /*
...@@ -986,7 +986,7 @@ static unsigned long clear_active_flags(struct list_head *page_list, ...@@ -986,7 +986,7 @@ static unsigned long clear_active_flags(struct list_head *page_list,
struct page *page; struct page *page;
list_for_each_entry(page, page_list, lru) { list_for_each_entry(page, page_list, lru) {
lru = page_is_file_cache(page); lru = page_lru_base_type(page);
if (PageActive(page)) { if (PageActive(page)) {
lru += LRU_ACTIVE; lru += LRU_ACTIVE;
ClearPageActive(page); ClearPageActive(page);
...@@ -2652,7 +2652,7 @@ static void check_move_unevictable_page(struct page *page, struct zone *zone) ...@@ -2652,7 +2652,7 @@ static void check_move_unevictable_page(struct page *page, struct zone *zone)
retry: retry:
ClearPageUnevictable(page); ClearPageUnevictable(page);
if (page_evictable(page, NULL)) { if (page_evictable(page, NULL)) {
enum lru_list l = LRU_INACTIVE_ANON + page_is_file_cache(page); enum lru_list l = page_lru_base_type(page);
__dec_zone_state(zone, NR_UNEVICTABLE); __dec_zone_state(zone, NR_UNEVICTABLE);
list_move(&page->lru, &zone->lru[l].list); list_move(&page->lru, &zone->lru[l].list);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment