From nobody Thu Mar 23 11:56:07 2023 X-Original-To: freebsd-fs@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4Pj3hc48gLz41FjD for ; Thu, 23 Mar 2023 11:56:16 +0000 (UTC) (envelope-from kostikbel@gmail.com) Received: from kib.kiev.ua (kib.kiev.ua [IPv6:2001:470:d5e7:1::1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 4Pj3hb0dzjz4GWW for ; Thu, 23 Mar 2023 11:56:14 +0000 (UTC) (envelope-from kostikbel@gmail.com) Authentication-Results: mx1.freebsd.org; dkim=none; spf=softfail (mx1.freebsd.org: 2001:470:d5e7:1::1 is neither permitted nor denied by domain of kostikbel@gmail.com) smtp.mailfrom=kostikbel@gmail.com; dmarc=fail reason="No valid SPF, No valid DKIM" header.from=gmail.com (policy=none) Received: from tom.home (kib@localhost [127.0.0.1]) by kib.kiev.ua (8.17.1/8.17.1) with ESMTPS id 32NBu852095009 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NO); Thu, 23 Mar 2023 13:56:11 +0200 (EET) (envelope-from kostikbel@gmail.com) DKIM-Filter: OpenDKIM Filter v2.10.3 kib.kiev.ua 32NBu852095009 Received: (from kostik@localhost) by tom.home (8.17.1/8.17.1/Submit) id 32NBu7N3095008; Thu, 23 Mar 2023 13:56:07 +0200 (EET) (envelope-from kostikbel@gmail.com) X-Authentication-Warning: tom.home: kostik set sender to kostikbel@gmail.com using -f Date: Thu, 23 Mar 2023 13:56:07 +0200 From: Konstantin Belousov To: Alexander Lochmann Cc: freebsd-fs@freebsd.org Subject: Re: Understanding locking for buf Message-ID: References: <1743b9f5-69be-b775-fb57-92b8115d4a81@tu-dortmund.de> <6b1181f7-a58f-8d71-a05e-2dcb0a66ae4c@tu-dortmund.de> <2c5e6f8d-037b-9bfe-bdad-4a367bdbc65d@tu-dortmund.de> List-Id: Filesystems List-Archive: https://lists.freebsd.org/archives/freebsd-fs List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-freebsd-fs@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Spam-Status: No, score=-1.0 required=5.0 tests=ALL_TRUSTED,BAYES_00, DKIM_ADSP_CUSTOM_MED,FORGED_GMAIL_RCVD,FREEMAIL_FROM, NML_ADSP_CUSTOM_MED autolearn=no autolearn_force=no version=4.0.0 X-Spam-Checker-Version: SpamAssassin 4.0.0 (2022-12-14) on tom.home X-Spamd-Result: default: False [-1.18 / 15.00]; NEURAL_HAM_LONG(-1.00)[-1.000]; NEURAL_HAM_MEDIUM(-1.00)[-1.000]; NEURAL_SPAM_SHORT(0.82)[0.816]; MIME_GOOD(-0.10)[text/plain]; DMARC_POLICY_SOFTFAIL(0.10)[gmail.com : No valid SPF, No valid DKIM,none]; FREEMAIL_FROM(0.00)[gmail.com]; FROM_EQ_ENVFROM(0.00)[]; MLMMJ_DEST(0.00)[freebsd-fs@freebsd.org]; RCPT_COUNT_TWO(0.00)[2]; R_DKIM_NA(0.00)[]; ASN(0.00)[asn:6939, ipnet:2001:470::/32, country:US]; FREEMAIL_ENVFROM(0.00)[gmail.com]; TO_DN_SOME(0.00)[]; TO_MATCH_ENVRCPT_SOME(0.00)[]; MIME_TRACE(0.00)[0:+]; FROM_HAS_DN(0.00)[]; RCVD_COUNT_THREE(0.00)[3]; ARC_NA(0.00)[]; R_SPF_SOFTFAIL(0.00)[~all]; HAS_XAW(0.00)[]; RCVD_TLS_LAST(0.00)[] X-Rspamd-Queue-Id: 4Pj3hb0dzjz4GWW X-Spamd-Bar: - X-ThisMailContainsUnwantedMimeParts: N 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()])