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.94.2) (envelope-from ) id 1txEUO-005BWV-92 for pgsql-hackers@arkaria.postgresql.org; Wed, 26 Mar 2025 00:19:24 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1txEUM-00CBj3-Vn for pgsql-hackers@arkaria.postgresql.org; Wed, 26 Mar 2025 00:19:22 +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.94.2) (envelope-from ) id 1txEUM-00CBiv-IR for pgsql-hackers@lists.postgresql.org; Wed, 26 Mar 2025 00:19:22 +0000 Received: from mail-pl1-x633.google.com ([2607:f8b0:4864:20::633]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1txEUJ-0018ge-2l for pgsql-hackers@postgresql.org; Wed, 26 Mar 2025 00:19:21 +0000 Received: by mail-pl1-x633.google.com with SMTP id d9443c01a7336-22409077c06so137532985ad.1 for ; Tue, 25 Mar 2025 17:19:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=leadboat.com; s=google; t=1742948359; x=1743553159; darn=postgresql.org; h=user-agent:in-reply-to:content-disposition:mime-version:references :message-id:subject:cc:to:from:date:from:to:cc:subject:date :message-id:reply-to; bh=6Kotcu3xFwUMHBtg1QQ3eEkizBII8EZwVPua4e6CjEQ=; b=BaWYb04capAgsrU102F5Npf4+9LUvh0jvZTKQ3ME6p9wLqlGS501YxCQOh/NkBlp42 BiWV6B7OQb8XbFf8/8hGM6eivo0v7m44kicy9xCexdThcTYCCPskkeFPfkqmxGT7Xtqk 0Poam/xH3KvtN+N1OWFIGSKaAG/vbMofqFo8s= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1742948359; x=1743553159; h=user-agent:in-reply-to:content-disposition:mime-version:references :message-id:subject:cc:to:from:date:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=6Kotcu3xFwUMHBtg1QQ3eEkizBII8EZwVPua4e6CjEQ=; b=mDU9TkXd2JpnZZgYW0VKdI9Ffbj+WdQlsd7UlmpBqyZJpHxA8guuG9XWYDHZbjD3f0 ELbDRzqyqoQaNPW54SMs20jNogMsC/18FAd65YpcnRADTx5ijSQGy/jieHEKqrBNEvWG +/85NCvhePBspLomZgwaJupG90i/0kPGFdddFLMs0A8TzQ8Vz3EVcZCCUo7HZZ2v6/t8 cIHSbUPwGCb2upP+PaPGGXTPA/UyTl0z16rGCKpePJuArObnJgG/UNQqt4qJ09emXeaa KTaeaq0fsBkX0yFQyPrjep5PLa0QKVduX3k80NsOv+zQwOKFTt4exrGmf5ibVUHXyQTS UYRQ== X-Forwarded-Encrypted: i=1; AJvYcCWOfvS0uYtQAGTFvXBFhjSRoHpgM89TR4AqOVFzgDl6KqcPe9XHd9bQncwvm5zRPXhBFz4ITMg2g/uLJML1@postgresql.org X-Gm-Message-State: AOJu0YzTFySRRNVRiKedcLLDCnx9r7ji5j7POC1P9/NcOLBOdu0t1dxC roANjsJQtBWIhxpy6XcT9ZJLp1Hb4BN7pe/6dSV2S2riKKCDxNk3X40DAKI5cQ== X-Gm-Gg: ASbGncszwcRo7uQTKQHT5QA14Whyp0WfrKRS2hxpx5dOZ21PRx/9LGN7LAE5Ukr9WqY jsre+o8f0JAjopv3VS1TYJN5THG3xOSmzuuTGtyFcCjTWJy1JKe809lt2+xPsLSR7+ozFVchOc1 RL9lbWo5VFFhVuwjw8C0s54+gat1JYnhoZxMWdcnpxa76xpE1mmQZjb+6G5QK84cz7Oku6IP+Oz +B/Ri3oBgG1/Sv2iwOpVBy+j48Zz+B7J8VfeezreZU6hrJn4xCAWzEut/XxjaevOI5DNLy+urSP iWHdwOC0pe2E4FQUBl83pWQL2TzzKhkueZz1536bpg== X-Google-Smtp-Source: AGHT+IF/OD3lzPbCqC4WUo27BUo/IvqRUlXbKUktRkwVzgsTctCaadavXVEi6/FO/F+9gTHQTyfqhw== X-Received: by 2002:a17:902:d549:b0:224:a96:e39 with SMTP id d9443c01a7336-22780c55343mr310983695ad.9.1742948358410; Tue, 25 Mar 2025 17:19:18 -0700 (PDT) Received: from google.com ([2601:647:5600:80d0::31cd]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-73905fe33d0sm10865465b3a.70.2025.03.25.17.19.17 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Tue, 25 Mar 2025 17:19:17 -0700 (PDT) Date: Tue, 25 Mar 2025 17:19:15 -0700 From: Noah Misch To: Andres Freund Cc: Antonin Houska , pgsql-hackers@postgresql.org, Thomas Munro , Heikki Linnakangas , Robert Haas , Jakub Wartak , Jelte Fennema-Nio Subject: Re: AIO v2.5 Message-ID: <20250326001915.bc.nmisch@google.com> References: <5dzyoduxlvfg55oqtjyjehez5uoq6hnwgzor4kkybkfdgkj7ag@rbi4gsmzaczk> <20250312035743.f5.nmisch@google.com> <4b3f32ug3cayekysqlgspz2qjmeb7lca3gvazayglxr2m3d4dv@il33accgsji7> <17906.1741863183@localhost> <3yxd5r23zly5bytvgyktbxtxq2r3gbpi7xd4dugevh3h4w4q6c@lu6oatjjpltz> <6ak556uyqiptdwjaci4kbi5eykwkmzqgkbtkyaosjnopjhncrc@2v4ac2jwyz22> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/2.2.12 (2023-09-09) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Mon, Mar 24, 2025 at 09:18:06PM -0400, Andres Freund wrote: > Attached v2.12, with the following changes: > TODO: > Wonder if it's worth adding some coverage for when checksums are disabled? > Probably not necessary? Probably not necessary, agreed. Orthogonal to AIO, it's likely worth a CI "SPECIAL" and/or buildfarm animal that runs all tests w/ checksums disabled. > Subject: [PATCH v2.12 01/28] aio: Be more paranoid about interrupts Ready for commit > Subject: [PATCH v2.12 02/28] aio: Pass result of local callbacks to > ->report_return Ready for commit w/ up to one cosmetic change: > @@ -296,7 +299,9 @@ pgaio_io_call_complete_local(PgAioHandle *ioh) > > /* > * Note that we don't save the result in ioh->distilled_result, the local > - * callback's result should not ever matter to other waiters. > + * callback's result should not ever matter to other waiters. However, the > + * local backend does care, so we return the result as modified by local > + * callbacks, which then can be passed to ioh->report_return->result. > */ > pgaio_debug_io(DEBUG3, ioh, > "after local completion: distilled result: (status %s, id %u, error_data %d, result %d), raw_result: %d", Should this debug message remove the word "distilled", since this commit solidifies distilled_result as referring to the complete_shared result? > Subject: [PATCH v2.12 03/28] aio: Add liburing dependency Ready for commit > Subject: [PATCH v2.12 04/28] aio: Add io_method=io_uring Ready for commit w/ open_fd.fixup > Subject: [PATCH v2.12 05/28] aio: Implement support for reads in smgr/md/fd Ready for commit w/ up to two cosmetic changes: > +/* > + * AIO error reporting callback for mdstartreadv(). > + * > + * Errors are encoded as follows: > + * - PgAioResult.error_data != 0 encodes IO that failed with errno != 0 I recommend replacing "errno != 0" with either "that errno" or "errno == error_data". Second, the aio_internal.h comment changes discussed in postgr.es/m/20250325155808.f7.nmisch@google.com and earlier. > Subject: [PATCH v2.12 06/28] aio: Add README.md explaining higher level design Ready for commit (This and the previous patch have three spots that would change with the s/prep/start/ renames. No opinion on whether to rename before or rename after.) > Subject: [PATCH v2.12 07/28] localbuf: Track pincount in BufferDesc as well The plan here looks good: postgr.es/m/dbeeaize47y7esifdrinpa2l7cqqb67k72exvuf3appyxywjnc@7bt76mozhcy2 > Subject: [PATCH v2.12 08/28] bufmgr: Implement AIO read support See review here and later discussion: postgr.es/m/20250325022037.91.nmisch@google.com > Subject: [PATCH v2.12 09/28] bufmgr: Use AIO in StartReadBuffers() Ready for commit after a batch of small things, all but one of which have no implications beyond code cosmetics. This is my first comprehensive review of this patch. I like the test coverage (by the end of the patch series). For anyone else following, I found "diff -w" helpful for the bufmgr.c changes. That's because a key part is former WaitReadBuffers() code moving up an indentation level to its home in new subroutine AsyncReadBuffers(). > Assert(*nblocks == 1 || allow_forwarding); > Assert(*nblocks > 0); > Assert(*nblocks <= MAX_IO_COMBINE_LIMIT); > + Assert(*nblocks == 1 || allow_forwarding); Duplicates the assert three lines back. > + nblocks = aio_ret->result.result; > + > + elog(DEBUG3, "partial read, will retry"); > + > + } > + else if (aio_ret->result.status == PGAIO_RS_ERROR) > + { > + pgaio_result_report(aio_ret->result, &aio_ret->target_data, ERROR); > + nblocks = 0; /* silence compiler */ > + } > > Assert(nblocks > 0); > Assert(nblocks <= MAX_IO_COMBINE_LIMIT); > > + operation->nblocks_done += nblocks; I struggled somewhat from the variety of "nblocks" variables: this local nblocks, operation->nblocks, actual_nblocks, and *nblocks in/out parameters of some functions. No one of them is clearly wrong to use the name, and some of these names are preexisting. That said, if you see opportunities to push in the direction of more-specific names, I'd welcome it. For example, this local variable could become add_to_nblocks_done instead. > + AsyncReadBuffers(operation, &nblocks); I suggest renaming s/nblocks/ignored_nblocks_progress/ here. > + * If we need to wait for IO before we can get a handle, submit already > + * staged IO first, so that other backends don't need to wait. There s/already staged/already-staged/. Normally I'd skip this as nitpicking, but I misread this particular sentence twice, as "submit" being the subject that "staged" something. (It's still nitpicking, alas.) > /* > * How many neighboring-on-disk blocks can we scatter-read into other > * buffers at the same time? In this case we don't wait if we see an > - * I/O already in progress. We already hold BM_IO_IN_PROGRESS for the > + * I/O already in progress. We already set BM_IO_IN_PROGRESS for the > * head block, so we should get on with that I/O as soon as possible. > - * We'll come back to this block again, above. > + * > + * We'll come back to this block in the next call to > + * StartReadBuffers() -> AsyncReadBuffers(). Did this mean to say "WaitReadBuffers() -> AsyncReadBuffers()"? I'm guessing so, since WaitReadBuffers() is the one that loops. It might be referring to read_stream_start_pending_read()'s next StartReadBuffers(), though. I think this could just delete the last sentence. The function header comment already mentions the possibility of reading a subset of the request. This spot doesn't need to detail how the higher layers come back to here. > + smgrstartreadv(ioh, operation->smgr, forknum, > + blocknum + nblocks_done, > + io_pages, io_buffers_len); > + pgstat_count_io_op_time(io_object, io_context, IOOP_READ, > + io_start, 1, *nblocks_progress * BLCKSZ); We don't assign *nblocks_progress until lower in the function, so I think "io_buffers_len" should replace "*nblocks_progress" here. (This is my only non-cosmetic comment on this patch.) > Subject: [PATCH v2.12 10/28] aio: Basic read_stream adjustments for real AIO (Still reviewing this and later patches, but incidental observations follow.) > Subject: [PATCH v2.12 16/28] aio: Add test_aio module > +use List::Util qw(sample); sample() is new in 2020: https://metacpan.org/release/PEVANS/Scalar-List-Utils-1.68/source/Changes#L100 Hence, I'd expect some buildfarm failures. I'd try to use shuffle(), then take the first N elements. > +++ b/src/test/modules/test_aio/test_aio.c > @@ -0,0 +1,712 @@ > +/*------------------------------------------------------------------------- > + * > + * delay_execution.c > + * Test module to allow delay between parsing and execution of a query. > + * > + * The delay is implemented by taking and immediately releasing a specified > + * advisory lock. If another process has previously taken that lock, the > + * current process will be blocked until the lock is released; otherwise, > + * there's no effect. This allows an isolationtester script to reliably > + * test behaviors where some specified action happens in another backend > + * between parsing and execution of any desired query. > + * > + * Copyright (c) 2020-2025, PostgreSQL Global Development Group > + * > + * IDENTIFICATION > + * src/test/modules/test_aio/test_aio.c To elaborate on my last review, the entire header comment was a copy from delay_execution.c. v2.12 fixes the IDENTIFICATION, but the rest needs updates. Thanks, nm