[RFC] Understanding the locking of struct buf

Alexander Lochmann alexander.lochmann at tu-dortmund.de
Fri Mar 12 18:57:58 UTC 2021


Hi folks!

According to the definition [1], any access to a struct buf is protected
by a lock:
1) Are there exceptions to those locking rules for reading and/or
writing a member?
E.g. any read is permitted without a lock being held.
Can b_bcount, for example, be read without a lock?

2) In vfs_bio.c, for example, the BUF_KERNPROC macro is used to move
ownership of a buf.b_lock to the kernel.
In _lockmgr_disown() [2] WITNESS_UNLOCK() is called to emulate an
unlock. So, shouldn't be there a WITNESS_LOCK() for that lock?
Otherwise, the Witness system might complain about the upcoming unlock.

3) Is the function brelse()/bqrelse() considered to be a destruction
function?
Hence, no lock (buf.b_lock) is needed within this function to access a
struct buf.

Thanks!

Regards,
Alex

[1] https://github.com/freebsd/freebsd-src/blob/main/sys/sys/buf.h#L99
[2]
https://github.com/freebsd/freebsd-src/blob/main/sys/kern/kern_lock.c#L1616
[3] https://github.com/freebsd/freebsd-src/blob/main/sys/sys/buf.h#L387

-- 
Technische Universität Dortmund
Alexander Lochmann                PGP key: 0xBC3EF6FD
Otto-Hahn-Str. 16                 phone:  +49.231.7556141
D-44227 Dortmund                  fax:    +49.231.7556116
http://ess.cs.tu-dortmund.de/Staff/al


More information about the freebsd-fs mailing list