Date: Fri, 12 Mar 2021 19:57:54 +0100 From: Alexander Lochmann <alexander.lochmann@tu-dortmund.de> To: freebsd-fs@freebsd.org Subject: [RFC] Understanding the locking of struct buf Message-ID: <49130618-349a-bfc7-6d26-0c3763904dc5@tu-dortmund.de>
next in thread | raw e-mail | index | archive | help
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
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?49130618-349a-bfc7-6d26-0c3763904dc5>