From nobody Wed Aug 17 16:14:32 2022 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 4M7ClF6SZDz4ZpPf; Wed, 17 Aug 2022 16:14:33 +0000 (UTC) (envelope-from glebius@freebsd.org) Received: from cell.glebi.us (glebi.us [162.251.186.162]) (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-signature RSA-PSS (2048 bits) client-digest SHA256) (Client CN "cell.glebi.us", Issuer "cell.glebi.us" (not verified)) by mx1.freebsd.org (Postfix) with ESMTPS id 4M7ClF1rc4z3jKT; Wed, 17 Aug 2022 16:14:33 +0000 (UTC) (envelope-from glebius@freebsd.org) Received: from cell.glebi.us (localhost [127.0.0.1]) by cell.glebi.us (8.16.1/8.16.1) with ESMTPS id 27HGEWu7031524 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NO); Wed, 17 Aug 2022 09:14:32 -0700 (PDT) (envelope-from glebius@freebsd.org) Received: (from glebius@localhost) by cell.glebi.us (8.16.1/8.16.1/Submit) id 27HGEWkh031523; Wed, 17 Aug 2022 09:14:32 -0700 (PDT) (envelope-from glebius@freebsd.org) X-Authentication-Warning: cell.glebi.us: glebius set sender to glebius@freebsd.org using -f Date: Wed, 17 Aug 2022 09:14:32 -0700 From: Gleb Smirnoff 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: 9ac6eda6c6a3 - main - pipe: try to skip locking the pipe if a non-blocking fd is used Message-ID: References: <202208171423.27HENpvp024623@gitrepo.freebsd.org> <05eb9b32-d466-57c2-a01f-d34955873ac8@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: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <05eb9b32-d466-57c2-a01f-d34955873ac8@FreeBSD.org> X-Rspamd-Queue-Id: 4M7ClF1rc4z3jKT X-Spamd-Bar: --- Authentication-Results: mx1.freebsd.org; dkim=none; dmarc=none; spf=softfail (mx1.freebsd.org: 162.251.186.162 is neither permitted nor denied by domain of glebius@freebsd.org) smtp.mailfrom=glebius@freebsd.org X-Spamd-Result: default: False [-3.10 / 15.00]; NEURAL_HAM_LONG(-1.00)[-1.000]; NEURAL_HAM_MEDIUM(-1.00)[-1.000]; NEURAL_HAM_SHORT(-1.00)[-0.999]; MIME_GOOD(-0.10)[text/plain]; MLMMJ_DEST(0.00)[dev-commits-src-all@freebsd.org,dev-commits-src-main@freebsd.org]; ARC_NA(0.00)[]; FROM_EQ_ENVFROM(0.00)[]; R_DKIM_NA(0.00)[]; RCVD_COUNT_THREE(0.00)[3]; ASN(0.00)[asn:27348, ipnet:162.251.186.0/24, country:US]; MIME_TRACE(0.00)[0:+]; RCPT_COUNT_FIVE(0.00)[5]; R_SPF_SOFTFAIL(0.00)[~all:c]; DMARC_NA(0.00)[freebsd.org]; FROM_HAS_DN(0.00)[]; FREEFALL_USER(0.00)[glebius]; RCVD_TLS_LAST(0.00)[]; TO_DN_SOME(0.00)[]; HAS_XAW(0.00)[]; TO_MATCH_ENVRCPT_ALL(0.00)[]; MID_RHS_MATCH_FROM(0.00)[] X-ThisMailContainsUnwantedMimeParts: N On Wed, Aug 17, 2022 at 09:04:02AM -0700, John Baldwin wrote: J> On 8/17/22 8:39 AM, Gleb Smirnoff wrote: J> > On Wed, Aug 17, 2022 at 08:34:22AM -0700, Gleb Smirnoff wrote: J> > T> This also breaks API. Although not explicitly narrated by POSIX or our J> > T> documentation, but there is a strong contract that, if application had J> > T> received a non-blocking fd from event dispatcher (kevent, poll, select) J> > T> as writable, then it is possible to write thre non-zero bytes with next J> > T> syscall. J> > J> > Actually for poll(2) and kevent(2) you can almost read this contract between J> > the lines: J> > J> > POLLWRNORM Normal data may be written without blocking. J> > J> > EVFILT_WRITE Takes a descriptor as the identifier, and returns J> > whenever it is possible to write to the descriptor. J> > For sockets, pipes and fifos, data will contain the J> > amount of space remaining in the write buffer. The J> > filter will set EV_EOF when the reader disconnects, J> > and for the fifo case, this will be cleared when a J> > new reader connects. Note that this filter is not J> > supported for vnodes. J> > J> > So with this change it may happen that previous return of poll or kevent J> > returned incorrect information. J> J> While I largely agree with your sentiment, I think the actual contract is a J> bit weaker than you stated and something more like: J> J> "If a non-blocking fd becomes writable and the event is published, at least J> one thread will be able to write without blocking." J> J> That is, the contract you stated is true when there is a single writer, but J> with multiple writers it is not true. You might get a kevent back that says J> you have X bytes of room to write, yet be able to write less than X because J> of concurrent writes in other threads. Even this contract is broken, as EAGAIN can be returned to a single writer, while a reader keeps the pipe locked in the kernel. -- Gleb Smirnoff