From owner-svn-src-user@freebsd.org Thu Dec 17 01:33:47 2015 Return-Path: Delivered-To: svn-src-user@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 F1F70A4A483 for ; Thu, 17 Dec 2015 01:33:46 +0000 (UTC) (envelope-from markj@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 B1E8B1DB8; Thu, 17 Dec 2015 01:33:46 +0000 (UTC) (envelope-from markj@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id tBH1Xj93055489; Thu, 17 Dec 2015 01:33:45 GMT (envelope-from markj@FreeBSD.org) Received: (from markj@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id tBH1XjKO055488; Thu, 17 Dec 2015 01:33:45 GMT (envelope-from markj@FreeBSD.org) Message-Id: <201512170133.tBH1XjKO055488@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: markj set sender to markj@FreeBSD.org using -f From: Mark Johnston Date: Thu, 17 Dec 2015 01:33:45 +0000 (UTC) To: src-committers@freebsd.org, svn-src-user@freebsd.org Subject: svn commit: r292393 - user/alc/PQ_LAUNDRY/sys/vm X-SVN-Group: user MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-user@freebsd.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: "SVN commit messages for the experimental " user" src tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 17 Dec 2015 01:33:47 -0000 Author: markj Date: Thu Dec 17 01:33:45 2015 New Revision: 292393 URL: https://svnweb.freebsd.org/changeset/base/292393 Log: Use an sx lock rather than a hand-rolled lock to serialize swapon/swapoff. Modified: user/alc/PQ_LAUNDRY/sys/vm/swap_pager.c Modified: user/alc/PQ_LAUNDRY/sys/vm/swap_pager.c ============================================================================== --- user/alc/PQ_LAUNDRY/sys/vm/swap_pager.c Thu Dec 17 01:31:26 2015 (r292392) +++ user/alc/PQ_LAUNDRY/sys/vm/swap_pager.c Thu Dec 17 01:33:45 2015 (r292393) @@ -147,12 +147,12 @@ struct swblock { }; static MALLOC_DEFINE(M_VMPGDATA, "vm_pgdata", "swap pager private data"); +static struct sx sw_conf_sx; static struct mtx sw_dev_mtx; static TAILQ_HEAD(, swdevt) swtailq = TAILQ_HEAD_INITIALIZER(swtailq); 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 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(&sw_conf_sx, "swapconf"); /* * Device Stripe, in PAGE_SIZE'd blocks @@ -2004,9 +2005,7 @@ sys_swapon(struct thread *td, struct swa return (error); mtx_lock(&Giant); - while (swdev_syscall_active) - tsleep(&swdev_syscall_active, PUSER - 1, "swpon", 0); - swdev_syscall_active = 1; + sx_xlock(&sw_conf_sx); /* * Swap metadata may not fit in the KVM if we have physical @@ -2041,8 +2040,7 @@ sys_swapon(struct thread *td, struct swa if (error) vrele(vp); done: - swdev_syscall_active = 0; - wakeup_one(&swdev_syscall_active); + sx_xunlock(&sw_conf_sx); mtx_unlock(&Giant); return (error); } @@ -2174,9 +2172,7 @@ sys_swapoff(struct thread *td, struct sw return (error); mtx_lock(&Giant); - while (swdev_syscall_active) - tsleep(&swdev_syscall_active, PUSER - 1, "swpoff", 0); - swdev_syscall_active = 1; + sx_xlock(&sw_conf_sx); NDINIT(&nd, LOOKUP, FOLLOW | AUDITVNODE1, UIO_USERSPACE, uap->name, td); @@ -2198,8 +2194,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); + sx_xunlock(&sw_conf_sx); mtx_unlock(&Giant); return (error); } @@ -2213,6 +2208,7 @@ swapoff_one(struct swdevt *sp, struct uc #endif mtx_assert(&Giant, MA_OWNED); + sx_assert(&sw_conf_sx, SA_XLOCKED); #ifdef MAC (void) vn_lock(sp->sw_vp, LK_EXCLUSIVE | LK_RETRY); error = mac_system_check_swapoff(cred, sp->sw_vp); @@ -2275,10 +2271,7 @@ swapoff_all(void) int error; mtx_lock(&Giant); - while (swdev_syscall_active) - tsleep(&swdev_syscall_active, PUSER - 1, "swpoff", 0); - swdev_syscall_active = 1; - + sx_xlock(&sw_conf_sx); mtx_lock(&sw_dev_mtx); TAILQ_FOREACH_SAFE(sp, &swtailq, sw_list, spt) { mtx_unlock(&sw_dev_mtx); @@ -2296,9 +2289,7 @@ swapoff_all(void) mtx_lock(&sw_dev_mtx); } mtx_unlock(&sw_dev_mtx); - - swdev_syscall_active = 0; - wakeup_one(&swdev_syscall_active); + sx_xunlock(&sw_conf_sx); mtx_unlock(&Giant); }