From 3dc69d3351efc883bd9d1e6532c2859712d3847f Mon Sep 17 00:00:00 2001 From: Johannes Weiner Date: Wed, 3 Jun 2020 16:02:40 -0700 Subject: [PATCH 2363/2944] mm: fold and remove lru_cache_add_anon() and lru_cache_add_file() task #31256938 commit 6058eaec816f29fbe33c9d35694614c9a4ed75ba upstream They're the same function, and for the purpose of all callers they are equivalent to lru_cache_add(). [akpm@linux-foundation.org: fix it for local_lock changes] Signed-off-by: Johannes Weiner Signed-off-by: Andrew Morton Reviewed-by: Rik van Riel Acked-by: Michal Hocko Acked-by: Minchan Kim Cc: Joonsoo Kim Link: http://lkml.kernel.org/r/20200520232525.798933-5-hannes@cmpxchg.org Signed-off-by: Linus Torvalds Signed-off-by: zhongjiang-ali Reviewed-by: Xunlei Pang --- fs/cifs/file.c | 10 +++++----- fs/fuse/dev.c | 2 +- include/linux/swap.h | 2 -- mm/khugepaged.c | 2 +- mm/memory.c | 2 +- mm/shmem.c | 6 +++--- mm/swap.c | 38 ++++++++------------------------------ mm/swap_state.c | 2 +- 8 files changed, 20 insertions(+), 44 deletions(-) diff --git a/fs/cifs/file.c b/fs/cifs/file.c index d5293ef..24a3519 100644 --- a/fs/cifs/file.c +++ b/fs/cifs/file.c @@ -3634,7 +3634,7 @@ int cifs_file_mmap(struct file *file, struct vm_area_struct *vma) 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)) { @@ -3704,7 +3704,7 @@ int cifs_file_mmap(struct file *file, struct vm_area_struct *vma) * 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); @@ -3714,7 +3714,7 @@ int cifs_file_mmap(struct file *file, struct vm_area_struct *vma) 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; @@ -3898,7 +3898,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); } @@ -3930,7 +3930,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); } diff --git a/fs/fuse/dev.c b/fs/fuse/dev.c index c9c7430..3202ead 100644 --- a/fs/fuse/dev.c +++ b/fs/fuse/dev.c @@ -931,7 +931,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); diff --git a/include/linux/swap.h b/include/linux/swap.h index a3c183c..ebf20f3 100644 --- a/include/linux/swap.h +++ b/include/linux/swap.h @@ -333,8 +333,6 @@ struct vma_swap_readahead { /* 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 *); diff --git a/mm/khugepaged.c b/mm/khugepaged.c index 9fd96c67..d1f5fab 100644 --- a/mm/khugepaged.c +++ b/mm/khugepaged.c @@ -1625,7 +1625,7 @@ static void collapse_shmem(struct mm_struct *mm, SetPageUptodate(new_page); page_ref_add(new_page, HPAGE_PMD_NR - 1); set_page_dirty(new_page); - lru_cache_add_anon(new_page); + lru_cache_add(new_page); /* * Remove pte page tables, so we can re-fault the page as huge. diff --git a/mm/memory.c b/mm/memory.c index dc421c4..dde0e79 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -2980,7 +2980,7 @@ vm_fault_t do_swap_page(struct vm_fault *vmf) goto out_page; } - lru_cache_add_anon(page); + lru_cache_add(page); swap_readpage(page, true); } } else { diff --git a/mm/shmem.c b/mm/shmem.c index 301c37e..3e0a428 100644 --- a/mm/shmem.c +++ b/mm/shmem.c @@ -1608,7 +1608,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; } @@ -1824,7 +1824,7 @@ static int shmem_getpage_gfp(struct inode *inode, pgoff_t index, } if (error) goto unacct; - lru_cache_add_anon(page); + lru_cache_add(page); spin_lock_irq(&info->lock); info->alloced += 1 << compound_order(page); @@ -2321,7 +2321,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(&info->lock); info->alloced++; diff --git a/mm/swap.c b/mm/swap.c index 51f882c..f62cbd8 100644 --- a/mm/swap.c +++ b/mm/swap.c @@ -398,35 +398,6 @@ void mark_page_accessed(struct page *page) } EXPORT_SYMBOL(mark_page_accessed); -static void __lru_cache_add(struct page *page) -{ - struct pagevec *pvec = &get_cpu_var(lru_add_pvec); - - get_page(page); - if (!pagevec_add(pvec, page) || PageCompound(page)) - __pagevec_lru_add(pvec); - put_cpu_var(lru_add_pvec); -} - -/** - * 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. @@ -438,10 +409,17 @@ void lru_cache_add_file(struct page *page) */ void lru_cache_add(struct page *page) { + struct pagevec *pvec = &get_cpu_var(lru_add_pvec); + VM_BUG_ON_PAGE(PageActive(page) && PageUnevictable(page), page); VM_BUG_ON_PAGE(PageLRU(page), page); - __lru_cache_add(page); + + get_page(page); + if (!pagevec_add(pvec, page) || PageCompound(page)) + __pagevec_lru_add(pvec); + put_cpu_var(lru_add_pvec); } +EXPORT_SYMBOL(lru_cache_add); /** * lru_cache_add_active_or_unevictable diff --git a/mm/swap_state.c b/mm/swap_state.c index 989b87a..46dfd9f 100644 --- a/mm/swap_state.c +++ b/mm/swap_state.c @@ -472,7 +472,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; -- 1.8.3.1