[PATCH v2 8/8] mm/swap: Enable swap slots cache usage
From: Tim Chen
Date: Thu Oct 20 2016 - 19:33:23 EST
Initialize swap slots cache and enable it on swap on.
Drain swap slots on swap off.
Signed-off-by: Tim Chen <tim.c.chen@xxxxxxxxxxxxxxx>
---
mm/swapfile.c | 13 ++++++++++---
1 file changed, 10 insertions(+), 3 deletions(-)
diff --git a/mm/swapfile.c b/mm/swapfile.c
index caf9fe6..e98c725 100644
--- a/mm/swapfile.c
+++ b/mm/swapfile.c
@@ -2132,7 +2132,7 @@ SYSCALL_DEFINE1(swapoff, const char __user *, specialfile)
struct address_space *mapping;
struct inode *inode;
struct filename *pathname;
- int err, found = 0;
+ int err, found = 0, has_swap = 0;
unsigned int old_block_size;
if (!capable(CAP_SYS_ADMIN))
@@ -2144,6 +2144,7 @@ SYSCALL_DEFINE1(swapoff, const char __user *, specialfile)
if (IS_ERR(pathname))
return PTR_ERR(pathname);
+ disable_swap_slots_cache();
victim = file_open_name(pathname, O_RDWR|O_LARGEFILE, 0);
err = PTR_ERR(victim);
if (IS_ERR(victim))
@@ -2153,10 +2154,13 @@ SYSCALL_DEFINE1(swapoff, const char __user *, specialfile)
spin_lock(&swap_lock);
plist_for_each_entry(p, &swap_active_head, list) {
if (p->flags & SWP_WRITEOK) {
- if (p->swap_file->f_mapping == mapping) {
+ if (p->swap_file->f_mapping == mapping)
found = 1;
+ else
+ ++has_swap;
+ /* there is another swap device left? */
+ if (found && has_swap)
break;
- }
}
}
if (!found) {
@@ -2275,6 +2279,8 @@ out_dput:
filp_close(victim, NULL);
out:
putname(pathname);
+ if (has_swap)
+ reenable_swap_slots_cache();
return err;
}
@@ -2692,6 +2698,7 @@ SYSCALL_DEFINE2(swapon, const char __user *, specialfile, int, swap_flags)
if (!capable(CAP_SYS_ADMIN))
return -EPERM;
+ enable_swap_slot_caches();
p = alloc_swap_info();
if (IS_ERR(p))
return PTR_ERR(p);
--
2.5.5