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 1w7xpp-0004wp-0K for pgsql-hackers@arkaria.postgresql.org; Wed, 01 Apr 2026 15:50:25 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1w7xpn-001DbZ-3D for pgsql-hackers@arkaria.postgresql.org; Wed, 01 Apr 2026 15:50:24 +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.96) (envelope-from ) id 1w7xp2-001AUU-1b for pgsql-hackers@lists.postgresql.org; Wed, 01 Apr 2026 15:49:37 +0000 Received: from fout-a2-smtp.messagingengine.com ([103.168.172.145]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.98.2) (envelope-from ) id 1w7xoy-000000002OT-3iNc for pgsql-hackers@postgresql.org; Wed, 01 Apr 2026 15:49:36 +0000 Received: from phl-compute-06.internal (phl-compute-06.internal [10.202.2.46]) by mailfout.phl.internal (Postfix) with ESMTP id 81B96EC025A; Wed, 1 Apr 2026 11:49:31 -0400 (EDT) Received: from phl-frontend-04 ([10.202.2.163]) by phl-compute-06.internal (MEProxy); Wed, 01 Apr 2026 11:49:31 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=anarazel.de; h= cc:cc:content-transfer-encoding:content-type:content-type:date :date:from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:subject:subject:to:to; s=fm2; t=1775058571; x=1775144971; bh=XUM2KWXxTD5+o1VI++2ti+d1DxOErc2AFyC4zZ64Pdk=; b= uHnFmlgNuyxlH1zdEYPPosy0yrh63PF6pnaeRRHe7v7+u0nTJf5uJR3qEyv16rO0 ZaDLv9CR+AUo/oZi2BbLA5aCf8jMRLov1nxm8At8Yqw2uWh4zNY73yZlgMqo3h9M au3DZmru/JeEbFfKmm6aK16AnnnFCXmrU0WJHcsKGUMB7m4KYYjYz2VkhVA+iAkI YXQIOj50/KXntV80JRR9MUgSEYvVHiD8Pnto/5AK82BpHPWkDQ4nq2IKh3zK3LnQ 9+2zVosS/rFwrkR2tyluFymHLKOv1v4JqJ8egaU0ANDVFhC7dip2792bmjKKgef3 RrGCUqGYBtJF/vrMYTZsOA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:content-type:date:date:feedback-id:feedback-id :from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:subject:subject:to:to:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm2; t=1775058571; x= 1775144971; bh=XUM2KWXxTD5+o1VI++2ti+d1DxOErc2AFyC4zZ64Pdk=; b=h mUSdYsPOCvqZHXqVxwYqjKolqoiEv+cOkHyQt5PxDI994LyhdT4lfubi5ilm8GiR DCkLmzTiTmWcZ+CGqlT5muBwfDzz45sHGbrgJwYKEX1ehn8DQvnsWBest6ZBRYUZ IHY0Fidin7lIKkbY3k8GockC7U9PSQAGMTe4aIifa7RsRaZh/4BdlG3XOKgmKChM 6EG30jU+pHNtqax/yj0IGMVFBSl/7OLvN7XVUUUyWEyqLhfjlqLDmgPxSy5O5off tHCAtNtwIp5MEyytOkiO8kqLSUkX4wjHECfda5Kw9sewwSLfaEnosWHfw9seSvBb zfDX4gVUtc4tYE1BfReCg== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeefhedrtddtgdefhedvucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfurfetoffkrfgpnffqhgenuceurghi lhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmnecujfgurh epfffhvfevuffkfhggtggugfgjsehtkefstddttdejnecuhfhrohhmpeetnhgurhgvshcu hfhrvghunhguuceorghnughrvghssegrnhgrrhgriigvlhdruggvqeenucggtffrrghtth gvrhhnpedtleelvdfgjedvffeiueekfeeuleffhfegfffhgfffkeevueehieehhfeigffh vdenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpegrnh gurhgvshesrghnrghrrgiivghlrdguvgdpnhgspghrtghpthhtohepiedpmhhouggvpehs mhhtphhouhhtpdhrtghpthhtohepphhgsegsohifthdrihgvpdhrtghpthhtohepthhvse hfuhiiiiihrdgtiidprhgtphhtthhopegshigrvhhuiiekudesghhmrghilhdrtghomhdp rhgtphhtthhopehmvghlrghnihgvphhlrghgvghmrghnsehgmhgrihhlrdgtohhmpdhrtg hpthhtohepthhhohhmrghsrdhmuhhnrhhosehgmhgrihhlrdgtohhmpdhrtghpthhtohep phhgshhqlhdqhhgrtghkvghrshesphhoshhtghhrvghsqhhlrdhorhhg X-ME-Proxy: Feedback-ID: id4a34324:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Wed, 1 Apr 2026 11:49:30 -0400 (EDT) Date: Wed, 1 Apr 2026 11:49:30 -0400 From: Andres Freund To: Melanie Plageman Cc: pgsql-hackers@postgresql.org, Thomas Munro , Peter Geoghegan , Tomas Vondra , Nazir Bilal Yavuz Subject: Re: AIO / read stream heuristics adjustments for index prefetching Message-ID: References: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Hi, On 2026-04-01 10:52:03 -0400, Melanie Plageman wrote: > On Tue, Mar 31, 2026 at 12:02 PM Andres Freund wrote: > > > > 0008: WIP: read stream: Split decision about look ahead for AIO and combining > > > > Until now read stream has used a single look-ahead distance to control > > lookahead for both IO combining and read-ahead. That's sub-optimal, as we > > want to do IO combining even when we don't need to do any readahead, as > > avoiding the syscall overhead is important to reduce CPU overhead when > > data is in the kernel page cache. > > > > This is a prototype for what it could look like to split those > > decisions. Thereby fixing the regression mentioned in 0006. > > I wonder if we need to keep the combine_limit member in the read > stream. Could we just use io_combine_limit without ramping up and > down? This is mainly for code complexity reasons. I thought so at first too, but it unfortunately leads to substantial regressions with index prefetching, due to reading ahead unnecessarily far in cases where we really just needed one block. > Perhaps to allow fast path reentry, we could use distance_decay_holdoff == 0 > and ios_in_progress == 0 instead of combine_distance == 0. Somewhat orthogonal: I really dislike the code to re-enter fastpath. I've now broken it a few times without noticing. Especially when using a lower distance, it's easy for the gating conditions to be fulfilled if read_stream_look_ahead() decided to not *yet* do look ahead, because there's still a pinned buffer and the distance is low. ISTM that it really should only be checked after we did a lookahead and found it to be a buffer hit. Greetings, Andres Freund