A question about in lock usage in FreeBSD

Konstantin Belousov kostikbel at gmail.com
Wed Jun 14 16:16:53 UTC 2017


On Wed, Jun 14, 2017 at 08:45:21AM -0700, Conrad Meyer wrote:
> On Wed, Jun 14, 2017 at 12:49 AM, Jia-Ju Bai <baijiaju1990 at 163.com> wrote:
> > Namely, it is unsafe that the thread calls the function which may sleep when
> > the thread holds mutexes, reader/writer locks or read-mostly locks.
> > Is it right?
> 
> Correct.  sxlocks ("shared-exclusive," although I tend to think of the
> "s" as standing for "sleepable") can be held calling functions which
> may sleep.

Note that 'can' there refers only to the ability to make calls into the
locking subsystem without making it panic or triggering witness warnings.
The concrete sleepable locks itself might be unsuitable to held during
specific sleep, or cause some side effects if owned while sleeping that 
make the system unusable.

For instance, we used to own vnode and buffer locks while filesystems
copied data in/out in the VOP_READ and VOP_WRITE. It was tolerated by
locking subsystem but was the source of large series of hard to tackle
deadlocks.

In other words, the permit to own the sleepable locks while sleeping is
only about an absence of the tiranic overseer who disallows that, and
not a guarantee that the permit is handy to use.


More information about the freebsd-hackers mailing list