Date: Thu, 23 Mar 2023 13:56:07 +0200 From: Konstantin Belousov <kostikbel@gmail.com> To: Alexander Lochmann <alexander.lochmann@tu-dortmund.de> Cc: freebsd-fs@freebsd.org Subject: Re: Understanding locking for buf Message-ID: <ZBw%2BV1V5A%2B60CrKF@kib.kiev.ua> In-Reply-To: <bd174e6f-5510-5a6d-ea4e-d2d58f902c8b@tu-dortmund.de> References: <Y/4fz/hEyNiTjGmb@kib.kiev.ua> <1743b9f5-69be-b775-fb57-92b8115d4a81@tu-dortmund.de> <ZAE9FKivOiVYGggy@kib.kiev.ua> <ac91fec9-9b26-c770-409c-040ea4545e8c@tu-dortmund.de> <ZAkq5HSXp4QEjXeu@kib.kiev.ua> <6b1181f7-a58f-8d71-a05e-2dcb0a66ae4c@tu-dortmund.de> <ZBL8aN49i2bcEKuj@kib.kiev.ua> <2c5e6f8d-037b-9bfe-bdad-4a367bdbc65d@tu-dortmund.de> <ZBig5SBdiZ62/X9T@kib.kiev.ua> <bd174e6f-5510-5a6d-ea4e-d2d58f902c8b@tu-dortmund.de>
next in thread | previous in thread | raw e-mail | index | archive | help
On Tue, Mar 21, 2023 at 02:54:35PM +0100, Alexander Lochmann wrote: > > > On 20.03.23 19:07, Konstantin Belousov wrote: > > On Mon, Mar 20, 2023 at 11:25:30AM +0100, Alexander Lochmann wrote: > > > > > > > > > On 16.03.23 12:24, Konstantin Belousov wrote: > > > > > Is the following correct? > > > > > The aforementioned accesses by 100033 in g_vfs_done() are no violations with > > > > > respect to the locking rule because from a global perspective the buf is > > > > > locked. It is the only concurrent access at that moment. > > > > I would formulate it differently: > > > > No other thread might legitimately get access to the buffer using > > > > either bread() or getblk() until current io operation finishes. > > > > The io operation is handled in two contexts: top-level, where a thread > > > > used getblk() as usual to claim buffer ownership, and completion > > > > thread context (geom up thread). The completion code legitimately > > > > manipulates the buffer, because the top-level code expects that after > > > > the buffer strategy routine is called, effectively moving the ownership > > > > to the geom up thread. > > > Thx. But the top-level thread, using getblk(), legitimately releases the > > > lock. Am I right? > > No. It does not, please re-read what I wrote. > Yeah, but that's what I meant a few mails ago. > The lock is acquired *and* released by the top-level thread. Although some > accesses happen from the geom thread. Sometimes yes, the buffer lifecycle is managed in the way you demonstrated below. I do not understand the goal of this conversation. Can you formulate what you are trying to achieve, please? > > (The numbers are the logged thread ids.) > In our log, I see the following: > - Kernel tries to mount the rootfs via readsuper(). The thread id is 100002. > - 100002 allocates an instance of struct buf. > - The b_lock is acquired by 100002 in buf_alloc(). > - Various accesses to buf by 100002. > - Various accesses to buf by 100033 during g_vfs_done(). > - Again various accesses to buf by 100002. > - The instances is unlocked and freed by 100002. (readsuper() -> > ffs_use_bread() -> brelse() -> buf_free()[ -> BUF_UNLOCK()])
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?ZBw%2BV1V5A%2B60CrKF>