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 1u0oQU-008Md0-J9 for pgsql-hackers@arkaria.postgresql.org; Fri, 04 Apr 2025 21:18:10 +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 1u0oQT-004uCU-C0 for pgsql-hackers@arkaria.postgresql.org; Fri, 04 Apr 2025 21:18:09 +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 1u0oQS-004uB9-MU for pgsql-hackers@lists.postgresql.org; Fri, 04 Apr 2025 21:18:09 +0000 Received: from mail-pl1-x62e.google.com ([2607:f8b0:4864:20::62e]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1u0oQQ-002z6z-1F for pgsql-hackers@postgresql.org; Fri, 04 Apr 2025 21:18:07 +0000 Received: by mail-pl1-x62e.google.com with SMTP id d9443c01a7336-227b650504fso24388975ad.0 for ; Fri, 04 Apr 2025 14:18:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=leadboat.com; s=google; t=1743801485; x=1744406285; 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=1VbmVKk5aXruppGfjzyzqqerwQxSC2PCwa0VZ+i7w8I=; b=HMOKza7lnfgcaEE+21p/bRa8EbAqvB/oNXL0EZy3v7PSh6kYVmBWqFghcH34yWh72f Ck7ZcVtP5yXYHBkb/+tJsBXfVGEnJGsuUu1iMpopLz6dUonDGPkx/q01DV2HuQi6WHOh qRRHEMCyupczVAEg1H90nUoGuBrluplTWjFwE= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1743801485; x=1744406285; 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=1VbmVKk5aXruppGfjzyzqqerwQxSC2PCwa0VZ+i7w8I=; b=kc8OEt+WYRIskIN+5OlwlK1GbTBR/c+/U5Md2dWfxdvVYQefX+uXUz+XU75f9V1Db4 WJPEWfyu0DHjcgK7hbe3HESsP/g7P0/cQxd39HFAgjXXr68GLpvLfOPAsBWsBIEwUFY3 5P6wmnrgoeLlGmBTGPIxvjDXfhPQDiB+IeE0ykadx7fLcoZ160xIQGkmKJzA2655VPMG +uiYC0RkHm8i5FtMzBSPP0Wx71q0dY1AXYFMq+XTqMNbXX6tXz6Q5qohjkAxEVa2Xli6 A0HSRiQwzGpect9biueXv0FFyX9NAxBefKaWV7Yu9/2dTBuc8i81wJQDbn4dyB1G+5Ng epRA== X-Gm-Message-State: AOJu0YwtvMGVvBaDvmNVBVjoEGR79ThJdvQvIKN5SaEDjXcW0hprhhnh thtga1EoTuHGCJM+FqXoXviwUvt7GldPJFxwt0FA+D/RKPnhG1ej6C50CTxs6A== X-Gm-Gg: ASbGncsyT8lRqeLN2nFaxBk0Dv05wBxxdn2IkL+0g1h9vXkBijyq3G698lgmuC0FzE3 rYV714i9rYfFM0e/bxMtrgQ3tN1t9yOdiFYinA8RYuAgsTlO4SZB3+f/u4uYP4jDoW+ObsAOLC1 8Dvidgi4rvj5gLgibvlDPPA1InONtIV8FrNsvs4RzcdJ11Flc3rhxYLGpnxwtOpUT0MKOc282fi ALTygHkdW2v/iJqt7ib3s5Sy0Rr6xbjBoTQj0tAqumNKefV/1ay0r6H4FuRkdfUZpdCw0pp80JH VXf9A4Lt/PbCBmdlh2aaHp7QOKaMKi7KnGsPC/+HfJmx7TZL9dmU X-Google-Smtp-Source: AGHT+IEK1gA36vShzDUac8BtyGDENJrSX6QHPH2B6U5yU7Av+C1gV0DczAyRdADP1OEH4PG20YKPYA== X-Received: by 2002:a17:902:d48d:b0:223:66bc:f1de with SMTP id d9443c01a7336-22a8a06b382mr59979605ad.21.1743801484853; Fri, 04 Apr 2025 14:18:04 -0700 (PDT) Received: from google.com ([2601:647:5600:80d0::31cd]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-739d97ee2e4sm3898422b3a.43.2025.04.04.14.18.03 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Fri, 04 Apr 2025 14:18:04 -0700 (PDT) Date: Fri, 4 Apr 2025 14:18:02 -0700 From: Noah Misch To: Andres Freund Cc: pgsql-hackers@postgresql.org, Thomas Munro , Heikki Linnakangas , Robert Haas , Jakub Wartak , Jelte Fennema-Nio , Antonin Houska Subject: Re: AIO v2.5 Message-ID: <20250404211802.fc.nmisch@google.com> References: <20250329212929.a6.nmisch@google.com> <7s6fclfekpcxoaaorwrq67v4vmgixf2dcjcgznuj7vxs3ie3wq@okqbi5vabqbx> <20250401151159.51.nmisch@google.com> <3pd4322mogfmdd5nln3zphdwhtmq3rzdldqjwb2sfqzcgs22lf@ok2gletdaoe6> <20250403194023.c4.nmisch@google.com> 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 Fri, Apr 04, 2025 at 03:16:18PM -0400, Andres Freund wrote: > On 2025-04-03 12:40:23 -0700, Noah Misch wrote: > > On Thu, Apr 03, 2025 at 02:19:43PM -0400, Andres Freund wrote: > > In the general case, we could want client requests as follows: > > > > - If completor==definer and has not dropped pin: > > - Make defined before verifying page. That's all. It might be cleaner to > > do this when first retrieving a return value from io_uring, since this > > just makes up for what Valgrind already does for readv(). > > Yea, I think it's better to do that in io_uring. It's what I have done in the > attached. > > > > - If completor!=definer or has dropped pin: > > - Make NOACCESS in definer when definer cedes its own pin. > > That's the current behaviour for shared buffers, right? Yes. > > - For io_method=worker, make UNDEFINED before starting readv(). It might be > > cleanest to do this when the worker first acts as the owner of the AIO > > subsystem pin, if that's a clear moment earlier than readv(). > > Hm, what do we need this for? At the time, we likely didn't need it: - If the worker does its own PinBuffer*()+unpin, we don't need it. Those functions do the Valgrind client requests. - If the worker relies on the AIO-subsystem-owned pin and does neither regular pin nor regular unpin, we don't need it. Buffers are always "defined". - If the worker relies on the AIO-subsystem-owned pin to skip PinBuffer*() but uses regular unpin code, then the buffer may be NOACCESS. Then one would need this. But this would be questionable for other reasons. Your proposed change to set NOACCESS in buffer_readv_complete_one() interacts with things further, making the UNDEFINED necessary. > > - Make DEFINED in completor before verifying page. It might be cleaner to > > do this when the completor first retrieves a return value from io_uring, > > since this just makes up for what Valgrind already does for readv(). > > I think we can't rely on the marking during retrieving it from io_uring, as > that might have happened in a different backend for a temp buffer. That'd only > happen if we got io_uring events for *another* IO that involved a shared rel, > but it can happen. Good point. I think the VALGRIND_MAKE_MEM_DEFINED() in pgaio_uring_drain_locked() isn't currently needed at all. If completor-subxact==definer-subxact, PinBuffer() already did what Valgrind needs. Otherwise, buffer_readv_complete_one() does what Valgrind needs. If that's right, it would still be nice to reach the right VALGRIND_MAKE_MEM_DEFINED() without involving bufmgr. That helps future, non-bufmgr AIO use cases. It's tricky to pick the right place for that VALGRIND_MAKE_MEM_DEFINED(): - pgaio_uring_drain_locked() is problematic, I think. In the localbuf case, the iovec base address is relevant only in the ioh-defining process. In the shmem completor!=definer case, this runs only in the completor. - A complete_local callback solves those problems. However, if the AIO-defining subxact aborted, then we shouldn't set DEFINED at all, since the buffer mapping may have changed by the time of complete_local. - Putting it in the place that would call pgaio_result_report(ERROR) if needed, e.g. ProcessReadBuffersResult(), solves the problem of the buffer mapping having moved. ProcessReadBuffersResult() doesn't even need this, since PinBuffer() already did it. Each future AIO use case will have a counterpart of ProcessReadBuffersResult() that consumes the result and proceeds with tasks that depend on the AIO. That's the place. Is that right? I got this wrong a few times while trying to think through it, so I'm not too confident in the above. > > > Not quite sure if we should mark > > > the entire IOV is efined or just the portion that was actually read - the > > > latter is additional fiddly code, and it's not clear it's likely to be helpful? > > > > Seems fine to do the simpler way if that saves fiddly code. > > Can't quite decide, it's just at the border of what I consider too > fiddly... See the change to method_io_uring.c in the attached patch. It is at the border, as you say, but I'd tend to keep it. > Subject: [PATCH v1 1/3] localbuf: Add Valgrind buffer access instrumentation Ready for commit > Subject: [PATCH v1 2/3] aio: Make AIO compatible with valgrind See above about pgaio_uring_drain_locked(). > related code until it is pinned bu "user" code again. But it requires some s/bu/by/ > + * Return the iovecand its length. Currently only expected to be used by s/iovecand/iovec and/ > @@ -361,13 +405,16 @@ pgaio_uring_drain_locked(PgAioUringContext *context) > for (int i = 0; i < ncqes; i++) > { > struct io_uring_cqe *cqe = cqes[i]; > + int32 res; > PgAioHandle *ioh; > > ioh = io_uring_cqe_get_data(cqe); > errcallback.arg = ioh; > + res = cqe->res; > + > io_uring_cqe_seen(&context->io_uring_ring, cqe); > > - pgaio_io_process_completion(ioh, cqe->res); > + pgaio_uring_io_process_completion(ioh, res); I guess this is a distinct cleanup, done to avoid any suspicion of cqe being reused asynchronously after io_uring_cqe_seen(). Is that right? > Subject: [PATCH v1 3/3] aio: Avoid spurious coverity warning Ready for commit