Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S934159AbcJTXdT (ORCPT ); Thu, 20 Oct 2016 19:33:19 -0400 Received: from mga01.intel.com ([192.55.52.88]:32157 "EHLO mga01.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933781AbcJTXcr (ORCPT ); Thu, 20 Oct 2016 19:32:47 -0400 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.31,521,1473145200"; d="scan'208";a="1056877511" From: Tim Chen To: Andrew Morton Cc: Tim Chen , Ying Huang , dave.hansen@intel.com, ak@linux.intel.com, aaron.lu@intel.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org, Hugh Dickins , Shaohua Li , Minchan Kim , Rik van Riel , Andrea Arcangeli , "Kirill A . Shutemov" , Vladimir Davydov , Johannes Weiner , Michal Hocko , Hillf Danton Subject: [PATCH v2 8/8] mm/swap: Enable swap slots cache usage Date: Thu, 20 Oct 2016 16:31:47 -0700 Message-Id: <24619a5b1749f6fb62de70d9def6d20d25229a65.1477004978.git.tim.c.chen@linux.intel.com> X-Mailer: git-send-email 2.5.5 In-Reply-To: References: In-Reply-To: References: Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1747 Lines: 64 Initialize swap slots cache and enable it on swap on. Drain swap slots on swap off. Signed-off-by: Tim Chen --- 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