From nobody Mon Sep 22 21:05:15 2025 X-Original-To: dev-commits-src-all@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 4cVwcS3wf6z68RTN; Mon, 22 Sep 2025 21:05:28 +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 4cVwcR6b8sz3JcB; Mon, 22 Sep 2025 21:05:27 +0000 (UTC) (envelope-from kostikbel@gmail.com) Authentication-Results: mx1.freebsd.org; none Received: from tom.home (kib@localhost [127.0.0.1] (may be forged)) by kib.kiev.ua (8.18.1/8.18.1) with ESMTP id 58ML5Fj1059607; Tue, 23 Sep 2025 00:05:18 +0300 (EEST) (envelope-from kostikbel@gmail.com) DKIM-Filter: OpenDKIM Filter v2.10.3 kib.kiev.ua 58ML5Fj1059607 Received: (from kostik@localhost) by tom.home (8.18.1/8.18.1/Submit) id 58ML5Fhs059606; Tue, 23 Sep 2025 00:05:15 +0300 (EEST) (envelope-from kostikbel@gmail.com) X-Authentication-Warning: tom.home: kostik set sender to kostikbel@gmail.com using -f Date: Tue, 23 Sep 2025 00:05:15 +0300 From: Konstantin Belousov To: John Baldwin Cc: Mateusz Guzik , src-committers@freebsd.org, dev-commits-src-all@freebsd.org, dev-commits-src-main@freebsd.org Subject: Re: git: 40a42785dbba - main - fcntl(F_SETFL): only allow one thread to perform F_SETFL Message-ID: References: <202509191419.58JEJsvj031867@gitrepo.freebsd.org> <92831372-745d-4612-b38f-aeb235dd8cca@FreeBSD.org> List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-all@freebsd.org Sender: owner-dev-commits-src-all@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit 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.1 X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on tom.home X-Spamd-Bar: ---- X-Spamd-Result: default: False [-4.00 / 15.00]; REPLY(-4.00)[] X-Rspamd-Pre-Result: action=no action; module=replies; Message is reply to one we originated X-Rspamd-Queue-Id: 4cVwcR6b8sz3JcB On Mon, Sep 22, 2025 at 06:42:34PM +0100, John Baldwin wrote: > On 9/22/25 13:40, Mateusz Guzik wrote: > > On Mon, Sep 22, 2025 at 7:39 PM John Baldwin wrote: > > > > > > On 9/22/25 04:54, Mateusz Guzik wrote: > > > > On Mon, Sep 22, 2025 at 10:41 AM John Baldwin wrote: > > > > > > > > > > On 9/19/25 10:19, Konstantin Belousov wrote: > > > > > > The branch main has been updated by kib: > > > > > > > > > > > > URL: https://cgit.FreeBSD.org/src/commit/?id=40a42785dbba93cc5196178fc49d340c1a89cabe > > > > > > > > > > > > commit 40a42785dbba93cc5196178fc49d340c1a89cabe > > > > > > Author: Konstantin Belousov > > > > > > AuthorDate: 2025-09-11 10:05:04 +0000 > > > > > > Commit: Konstantin Belousov > > > > > > CommitDate: 2025-09-19 14:19:13 +0000 > > > > > > > > > > > > fcntl(F_SETFL): only allow one thread to perform F_SETFL > > > > > > > > > > > > Use f_vflags file locking for this. > > > > > > Allowing more than one thread handling F_SETFL might cause de-sync > > > > > > between real driver state and flags. > > > > > > > > > > > > Reviewed by: markj > > > > > > Tested by: pho > > > > > > Sponsored by: The FreeBSD Foundation > > > > > > MFC after: 2 weeks > > > > > > Differential revision: https://reviews.freebsd.org/D52487 > > > > > > > > > > Thanks for fixing this. I still slightly worry that "home-grown" locks > > > > > aren't visible to WITNESS and it's checking. > > > > > > > > > > > > > Another problem with these is that they don't do adaptive spinning. > > > > > > > > In particular for file offset, it *is* putting threads off cpu in real > > > > workloads when it plausibly could be avoided. > > > > > > > > I think the real thing to do here is to drop the hand-rolled machinery > > > > and use an sx lock. > > > > > > > > Currently struct file is 80 bytes which is a very nasty size from > > > > caching standpoint. > > > > > > > > Locks are 32 bytes in size, which is another problem, but ultimately > > > > one can be added here without growing the struct past 128 bytes. > > > > > > > > The only issue here is that files are marked as NOFREE, so this memory > > > > can *never* be reclaimed. > > > > > > > > One could be tempted to use smr here, but the cost of smr_enter is > > > > prohibitive. There is a lazy variant which does not do atomics, which > > > > perhaps could work, but that 0 users in the tree and was probably > > > > never tested. > > > > > > > > With 32-bit archs going away I don't think it's a big deal though. > > > > > > > > For interested, on Linux the struct is 256 bytes. > > > > > > I had suggested in an earlier review adding an sx-pool similar to our > > > existing mtxpool and using that. That would avoid bloating the structure > > > with a dedicated lock. > > > > > > > Per my previous e-mail the offset lock is already contested. I am curious how they are? If several threads do read(2)/write(2) kind of io on the same fd, they get what they deserve. > > > > Using a pool over a lock embedded into the struct would hinder performance. > > > > I explained why I don't consider embedding sx into struct file to be a problem. Are you saying that struct file falls into 128-byte zone, and has enough space for sx?