From nobody Sun Jan 14 00:23:43 2024 X-Original-To: freebsd-threads@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 4TCGGh3pYDz572Qv for ; Sun, 14 Jan 2024 00:23:56 +0000 (UTC) (envelope-from asomers@gmail.com) Received: from mail-qv1-f45.google.com (mail-qv1-f45.google.com [209.85.219.45]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (2048 bits) client-digest SHA256) (Client CN "smtp.gmail.com", Issuer "GTS CA 1D4" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4TCGGg6CsGz4lZ1; Sun, 14 Jan 2024 00:23:55 +0000 (UTC) (envelope-from asomers@gmail.com) Authentication-Results: mx1.freebsd.org; dkim=none; dmarc=fail reason="SPF not aligned (relaxed), No valid DKIM" header.from=freebsd.org (policy=none); spf=pass (mx1.freebsd.org: domain of asomers@gmail.com designates 209.85.219.45 as permitted sender) smtp.mailfrom=asomers@gmail.com Received: by mail-qv1-f45.google.com with SMTP id 6a1803df08f44-67f7bd86cafso49367296d6.0; Sat, 13 Jan 2024 16:23:55 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1705191835; x=1705796635; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=o/rL1813/OlakPo7+QOR4nmAWL3KG78SbQQo12xe2wI=; b=Me/8xwN33nk0WrbOF9IPeLfjt1P8PV3CAU7pw+JhPu77S+9JvTIxozqVRtsaLXnevq e4qu0nygIUT6G2lAlaZY7/tTt6PxzkvGNs5vdkW5THqkkNILzMr7Sl10Iw5x+13cTJA5 5o2nAFk9kPly0XBLO+BmqxDOjbJce0togV1S8ti3i8buFiNnY6azIVJk9CWutgWyZ+hj mNfSfgLHthg+u+EOmY/iAsfMqnfMI57qKhwuEmroeMl5sAYx2R1CYTIQYlUMQdjABN8T sHPNeymOwGKOZF9kNHH2HmMUTK95yYwcgELG1snUpmbuPWr91hL50kkFgTFtukigVw/t gvSA== X-Gm-Message-State: AOJu0YxWQAm6RtO51rkyDPTFwPUuXbFNEBfFh4yi/5UZCoBNup37hd7d yJQ8GrEr4r4nPfv67qBn+IqUsmwtvK/KuSyx7CbV3IUB X-Google-Smtp-Source: AGHT+IFJeYboaA46R7BpS38bwucSpl2WAklhBAsyDcdZpWma2iWlMvE3jJI7ApmiDtLemBUVCVfSuvXRC5ZEkK3vlXU= X-Received: by 2002:a05:6214:dad:b0:680:aedb:72fe with SMTP id h13-20020a0562140dad00b00680aedb72femr4742156qvh.81.1705191835004; Sat, 13 Jan 2024 16:23:55 -0800 (PST) List-Id: Threading List-Archive: https://lists.freebsd.org/archives/freebsd-threads List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-freebsd-threads@freebsd.org X-BeenThere: freebsd-threads@freebsd.org MIME-Version: 1.0 References: In-Reply-To: From: Alan Somers Date: Sat, 13 Jan 2024 17:23:43 -0700 Message-ID: Subject: Re: aio_read2() and aio_write2() To: =?UTF-8?Q?Vin=C3=ADcius_dos_Santos_Oliveira?= Cc: freebsd-threads@freebsd.org, Konstantin Belousov Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spamd-Bar: -- X-Spamd-Result: default: False [-2.89 / 15.00]; NEURAL_HAM_LONG(-1.00)[-1.000]; NEURAL_HAM_SHORT(-1.00)[-0.997]; NEURAL_HAM_MEDIUM(-0.99)[-0.994]; FORGED_SENDER(0.30)[asomers@freebsd.org,asomers@gmail.com]; R_SPF_ALLOW(-0.20)[+ip4:209.85.128.0/17]; DMARC_POLICY_SOFTFAIL(0.10)[freebsd.org : SPF not aligned (relaxed), No valid DKIM,none]; MIME_GOOD(-0.10)[text/plain]; RCVD_TLS_LAST(0.00)[]; RCPT_COUNT_THREE(0.00)[3]; MIME_TRACE(0.00)[0:+]; FREEMAIL_TO(0.00)[gmail.com]; RCVD_COUNT_ONE(0.00)[1]; TO_DN_SOME(0.00)[]; ARC_NA(0.00)[]; MISSING_XM_UA(0.00)[]; FROM_HAS_DN(0.00)[]; FREEMAIL_ENVFROM(0.00)[gmail.com]; MLMMJ_DEST(0.00)[freebsd-threads@freebsd.org]; TO_MATCH_ENVRCPT_SOME(0.00)[]; FROM_NEQ_ENVFROM(0.00)[asomers@freebsd.org,asomers@gmail.com]; FREEFALL_USER(0.00)[asomers]; R_DKIM_NA(0.00)[]; RWL_MAILSPIKE_POSSIBLE(0.00)[209.85.219.45:from]; TAGGED_RCPT(0.00)[]; ASN(0.00)[asn:15169, ipnet:209.85.128.0/17, country:US]; RCVD_IN_DNSWL_NONE(0.00)[209.85.219.45:from] X-Rspamd-Queue-Id: 4TCGGg6CsGz4lZ1 On Sat, Jan 13, 2024 at 4:46=E2=80=AFPM Vin=C3=ADcius dos Santos Oliveira wrote: > > Em s=C3=A1b., 13 de jan. de 2024 =C3=A0s 19:18, Alan Somers > escreveu: > > I'm not on this mailing list, but I saw kib's code review and I have > > some comments > > > > > Can we have some aio_read() function that ignores aio_offset (i.e. th= e current file position is used)? I'm trying to port libboost's ASIO file s= upport to FreeBSD, and I stumbled upon this limitation. > > > > The fundamental problem with using the file's seek offset with AIO is > > that multiple operations may be in-flight at any one time that depend > > on the seek offset, and there's nothing that enforces their ordering. > > That's not different from creating two threads and calling read() from > both threads in parallel. The kernel can do nothing to prevent bugs in > userspace applications. It's already possible to violate ordering > using threads. > > > How does boost.asio address this problem? > > You don't address this problem. Applications doing this are buggy. > io_uring in Linux doesn't address this problem. IOCP in Windows does > give a few guarantees, but for now I'd argue against it. > > Applications shouldn't start a second stream operation when the last > one hasn't even finished yet. If you shouldn't start a second stream until the first has finished, the what is the reason for using AIO? This doesn't sound like a good application for AIO to me. > > > Are its operations completed in a strict sequence? > > When the kernel dispatches completion events (SIGEV_KEVENT/EVFILT_AIO) > to the process, Boost.Asio will route them to the correct module > within the program (the one that started the associated operation). > The program can retain ordering by only scheduling new operations when > the last one finished. Boost.Asio by itself will act just as a > portable layer between the program and the OS. Boost.Asio won't by > itself give any sequencing guarantee. > > Ordering problems can happen even if you only use kqueue with a single > thread. Here's an example from the real-world: > https://sourceforge.net/p/asio/mailman/asio-users/thread/5357B16C.6070508= %40mail1.stofanet.dk/ > (keep reading past the multi-threading problems) > > Here's a condensed explanation for what happened in the example: > https://docs.emilua.org/api/0.6/tutorial/streams.html#composed-operations > > -- > Vin=C3=ADcius dos Santos Oliveira > https://vinipsmaker.github.io/