Skip to content

Commit 401a8e1

Browse files
hnaztorvalds
authored andcommitted
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: Johannes Weiner <hannes@cmpxchg.org> Reviewed-by: Rik van Riel <riel@redhat.com> Cc: Minchan Kim <minchan.kim@gmail.com> Reviewed-by: KOSAKI Motohiro <kosaki.motohiro@jp.fujitsu.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent b7c46d1 commit 401a8e1

File tree

3 files changed

+24
-9
lines changed

3 files changed

+24
-9
lines changed

include/linux/mm_inline.h

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,21 +39,36 @@ del_page_from_lru_list(struct zone *zone, struct page *page, enum lru_list l)
3939
mem_cgroup_del_lru_list(page, l);
4040
}
4141

42+
/**
43+
* page_lru_base_type - which LRU list type should a page be on?
44+
* @page: the page to test
45+
*
46+
* Used for LRU list index arithmetic.
47+
*
48+
* Returns the base LRU type - file or anon - @page should be on.
49+
*/
50+
static inline enum lru_list page_lru_base_type(struct page *page)
51+
{
52+
if (page_is_file_cache(page))
53+
return LRU_INACTIVE_FILE;
54+
return LRU_INACTIVE_ANON;
55+
}
56+
4257
static inline void
4358
del_page_from_lru(struct zone *zone, struct page *page)
4459
{
45-
enum lru_list l = LRU_BASE;
60+
enum lru_list l;
4661

4762
list_del(&page->lru);
4863
if (PageUnevictable(page)) {
4964
__ClearPageUnevictable(page);
5065
l = LRU_UNEVICTABLE;
5166
} else {
67+
l = page_lru_base_type(page);
5268
if (PageActive(page)) {
5369
__ClearPageActive(page);
5470
l += LRU_ACTIVE;
5571
}
56-
l += page_is_file_cache(page);
5772
}
5873
__dec_zone_state(zone, NR_LRU_BASE + l);
5974
mem_cgroup_del_lru_list(page, l);
@@ -68,14 +83,14 @@ del_page_from_lru(struct zone *zone, struct page *page)
6883
*/
6984
static inline enum lru_list page_lru(struct page *page)
7085
{
71-
enum lru_list lru = LRU_BASE;
86+
enum lru_list lru;
7287

7388
if (PageUnevictable(page))
7489
lru = LRU_UNEVICTABLE;
7590
else {
91+
lru = page_lru_base_type(page);
7692
if (PageActive(page))
7793
lru += LRU_ACTIVE;
78-
lru += page_is_file_cache(page);
7994
}
8095

8196
return lru;

mm/swap.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ static void pagevec_move_tail(struct pagevec *pvec)
118118
spin_lock(&zone->lru_lock);
119119
}
120120
if (PageLRU(page) && !PageActive(page) && !PageUnevictable(page)) {
121-
int lru = page_is_file_cache(page);
121+
int lru = page_lru_base_type(page);
122122
list_move_tail(&page->lru, &zone->lru[lru].list);
123123
pgmoved++;
124124
}
@@ -181,7 +181,7 @@ void activate_page(struct page *page)
181181
spin_lock_irq(&zone->lru_lock);
182182
if (PageLRU(page) && !PageActive(page) && !PageUnevictable(page)) {
183183
int file = page_is_file_cache(page);
184-
int lru = LRU_BASE + file;
184+
int lru = page_lru_base_type(page);
185185
del_page_from_lru_list(zone, page, lru);
186186

187187
SetPageActive(page);

mm/vmscan.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -531,7 +531,7 @@ void putback_lru_page(struct page *page)
531531
* unevictable page on [in]active list.
532532
* We know how to handle that.
533533
*/
534-
lru = active + page_is_file_cache(page);
534+
lru = active + page_lru_base_type(page);
535535
lru_cache_add_lru(page, lru);
536536
} else {
537537
/*
@@ -986,7 +986,7 @@ static unsigned long clear_active_flags(struct list_head *page_list,
986986
struct page *page;
987987

988988
list_for_each_entry(page, page_list, lru) {
989-
lru = page_is_file_cache(page);
989+
lru = page_lru_base_type(page);
990990
if (PageActive(page)) {
991991
lru += LRU_ACTIVE;
992992
ClearPageActive(page);
@@ -2652,7 +2652,7 @@ static void check_move_unevictable_page(struct page *page, struct zone *zone)
26522652
retry:
26532653
ClearPageUnevictable(page);
26542654
if (page_evictable(page, NULL)) {
2655-
enum lru_list l = LRU_INACTIVE_ANON + page_is_file_cache(page);
2655+
enum lru_list l = page_lru_base_type(page);
26562656

26572657
__dec_zone_state(zone, NR_UNEVICTABLE);
26582658
list_move(&page->lru, &zone->lru[l].list);

0 commit comments

Comments
 (0)