From owner-svn-src-head@freebsd.org Sat Oct 24 17:25:00 2020 Return-Path: Delivered-To: svn-src-head@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id EA55D44F134; Sat, 24 Oct 2020 17:25:00 +0000 (UTC) (envelope-from kostikbel@gmail.com) Received: from kib.kiev.ua (kib.kiev.ua [IPv6:2001:470:d5e7:1::1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 4CJSf456Fqz3bJZ; Sat, 24 Oct 2020 17:25:00 +0000 (UTC) (envelope-from kostikbel@gmail.com) Received: from tom.home (kib@localhost [127.0.0.1]) by kib.kiev.ua (8.16.1/8.16.1) with ESMTPS id 09OHOqDi043466 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NO); Sat, 24 Oct 2020 20:24:55 +0300 (EEST) (envelope-from kostikbel@gmail.com) DKIM-Filter: OpenDKIM Filter v2.10.3 kib.kiev.ua 09OHOqDi043466 Received: (from kostik@localhost) by tom.home (8.16.1/8.16.1/Submit) id 09OHOqCj043465; Sat, 24 Oct 2020 20:24:52 +0300 (EEST) (envelope-from kostikbel@gmail.com) X-Authentication-Warning: tom.home: kostik set sender to kostikbel@gmail.com using -f Date: Sat, 24 Oct 2020 20:24:52 +0300 From: Konstantin Belousov To: Mateusz Guzik Cc: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: Re: svn commit: r366997 - head/sys/kern Message-ID: <20201024172452.GD2643@kib.kiev.ua> References: <202010241330.09ODUb6x089521@repo.freebsd.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <202010241330.09ODUb6x089521@repo.freebsd.org> X-Spam-Status: No, score=-1.0 required=5.0 tests=ALL_TRUSTED,BAYES_00, DKIM_ADSP_CUSTOM_MED,FORGED_GMAIL_RCVD,FREEMAIL_FROM, NML_ADSP_CUSTOM_MED autolearn=no autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on tom.home X-Rspamd-Queue-Id: 4CJSf456Fqz3bJZ X-Spamd-Bar: ---- Authentication-Results: mx1.freebsd.org; none X-Spamd-Result: default: False [-4.00 / 15.00]; REPLY(-4.00)[]; ASN(0.00)[asn:6939, ipnet:2001:470::/32, country:US] X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.33 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: Sat, 24 Oct 2020 17:25:01 -0000 On Sat, Oct 24, 2020 at 01:30:37PM +0000, Mateusz Guzik wrote: > Author: mjg > Date: Sat Oct 24 13:30:37 2020 > New Revision: 366997 > URL: https://svnweb.freebsd.org/changeset/base/366997 > > Log: > vfs: fix a race where reclaim vholds freed vnodes A description of the race in the commit message would be respectful to other readers of the code, so that we do not need to reverse-eng the change to understand what and why was fixed. > > Reported by: pho > Tested by: pho (previous version) > Fixes: r366974 ("vfs: stop taking the interlock in vnode reclaim") > > Modified: > head/sys/kern/vfs_subr.c > > Modified: head/sys/kern/vfs_subr.c > ============================================================================== > --- head/sys/kern/vfs_subr.c Sat Oct 24 13:16:10 2020 (r366996) > +++ head/sys/kern/vfs_subr.c Sat Oct 24 13:30:37 2020 (r366997) > @@ -109,6 +109,7 @@ static void syncer_shutdown(void *arg, int howto); > static int vtryrecycle(struct vnode *vp); > static void v_init_counters(struct vnode *); > static void vgonel(struct vnode *); > +static bool vhold_recycle(struct vnode *); > static void vfs_knllock(void *arg); > static void vfs_knlunlock(void *arg); > static void vfs_knl_assert_locked(void *arg); > @@ -1126,7 +1127,8 @@ restart: > goto next_iter; > } > > - vhold(vp); > + if (!vhold_recycle(vp)) > + goto next_iter; > TAILQ_REMOVE(&vnode_list, mvp, v_vnodelist); > TAILQ_INSERT_AFTER(&vnode_list, vp, mvp, v_vnodelist); > mtx_unlock(&vnode_list_mtx); > @@ -1231,7 +1233,8 @@ restart: > if (__predict_false(vp->v_type == VBAD || vp->v_type == VNON)) { > continue; > } > - vhold(vp); > + if (!vhold_recycle(vp)) > + continue; > count--; > mtx_unlock(&vnode_list_mtx); > vtryrecycle(vp); > @@ -3248,13 +3251,11 @@ vholdnz(struct vnode *vp) > * However, while this is more performant, it hinders debugging by eliminating > * the previously mentioned invariant. > */ > -bool > -vhold_smr(struct vnode *vp) > +static bool __always_inline > +_vhold_cond(struct vnode *vp) > { > int count; > > - VFS_SMR_ASSERT_ENTERED(); > - > count = atomic_load_int(&vp->v_holdcnt); > for (;;) { > if (count & VHOLD_NO_SMR) { > @@ -3270,6 +3271,28 @@ vhold_smr(struct vnode *vp) > return (true); > } > } > +} > + > +bool > +vhold_smr(struct vnode *vp) > +{ > + > + VFS_SMR_ASSERT_ENTERED(); > + return (_vhold_cond(vp)); > +} > + > +/* > + * Special case for vnode recycling. > + * > + * Vnodes are present on the global list until UMA takes them out. > + * Attempts to recycle only need the relevant lock and have no use for SMR. > + */ > +static bool > +vhold_recycle(struct vnode *vp) > +{ > + > + mtx_assert(&vnode_list_mtx, MA_OWNED); > + return (_vhold_cond(vp)); > } > > static void __noinline