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 1t67dF-00An3s-EO for pgsql-hackers@arkaria.postgresql.org; Wed, 30 Oct 2024 12:17:01 +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 1t67dD-008P4s-ND for pgsql-hackers@arkaria.postgresql.org; Wed, 30 Oct 2024 12:17:00 +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 1t67dD-008P4k-DR for pgsql-hackers@lists.postgresql.org; Wed, 30 Oct 2024 12:16:59 +0000 Received: from lahtoruutu.iki.fi ([2a0b:5c81:1c1::37]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1t67dA-003cMI-J7 for pgsql-hackers@postgresql.org; Wed, 30 Oct 2024 12:16:58 +0000 Received: from [192.168.1.110] (dsl-hkibng22-50ddb7-241.dhcp.inet.fi [80.221.183.241]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: hlinnaka) by lahtoruutu.iki.fi (Postfix) with ESMTPSA id 4XdmMR3b51z49Q3N; Wed, 30 Oct 2024 14:16:51 +0200 (EET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=iki.fi; s=lahtoruutu; t=1730290611; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=2lzrzPMGTd4d6rOlFFo784e9ojDzbpJCWzl7qnVfxHg=; b=Eg8wphlI5SdvD1s4YD91sBn1JUc7akCJTuReWsJBHPTaJuNwCsIa1PckczefYRvRrtAoTI jCGjIY+1Z8uWqtS6vo2nbOlhwKsbqu3lJYNbIbxvgID/h4kx7AEtqz8EIFRPYW9GN5VgeI t1zVMThfla26VAJsnQ5++E4lsnzKRvOI3f9+8KNHng5XtcTZPNUSjOVXFk9DeZhgXE3JYJ q8YJqvo/DysN0btdMDRnO2x5zazA9fGkXDx++2nI+JNAQv9QQs9eaRyeNGaMoiCzxFuLdS XByPWta0Ma408yhe34NDH2yNODdWeOGGoInd7Ennm67bgMlVw3dt/TvN13lpUQ== ARC-Seal: i=1; s=lahtoruutu; d=iki.fi; t=1730290611; a=rsa-sha256; cv=none; b=HA83sYlybqYLNyPOKjoVgBpFqNDSFxbv4ryOFKFpP2+StzBGkZD0khVTZS5MJabuOsp7x6 Mtjk0bSlL4L8MyUrzz4LwilEkX6FNbAZz+87HqwwoPuJfOYFIaWSXHg7sXMf4nhsoWNoyy uMFpWQfJzdTvBmHFh2OQEZWfn0fm+sK2jRU9SAIqC7aBSNDxrk34lIAgh33gzDfWeU7iDU ldo5oNaNYqMkeJd176V6ZIvJqPheWXzInf/4h3V/lMbA1ShNgJKwoP89beaG1BkPW43Zwp xkfcXbLxSLPRdwt7dTNCR/x4XZZemgfgIgsFiqcUXSb3IU/YB/71VODKSNgj3w== ARC-Authentication-Results: i=1; ORIGINATING; auth=pass smtp.auth=hlinnaka smtp.mailfrom=hlinnaka@iki.fi ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=iki.fi; s=lahtoruutu; t=1730290611; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=2lzrzPMGTd4d6rOlFFo784e9ojDzbpJCWzl7qnVfxHg=; b=nmJXvBsRYMPkAW2kvVndOgT54M0s6jpBRJVX8DRigpEZChTCET6BnNCnetWRk+4oMpSixT fj9WZMMFXPHn+pCWK6ua8hcXMfQ26tokIIOKo25U5kHidYt7zrtEixFLr3Uwg++x/4tSyX nG27/rEoRJTeLjM+CePwKg3EiQqntgBEnKZpT3tgI5m3J+mx0GUJHHN2lzUmXp5HiOlF+g 8X95DKQWaV5kvtYgyi2FI8qKfHFdv96ZFQhk1m95F8wxKhou4H76TogUMIFB5zXC+jGTd0 nn+Keh8eKwUI44XYpXOFHDdCinU00gf9qeffREsz/Y+iSzoUcCPTLGZdX9i+Gw== Message-ID: Date: Wed, 30 Oct 2024 14:16:51 +0200 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: AIO writes vs hint bits vs checksums To: Andres Freund , pgsql-hackers@postgresql.org Cc: Noah Misch , Robert Haas , Thomas Munro References: Content-Language: en-US From: Heikki Linnakangas In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On 24/09/2024 18:55, Andres Freund wrote: > What I'd instead like to propose is to implement the right to set hint bits as > a bit in each buffer's state, similar to BM_IO_IN_PROGRESS. Tentatively I > named this BM_SETTING_HINTS. It's only allowed to set BM_SETTING_HINTS when > BM_IO_IN_PROGRESS isn't already set and StartBufferIO has to wait for > BM_SETTING_HINTS to be unset to start IO. > > Naively implementing this, by acquiring and releasing the permission to set > hint bits in SetHintBits() unfortunately leads to a significant performance > regression. While the performance is unaffected for OLTPish workloads like > pgbench (both read and write), sequential scans of unhinted tables regress > significantly, due to the per-tuple lock acquisition this would imply. It'd be nice to implement this without having to set and clear BM_SETTING_HINTS every time. Could we put the overhead on the FlushBuffer() instead? How about something like this: To set hint bits: 1. Lock page in SHARED mode. 2. Read BM_IO_IN_PROGRESS 3. If !BM_IO_IN_PROGRESS, set hint bits, otherwise don't 4. Unlock page To flush a buffer: 1. Lock page in SHARED mode 2. Set BM_IO_IN_PROGRESS 3. Read the lock count on the buffer lock, to see if we're the only locker. 4. If anyone else is holding the lock, upgrade it to exclusive mode, and immediately downgrade back to share mode. 5. calculate CRC, flush the buffer 6. Clear BM_IO_IN_PROGRESS and unlock page. This goes back to the idea of adding LWLock support for this, but the amount of changes could be pretty small. The missing operation we don't have today is reading the share-lock count on the lock in step 3. That seems simple to add. Acquiring the exclusive lock in step 4 is just a way to wait for all the existing share-lockers to release the lock. You wouldn't need to block new share-lockers. We have LW_WAIT_UNTIL_FREE, which is almost what we need, but it currently ignores share-lockers. So doing this "properly" would require more changes to LWLocks. Briefly acquiring an exclusive lock seems acceptable though. > But: We can address this and improve performance over the status quo! Today we > determine tuple visiblity determination one-by-one, even when checking the > visibility of an entire page worth of tuples. Yes, batching the visibility checks makes sense in any case. -- Heikki Linnakangas Neon (https://neon.tech)