Date: Wed, 10 Aug 2016 12:11:12 +0000 (UTC) From: Konstantin Belousov <kib@FreeBSD.org> To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-11@freebsd.org Subject: svn commit: r303905 - stable/11/sys/vm Message-ID: <201608101211.u7ACBC0j039360@repo.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: kib Date: Wed Aug 10 12:11:11 2016 New Revision: 303905 URL: https://svnweb.freebsd.org/changeset/base/303905 Log: MFC r303448: Do not delegate a work to geom event thread which can be done inline. MFC r303703: Explain why swapgeom_close_ev() is delegated. Approved by: re (gjb) Modified: stable/11/sys/vm/swap_pager.c Directory Properties: stable/11/ (props changed) Modified: stable/11/sys/vm/swap_pager.c ============================================================================== --- stable/11/sys/vm/swap_pager.c Wed Aug 10 10:36:11 2016 (r303904) +++ stable/11/sys/vm/swap_pager.c Wed Aug 10 12:11:11 2016 (r303905) @@ -395,7 +395,7 @@ SYSCTL_INT(_vm, OID_AUTO, dmmax, CTLFLAG static void swp_sizecheck(void); static void swp_pager_async_iodone(struct buf *bp); -static int swapongeom(struct thread *, struct vnode *); +static int swapongeom(struct vnode *); static int swaponvp(struct thread *, struct vnode *, u_long); static int swapoff_one(struct swdevt *sp, struct ucred *cred); @@ -2019,7 +2019,7 @@ sys_swapon(struct thread *td, struct swa vp = nd.ni_vp; if (vn_isdisk(vp, &error)) { - error = swapongeom(td, vp); + error = swapongeom(vp); } else if (vp->v_type == VREG && (vp->v_mount->mnt_vfc->vfc_flags & VFCF_NETWORK) != 0 && (error = VOP_GETATTR(vp, &attr, td->td_ucred)) == 0) { @@ -2431,8 +2431,9 @@ swapgeom_acquire(struct g_consumer *cp) } /* - * Remove a reference from the g_consumer. Post a close event if - * all references go away. + * Remove a reference from the g_consumer. Post a close event if all + * references go away, since the function might be called from the + * biodone context. */ static void swapgeom_release(struct g_consumer *cp, struct swdevt *sp) @@ -2555,22 +2556,19 @@ swapgeom_close(struct thread *td, struct cp = sw->sw_id; sw->sw_id = NULL; mtx_unlock(&sw_dev_mtx); - /* XXX: direct call when Giant untangled */ + + /* + * swapgeom_close() may be called from the biodone context, + * where we cannot perform topology changes. Delegate the + * work to the events thread. + */ if (cp != NULL) g_waitfor_event(swapgeom_close_ev, cp, M_WAITOK, NULL); } - -struct swh0h0 { - struct cdev *dev; - struct vnode *vp; - int error; -}; - -static void -swapongeom_ev(void *arg, int flags) +static int +swapongeom_locked(struct cdev *dev, struct vnode *vp) { - struct swh0h0 *swh; struct g_provider *pp; struct g_consumer *cp; static struct g_geom *gp; @@ -2578,20 +2576,15 @@ swapongeom_ev(void *arg, int flags) u_long nblks; int error; - swh = arg; - swh->error = 0; - pp = g_dev_getprovider(swh->dev); - if (pp == NULL) { - swh->error = ENODEV; - return; - } + pp = g_dev_getprovider(dev); + if (pp == NULL) + return (ENODEV); mtx_lock(&sw_dev_mtx); TAILQ_FOREACH(sp, &swtailq, sw_list) { cp = sp->sw_id; if (cp != NULL && cp->provider == pp) { mtx_unlock(&sw_dev_mtx); - swh->error = EBUSY; - return; + return (EBUSY); } } mtx_unlock(&sw_dev_mtx); @@ -2608,34 +2601,31 @@ swapongeom_ev(void *arg, int flags) * set an exclusive count :-( */ error = g_access(cp, 1, 1, 0); - if (error) { + if (error != 0) { g_detach(cp); g_destroy_consumer(cp); - swh->error = error; - return; + return (error); } nblks = pp->mediasize / DEV_BSIZE; - swaponsomething(swh->vp, cp, nblks, swapgeom_strategy, - swapgeom_close, dev2udev(swh->dev), + swaponsomething(vp, cp, nblks, swapgeom_strategy, + swapgeom_close, dev2udev(dev), (pp->flags & G_PF_ACCEPT_UNMAPPED) != 0 ? SW_UNMAPPED : 0); - swh->error = 0; + return (0); } static int -swapongeom(struct thread *td, struct vnode *vp) +swapongeom(struct vnode *vp) { int error; - struct swh0h0 swh; vn_lock(vp, LK_EXCLUSIVE | LK_RETRY); - - swh.dev = vp->v_rdev; - swh.vp = vp; - swh.error = 0; - /* XXX: direct call when Giant untangled */ - error = g_waitfor_event(swapongeom_ev, &swh, M_WAITOK, NULL); - if (!error) - error = swh.error; + if (vp->v_type != VCHR || (vp->v_iflag & VI_DOOMED) != 0) { + error = ENOENT; + } else { + g_topology_lock(); + error = swapongeom_locked(vp->v_rdev, vp); + g_topology_unlock(); + } VOP_UNLOCK(vp, 0); return (error); }
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201608101211.u7ACBC0j039360>