Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1w3fsM-001ReA-1e for pgsql-hackers@arkaria.postgresql.org; Fri, 20 Mar 2026 19:51:18 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1w3fsJ-0084T0-2d for pgsql-hackers@arkaria.postgresql.org; Fri, 20 Mar 2026 19:51:16 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1w3fsJ-0084Sr-0i for pgsql-hackers@lists.postgresql.org; Fri, 20 Mar 2026 19:51:15 +0000 Received: from mail-ed1-x530.google.com ([2a00:1450:4864:20::530]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.98.2) (envelope-from ) id 1w3fsH-00000000Dfu-3Jit for pgsql-hackers@postgresql.org; Fri, 20 Mar 2026 19:51:14 +0000 Received: by mail-ed1-x530.google.com with SMTP id 4fb4d7f45d1cf-6634bb959a2so3708020a12.1 for ; Fri, 20 Mar 2026 12:51:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1774036271; cv=none; d=google.com; s=arc-20240605; b=JjlcSfBwT3mn3xJvEkT8KPRRiDPtgCKN7FvOrbOlnBrNadD4acRxMcBfKcrpMSVX6I kVyEZoWhV8vLlfOewBVwye63ktgltL0WH2nTUq1LunGAUsbTfTKSskbr70I9Wln7zjrN i9r1o8C5XExwryfcSAktj+dOdNDYV/gVo82Js+rzKgmCFrwJsc6OldHszWnuU2T6rGtH sJ8Ut2FhdrGp+BWynNv4pLfTnsaOBBWt0T7YCH/ujn1T3mhHAxKxPkTfshm8mbUWzPhN aEgHvGhrHjYA4lv31V66byI9Yw4YJGaFBIKVpULFUZLkWDHxTZVvVSqpdRg31SNjETEE DAhA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=7VX3ysj6cQD9fqvXshv/ZRQwsvBLFm2mvMYFPBkdKy4=; fh=6dkExZJ6PBdUpxKHp/1aSLeICOT/ls4kyU0wpz7HoBY=; b=jjZ3xncV+m3tm3maqdOsHJFFpBrnUh23Adc34iwohw5NR4PlnFqKvscsm+DzYrJb65 qklkXd0WblnYk33Ch4uC2XBP6+uWJ8Gto7qiAYffxMzH9kW2sJ/t2mjtBEFDwCxECMR5 c0z1jxpW+6TgU9Mj+Jo7TnwgZHEw80IpUCgiyo62cZs7GteRivkjBkyJ+s6C1oOwQPRB HJYzBbTCuY7INPztA0a6OdnT7jyLDBWGvsChTCqjACtZQjVQQJyz2BmNM+HVSlVJqR+f LyLm3vgUqNilgwRQy+Dk94i2SVlj1tM5Kc2d1AI1YMyCc/karIqFN2/ygXQ0UuLTS09c AfPQ==; darn=postgresql.org ARC-Authentication-Results: i=1; mx.google.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1774036271; x=1774641071; darn=postgresql.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=7VX3ysj6cQD9fqvXshv/ZRQwsvBLFm2mvMYFPBkdKy4=; b=h89acytaPkuBmdlaRjDlct7FrO44RUOFnteE0qM8ydlCOmqWil0XxNqI56+XXF+JwD y0Ejm58Cv2/fWRb+S8sLx7n0pgXtMYEYqbbZTVmYpr1wqYWPCgR5w2o6qMV7QIQ/81mh mZJP+2SJLBwZ1rRSLNHR9e5fSfmW4OFBho/SMlC3Q46Itlpv1vK79Rd+EEDTzE9ruXcO 0kCDAeBFqqrveOZTXtzu6G3y6SNoBF+/lLKXDeQ1gxvzx1efKDiQmeZI+1C9lhGAoKXI eT8RZ3BeAsG1Qffyt7eVZV+9yA0xyU6WT7TVehzuAeUcHCBeqji4jTLeN13bt5oDzp0w hoYg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1774036271; x=1774641071; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=7VX3ysj6cQD9fqvXshv/ZRQwsvBLFm2mvMYFPBkdKy4=; b=bx9Ed/5zQwvZLZB434t8iuyQ171EH4IWL5uw8f2MYIcqSSWFbsu77WA5NnWnE02IEU bMUToC4H9Ti3WZs/v0qF3G16pHtKM353z47p1K8yqJl+Ej792+ARbCK9vOKTpyJL0qjn xaSb3Lj57GxlhLgPpcD8o+W5Fg5b+siksFpdBDlOfc8scUPo+zY8E5ABuQSYZx0AeoLN 8Q1XoLUZRrIBnEb0QpoP6PD60BNKrub/+HyDUey3ULm2mm016AzQRoLpbkWlg2eTy6+r MJ06PZUuhRrnR5MPyVVe5FRr2QLSlEwnNp0t0L+wSqyROJHKrqUJx/++R0yX2sQy0G1v 0CwA== X-Forwarded-Encrypted: i=1; AJvYcCWlSH3qu5oWp/429HU8Tbk+Pt0hauRE/pm8YOIYGKiFhmjmR5tWan6arEF9eOxlzTPjncCLq94zRpNr9oRi@postgresql.org X-Gm-Message-State: AOJu0YzUqujp+Y/TlwGYVWxDayzLAWfWDRoqwuFtsDfCTtWrODKNXir/ jrtP0/F7aWk/WYNlKZ9dP3SSZCMY3/5rjm+/ZjP5gXNPCYq12zhAbonKctlCFBhJ1M7VQ9ZXKl+ c66b3wnMP//7IGnsqLCS28MeQy2Mt07CQt6os X-Gm-Gg: ATEYQzwgXbBfFPqtCtsY3XTu30E1dT/o2JoBFnpL37X8gqTpzpz0BTXXl8Hf3EZtZda oDuS8njQLzGeWQMAyDxTesDpTUqWZx3+SZufIRNANt9saqUHaAPpFkkf2K4q969f4tEEs9B9WbZ wWRAHEOO6q166inyhuYofVr5DxwOah9eWtagpXqdgyq/9558cXAp51i7lOaD8oxFpUeHhB5gqMy Xwqgv5iIblkPhKFU+riiQwsGCiLsiVGvhEcQbXxiJPS6YxYlsHoKp47A85e5MR0SQxie5e4V/w5 SsJiX5tAgwzgLvZ9Qnm63Ix452hMyPLBooyJgrghEPIFABa8v003dbyKJAjEaQks00bxuyaw/qv eJu7rKo/V X-Received: by 2002:a05:6402:5d0:b0:65b:f342:d1a2 with SMTP id 4fb4d7f45d1cf-668c8f08c14mr3612725a12.6.1774036270387; Fri, 20 Mar 2026 12:51:10 -0700 (PDT) MIME-Version: 1.0 References: <42rdu4q44kvsq53fz5qgzuawqpaytvnemsnquynlfch5mqhc2m@6ytnlgivtzro> In-Reply-To: <42rdu4q44kvsq53fz5qgzuawqpaytvnemsnquynlfch5mqhc2m@6ytnlgivtzro> From: Melanie Plageman Date: Fri, 20 Mar 2026 15:50:59 -0400 X-Gm-Features: AaiRm5181421TXmFm6efpMT97BkiS-RapROYoeWyrIgAz7Z8mT4u_alysdEIV70 Message-ID: Subject: Re: Don't synchronously wait for already-in-progress IO in read stream To: Andres Freund Cc: Nazir Bilal Yavuz , Thomas Munro , pgsql-hackers@postgresql.org, Peter Geoghegan , Tomas Vondra Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Thu, Mar 19, 2026 at 6:22=E2=80=AFPM Andres Freund = wrote: > > Thinking about it more, I also got worried about the duplicating of > logic. It's perhaps acceptable with the patches as-is, but we'll soon nee= d > something very similar for AIO writes. Then we'd end up with like 5 varia= nts, > because we'd still need the existing StartBufferIO() for some cases where= we > do want to wait (e.g. the edge case in ExtendBufferedRelShared()). > > In the attached prototype I replaced your patch introducing > PrepareHeadBufferReadIO()/ PrepareAdditionalBufferReadIO() with one that > instead revises StartBufferIO() to have the enum return value you introdu= ced > and a PgAioWaitRef * argument that callers that would like to asynchronou= sly > wait for the IO to complete (others pass NULL). There are some other clea= nups > in it too, see the commit message for more details. I've come around to this. The aspect I like least is that io_wref is used both as an output parameter _and_ a decision input parameter. Some callers never want to wait on in-progress IO (and don't have to), while others must eventually wait but can defer that waiting as long as they have a wait reference. If they can't get a wait reference, they have no way to wait later, so they must wait now. The presence of io_wref indicates this difference. I think it's important to express that less mechanically than in your current header comment and comment in the else block of StartSharedBufferIO() where we do the waiting. Explaining first=E2=80=94bef= ore detailing argument combinations=E2=80=94why a caller would want to pass io_wref might help. However, I do think you need to enumerate the different combinations of wait and io_wref (as you've done) to make it clear what they are. I, for example, find it very confusing what wait =3D=3D false and io_wref not NULL would mean. If IO is in progress on the buffer and the io_wref is not valid yet, the caller would get the expected BUFFER_IO_IN_PROGRESS return value but io_wref won't be set. I could see callers easily misinterpreting the API and passing this combination when what they want is wait =3D=3D true and io_wref not NULL -- because they don't want to synchronously wait. I don't have any good suggestions despite thinking about it, though. Two other things about 0007: for (int i =3D nblocks_done + 1; i < operation->nblocks; i++) { /* Must be consecutive block numbers. */ Assert(BufferGetBlockNumber(buffers[i - 1]) =3D=3D BufferGetBlockNumber(buffers[i]) - 1); status =3D StartBufferIO(buffers[nblocks_done], true, false, NULL); Copy-paste bug above, should be StartBufferIO(buffers[i],... I would mention that currently BUFFER_IO_IN_PROGRESS is not used in the first StartBufferIO() case, so that is dead code as of this commit > I also updated "Restructure AsyncReadBuffers()" to move > pgstat_prepare_report_checksum_failure() and the computation of flags to > before the ReadBuffersCanStartIO(). And added a comment explaining why l= ittle > should be added between the ReadBuffersCanStartIO() calls. > > Thoughts? Yea, definitely think the comment is important. - Melanie