Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 6 Jul 2020 02:00:35 +0000 (UTC)
From:      Mateusz Guzik <mjg@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r362951 - head/sys/kern
Message-ID:  <202007060200.06620ZZu037942@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: mjg
Date: Mon Jul  6 02:00:35 2020
New Revision: 362951
URL: https://svnweb.freebsd.org/changeset/base/362951

Log:
  vfs: expand on vhold_smr comment

Modified:
  head/sys/kern/vfs_subr.c

Modified: head/sys/kern/vfs_subr.c
==============================================================================
--- head/sys/kern/vfs_subr.c	Sun Jul  5 23:07:54 2020	(r362950)
+++ head/sys/kern/vfs_subr.c	Mon Jul  6 02:00:35 2020	(r362951)
@@ -3441,10 +3441,23 @@ vholdnz(struct vnode *vp)
 }
 
 /*
- * Grab a hold count as long as the vnode is not getting freed.
+ * Grab a hold count unless the vnode is freed.
  *
  * Only use this routine if vfs smr is the only protection you have against
  * freeing the vnode.
+ *
+ * The code loops trying to add a hold count as long as the VHOLD_NO_SMR flag
+ * is not set.  After the flag is set the vnode becomes immutable to anyone but
+ * the thread which managed to set the flag.
+ *
+ * It may be tempting to replace the loop with:
+ * count = atomic_fetchadd_int(&vp->v_holdcnt, 1);
+ * if (count & VHOLD_NO_SMR) {
+ *     backpedal and error out;
+ * }
+ *
+ * However, while this is more performant, it hinders debugging by eliminating
+ * the previously mentioned invariant.
  */
 bool
 vhold_smr(struct vnode *vp)



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202007060200.06620ZZu037942>