[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <24619a5b1749f6fb62de70d9def6d20d25229a65.1477004978.git.tim.c.chen@linux.intel.com>
Date: Thu, 20 Oct 2016 16:31:47 -0700
From: Tim Chen <tim.c.chen@...ux.intel.com>
To: Andrew Morton <akpm@...ux-foundation.org>
Cc: Tim Chen <tim.c.chen@...ux.intel.com>,
Ying Huang <ying.huang@...el.com>, dave.hansen@...el.com,
ak@...ux.intel.com, aaron.lu@...el.com, linux-mm@...ck.org,
linux-kernel@...r.kernel.org, Hugh Dickins <hughd@...gle.com>,
Shaohua Li <shli@...nel.org>, Minchan Kim <minchan@...nel.org>,
Rik van Riel <riel@...hat.com>,
Andrea Arcangeli <aarcange@...hat.com>,
"Kirill A . Shutemov" <kirill.shutemov@...ux.intel.com>,
Vladimir Davydov <vdavydov.dev@...il.com>,
Johannes Weiner <hannes@...xchg.org>,
Michal Hocko <mhocko@...nel.org>,
Hillf Danton <hillf.zj@...baba-inc.com>
Subject: [PATCH v2 8/8] mm/swap: Enable swap slots cache usage
Initialize swap slots cache and enable it on swap on.
Drain swap slots on swap off.
Signed-off-by: Tim Chen <tim.c.chen@...ux.intel.com>
---
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
Powered by blists - more mailing lists