Skip to content

Commit

Permalink
mm: fold and remove lru_cache_add_anon() and lru_cache_add_file()
Browse files Browse the repository at this point in the history
They're the same function, and for the purpose of all callers they are
equivalent to lru_cache_add().

[[email protected]: fix it for local_lock changes]
Signed-off-by: Johannes Weiner <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Reviewed-by: Rik van Riel <[email protected]>
Acked-by: Michal Hocko <[email protected]>
Acked-by: Minchan Kim <[email protected]>
Cc: Joonsoo Kim <[email protected]>
Link: http://lkml.kernel.org/r/[email protected]
Signed-off-by: Linus Torvalds <[email protected]>
  • Loading branch information
hnaz authored and torvalds committed Jun 4, 2020
1 parent c843966 commit 6058eae
Show file tree
Hide file tree
Showing 8 changed files with 23 additions and 51 deletions.
10 changes: 5 additions & 5 deletions fs/cifs/file.c
Original file line number Diff line number Diff line change
Expand Up @@ -4162,7 +4162,7 @@ cifs_readv_complete(struct work_struct *work)
for (i = 0; i < rdata->nr_pages; i++) {
struct page *page = rdata->pages[i];

lru_cache_add_file(page);
lru_cache_add(page);

if (rdata->result == 0 ||
(rdata->result == -EAGAIN && got_bytes)) {
Expand Down Expand Up @@ -4232,7 +4232,7 @@ readpages_fill_pages(struct TCP_Server_Info *server,
* fill them until the writes are flushed.
*/
zero_user(page, 0, PAGE_SIZE);
lru_cache_add_file(page);
lru_cache_add(page);
flush_dcache_page(page);
SetPageUptodate(page);
unlock_page(page);
Expand All @@ -4242,7 +4242,7 @@ readpages_fill_pages(struct TCP_Server_Info *server,
continue;
} else {
/* no need to hold page hostage */
lru_cache_add_file(page);
lru_cache_add(page);
unlock_page(page);
put_page(page);
rdata->pages[i] = NULL;
Expand Down Expand Up @@ -4437,7 +4437,7 @@ static int cifs_readpages(struct file *file, struct address_space *mapping,
/* best to give up if we're out of mem */
list_for_each_entry_safe(page, tpage, &tmplist, lru) {
list_del(&page->lru);
lru_cache_add_file(page);
lru_cache_add(page);
unlock_page(page);
put_page(page);
}
Expand Down Expand Up @@ -4475,7 +4475,7 @@ static int cifs_readpages(struct file *file, struct address_space *mapping,
add_credits_and_wake_if(server, &rdata->credits, 0);
for (i = 0; i < rdata->nr_pages; i++) {
page = rdata->pages[i];
lru_cache_add_file(page);
lru_cache_add(page);
unlock_page(page);
put_page(page);
}
Expand Down
2 changes: 1 addition & 1 deletion fs/fuse/dev.c
Original file line number Diff line number Diff line change
Expand Up @@ -840,7 +840,7 @@ static int fuse_try_move_page(struct fuse_copy_state *cs, struct page **pagep)
get_page(newpage);

if (!(buf->flags & PIPE_BUF_FLAG_LRU))
lru_cache_add_file(newpage);
lru_cache_add(newpage);

err = 0;
spin_lock(&cs->req->waitq.lock);
Expand Down
2 changes: 0 additions & 2 deletions include/linux/swap.h
Original file line number Diff line number Diff line change
Expand Up @@ -335,8 +335,6 @@ extern unsigned long nr_free_pagecache_pages(void);

/* linux/mm/swap.c */
extern void lru_cache_add(struct page *);
extern void lru_cache_add_anon(struct page *page);
extern void lru_cache_add_file(struct page *page);
extern void lru_add_page_tail(struct page *page, struct page *page_tail,
struct lruvec *lruvec, struct list_head *head);
extern void activate_page(struct page *);
Expand Down
8 changes: 2 additions & 6 deletions mm/khugepaged.c
Original file line number Diff line number Diff line change
Expand Up @@ -1879,13 +1879,9 @@ static void collapse_file(struct mm_struct *mm,

SetPageUptodate(new_page);
page_ref_add(new_page, HPAGE_PMD_NR - 1);

if (is_shmem) {
if (is_shmem)
set_page_dirty(new_page);
lru_cache_add_anon(new_page);
} else {
lru_cache_add_file(new_page);
}
lru_cache_add(new_page);

/*
* Remove pte page tables, so we can re-fault the page as huge.
Expand Down
2 changes: 1 addition & 1 deletion mm/memory.c
Original file line number Diff line number Diff line change
Expand Up @@ -3139,7 +3139,7 @@ vm_fault_t do_swap_page(struct vm_fault *vmf)
if (err)
goto out_page;

lru_cache_add_anon(page);
lru_cache_add(page);
swap_readpage(page, true);
}
} else {
Expand Down
6 changes: 3 additions & 3 deletions mm/shmem.c
Original file line number Diff line number Diff line change
Expand Up @@ -1609,7 +1609,7 @@ static int shmem_replace_page(struct page **pagep, gfp_t gfp,
*/
oldpage = newpage;
} else {
lru_cache_add_anon(newpage);
lru_cache_add(newpage);
*pagep = newpage;
}

Expand Down Expand Up @@ -1860,7 +1860,7 @@ static int shmem_getpage_gfp(struct inode *inode, pgoff_t index,
charge_mm);
if (error)
goto unacct;
lru_cache_add_anon(page);
lru_cache_add(page);

spin_lock_irq(&info->lock);
info->alloced += compound_nr(page);
Expand Down Expand Up @@ -2376,7 +2376,7 @@ static int shmem_mfill_atomic_pte(struct mm_struct *dst_mm,
if (!pte_none(*dst_pte))
goto out_release_unlock;

lru_cache_add_anon(page);
lru_cache_add(page);

spin_lock_irq(&info->lock);
info->alloced++;
Expand Down
42 changes: 10 additions & 32 deletions mm/swap.c
Original file line number Diff line number Diff line change
Expand Up @@ -424,37 +424,6 @@ void mark_page_accessed(struct page *page)
}
EXPORT_SYMBOL(mark_page_accessed);

static void __lru_cache_add(struct page *page)
{
struct pagevec *pvec;

local_lock(&lru_pvecs.lock);
pvec = this_cpu_ptr(&lru_pvecs.lru_add);
get_page(page);
if (!pagevec_add(pvec, page) || PageCompound(page))
__pagevec_lru_add(pvec);
local_unlock(&lru_pvecs.lock);
}

/**
* lru_cache_add_anon - add a page to the page lists
* @page: the page to add
*/
void lru_cache_add_anon(struct page *page)
{
if (PageActive(page))
ClearPageActive(page);
__lru_cache_add(page);
}

void lru_cache_add_file(struct page *page)
{
if (PageActive(page))
ClearPageActive(page);
__lru_cache_add(page);
}
EXPORT_SYMBOL(lru_cache_add_file);

/**
* lru_cache_add - add a page to a page list
* @page: the page to be added to the LRU.
Expand All @@ -466,10 +435,19 @@ EXPORT_SYMBOL(lru_cache_add_file);
*/
void lru_cache_add(struct page *page)
{
struct pagevec *pvec;

VM_BUG_ON_PAGE(PageActive(page) && PageUnevictable(page), page);
VM_BUG_ON_PAGE(PageLRU(page), page);
__lru_cache_add(page);

get_page(page);
local_lock(&lru_pvecs.lock);
pvec = this_cpu_ptr(&lru_pvecs.lru_add);
if (!pagevec_add(pvec, page) || PageCompound(page))
__pagevec_lru_add(pvec);
local_unlock(&lru_pvecs.lock);
}
EXPORT_SYMBOL(lru_cache_add);

/**
* lru_cache_add_active_or_unevictable
Expand Down
2 changes: 1 addition & 1 deletion mm/swap_state.c
Original file line number Diff line number Diff line change
Expand Up @@ -442,7 +442,7 @@ struct page *__read_swap_cache_async(swp_entry_t entry, gfp_t gfp_mask,

/* Caller will initiate read into locked page */
SetPageWorkingset(page);
lru_cache_add_anon(page);
lru_cache_add(page);
*new_page_allocated = true;
return page;

Expand Down

0 comments on commit 6058eae

Please sign in to comment.