Commit 10a9c496 authored by Christoph Hellwig's avatar Christoph Hellwig Committed by Linus Torvalds

mm: simplify try_to_unuse

Remove the unused frontswap and pages_to_unuse arguments, and mark the
function static now that the caller in frontswap is gone.

[akpm@linux-foundation.org: fix shmem_unuse() stub, per Matthew]

Link: https://lkml.kernel.org/r/20211224062246.1258487-9-hch@lst.deSigned-off-by: default avatarChristoph Hellwig <hch@lst.de>
Reviewed-by: default avatarJuergen Gross <jgross@suse.com>
Cc: Dan Streetman <ddstreet@ieee.org>
Cc: Geert Uytterhoeven <geert@linux-m68k.org>
Cc: Hugh Dickins <hughd@google.com>
Cc: Konrad Rzeszutek Wilk <Konrad.wilk@oracle.com>
Cc: Matthew Wilcox (Oracle) <willy@infradead.org>
Cc: Seth Jennings <sjenning@redhat.com>
Cc: Vitaly Wool <vitaly.wool@konsulko.com>
Cc: Naresh Kamboju <naresh.kamboju@linaro.org>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent 360be5da
...@@ -7,13 +7,6 @@ ...@@ -7,13 +7,6 @@
#include <linux/bitops.h> #include <linux/bitops.h>
#include <linux/jump_label.h> #include <linux/jump_label.h>
/*
* Return code to denote that requested number of
* frontswap pages are unused(moved to page cache).
* Used in shmem_unuse and try_to_unuse.
*/
#define FRONTSWAP_PAGES_UNUSED 2
struct frontswap_ops { struct frontswap_ops {
void (*init)(unsigned); /* this swap type was just swapon'ed */ void (*init)(unsigned); /* this swap type was just swapon'ed */
int (*store)(unsigned, pgoff_t, struct page *); /* store a page */ int (*store)(unsigned, pgoff_t, struct page *); /* store a page */
......
...@@ -83,8 +83,7 @@ extern void shmem_unlock_mapping(struct address_space *mapping); ...@@ -83,8 +83,7 @@ extern void shmem_unlock_mapping(struct address_space *mapping);
extern struct page *shmem_read_mapping_page_gfp(struct address_space *mapping, extern struct page *shmem_read_mapping_page_gfp(struct address_space *mapping,
pgoff_t index, gfp_t gfp_mask); pgoff_t index, gfp_t gfp_mask);
extern void shmem_truncate_range(struct inode *inode, loff_t start, loff_t end); extern void shmem_truncate_range(struct inode *inode, loff_t start, loff_t end);
extern int shmem_unuse(unsigned int type, bool frontswap, int shmem_unuse(unsigned int type);
unsigned long *fs_pages_to_unuse);
extern bool shmem_is_huge(struct vm_area_struct *vma, extern bool shmem_is_huge(struct vm_area_struct *vma,
struct inode *inode, pgoff_t index); struct inode *inode, pgoff_t index);
......
...@@ -9,7 +9,6 @@ ...@@ -9,7 +9,6 @@
extern spinlock_t swap_lock; extern spinlock_t swap_lock;
extern struct plist_head swap_active_head; extern struct plist_head swap_active_head;
extern struct swap_info_struct *swap_info[]; extern struct swap_info_struct *swap_info[];
extern int try_to_unuse(unsigned int, bool, unsigned long);
extern unsigned long generic_max_swapfile_size(void); extern unsigned long generic_max_swapfile_size(void);
extern unsigned long max_swapfile_size(void); extern unsigned long max_swapfile_size(void);
......
...@@ -36,7 +36,6 @@ ...@@ -36,7 +36,6 @@
#include <linux/uio.h> #include <linux/uio.h>
#include <linux/khugepaged.h> #include <linux/khugepaged.h>
#include <linux/hugetlb.h> #include <linux/hugetlb.h>
#include <linux/frontswap.h>
#include <linux/fs_parser.h> #include <linux/fs_parser.h>
#include <linux/swapfile.h> #include <linux/swapfile.h>
...@@ -1152,7 +1151,7 @@ static void shmem_evict_inode(struct inode *inode) ...@@ -1152,7 +1151,7 @@ static void shmem_evict_inode(struct inode *inode)
static int shmem_find_swap_entries(struct address_space *mapping, static int shmem_find_swap_entries(struct address_space *mapping,
pgoff_t start, unsigned int nr_entries, pgoff_t start, unsigned int nr_entries,
struct page **entries, pgoff_t *indices, struct page **entries, pgoff_t *indices,
unsigned int type, bool frontswap) unsigned int type)
{ {
XA_STATE(xas, &mapping->i_pages, start); XA_STATE(xas, &mapping->i_pages, start);
struct page *page; struct page *page;
...@@ -1173,9 +1172,6 @@ static int shmem_find_swap_entries(struct address_space *mapping, ...@@ -1173,9 +1172,6 @@ static int shmem_find_swap_entries(struct address_space *mapping,
entry = radix_to_swp_entry(page); entry = radix_to_swp_entry(page);
if (swp_type(entry) != type) if (swp_type(entry) != type)
continue; continue;
if (frontswap &&
!frontswap_test(swap_info[type], swp_offset(entry)))
continue;
indices[ret] = xas.xa_index; indices[ret] = xas.xa_index;
entries[ret] = page; entries[ret] = page;
...@@ -1228,26 +1224,20 @@ static int shmem_unuse_swap_entries(struct inode *inode, struct pagevec pvec, ...@@ -1228,26 +1224,20 @@ static int shmem_unuse_swap_entries(struct inode *inode, struct pagevec pvec,
/* /*
* If swap found in inode, free it and move page from swapcache to filecache. * If swap found in inode, free it and move page from swapcache to filecache.
*/ */
static int shmem_unuse_inode(struct inode *inode, unsigned int type, static int shmem_unuse_inode(struct inode *inode, unsigned int type)
bool frontswap, unsigned long *fs_pages_to_unuse)
{ {
struct address_space *mapping = inode->i_mapping; struct address_space *mapping = inode->i_mapping;
pgoff_t start = 0; pgoff_t start = 0;
struct pagevec pvec; struct pagevec pvec;
pgoff_t indices[PAGEVEC_SIZE]; pgoff_t indices[PAGEVEC_SIZE];
bool frontswap_partial = (frontswap && *fs_pages_to_unuse > 0);
int ret = 0; int ret = 0;
pagevec_init(&pvec); pagevec_init(&pvec);
do { do {
unsigned int nr_entries = PAGEVEC_SIZE; unsigned int nr_entries = PAGEVEC_SIZE;
if (frontswap_partial && *fs_pages_to_unuse < PAGEVEC_SIZE)
nr_entries = *fs_pages_to_unuse;
pvec.nr = shmem_find_swap_entries(mapping, start, nr_entries, pvec.nr = shmem_find_swap_entries(mapping, start, nr_entries,
pvec.pages, indices, pvec.pages, indices, type);
type, frontswap);
if (pvec.nr == 0) { if (pvec.nr == 0) {
ret = 0; ret = 0;
break; break;
...@@ -1257,14 +1247,6 @@ static int shmem_unuse_inode(struct inode *inode, unsigned int type, ...@@ -1257,14 +1247,6 @@ static int shmem_unuse_inode(struct inode *inode, unsigned int type,
if (ret < 0) if (ret < 0)
break; break;
if (frontswap_partial) {
*fs_pages_to_unuse -= ret;
if (*fs_pages_to_unuse == 0) {
ret = FRONTSWAP_PAGES_UNUSED;
break;
}
}
start = indices[pvec.nr - 1]; start = indices[pvec.nr - 1];
} while (true); } while (true);
...@@ -1276,8 +1258,7 @@ static int shmem_unuse_inode(struct inode *inode, unsigned int type, ...@@ -1276,8 +1258,7 @@ static int shmem_unuse_inode(struct inode *inode, unsigned int type,
* device 'type' back into memory, so the swap device can be * device 'type' back into memory, so the swap device can be
* unused. * unused.
*/ */
int shmem_unuse(unsigned int type, bool frontswap, int shmem_unuse(unsigned int type)
unsigned long *fs_pages_to_unuse)
{ {
struct shmem_inode_info *info, *next; struct shmem_inode_info *info, *next;
int error = 0; int error = 0;
...@@ -1300,8 +1281,7 @@ int shmem_unuse(unsigned int type, bool frontswap, ...@@ -1300,8 +1281,7 @@ int shmem_unuse(unsigned int type, bool frontswap,
atomic_inc(&info->stop_eviction); atomic_inc(&info->stop_eviction);
mutex_unlock(&shmem_swaplist_mutex); mutex_unlock(&shmem_swaplist_mutex);
error = shmem_unuse_inode(&info->vfs_inode, type, frontswap, error = shmem_unuse_inode(&info->vfs_inode, type);
fs_pages_to_unuse);
cond_resched(); cond_resched();
mutex_lock(&shmem_swaplist_mutex); mutex_lock(&shmem_swaplist_mutex);
...@@ -4015,8 +3995,7 @@ int __init shmem_init(void) ...@@ -4015,8 +3995,7 @@ int __init shmem_init(void)
return 0; return 0;
} }
int shmem_unuse(unsigned int type, bool frontswap, int shmem_unuse(unsigned int type)
unsigned long *fs_pages_to_unuse)
{ {
return 0; return 0;
} }
......
...@@ -1923,8 +1923,7 @@ static int unuse_pte(struct vm_area_struct *vma, pmd_t *pmd, ...@@ -1923,8 +1923,7 @@ static int unuse_pte(struct vm_area_struct *vma, pmd_t *pmd,
static int unuse_pte_range(struct vm_area_struct *vma, pmd_t *pmd, static int unuse_pte_range(struct vm_area_struct *vma, pmd_t *pmd,
unsigned long addr, unsigned long end, unsigned long addr, unsigned long end,
unsigned int type, bool frontswap, unsigned int type)
unsigned long *fs_pages_to_unuse)
{ {
struct page *page; struct page *page;
swp_entry_t entry; swp_entry_t entry;
...@@ -1945,9 +1944,6 @@ static int unuse_pte_range(struct vm_area_struct *vma, pmd_t *pmd, ...@@ -1945,9 +1944,6 @@ static int unuse_pte_range(struct vm_area_struct *vma, pmd_t *pmd,
continue; continue;
offset = swp_offset(entry); offset = swp_offset(entry);
if (frontswap && !frontswap_test(si, offset))
continue;
pte_unmap(pte); pte_unmap(pte);
swap_map = &si->swap_map[offset]; swap_map = &si->swap_map[offset];
page = lookup_swap_cache(entry, vma, addr); page = lookup_swap_cache(entry, vma, addr);
...@@ -1979,11 +1975,6 @@ static int unuse_pte_range(struct vm_area_struct *vma, pmd_t *pmd, ...@@ -1979,11 +1975,6 @@ static int unuse_pte_range(struct vm_area_struct *vma, pmd_t *pmd,
try_to_free_swap(page); try_to_free_swap(page);
unlock_page(page); unlock_page(page);
put_page(page); put_page(page);
if (*fs_pages_to_unuse && !--(*fs_pages_to_unuse)) {
ret = FRONTSWAP_PAGES_UNUSED;
goto out;
}
try_next: try_next:
pte = pte_offset_map(pmd, addr); pte = pte_offset_map(pmd, addr);
} while (pte++, addr += PAGE_SIZE, addr != end); } while (pte++, addr += PAGE_SIZE, addr != end);
...@@ -1996,8 +1987,7 @@ static int unuse_pte_range(struct vm_area_struct *vma, pmd_t *pmd, ...@@ -1996,8 +1987,7 @@ static int unuse_pte_range(struct vm_area_struct *vma, pmd_t *pmd,
static inline int unuse_pmd_range(struct vm_area_struct *vma, pud_t *pud, static inline int unuse_pmd_range(struct vm_area_struct *vma, pud_t *pud,
unsigned long addr, unsigned long end, unsigned long addr, unsigned long end,
unsigned int type, bool frontswap, unsigned int type)
unsigned long *fs_pages_to_unuse)
{ {
pmd_t *pmd; pmd_t *pmd;
unsigned long next; unsigned long next;
...@@ -2009,8 +1999,7 @@ static inline int unuse_pmd_range(struct vm_area_struct *vma, pud_t *pud, ...@@ -2009,8 +1999,7 @@ static inline int unuse_pmd_range(struct vm_area_struct *vma, pud_t *pud,
next = pmd_addr_end(addr, end); next = pmd_addr_end(addr, end);
if (pmd_none_or_trans_huge_or_clear_bad(pmd)) if (pmd_none_or_trans_huge_or_clear_bad(pmd))
continue; continue;
ret = unuse_pte_range(vma, pmd, addr, next, type, ret = unuse_pte_range(vma, pmd, addr, next, type);
frontswap, fs_pages_to_unuse);
if (ret) if (ret)
return ret; return ret;
} while (pmd++, addr = next, addr != end); } while (pmd++, addr = next, addr != end);
...@@ -2019,8 +2008,7 @@ static inline int unuse_pmd_range(struct vm_area_struct *vma, pud_t *pud, ...@@ -2019,8 +2008,7 @@ static inline int unuse_pmd_range(struct vm_area_struct *vma, pud_t *pud,
static inline int unuse_pud_range(struct vm_area_struct *vma, p4d_t *p4d, static inline int unuse_pud_range(struct vm_area_struct *vma, p4d_t *p4d,
unsigned long addr, unsigned long end, unsigned long addr, unsigned long end,
unsigned int type, bool frontswap, unsigned int type)
unsigned long *fs_pages_to_unuse)
{ {
pud_t *pud; pud_t *pud;
unsigned long next; unsigned long next;
...@@ -2031,8 +2019,7 @@ static inline int unuse_pud_range(struct vm_area_struct *vma, p4d_t *p4d, ...@@ -2031,8 +2019,7 @@ static inline int unuse_pud_range(struct vm_area_struct *vma, p4d_t *p4d,
next = pud_addr_end(addr, end); next = pud_addr_end(addr, end);
if (pud_none_or_clear_bad(pud)) if (pud_none_or_clear_bad(pud))
continue; continue;
ret = unuse_pmd_range(vma, pud, addr, next, type, ret = unuse_pmd_range(vma, pud, addr, next, type);
frontswap, fs_pages_to_unuse);
if (ret) if (ret)
return ret; return ret;
} while (pud++, addr = next, addr != end); } while (pud++, addr = next, addr != end);
...@@ -2041,8 +2028,7 @@ static inline int unuse_pud_range(struct vm_area_struct *vma, p4d_t *p4d, ...@@ -2041,8 +2028,7 @@ static inline int unuse_pud_range(struct vm_area_struct *vma, p4d_t *p4d,
static inline int unuse_p4d_range(struct vm_area_struct *vma, pgd_t *pgd, static inline int unuse_p4d_range(struct vm_area_struct *vma, pgd_t *pgd,
unsigned long addr, unsigned long end, unsigned long addr, unsigned long end,
unsigned int type, bool frontswap, unsigned int type)
unsigned long *fs_pages_to_unuse)
{ {
p4d_t *p4d; p4d_t *p4d;
unsigned long next; unsigned long next;
...@@ -2053,16 +2039,14 @@ static inline int unuse_p4d_range(struct vm_area_struct *vma, pgd_t *pgd, ...@@ -2053,16 +2039,14 @@ static inline int unuse_p4d_range(struct vm_area_struct *vma, pgd_t *pgd,
next = p4d_addr_end(addr, end); next = p4d_addr_end(addr, end);
if (p4d_none_or_clear_bad(p4d)) if (p4d_none_or_clear_bad(p4d))
continue; continue;
ret = unuse_pud_range(vma, p4d, addr, next, type, ret = unuse_pud_range(vma, p4d, addr, next, type);
frontswap, fs_pages_to_unuse);
if (ret) if (ret)
return ret; return ret;
} while (p4d++, addr = next, addr != end); } while (p4d++, addr = next, addr != end);
return 0; return 0;
} }
static int unuse_vma(struct vm_area_struct *vma, unsigned int type, static int unuse_vma(struct vm_area_struct *vma, unsigned int type)
bool frontswap, unsigned long *fs_pages_to_unuse)
{ {
pgd_t *pgd; pgd_t *pgd;
unsigned long addr, end, next; unsigned long addr, end, next;
...@@ -2076,16 +2060,14 @@ static int unuse_vma(struct vm_area_struct *vma, unsigned int type, ...@@ -2076,16 +2060,14 @@ static int unuse_vma(struct vm_area_struct *vma, unsigned int type,
next = pgd_addr_end(addr, end); next = pgd_addr_end(addr, end);
if (pgd_none_or_clear_bad(pgd)) if (pgd_none_or_clear_bad(pgd))
continue; continue;
ret = unuse_p4d_range(vma, pgd, addr, next, type, ret = unuse_p4d_range(vma, pgd, addr, next, type);
frontswap, fs_pages_to_unuse);
if (ret) if (ret)
return ret; return ret;
} while (pgd++, addr = next, addr != end); } while (pgd++, addr = next, addr != end);
return 0; return 0;
} }
static int unuse_mm(struct mm_struct *mm, unsigned int type, static int unuse_mm(struct mm_struct *mm, unsigned int type)
bool frontswap, unsigned long *fs_pages_to_unuse)
{ {
struct vm_area_struct *vma; struct vm_area_struct *vma;
int ret = 0; int ret = 0;
...@@ -2093,8 +2075,7 @@ static int unuse_mm(struct mm_struct *mm, unsigned int type, ...@@ -2093,8 +2075,7 @@ static int unuse_mm(struct mm_struct *mm, unsigned int type,
mmap_read_lock(mm); mmap_read_lock(mm);
for (vma = mm->mmap; vma; vma = vma->vm_next) { for (vma = mm->mmap; vma; vma = vma->vm_next) {
if (vma->anon_vma) { if (vma->anon_vma) {
ret = unuse_vma(vma, type, frontswap, ret = unuse_vma(vma, type);
fs_pages_to_unuse);
if (ret) if (ret)
break; break;
} }
...@@ -2110,7 +2091,7 @@ static int unuse_mm(struct mm_struct *mm, unsigned int type, ...@@ -2110,7 +2091,7 @@ static int unuse_mm(struct mm_struct *mm, unsigned int type,
* if there are no inuse entries after prev till end of the map. * if there are no inuse entries after prev till end of the map.
*/ */
static unsigned int find_next_to_unuse(struct swap_info_struct *si, static unsigned int find_next_to_unuse(struct swap_info_struct *si,
unsigned int prev, bool frontswap) unsigned int prev)
{ {
unsigned int i; unsigned int i;
unsigned char count; unsigned char count;
...@@ -2124,8 +2105,7 @@ static unsigned int find_next_to_unuse(struct swap_info_struct *si, ...@@ -2124,8 +2105,7 @@ static unsigned int find_next_to_unuse(struct swap_info_struct *si,
for (i = prev + 1; i < si->max; i++) { for (i = prev + 1; i < si->max; i++) {
count = READ_ONCE(si->swap_map[i]); count = READ_ONCE(si->swap_map[i]);
if (count && swap_count(count) != SWAP_MAP_BAD) if (count && swap_count(count) != SWAP_MAP_BAD)
if (!frontswap || frontswap_test(si, i)) break;
break;
if ((i % LATENCY_LIMIT) == 0) if ((i % LATENCY_LIMIT) == 0)
cond_resched(); cond_resched();
} }
...@@ -2136,12 +2116,7 @@ static unsigned int find_next_to_unuse(struct swap_info_struct *si, ...@@ -2136,12 +2116,7 @@ static unsigned int find_next_to_unuse(struct swap_info_struct *si,
return i; return i;
} }
/* static int try_to_unuse(unsigned int type)
* If the boolean frontswap is true, only unuse pages_to_unuse pages;
* pages_to_unuse==0 means all pages; ignored if frontswap is false
*/
int try_to_unuse(unsigned int type, bool frontswap,
unsigned long pages_to_unuse)
{ {
struct mm_struct *prev_mm; struct mm_struct *prev_mm;
struct mm_struct *mm; struct mm_struct *mm;
...@@ -2155,13 +2130,10 @@ int try_to_unuse(unsigned int type, bool frontswap, ...@@ -2155,13 +2130,10 @@ int try_to_unuse(unsigned int type, bool frontswap,
if (!READ_ONCE(si->inuse_pages)) if (!READ_ONCE(si->inuse_pages))
return 0; return 0;
if (!frontswap)
pages_to_unuse = 0;
retry: retry:
retval = shmem_unuse(type, frontswap, &pages_to_unuse); retval = shmem_unuse(type);
if (retval) if (retval)
goto out; return retval;
prev_mm = &init_mm; prev_mm = &init_mm;
mmget(prev_mm); mmget(prev_mm);
...@@ -2178,11 +2150,10 @@ int try_to_unuse(unsigned int type, bool frontswap, ...@@ -2178,11 +2150,10 @@ int try_to_unuse(unsigned int type, bool frontswap,
spin_unlock(&mmlist_lock); spin_unlock(&mmlist_lock);
mmput(prev_mm); mmput(prev_mm);
prev_mm = mm; prev_mm = mm;
retval = unuse_mm(mm, type, frontswap, &pages_to_unuse); retval = unuse_mm(mm, type);
if (retval) { if (retval) {
mmput(prev_mm); mmput(prev_mm);
goto out; return retval;
} }
/* /*
...@@ -2199,7 +2170,7 @@ int try_to_unuse(unsigned int type, bool frontswap, ...@@ -2199,7 +2170,7 @@ int try_to_unuse(unsigned int type, bool frontswap,
i = 0; i = 0;
while (READ_ONCE(si->inuse_pages) && while (READ_ONCE(si->inuse_pages) &&
!signal_pending(current) && !signal_pending(current) &&
(i = find_next_to_unuse(si, i, frontswap)) != 0) { (i = find_next_to_unuse(si, i)) != 0) {
entry = swp_entry(type, i); entry = swp_entry(type, i);
page = find_get_page(swap_address_space(entry), i); page = find_get_page(swap_address_space(entry), i);
...@@ -2217,14 +2188,6 @@ int try_to_unuse(unsigned int type, bool frontswap, ...@@ -2217,14 +2188,6 @@ int try_to_unuse(unsigned int type, bool frontswap,
try_to_free_swap(page); try_to_free_swap(page);
unlock_page(page); unlock_page(page);
put_page(page); put_page(page);
/*
* For frontswap, we just need to unuse pages_to_unuse, if
* it was specified. Need not check frontswap again here as
* we already zeroed out pages_to_unuse if not frontswap.
*/
if (pages_to_unuse && --pages_to_unuse == 0)
goto out;
} }
/* /*
...@@ -2242,10 +2205,10 @@ int try_to_unuse(unsigned int type, bool frontswap, ...@@ -2242,10 +2205,10 @@ int try_to_unuse(unsigned int type, bool frontswap,
if (READ_ONCE(si->inuse_pages)) { if (READ_ONCE(si->inuse_pages)) {
if (!signal_pending(current)) if (!signal_pending(current))
goto retry; goto retry;
retval = -EINTR; return -EINTR;
} }
out:
return (retval == FRONTSWAP_PAGES_UNUSED) ? 0 : retval; return 0;
} }
/* /*
...@@ -2577,7 +2540,7 @@ SYSCALL_DEFINE1(swapoff, const char __user *, specialfile) ...@@ -2577,7 +2540,7 @@ SYSCALL_DEFINE1(swapoff, const char __user *, specialfile)
disable_swap_slots_cache_lock(); disable_swap_slots_cache_lock();
set_current_oom_origin(); set_current_oom_origin();
err = try_to_unuse(p->type, false, 0); /* force unuse all pages */ err = try_to_unuse(p->type);
clear_current_oom_origin(); clear_current_oom_origin();
if (err) { if (err) {
......
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