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 1rmBGC-006Vqm-Kl for pgsql-hackers@arkaria.postgresql.org; Mon, 18 Mar 2024 11:34:33 +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 1rmBGA-000kFX-Ci for pgsql-hackers@arkaria.postgresql.org; Mon, 18 Mar 2024 11:34:30 +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 1rmBGA-000kFP-2V for pgsql-hackers@lists.postgresql.org; Mon, 18 Mar 2024 11:34:30 +0000 Received: from mail-lf1-x12a.google.com ([2a00:1450:4864:20::12a]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1rmBG6-005Aml-Jq for pgsql-hackers@postgresql.org; Mon, 18 Mar 2024 11:34:29 +0000 Received: by mail-lf1-x12a.google.com with SMTP id 2adb3069b0e04-5101cd91017so6868149e87.2 for ; Mon, 18 Mar 2024 04:34:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=enterprisedb.com; s=google; t=1710761664; x=1711366464; darn=postgresql.org; h=content-transfer-encoding:in-reply-to:content-language:references :cc:to:from:subject:user-agent:mime-version:date:message-id:from:to :cc:subject:date:message-id:reply-to; bh=+JOFidPlCXUrDiBY/6o57Tid1tHO7gQkEsrvsTrk4MI=; b=ecfX3fDT55jvi1hu8v96z6klYfsUCQaI7SiHe51b5WskKDIHdCdnnpx17vpbGz4WaF N4vkBuRdE3jf3PJ9U/VKK9B0kYcsS5rf7biPHjawfXUB+6aUZzYsDc3pOP1nubgAzivu Xy+ukO8jXBV0furCnbcWS6AEdhclFmvREujZ1HpUbN7+xKzqBPB18F5cps7WM9wkdokD mqhaacOs6ZnjLLewU7AfEbytspqB3r6Onmcl2XeNz0sYsj1VGxnCqCAgGUKRERYKfts6 YaNAn5LXaLkZY3Ruw9Ct60iaFy37Aj7ZGehc/EOGio85Q2oQswAp/5EZ5cu1blfI6jBU hLLQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1710761664; x=1711366464; h=content-transfer-encoding:in-reply-to:content-language:references :cc:to:from:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=+JOFidPlCXUrDiBY/6o57Tid1tHO7gQkEsrvsTrk4MI=; b=gtxnU8dp68X/w/YyR48F0/nQEkp40Roxq90rssMCgO6VZxTM8BLKBurvzSDjmCRSc4 fEqAJKws5VBs/Q5RsGF3NWzzHWad1ioYC8PHkwKT5J8qeK5MINjGeOhyNT64VA2Bo4+k ydFUq+bgLLtTYucm3f5TgxSr6aOia77/Oe5koqzYDn0KJ+rS40zMzketZYrGMtAHQ5AV HRQt36ITU1y/o9kvCclvvEZ1S/vvDaBuOm7wfwtUyKU/LEnIqn4PC2cHO9wgrFNgVMFY uq2F3Z9FdmIngqdZQlpLATF85OKfIhIpLSCmXX5PCNU0P1CRnu6OywJYNtpbSR5EUfl5 TDiQ== X-Forwarded-Encrypted: i=1; AJvYcCWFo/ANFgX5xvSrlvbYGlRnmdvpCqN4uExqbwMK3bNYPUUyYOb9syt8jEDOAY1ji2xAgViAVgKYqoATwvaGO+1RUZRkstrxXUVyPF9N X-Gm-Message-State: AOJu0YzRWu1Gv1ZRPX80JGhLPiDbpAZV6369dKImRpOGpnjsErOy02CF hHG+3xbSflfZ4ueE/DSbphbIPIBk6rTbWQ6DFa7H5r5PsAny5cJIpwYx47Fyng== X-Google-Smtp-Source: AGHT+IFXZLWP5Gpg+L7W5hlQ5haOedMiS7+VfN51tWJeaj/iW5nfyPsdkLZHVwvECrrnv6g2CoeS2g== X-Received: by 2002:ac2:4652:0:b0:513:d8b4:90be with SMTP id s18-20020ac24652000000b00513d8b490bemr6796424lfo.24.1710761663881; Mon, 18 Mar 2024 04:34:23 -0700 (PDT) Received: from [10.137.0.18] (ip-86-49-229-30.bb.vodafone.cz. [86.49.229.30]) by smtp.gmail.com with ESMTPSA id hg13-20020a05600c538d00b004140b6625dcsm5221356wmb.13.2024.03.18.04.34.23 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 18 Mar 2024 04:34:23 -0700 (PDT) Message-ID: <059b1665-38aa-450f-a7a0-0bdd37104069@enterprisedb.com> Date: Mon, 18 Mar 2024 12:34:23 +0100 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: BitmapHeapScan streaming read user and prelim refactoring From: Tomas Vondra To: Andres Freund Cc: Melanie Plageman , Heikki Linnakangas , Dilip Kumar , Robert Haas , Nazir Bilal Yavuz , Pg Hackers , Thomas Munro References: <20240314181625.a7uigo5ujaogfd6x@liskov> <2ed1e06b-feae-4c61-9f58-3fcc358104c7@enterprisedb.com> <20240315211449.en2jcmdqxv5o6tlz@alap3.anarazel.de> <20240316191226.b3c2vodhs23ibom4@alap3.anarazel.de> <20240317163809.2y6h7btfuo76r4z7@alap3.anarazel.de> <1d9902c0-43b9-4ae7-8c19-70bab3802bd1@enterprisedb.com> Content-Language: en-US In-Reply-To: <1d9902c0-43b9-4ae7-8c19-70bab3802bd1@enterprisedb.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On 3/17/24 20:36, Tomas Vondra wrote: > > ... > >> Besides a lot of other things, I finally added debugging fprintfs printing the >> pid, (prefetch, read), block number. Even looking at tiny excerpts of the >> large amount of output that generates shows that two iterators were out of >> sync. >> > > Thanks. I did experiment with fprintf, but it's quite cumbersome, so I > was hoping you came up with some smart way to trace this king of stuff. > For example I was wondering if ebpf would be a more convenient way. > FWIW I just realized why I failed to identify this "late prefetch" issue during my investigation. I was experimenting with instrumenting this by adding a LD_PRELOAD library, logging all pread/fadvise calls. But the FilePrefetch call is skipped in the page is already in shared buffers, so this case "disappeared" during processing which matched the two calls by doing an "inner join". That being said, I think tracing this using LD_PRELOAD or perf may be more convenient way to see what's happening. For example I ended up doing this: perf record -a -e syscalls:sys_enter_fadvise64 \ -e syscalls:sys_exit_fadvise64 \ -e syscalls:sys_enter_pread64 \ -e syscalls:sys_exit_pread64 perf script -ns Alternatively, perf-trace can be used and prints the filename too (but time has ms resolution only). Processing this seems comparable to the fprintf approach. It still has the issue that some of the fadvise calls may be absent if the prefetch iterator gets too far behind, but I think that can be detected / measured by simply counting the fadvise calls, and comparing them to pread calls. We expect these to be about the same, so (#pread - #fadvise) / #fadvise is a measure of how many were "late" and skipped. It also seems better than fprintf because it traces the actual syscalls, not just calls to glibc wrappers. For example I saw this postgres 54769 [001] 33768.771524828: syscalls:sys_enter_pread64: ..., pos: 0x30d04000 postgres 54769 [001] 33768.771526867: syscalls:sys_exit_pread64: 0x2000 postgres 54820 [000] 33768.771527473: syscalls:sys_enter_fadvise64: ..., offset: 0x30d04000, ... postgres 54820 [000] 33768.771528320: syscalls:sys_exit_fadvise64: 0x0 which is clearly a case where we issue fadvise after pread of the same block already completed. regards -- Tomas Vondra EnterpriseDB: http://www.enterprisedb.com The Enterprise PostgreSQL Company