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 1umDR0-00BlhG-Jp for pgsql-hackers@arkaria.postgresql.org; Wed, 13 Aug 2025 15:30: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 1umDQy-00GIja-Oz for pgsql-hackers@arkaria.postgresql.org; Wed, 13 Aug 2025 15:30: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 1umDOx-00GAck-BL for pgsql-hackers@lists.postgresql.org; Wed, 13 Aug 2025 15:28:31 +0000 Received: from fhigh-a1-smtp.messagingengine.com ([103.168.172.152]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1umDOu-000Yh6-1Q for pgsql-hackers@lists.postgresql.org; Wed, 13 Aug 2025 15:28:31 +0000 Received: from phl-compute-05.internal (phl-compute-05.internal [10.202.2.45]) by mailfhigh.phl.internal (Postfix) with ESMTP id D53061400169; Wed, 13 Aug 2025 11:28:26 -0400 (EDT) Received: from phl-mailfrontend-02 ([10.202.2.163]) by phl-compute-05.internal (MEProxy); Wed, 13 Aug 2025 11:28:26 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=anarazel.de; h= cc:cc: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=fm3; t=1755098906; x=1755185306; bh=Azn4vtpZoO qheXN4fuS1r1H7e5SUmazZXKn406ZoL7o=; b=ZaZW1paLb0j2kbeeq6Ib3s5fR/ T3AChAaQvW5eCw53BOwLhKZ38e8r3h8HJMJKFx5gmuEyp/GKPMY10eDE7wffZO8r BMQSnFRC9/w4aHzaxz9Ps0O2DK57qZg0Xh62WRs0fV1JGFLT5Rq/+/ZdBuiZl3aF hrfJlSZVoD7hC2nyZ5GfSV0GtUyKxYiLW4a1tm/x4YlHnQgxkX4TYwYtmDkr0DdG 9sGnEavV7WEtfSCnpewF2wqCktAiRN/YAgx3XRaRxnnxxRnKcuQ0TNIwCaUTBFC/ FJYAlRzX6jZFxc0rVBchgyql7NYZZ/g4I6FgmeHREuU3Q10kLxD5v13Xbd+Q== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc: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=fm3; t= 1755098906; x=1755185306; bh=Azn4vtpZoOqheXN4fuS1r1H7e5SUmazZXKn 406ZoL7o=; b=L6uXzWRBNB35YtEF8/SdWX9OKWjN/VHtePSn5n+xZ1F8UT32kxI iFl57FiFC+TDullvA+Nt1vvVN/W7157cx6VLg5uqYnpQnuMNOk161NlfTxW9w1tQ LOjWD6zLNH0WNqF1toewP9bRS/yj7v8KwzNBJXH3HUBUYJG07CaFHKdOoT/3sCs0 Dm36MPlSRo5ZWIdxjrq1Kei4nR/kReMexTEcqHYNRgVmVIVIEwIvLROzpEiuOZkp r5gaIcknanURWh0Ri6xEhNt7hgjDhPy7bDbnq8d2pTQAD/xt71agcpn7Wuyr2BuS kccRov+iEm9q+enRcL8uB/PgxTBuySjZfbQ== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeffedrtdefgddufeekheejucetufdoteggodetrf dotffvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfurfetoffkrfgpnffqhgenuceu rghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmnecujf gurhepfffhvfevuffkfhggtggujgesthdtsfdttddtvdenucfhrhhomheptehnughrvghs ucfhrhgvuhhnugcuoegrnhgurhgvshesrghnrghrrgiivghlrdguvgeqnecuggftrfgrth htvghrnhepfeffgfelvdffgedtveelgfdtgefghfdvkefggeetieevjeekteduleevjefh ueegnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomheprg hnughrvghssegrnhgrrhgriigvlhdruggvpdhnsggprhgtphhtthhopedutddpmhhouggv pehsmhhtphhouhhtpdhrtghpthhtohepphhgsegsohifthdrihgvpdhrtghpthhtohepkh hnihiihhhnihhksehgrghrrhgvthdrrhhupdhrtghpthhtohepsgihrghvuhiikedusehg mhgrihhlrdgtohhmpdhrtghpthhtohepughilhhiphgsrghlrghuthesghhmrghilhdrtg homhdprhgtphhtthhopehmvghlrghnihgvphhlrghgvghmrghnsehgmhgrihhlrdgtohhm pdhrtghpthhtoheprhhosggvrhhtmhhhrggrshesghhmrghilhdrtghomhdprhgtphhtth hopehthhhomhgrshdrmhhunhhrohesghhmrghilhdrtghomhdprhgtphhtthhopehpghhs qhhlqdhhrggtkhgvrhhssehlihhsthhsrdhpohhsthhgrhgvshhqlhdrohhrghdprhgtph htthhopehgkhhokhholhgrthhoshesphhrohhtohhnmhgrihhlrdgtohhm X-ME-Proxy: Feedback-ID: id4a34324:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Wed, 13 Aug 2025 11:28:26 -0400 (EDT) Date: Wed, 13 Aug 2025 10:44:33 -0400 From: Andres Freund To: Tomas Vondra Cc: Peter Geoghegan , Thomas Munro , Nazir Bilal Yavuz , Robert Haas , Melanie Plageman , PostgreSQL Hackers , Georgios , Konstantin Knizhnik , Dilip Kumar Subject: Re: index prefetching Message-ID: References: <51b5f71b-5f19-4453-91ff-2b9f2a840c58@vondra.me> <6cb6109d-71d6-490c-8056-d8885081b008@vondra.me> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <6cb6109d-71d6-490c-8056-d8885081b008@vondra.me> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Hi, On 2025-08-13 14:15:37 +0200, Tomas Vondra wrote: > In fact, I believe this is about io_method. I initially didn't see the > difference you described, and then I realized I set io_method=sync to > make it easier to track the block access. And if I change io_method to > worker, I get different stats, that also change between runs. > > With "sync" I always get this (after a restart): > > Buffers: shared hit=7435 read=52801 > > while with "worker" I get this: > > Buffers: shared hit=4879 read=52801 > Buffers: shared hit=5151 read=52801 > Buffers: shared hit=4978 read=52801 > > So not only it changes run to tun, it also does not add up to 60236. This is reproducible on master? If so, how? > I vaguely recall I ran into this some time ago during AIO benchmarking, > and IIRC it's due to how StartReadBuffersImpl() may behave differently > depending on I/O started earlier. It only calls PinBufferForBlock() in > some cases, and PinBufferForBlock() is what updates the hits. Hm, I don't immediately see an issue there. The only case we don't call PinBufferForBlock() is if we already have pinned the relevant buffer in a prior call to StartReadBuffersImpl(). If this happens only with the prefetching patch applied, is is possible that what happens here is that we occasionally re-request buffers that already in the process of being read in? That would only happen with a read stream and io_method != sync (since with sync we won't read ahead). If we have to start reading in a buffer that's already undergoing IO we wait for the IO to complete and count that access as a hit: /* * Check if we can start IO on the first to-be-read buffer. * * If an I/O is already in progress in another backend, we want to wait * for the outcome: either done, or something went wrong and we will * retry. */ if (!ReadBuffersCanStartIO(buffers[nblocks_done], false)) { ... /* * Report and track this as a 'hit' for this backend, even though it * must have started out as a miss in PinBufferForBlock(). The other * backend will track this as a 'read'. */ ... if (persistence == RELPERSISTENCE_TEMP) pgBufferUsage.local_blks_hit += 1; else pgBufferUsage.shared_blks_hit += 1; ... Greetings, Andres Freund