Skip to content

Commit 10a9c49

Browse files
Christoph Hellwigtorvalds
authored andcommitted
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. [[email protected]: fix shmem_unuse() stub, per Matthew] Link: https://lkml.kernel.org/r/[email protected] Signed-off-by: Christoph Hellwig <[email protected]> Reviewed-by: Juergen Gross <[email protected]> Cc: Dan Streetman <[email protected]> Cc: Geert Uytterhoeven <[email protected]> Cc: Hugh Dickins <[email protected]> Cc: Konrad Rzeszutek Wilk <[email protected]> Cc: Matthew Wilcox (Oracle) <[email protected]> Cc: Seth Jennings <[email protected]> Cc: Vitaly Wool <[email protected]> Cc: Naresh Kamboju <[email protected]> Signed-off-by: Andrew Morton <[email protected]> Signed-off-by: Linus Torvalds <[email protected]>
1 parent 360be5d commit 10a9c49

File tree

5 files changed

+30
-97
lines changed

5 files changed

+30
-97
lines changed

include/linux/frontswap.h

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,6 @@
77
#include <linux/bitops.h>
88
#include <linux/jump_label.h>
99

10-
/*
11-
* Return code to denote that requested number of
12-
* frontswap pages are unused(moved to page cache).
13-
* Used in shmem_unuse and try_to_unuse.
14-
*/
15-
#define FRONTSWAP_PAGES_UNUSED 2
16-
1710
struct frontswap_ops {
1811
void (*init)(unsigned); /* this swap type was just swapon'ed */
1912
int (*store)(unsigned, pgoff_t, struct page *); /* store a page */

include/linux/shmem_fs.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,7 @@ extern void shmem_unlock_mapping(struct address_space *mapping);
8383
extern struct page *shmem_read_mapping_page_gfp(struct address_space *mapping,
8484
pgoff_t index, gfp_t gfp_mask);
8585
extern void shmem_truncate_range(struct inode *inode, loff_t start, loff_t end);
86-
extern int shmem_unuse(unsigned int type, bool frontswap,
87-
unsigned long *fs_pages_to_unuse);
86+
int shmem_unuse(unsigned int type);
8887

8988
extern bool shmem_is_huge(struct vm_area_struct *vma,
9089
struct inode *inode, pgoff_t index);

include/linux/swapfile.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
extern spinlock_t swap_lock;
1010
extern struct plist_head swap_active_head;
1111
extern struct swap_info_struct *swap_info[];
12-
extern int try_to_unuse(unsigned int, bool, unsigned long);
1312
extern unsigned long generic_max_swapfile_size(void);
1413
extern unsigned long max_swapfile_size(void);
1514

mm/shmem.c

Lines changed: 6 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@
3636
#include <linux/uio.h>
3737
#include <linux/khugepaged.h>
3838
#include <linux/hugetlb.h>
39-
#include <linux/frontswap.h>
4039
#include <linux/fs_parser.h>
4140
#include <linux/swapfile.h>
4241

@@ -1152,7 +1151,7 @@ static void shmem_evict_inode(struct inode *inode)
11521151
static int shmem_find_swap_entries(struct address_space *mapping,
11531152
pgoff_t start, unsigned int nr_entries,
11541153
struct page **entries, pgoff_t *indices,
1155-
unsigned int type, bool frontswap)
1154+
unsigned int type)
11561155
{
11571156
XA_STATE(xas, &mapping->i_pages, start);
11581157
struct page *page;
@@ -1173,9 +1172,6 @@ static int shmem_find_swap_entries(struct address_space *mapping,
11731172
entry = radix_to_swp_entry(page);
11741173
if (swp_type(entry) != type)
11751174
continue;
1176-
if (frontswap &&
1177-
!frontswap_test(swap_info[type], swp_offset(entry)))
1178-
continue;
11791175

11801176
indices[ret] = xas.xa_index;
11811177
entries[ret] = page;
@@ -1228,26 +1224,20 @@ static int shmem_unuse_swap_entries(struct inode *inode, struct pagevec pvec,
12281224
/*
12291225
* If swap found in inode, free it and move page from swapcache to filecache.
12301226
*/
1231-
static int shmem_unuse_inode(struct inode *inode, unsigned int type,
1232-
bool frontswap, unsigned long *fs_pages_to_unuse)
1227+
static int shmem_unuse_inode(struct inode *inode, unsigned int type)
12331228
{
12341229
struct address_space *mapping = inode->i_mapping;
12351230
pgoff_t start = 0;
12361231
struct pagevec pvec;
12371232
pgoff_t indices[PAGEVEC_SIZE];
1238-
bool frontswap_partial = (frontswap && *fs_pages_to_unuse > 0);
12391233
int ret = 0;
12401234

12411235
pagevec_init(&pvec);
12421236
do {
12431237
unsigned int nr_entries = PAGEVEC_SIZE;
12441238

1245-
if (frontswap_partial && *fs_pages_to_unuse < PAGEVEC_SIZE)
1246-
nr_entries = *fs_pages_to_unuse;
1247-
12481239
pvec.nr = shmem_find_swap_entries(mapping, start, nr_entries,
1249-
pvec.pages, indices,
1250-
type, frontswap);
1240+
pvec.pages, indices, type);
12511241
if (pvec.nr == 0) {
12521242
ret = 0;
12531243
break;
@@ -1257,14 +1247,6 @@ static int shmem_unuse_inode(struct inode *inode, unsigned int type,
12571247
if (ret < 0)
12581248
break;
12591249

1260-
if (frontswap_partial) {
1261-
*fs_pages_to_unuse -= ret;
1262-
if (*fs_pages_to_unuse == 0) {
1263-
ret = FRONTSWAP_PAGES_UNUSED;
1264-
break;
1265-
}
1266-
}
1267-
12681250
start = indices[pvec.nr - 1];
12691251
} while (true);
12701252

@@ -1276,8 +1258,7 @@ static int shmem_unuse_inode(struct inode *inode, unsigned int type,
12761258
* device 'type' back into memory, so the swap device can be
12771259
* unused.
12781260
*/
1279-
int shmem_unuse(unsigned int type, bool frontswap,
1280-
unsigned long *fs_pages_to_unuse)
1261+
int shmem_unuse(unsigned int type)
12811262
{
12821263
struct shmem_inode_info *info, *next;
12831264
int error = 0;
@@ -1300,8 +1281,7 @@ int shmem_unuse(unsigned int type, bool frontswap,
13001281
atomic_inc(&info->stop_eviction);
13011282
mutex_unlock(&shmem_swaplist_mutex);
13021283

1303-
error = shmem_unuse_inode(&info->vfs_inode, type, frontswap,
1304-
fs_pages_to_unuse);
1284+
error = shmem_unuse_inode(&info->vfs_inode, type);
13051285
cond_resched();
13061286

13071287
mutex_lock(&shmem_swaplist_mutex);
@@ -4015,8 +3995,7 @@ int __init shmem_init(void)
40153995
return 0;
40163996
}
40173997

4018-
int shmem_unuse(unsigned int type, bool frontswap,
4019-
unsigned long *fs_pages_to_unuse)
3998+
int shmem_unuse(unsigned int type)
40203999
{
40214000
return 0;
40224001
}

mm/swapfile.c

Lines changed: 23 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -1923,8 +1923,7 @@ static int unuse_pte(struct vm_area_struct *vma, pmd_t *pmd,
19231923

19241924
static int unuse_pte_range(struct vm_area_struct *vma, pmd_t *pmd,
19251925
unsigned long addr, unsigned long end,
1926-
unsigned int type, bool frontswap,
1927-
unsigned long *fs_pages_to_unuse)
1926+
unsigned int type)
19281927
{
19291928
struct page *page;
19301929
swp_entry_t entry;
@@ -1945,9 +1944,6 @@ static int unuse_pte_range(struct vm_area_struct *vma, pmd_t *pmd,
19451944
continue;
19461945

19471946
offset = swp_offset(entry);
1948-
if (frontswap && !frontswap_test(si, offset))
1949-
continue;
1950-
19511947
pte_unmap(pte);
19521948
swap_map = &si->swap_map[offset];
19531949
page = lookup_swap_cache(entry, vma, addr);
@@ -1979,11 +1975,6 @@ static int unuse_pte_range(struct vm_area_struct *vma, pmd_t *pmd,
19791975
try_to_free_swap(page);
19801976
unlock_page(page);
19811977
put_page(page);
1982-
1983-
if (*fs_pages_to_unuse && !--(*fs_pages_to_unuse)) {
1984-
ret = FRONTSWAP_PAGES_UNUSED;
1985-
goto out;
1986-
}
19871978
try_next:
19881979
pte = pte_offset_map(pmd, addr);
19891980
} while (pte++, addr += PAGE_SIZE, addr != end);
@@ -1996,8 +1987,7 @@ static int unuse_pte_range(struct vm_area_struct *vma, pmd_t *pmd,
19961987

19971988
static inline int unuse_pmd_range(struct vm_area_struct *vma, pud_t *pud,
19981989
unsigned long addr, unsigned long end,
1999-
unsigned int type, bool frontswap,
2000-
unsigned long *fs_pages_to_unuse)
1990+
unsigned int type)
20011991
{
20021992
pmd_t *pmd;
20031993
unsigned long next;
@@ -2009,8 +1999,7 @@ static inline int unuse_pmd_range(struct vm_area_struct *vma, pud_t *pud,
20091999
next = pmd_addr_end(addr, end);
20102000
if (pmd_none_or_trans_huge_or_clear_bad(pmd))
20112001
continue;
2012-
ret = unuse_pte_range(vma, pmd, addr, next, type,
2013-
frontswap, fs_pages_to_unuse);
2002+
ret = unuse_pte_range(vma, pmd, addr, next, type);
20142003
if (ret)
20152004
return ret;
20162005
} while (pmd++, addr = next, addr != end);
@@ -2019,8 +2008,7 @@ static inline int unuse_pmd_range(struct vm_area_struct *vma, pud_t *pud,
20192008

20202009
static inline int unuse_pud_range(struct vm_area_struct *vma, p4d_t *p4d,
20212010
unsigned long addr, unsigned long end,
2022-
unsigned int type, bool frontswap,
2023-
unsigned long *fs_pages_to_unuse)
2011+
unsigned int type)
20242012
{
20252013
pud_t *pud;
20262014
unsigned long next;
@@ -2031,8 +2019,7 @@ static inline int unuse_pud_range(struct vm_area_struct *vma, p4d_t *p4d,
20312019
next = pud_addr_end(addr, end);
20322020
if (pud_none_or_clear_bad(pud))
20332021
continue;
2034-
ret = unuse_pmd_range(vma, pud, addr, next, type,
2035-
frontswap, fs_pages_to_unuse);
2022+
ret = unuse_pmd_range(vma, pud, addr, next, type);
20362023
if (ret)
20372024
return ret;
20382025
} while (pud++, addr = next, addr != end);
@@ -2041,8 +2028,7 @@ static inline int unuse_pud_range(struct vm_area_struct *vma, p4d_t *p4d,
20412028

20422029
static inline int unuse_p4d_range(struct vm_area_struct *vma, pgd_t *pgd,
20432030
unsigned long addr, unsigned long end,
2044-
unsigned int type, bool frontswap,
2045-
unsigned long *fs_pages_to_unuse)
2031+
unsigned int type)
20462032
{
20472033
p4d_t *p4d;
20482034
unsigned long next;
@@ -2053,16 +2039,14 @@ static inline int unuse_p4d_range(struct vm_area_struct *vma, pgd_t *pgd,
20532039
next = p4d_addr_end(addr, end);
20542040
if (p4d_none_or_clear_bad(p4d))
20552041
continue;
2056-
ret = unuse_pud_range(vma, p4d, addr, next, type,
2057-
frontswap, fs_pages_to_unuse);
2042+
ret = unuse_pud_range(vma, p4d, addr, next, type);
20582043
if (ret)
20592044
return ret;
20602045
} while (p4d++, addr = next, addr != end);
20612046
return 0;
20622047
}
20632048

2064-
static int unuse_vma(struct vm_area_struct *vma, unsigned int type,
2065-
bool frontswap, unsigned long *fs_pages_to_unuse)
2049+
static int unuse_vma(struct vm_area_struct *vma, unsigned int type)
20662050
{
20672051
pgd_t *pgd;
20682052
unsigned long addr, end, next;
@@ -2076,25 +2060,22 @@ static int unuse_vma(struct vm_area_struct *vma, unsigned int type,
20762060
next = pgd_addr_end(addr, end);
20772061
if (pgd_none_or_clear_bad(pgd))
20782062
continue;
2079-
ret = unuse_p4d_range(vma, pgd, addr, next, type,
2080-
frontswap, fs_pages_to_unuse);
2063+
ret = unuse_p4d_range(vma, pgd, addr, next, type);
20812064
if (ret)
20822065
return ret;
20832066
} while (pgd++, addr = next, addr != end);
20842067
return 0;
20852068
}
20862069

2087-
static int unuse_mm(struct mm_struct *mm, unsigned int type,
2088-
bool frontswap, unsigned long *fs_pages_to_unuse)
2070+
static int unuse_mm(struct mm_struct *mm, unsigned int type)
20892071
{
20902072
struct vm_area_struct *vma;
20912073
int ret = 0;
20922074

20932075
mmap_read_lock(mm);
20942076
for (vma = mm->mmap; vma; vma = vma->vm_next) {
20952077
if (vma->anon_vma) {
2096-
ret = unuse_vma(vma, type, frontswap,
2097-
fs_pages_to_unuse);
2078+
ret = unuse_vma(vma, type);
20982079
if (ret)
20992080
break;
21002081
}
@@ -2110,7 +2091,7 @@ static int unuse_mm(struct mm_struct *mm, unsigned int type,
21102091
* if there are no inuse entries after prev till end of the map.
21112092
*/
21122093
static unsigned int find_next_to_unuse(struct swap_info_struct *si,
2113-
unsigned int prev, bool frontswap)
2094+
unsigned int prev)
21142095
{
21152096
unsigned int i;
21162097
unsigned char count;
@@ -2124,8 +2105,7 @@ static unsigned int find_next_to_unuse(struct swap_info_struct *si,
21242105
for (i = prev + 1; i < si->max; i++) {
21252106
count = READ_ONCE(si->swap_map[i]);
21262107
if (count && swap_count(count) != SWAP_MAP_BAD)
2127-
if (!frontswap || frontswap_test(si, i))
2128-
break;
2108+
break;
21292109
if ((i % LATENCY_LIMIT) == 0)
21302110
cond_resched();
21312111
}
@@ -2136,12 +2116,7 @@ static unsigned int find_next_to_unuse(struct swap_info_struct *si,
21362116
return i;
21372117
}
21382118

2139-
/*
2140-
* If the boolean frontswap is true, only unuse pages_to_unuse pages;
2141-
* pages_to_unuse==0 means all pages; ignored if frontswap is false
2142-
*/
2143-
int try_to_unuse(unsigned int type, bool frontswap,
2144-
unsigned long pages_to_unuse)
2119+
static int try_to_unuse(unsigned int type)
21452120
{
21462121
struct mm_struct *prev_mm;
21472122
struct mm_struct *mm;
@@ -2155,13 +2130,10 @@ int try_to_unuse(unsigned int type, bool frontswap,
21552130
if (!READ_ONCE(si->inuse_pages))
21562131
return 0;
21572132

2158-
if (!frontswap)
2159-
pages_to_unuse = 0;
2160-
21612133
retry:
2162-
retval = shmem_unuse(type, frontswap, &pages_to_unuse);
2134+
retval = shmem_unuse(type);
21632135
if (retval)
2164-
goto out;
2136+
return retval;
21652137

21662138
prev_mm = &init_mm;
21672139
mmget(prev_mm);
@@ -2178,11 +2150,10 @@ int try_to_unuse(unsigned int type, bool frontswap,
21782150
spin_unlock(&mmlist_lock);
21792151
mmput(prev_mm);
21802152
prev_mm = mm;
2181-
retval = unuse_mm(mm, type, frontswap, &pages_to_unuse);
2182-
2153+
retval = unuse_mm(mm, type);
21832154
if (retval) {
21842155
mmput(prev_mm);
2185-
goto out;
2156+
return retval;
21862157
}
21872158

21882159
/*
@@ -2199,7 +2170,7 @@ int try_to_unuse(unsigned int type, bool frontswap,
21992170
i = 0;
22002171
while (READ_ONCE(si->inuse_pages) &&
22012172
!signal_pending(current) &&
2202-
(i = find_next_to_unuse(si, i, frontswap)) != 0) {
2173+
(i = find_next_to_unuse(si, i)) != 0) {
22032174

22042175
entry = swp_entry(type, i);
22052176
page = find_get_page(swap_address_space(entry), i);
@@ -2217,14 +2188,6 @@ int try_to_unuse(unsigned int type, bool frontswap,
22172188
try_to_free_swap(page);
22182189
unlock_page(page);
22192190
put_page(page);
2220-
2221-
/*
2222-
* For frontswap, we just need to unuse pages_to_unuse, if
2223-
* it was specified. Need not check frontswap again here as
2224-
* we already zeroed out pages_to_unuse if not frontswap.
2225-
*/
2226-
if (pages_to_unuse && --pages_to_unuse == 0)
2227-
goto out;
22282191
}
22292192

22302193
/*
@@ -2242,10 +2205,10 @@ int try_to_unuse(unsigned int type, bool frontswap,
22422205
if (READ_ONCE(si->inuse_pages)) {
22432206
if (!signal_pending(current))
22442207
goto retry;
2245-
retval = -EINTR;
2208+
return -EINTR;
22462209
}
2247-
out:
2248-
return (retval == FRONTSWAP_PAGES_UNUSED) ? 0 : retval;
2210+
2211+
return 0;
22492212
}
22502213

22512214
/*
@@ -2577,7 +2540,7 @@ SYSCALL_DEFINE1(swapoff, const char __user *, specialfile)
25772540
disable_swap_slots_cache_lock();
25782541

25792542
set_current_oom_origin();
2580-
err = try_to_unuse(p->type, false, 0); /* force unuse all pages */
2543+
err = try_to_unuse(p->type);
25812544
clear_current_oom_origin();
25822545

25832546
if (err) {

0 commit comments

Comments
 (0)