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 1uDDNl-007ni4-Ov for pgsql-hackers@arkaria.postgresql.org; Fri, 09 May 2025 02:22:38 +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 1uDDNj-007GyV-Vz for pgsql-hackers@arkaria.postgresql.org; Fri, 09 May 2025 02:22:36 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1uDDNj-007GyG-Bh for pgsql-hackers@lists.postgresql.org; Fri, 09 May 2025 02:22:35 +0000 Received: from mail-pj1-x102b.google.com ([2607:f8b0:4864:20::102b]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1uDDNf-000wmI-2P for pgsql-hackers@postgresql.org; Fri, 09 May 2025 02:22:34 +0000 Received: by mail-pj1-x102b.google.com with SMTP id 98e67ed59e1d1-30a93117e1bso2161770a91.1 for ; Thu, 08 May 2025 19:22:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=leadboat.com; s=google; t=1746757350; x=1747362150; 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=bZBcqtVXfQ2XrrlCDSVmKnyTfml83INEVexQbt6Gnzg=; b=C/gNDIF7JLXAN4nNinyH8b8/qdax/YghvsLSgmF3TYY1UgOShKqQ2fUOLMm+FO2SRU 0pKtyvtezKcmkB7WzL33bG72XJURfGnOXXvhRO9jixUR6HKRws30qHqg6mGNsNzoXBbA Xj0W0ghNvI4/nkQdKgIZ91ivs36ralUQj+Vkk= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1746757350; x=1747362150; 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=bZBcqtVXfQ2XrrlCDSVmKnyTfml83INEVexQbt6Gnzg=; b=uIQKVd7IVjpOOXs0nKQ3nU/D2M+1TNh14f5BD1FxMZtSswW/pZaNeqXFaBaqpHyUMU H1GWFses4OJThvORscEPlql45Bv/VKz6DgsGfeei2KOo3qSKrJfzVyeSrO+JGAjiHxHb 7YgKcESxYKbtMwa3L8ef/47xoqfkzelYAHRdRpdGhFnGwVfS/9/WW3zZyUQqwGs3dKl/ pRgbCTADT7YaYE1hsVvwQvzOrXrWe9h2YCb1Q0h5NhUQvKGQVs7pXfGlb3cejph6pTk7 /3G0Wpars0sDpL6J88nJGX9zNo5JDzguaD/METPzC5+oPqJ5Ekzz9Ddl2anrMQ55pc/N lJWQ== X-Forwarded-Encrypted: i=1; AJvYcCXt2Hzd97n/9OaJ2DD8cUlYjSaKGjtf7i5yppZV+7/czpyxgimdVIptcdPclzykD/xq5TMuhftz4Y954swD@postgresql.org X-Gm-Message-State: AOJu0Yw/oF47Aldk8GN8H3v5xUERiRRF5ClI1z13JFaptPUz5Muvjn6L 3iwBv5kb74mMw+jceF0Yu+8PBqEl5aA+gFGYgD/XgplPqPaQV3HiQy9jnKdVuQ== X-Gm-Gg: ASbGncu49yXH+633Ex54Qg6teaEnpCHhFWNTzCGbBmA0p2fsnEJzKlA6hBq/+X2k2gy jl5sPnU++vv5xPXzDwrzN/63AcMs8t5mocrWDKxSBaX8LzQBwN2n79Jh7mSo6A8aMgixIjEewgK OFG6XjRtmzD5Q4/v+5n6xpCJrcj4fxlf03HCkPURQ8wNcOjWF9OQtLZPa06ckqUkKw3d/LZtoBi 4yD0NonELUo8++4I36vlyYOP6tSnr3bVlijEmB+yd0NFbTO/xphImbWRakFeDZXo0KO3h++MQSo g2op2SDpFPqkAxqsamiSQL1ZXvF34x0KC3oc/A== X-Google-Smtp-Source: AGHT+IExQ5RGhXgs/Y0Ltt7hE+vCSRc1c30gw+Y2Ks9WyWXiTE4jjVBmlCca2TtZY2X0e/ZSGsjMKw== X-Received: by 2002:a17:90b:1e0a:b0:301:1c11:aa74 with SMTP id 98e67ed59e1d1-30c3d628b61mr2723382a91.28.1746757349738; Thu, 08 May 2025 19:22:29 -0700 (PDT) Received: from google.com ([2601:647:5600:80d0::31cd]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-30ad4d59d73sm2948255a91.29.2025.05.08.19.22.28 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Thu, 08 May 2025 19:22:29 -0700 (PDT) Date: Thu, 8 May 2025 19:22:27 -0700 From: Noah Misch To: Andres Freund Cc: Alexander Lakhin , pgsql-hackers@postgresql.org, Thomas Munro , Heikki Linnakangas , Robert Haas , Jakub Wartak , Jelte Fennema-Nio , Antonin Houska Subject: Re: AIO v2.5 Message-ID: <20250509022227.5b.nmisch@google.com> References: <3fhulsvzks4khqahl6tngcnuda7pyrrl7223tmjh2x2spralm3@iisldh6pcowy> <8160688e-db8e-4d7d-a7e7-ff366adf9717@gmail.com> <4nervqmqplfr23jrjvkp5tsumi6qgouhgjqlubf7ujrudw2epb@6mszddainl4u> <6a6756a0-bad5-4ee5-a591-c763af289940@gmail.com> <96abefe8-fa72-41f5-8840-0517125c24e3@gmail.com> <4qk3ehe6w7x7hfrldei2hefjcb7v7nfmj2owl2ir64craqcapz@kbrao22ljxeb> <062daca9-dfad-4750-9da8-b13388301ad9@gmail.com> <20250503030511.9b.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 Thu, May 08, 2025 at 09:06:18PM -0400, Andres Freund wrote: > On 2025-05-02 20:05:11 -0700, Noah Misch wrote: > > On Wed, Apr 30, 2025 at 04:00:35PM -0400, Andres Freund wrote: > We do need to hold interrupts in a few other places, I think - with some debug > infrastructure (things like calling ProcessBarrierSmgrRelease() whenever > interrupts could be processed and calling CFI() in errstart() in its return > false case) it's possible to find state confusions which trigger > assertions. The issue is that pgaio_io_update_state() contains a > pgaio_debug_io() and executing pgaio_closing_fd() in places that call > pgaio_io_update_state() doesn't end well. There's a similar danger with the > debug message in pgaio_io_reclaim(). > > In the attached patch I added an assertion to pgaio_io_update_state() > verifying that interrupts are held and added code to hold interrupts in the > relevant places. Works for me. > > For the "no free IOs despite no in-flight IOs" case, I'd replace the > > ereport(ERROR) with "return;" since we now know interrupt processing reclaimed > > an IO. > > Hm - it seems better to me to check if there are now free handles and return > if that's the case, but to keep the error check in case there actually is no > free IO? That seems like a not implausible bug... Works for me. > > Then decide what protection if any, we need against bugs causing an > > infinite loop in caller pgaio_io_acquire(). What's the case motivating the > > unbounded loop in pgaio_io_acquire(), as opposed to capping at two > > pgaio_io_acquire_nb() calls? If the theory is that pgaio_io_acquire() could > > be reentrant, what scenario would reach that reentrancy? > > I do not remember why I wrote this as an endless loop. If you prefer I could > change that as part of this patch. I asked because it would be sad to remove the ereport(ERROR) like I proposed and then have a bug cause a real infinite loop. Removing the loop was one way to prove that can't happen. As you say, another way would be keeping the ereport(ERROR) and guarding it with a free-handles check, like in your patch today. I don't have a strong preference between those. > It does seem rather dangerous that errstart() processes interrupts for debug > messages, but only if the debug message is actually logged. That's really a > recipe for hard to find bugs. I wonder if we should, at least in assertion > mode, process interrupts even if not emitting the message. Yes, that sounds excellent to have.