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 1tv4Rz-00GrNA-3r for pgsql-hackers@arkaria.postgresql.org; Thu, 20 Mar 2025 01:11:59 +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 1tv4Rx-00Emvu-Pp for pgsql-hackers@arkaria.postgresql.org; Thu, 20 Mar 2025 01:11:57 +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 1tv4RQ-00Ejmr-4G for pgsql-hackers@lists.postgresql.org; Thu, 20 Mar 2025 01:11:24 +0000 Received: from mail-pl1-x62a.google.com ([2607:f8b0:4864:20::62a]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1tv4RO-00022r-1p for pgsql-hackers@postgresql.org; Thu, 20 Mar 2025 01:11:23 +0000 Received: by mail-pl1-x62a.google.com with SMTP id d9443c01a7336-22622ddcc35so3664345ad.2 for ; Wed, 19 Mar 2025 18:11:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=leadboat.com; s=google; t=1742433081; x=1743037881; 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=2mmCjvXjYg/pEbDeZttyxg+RmL453L7CYu8gFZCpYz8=; b=dgGGSLsnzpbEGxMKdkGpGcb4QafZ1oBZ3+yimNFxUL4r6mvv3qQD8L+W2yd55YOHdE pKrSa4xedRqam5hVDGZWUO0G5Uzzhoi3lR7ft5oECnvPadQeSbTfJ+ovlQkV4R775EJE 5qbfc3G9Ms/1F2MbdPgk5SiVhUtB0dFoHhPHY= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1742433081; x=1743037881; 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=2mmCjvXjYg/pEbDeZttyxg+RmL453L7CYu8gFZCpYz8=; b=MIMzhDECIafgTDhTZO0qy7kz4qeMz2rRfbMIlQ3fS8BWwL1xQcEseYMVBsV1F5A9y2 9jecnWDMbB8QF/G9hxj2PJl2SniQ5hupj5iHmB+HXJGfLKuMUNCC0hH+cKvNXglccF/u eXLKOrHSUMOky7pPsLB8/bXSpkOkpiMpuImRReP+c6oIJyCMC4xnkvHpwxrQWUl46GnQ qSceCQOWD2BxY3tzCOPdhCf6A7M2+JRffRKM7lNn6cGfLmocM6eor8uK54ETKMRnCNMW zxFkumHgBZGmIq88i2syOmYyR3NQlZTiuTenlbKO9YxcldbqZacXzSUQu9ajBt/a6G13 XA1w== X-Forwarded-Encrypted: i=1; AJvYcCUaQZ3qvI50WKlFQGWjUzITPupoGKEU7SUrRwn4PKBk+bQznyNycNoCI07B+vjgqjx7CtaFBQozJUXInrE3@postgresql.org X-Gm-Message-State: AOJu0YxEIl8yXQvNaxuS3lb53X9GeLixtNlgdQ+GDRClsY1P70K1ZpOx JxYsKt3zvQxXNBIaVMrqIyELt7bVQFWko/HKslOpg5AOB8OcyeKN3OMvU/eYBA== X-Gm-Gg: ASbGncuVvd7yWTab44lppskiP/BqNtsHihYXo2iVyGaLz/970hSBMC+GLA2PNYjXsQX 6aGVEGYLg6JUSAO6n7R5X8PnH9e5WDslQjq1mlCJrFYJP9bGSYu+ipVodFJOfHMLZe+aRvdeT3X BQmfJ/d2WuUMv04umfidX6d8fH2mII3Vd+6kboB37mhg8pNxVeoEmuhCYcPZPkkSdd2JKsYX/Di f4jo14cm1jyFA3KPTcDAucF6A/PfwMTOcL20WpASWLtzyZcw28MOSdSW6EmR7/OiMrK1/jMsKef ux218O8/eShViMMCG3mg0rkIasGpHhyEwb5UiCMukQ== X-Google-Smtp-Source: AGHT+IE0NMaHQsY2Dp8QqYeAVVR6YZ+ku889p5f7aMrCJpdrRNQfObohExiN1SlCQ5hvSk/CA89LyA== X-Received: by 2002:a17:902:ccc7:b0:224:ff0:4360 with SMTP id d9443c01a7336-22649cb6a06mr82475095ad.53.1742433081398; Wed, 19 Mar 2025 18:11:21 -0700 (PDT) Received: from google.com ([2601:647:5600:80d0::31cd]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-737115749b3sm12482754b3a.81.2025.03.19.18.11.20 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Wed, 19 Mar 2025 18:11:20 -0700 (PDT) Date: Wed, 19 Mar 2025 18:11:18 -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: <20250320011118.8d.nmisch@google.com> References: <5dzyoduxlvfg55oqtjyjehez5uoq6hnwgzor4kkybkfdgkj7ag@rbi4gsmzaczk> <20250312035743.f5.nmisch@google.com> <4b3f32ug3cayekysqlgspz2qjmeb7lca3gvazayglxr2m3d4dv@il33accgsji7> <17906.1741863183@localhost> <3yxd5r23zly5bytvgyktbxtxq2r3gbpi7xd4dugevh3h4w4q6c@lu6oatjjpltz> <20250319212530.80.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 Wed, Mar 19, 2025 at 06:17:37PM -0400, Andres Freund wrote: > On 2025-03-19 14:25:30 -0700, Noah Misch wrote: > > commit 55b454d wrote: > > > aio: Infrastructure for io_method=worker > > > > > + /* Try to launch one. */ > > > + child = StartChildProcess(B_IO_WORKER); > > > + if (child != NULL) > > > + { > > > + io_worker_children[id] = child; > > > + ++io_worker_count; > > > + } > > > + else > > > + break; /* XXX try again soon? */ > > > > I'd change the comment to something like one of: > > > > retry after DetermineSleepTime() > > next LaunchMissingBackgroundProcesses() will retry in <60s > > Hm, we retry more frequently that that if there are new connections... Maybe > just "try again next time"? Works for me. > > On Tue, Mar 18, 2025 at 04:12:18PM -0400, Andres Freund wrote: > > > Subject: [PATCH v2.10 08/28] bufmgr: Implement AIO read support > > > > Some comments about BM_IO_IN_PROGRESS may need updates. This paragraph: > > > > * The BM_IO_IN_PROGRESS flag acts as a kind of lock, used to wait for I/O on a > > buffer to complete (and in releases before 14, it was accompanied by a > > per-buffer LWLock). The process doing a read or write sets the flag for the > > duration, and processes that need to wait for it to be cleared sleep on a > > condition variable. > > First draft: > * The BM_IO_IN_PROGRESS flag acts as a kind of lock, used to wait for I/O on a > buffer to complete (and in releases before 14, it was accompanied by a > per-buffer LWLock). The process start a read or write sets the flag. When the s/start/starting/ > I/O is completed, be it by the process that initiated the I/O or by another > process, the flag is removed and the Buffer's condition variable is signalled. > Processes that need to wait for the I/O to complete can wait for asynchronous > I/O to using BufferDesc->io_wref and for BM_IO_IN_PROGRESS to be unset by s/to using/by using/ > sleeping on the buffer's condition variable. Sounds good. > > And these individual lines from "git grep BM_IO_IN_PROGRESS": > > > > * i.e at most one BM_IO_IN_PROGRESS bit is set per proc. > > > > The last especially. > > Huh - yea. This isn't a "new" issue, I think I missed this comment in 16's > 12f3867f5534. I think the comment can just be deleted? Hmm, yes, it's orthogonal to $SUBJECT and deletion works fine. > > * I/O already in progress. We already hold BM_IO_IN_PROGRESS for the > > * only one process at a time can set the BM_IO_IN_PROGRESS bit. > > * only one process at a time can set the BM_IO_IN_PROGRESS bit. > > > For the other three lines and the paragraph, the notion > > of a process "holding" BM_IO_IN_PROGRESS or being the process to "set" it or > > being the process "doing a read" becomes less significant when one process > > starts the IO and another completes it. > > Hm. I think they'd be ok as-is, but we can probably improve them. Maybe Looking again, I agree they're okay. > > * Now it's safe to write buffer to disk. Note that no one else should > * have been able to write it while we were busy with log flushing because > * we got the exclusive right to perform I/O by setting the > * BM_IO_IN_PROGRESS bit. That's fine too. Maybe s/perform/stage/ or s/perform/start/. > > I see this relies on md_readv_complete having converted "result" to blocks. > > Was there some win from doing that as opposed to doing the division here? > > Division here ("blocks_read = prior_result.result / BLCKSZ") would feel easier > > to follow, to me. > > It seemed like that would be wrong layering - what if we had an smgr that > could store data in a compressed format? The raw read would be of a smaller > size. The smgr API deals in BlockNumbers, only the md.c layer should know > about bytes. I hadn't thought of that. That's a good reason.