From owner-svn-src-head@freebsd.org Sun May 22 23:25:02 2016 Return-Path: Delivered-To: svn-src-head@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 80BC8B3BCAE; Sun, 22 May 2016 23:25:02 +0000 (UTC) (envelope-from kib@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 4ADE11BF5; Sun, 22 May 2016 23:25:02 +0000 (UTC) (envelope-from kib@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id u4MNP1A9071365; Sun, 22 May 2016 23:25:01 GMT (envelope-from kib@FreeBSD.org) Received: (from kib@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id u4MNP1vo071364; Sun, 22 May 2016 23:25:01 GMT (envelope-from kib@FreeBSD.org) Message-Id: <201605222325.u4MNP1vo071364@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: kib set sender to kib@FreeBSD.org using -f From: Konstantin Belousov Date: Sun, 22 May 2016 23:25:01 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r300439 - head/sys/vm X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 22 May 2016 23:25:02 -0000 Author: kib Date: Sun May 22 23:25:01 2016 New Revision: 300439 URL: https://svnweb.freebsd.org/changeset/base/300439 Log: Replace hand-made exclusive lock, protecting against parallel swapon/swapoff invocations, with sx. Reviewed by: alc (as part of larger patch) Sponsored by: The FreeBSD Foundation Modified: head/sys/vm/swap_pager.c Modified: head/sys/vm/swap_pager.c ============================================================================== --- head/sys/vm/swap_pager.c Sun May 22 21:31:20 2016 (r300438) +++ head/sys/vm/swap_pager.c Sun May 22 23:25:01 2016 (r300439) @@ -152,7 +152,7 @@ static TAILQ_HEAD(, swdevt) swtailq = TA static struct swdevt *swdevhd; /* Allocate from here next */ static int nswapdev; /* Number of swap devices */ int swap_pager_avail; -static int swdev_syscall_active = 0; /* serialize swap(on|off) */ +static struct sx swdev_syscall_lock; /* serialize swap(on|off) */ static vm_ooffset_t swap_total; SYSCTL_QUAD(_vm, OID_AUTO, swap_total, CTLFLAG_RD, &swap_total, 0, @@ -487,6 +487,7 @@ swap_pager_init(void) TAILQ_INIT(&swap_pager_object_list[i]); mtx_init(&sw_alloc_mtx, "swap_pager list", NULL, MTX_DEF); mtx_init(&sw_dev_mtx, "swapdev", NULL, MTX_DEF); + sx_init(&swdev_syscall_lock, "swsysc"); /* * Device Stripe, in PAGE_SIZE'd blocks @@ -1664,7 +1665,7 @@ swap_pager_swapoff(struct swdevt *sp) struct swblock *swap; int i, j, retries; - GIANT_REQUIRED; + sx_assert(&swdev_syscall_lock, SA_XLOCKED); retries = 0; full_rescan: @@ -2005,10 +2006,7 @@ sys_swapon(struct thread *td, struct swa if (error) return (error); - mtx_lock(&Giant); - while (swdev_syscall_active) - tsleep(&swdev_syscall_active, PUSER - 1, "swpon", 0); - swdev_syscall_active = 1; + sx_xlock(&swdev_syscall_lock); /* * Swap metadata may not fit in the KVM if we have physical @@ -2043,9 +2041,7 @@ sys_swapon(struct thread *td, struct swa if (error) vrele(vp); done: - swdev_syscall_active = 0; - wakeup_one(&swdev_syscall_active); - mtx_unlock(&Giant); + sx_xunlock(&swdev_syscall_lock); return (error); } @@ -2175,10 +2171,7 @@ sys_swapoff(struct thread *td, struct sw if (error) return (error); - mtx_lock(&Giant); - while (swdev_syscall_active) - tsleep(&swdev_syscall_active, PUSER - 1, "swpoff", 0); - swdev_syscall_active = 1; + sx_xlock(&swdev_syscall_lock); NDINIT(&nd, LOOKUP, FOLLOW | AUDITVNODE1, UIO_USERSPACE, uap->name, td); @@ -2200,9 +2193,7 @@ sys_swapoff(struct thread *td, struct sw } error = swapoff_one(sp, td->td_ucred); done: - swdev_syscall_active = 0; - wakeup_one(&swdev_syscall_active); - mtx_unlock(&Giant); + sx_xunlock(&swdev_syscall_lock); return (error); } @@ -2214,7 +2205,7 @@ swapoff_one(struct swdevt *sp, struct uc int error; #endif - mtx_assert(&Giant, MA_OWNED); + sx_assert(&swdev_syscall_lock, SA_XLOCKED); #ifdef MAC (void) vn_lock(sp->sw_vp, LK_EXCLUSIVE | LK_RETRY); error = mac_system_check_swapoff(cred, sp->sw_vp); @@ -2276,10 +2267,7 @@ swapoff_all(void) const char *devname; int error; - mtx_lock(&Giant); - while (swdev_syscall_active) - tsleep(&swdev_syscall_active, PUSER - 1, "swpoff", 0); - swdev_syscall_active = 1; + sx_xlock(&swdev_syscall_lock); mtx_lock(&sw_dev_mtx); TAILQ_FOREACH_SAFE(sp, &swtailq, sw_list, spt) { @@ -2299,9 +2287,7 @@ swapoff_all(void) } mtx_unlock(&sw_dev_mtx); - swdev_syscall_active = 0; - wakeup_one(&swdev_syscall_active); - mtx_unlock(&Giant); + sx_xunlock(&swdev_syscall_lock); } void