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 1tODLH-004sT5-NB for pgsql-hackers@arkaria.postgresql.org; Thu, 19 Dec 2024 10:01:16 +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 1tODLH-00AVKk-2S for pgsql-hackers@arkaria.postgresql.org; Thu, 19 Dec 2024 10:01:14 +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 1tODLG-00AVCK-Iv for pgsql-hackers@lists.postgresql.org; Thu, 19 Dec 2024 10:01:14 +0000 Received: from mail.postgrespro.ru ([93.174.131.139]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1tODLB-000Yxj-OV for pgsql-hackers@lists.postgresql.org; Thu, 19 Dec 2024 10:01:13 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=postgrespro.ru; s=mx2023; t=1734602468; bh=KpjfaSgq6wE3ywhdROVADEuBDPBaJM8tIRSWwUfNLSI=; h=Message-ID:Date:User-Agent:Subject:To:Cc:References:From: In-Reply-To:From; b=vxZ7Z6/CiZt8jSJlzGMnwSPjgi6dYRnIAomuCWnl1SAJ4ZDNJbI5ob2tcVv6CMeM1 nGHgCIcl0ZocHr4Ni7WxbnpG0NLa2lNxbYo4ZR5zc9/SJ3qI22Zs7dcc3b+I439DXg FZTnJMXgEYnb6lWgA7XM3R2TTQouThO/whJHK0FP9Jild/s6WGJBpqDtyWBtFxXL6z cQ+Fc5G04kQK2Zu/BTcvlBjT6QSzMuH6MpTPBMs/B9TsdUOcAzbQBBUbyavLH2l/k7 /IBm3x2gNL1fAILtmXXyLTnOufdzhfsd+Ksvzyx8l+g1ECXqles4YusNNRZ66pWbA9 pQMfF9h+a2t6A== Received: from [172.30.49.34] (unknown [172.30.49.34]) (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) (Client did not present a certificate) (Authenticated sender: y.sokolov@postgrespro.ru) by mail.postgrespro.ru (Postfix/465) with ESMTPSA id 0B0E06026B; Thu, 19 Dec 2024 13:01:07 +0300 (MSK) Message-ID: Date: Thu, 19 Dec 2024 13:01:07 +0300 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: Fix bank selection logic in SLRU To: Dilip Kumar , "Andrey M. Borodin" Cc: "pgsql-hackers@lists.postgresql.org" , Alvaro Herrera References: <9444dc46-ca47-43ed-9058-89c456316306@postgrespro.ru> <4009750D-3EAE-4375-A7A8-3AD9922CDE1F@yandex-team.ru> Content-Language: en-US From: Yura Sokolov In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-KSMG-AntiPhishing: NotDetected, bases: 2024/12/19 08:33:00 X-KSMG-AntiSpam-Interceptor-Info: not scanned X-KSMG-AntiSpam-Status: not scanned, disabled by settings X-KSMG-AntiVirus: Kaspersky Secure Mail Gateway, version 2.1.0.7854, bases: 2024/12/19 06:47:00 #26889573 X-KSMG-AntiVirus-Status: NotDetected, skipped X-KSMG-LinksScanning: not scanned, disabled by settings X-KSMG-Message-Action: skipped X-KSMG-Rule-ID: 1 List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk 10.12.2024 17:07, Dilip Kumar wrote: > On Tue, 10 Dec 2024 at 6:32 PM, Andrey M. Borodin > wrote: > > > > > On 10 Dec 2024, at 15:39, Yura Sokolov > wrote: > > > > It is not critical bug, since it doesn't hurt correctness just > performance. In worst case only one bank will be used. > > Ugh... yeah. IMO the problem is that we do not have protection that > rejects values that are not power of 2. > If other values given system operates as if there are > 2^(popcount(n)-1) banks. So if we just round down value to nearest > power of 2 - we will help incorrectly configured systems to use > proper amount of memory and keep performance of properly configured > systems. > > > +1 > > > > IMO doing modulo is not necessary. And hash function is pure waste > of CPU cycles. > > > I agree I did some measurement "divide-modulo" vs "modulo using multiplication by reciprocal" vs "simple binary and" using simple C program [0]. (Note: loop is made to be dependent on previous iteration result so no parallel computation happens). Results on Ryzen 7 5825U: $ time ./div 100000000 15 3 # binary and real 0m0,943s $ time ./div 100000000 15 1 # multiply by reciprocal real 0m3,123s $ time ./div 100000000 15 0 # just plain `%` real 0m4,540s It means: - `&` takes 0.69ns - `mult-rec` takes 2.94ns - `%` takes 3.24ns. I believe, compared to further memory accesses it could be count as negligible. (Certainly, it could be worse on some older processors. But I still doubt it will be measurably worse on top of all other things SLRU does.) [0] https://gist.github.com/funny-falcon/173923b4fea7ffdf9e02595a0f99aa74 Regards, Yura Sokolov aka funny-falcon