Deadlock between nfsd and snapshots.

Tor Egge Tor.Egge at
Wed Aug 23 15:47:27 UTC 2006

> I have at least one questions:
> > > Protecting the existing i_flag and the timestamps with the vnode
> > > interlock when the current thread only has a shared vnode lock should
> > > be sufficient to protect against the races, removing the need for #3,
> > > #4 and #4 below.
> Could you, please, explain this point ? I did not wrap all accesses to
> i_flag and timestamps with vnode interlock, only ufs_itimes, ufs_lazyaccess
> and ufs_getattr for now.

As long as i_flag and the timstamps are never accessed without holding a shared
or exclusive vnode lock, the vnode interlock can be used to serialize access
for those holding a shared vnode lock.  Access is already serialized for those
holding an exclusive vnode lock, since no other thread can hold a shared or
exclusive lock for the same vnode at the same time.

An alternate locking protocol is to always use the vnode interlock to serialize
access to i_flag and the timestamps.  That increases the cost of accessing the
fields in code that uses an exclusive vnode lock, but can temporarily lower the
cost in other parts of the code (e.g. when scanning all the vnodes belonging to
a mount point looking for dirty vnodes) since the vnode lock would no longer be
needed to access i_flag and the timestamps.

Problems with your suggested patch:

ufs_lazyaccess() changes i_flags with only the vnode interlock held.  The vnode
interlock is not sufficient by itself to access i_flags without switching to
the alternate locking protocol.

ufs_itimes() doesn't optimize the common case where none of the flags are set.

- Tor Egge

More information about the freebsd-fs mailing list