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 1s1W2Z-00CrHC-IN for pgsql-hackers@arkaria.postgresql.org; Mon, 29 Apr 2024 18:47:51 +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 1s1W2X-001QOA-4S for pgsql-hackers@arkaria.postgresql.org; Mon, 29 Apr 2024 18:47:50 +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 1s1W2W-001QO1-Or for pgsql-hackers@lists.postgresql.org; Mon, 29 Apr 2024 18:47:49 +0000 Received: from mail-lj1-x235.google.com ([2a00:1450:4864:20::235]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1s1W2T-000eDd-FY for pgsql-hackers@postgresql.org; Mon, 29 Apr 2024 18:47:48 +0000 Received: by mail-lj1-x235.google.com with SMTP id 38308e7fff4ca-2dd6a7ae2dcso77254481fa.1 for ; Mon, 29 Apr 2024 11:47:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1714416463; x=1715021263; darn=postgresql.org; h=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=0I9+7apgg2tECjXUYllLP6rAKenqslhG0tfP8BinPjY=; b=ieWLWWU7X7mSQ8vdQslxkYnrhbp9KhzkiBZF3t3ns/L4eC5QpEaFJksos0bS+qEjUY XLqRYwG0Qfdh8YURyAaHyAOOB6YiTFBCBaBlil/myvFn4R2cCQEK9XeaZ7edCcZQoRbK n/6/thdIRWk1G0RbUlL03n1gIGT48GwV642v8zV71KwcPaiigNwFuXoUWHs6/wWaACzl EJ+ZteMPOA2HquNItZjslFuWoh6ehMWQwKEg8JH86V6AO1dcJ7Ny8y5xvp9UJwhPLLdc W7rfToznlJUMz6fHB6Y/pAXM7WWXfHzMVXNy0uATeADHD6J5UHDJjpLz7BjrPeqFMU68 wutg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1714416463; x=1715021263; h=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=0I9+7apgg2tECjXUYllLP6rAKenqslhG0tfP8BinPjY=; b=D3ENHhShxvM5J5Cs2CPvW5ri7eAs1iMfaPiRSN9Gyi8yifEnMU5gHnP3aefp14J4Y4 iuffS2iF9LK/C1WvtxOAofFHmCGmJkguVEdHYzXAJznUbTeKaUQGJvurMbzyYxaCYqSm pdr82TQsvM0rsonOEP1IYz0jemlTw4Xc4llzV7GtQeDG/fGPAlk1ma9ljkJ+NtD3CQZH 6qZVWRJtm4UiTVHzIbw0v6jwQ3RF7Q28OcZypQxlDwvte3ZzWcaZZi0cpGIHCv9jeaQL gBARmEhJ08IKY8rdMKdIOriVlATWSKg3Jtcn3yYb2wLGrvdeJ7QAOEFHIcf30q81KJhR Rsig== X-Forwarded-Encrypted: i=1; AJvYcCWIoysjNGNPn/vOM8hfFtWqzcZWINikLDVp2LioK2eR2yIKkguZYdasKrIToVIaAQdzYWzL8Q3zMje9P/1h7nQXLkUsDny/O4QWEo4A X-Gm-Message-State: AOJu0YyF2g3Sef+eU5MPSFZaEGHdgarmrhotwjayo19t3Fi4EtOtK4qS lp1Y6otdvLMPPQwPQXBLhtYSQhka4w1CG9WgUO40uw0W0tF/DE1SfpgVAlbeNTmqvw== X-Google-Smtp-Source: AGHT+IHHE8CXABO2ANigq82hsYWeNBVEcnGeJ6daBTWEb/ou5Fhlc/GQjKbGpJq6XeEGWpP9cNiDbQ== X-Received: by 2002:a2e:8793:0:b0:2df:c395:4482 with SMTP id n19-20020a2e8793000000b002dfc3954482mr6183624lji.32.1714416462651; Mon, 29 Apr 2024 11:47:42 -0700 (PDT) Received: from [192.168.0.18] (5cfcb9a1.dynamic.mv.ru. [92.252.185.161]) by smtp.gmail.com with ESMTPSA id j25-20020a2e6e19000000b002dd7615e1f7sm2650145ljc.95.2024.04.29.11.47.41 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 29 Apr 2024 11:47:42 -0700 (PDT) Content-Type: multipart/alternative; boundary="------------qXiBUNN3eSAeS2dDZcafQVSJ" Message-ID: <7f4f2ef7-460a-4395-bd58-eca4fca7c4c9@gmail.com> Date: Mon, 29 Apr 2024 21:47:41 +0300 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: Extension Enhancement: Buffer Invalidation in pg_buffercache From: Maksim Milyutin To: Thomas Munro , Maxim Orlov Cc: vignesh C , Palak Chaturvedi , Jim Nasby , pgsql-hackers@postgresql.org, Nitin Jadhav References: <8b8c709a-c7cc-4965-8296-64f549c27501@abcsql.com> <3510716d-d3f3-40c8-9f7f-d644171acfb6@gmail.com> Content-Language: en-US In-Reply-To: List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk This is a multi-part message in MIME format. --------------qXiBUNN3eSAeS2dDZcafQVSJ Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit On 14.04.2024 21:16, Maksim Milyutin wrote: > On 07.04.2024 02:07, Thomas Munro wrote: > >> So this is the version I plan to commit. >> >> +bool >> +EvictUnpinnedBuffer(Buffer buf) >> +{ >> ... >> + /* This will return false if it becomes dirty or someone else pins it. */ >> + result = InvalidateVictimBuffer(desc); >> + >> + UnpinBuffer(desc); >> + >> + return result; >> +} > > > Hi, Thomas! > > Should not we call at the end the StrategyFreeBuffer() function to add > target buffer to freelist and not miss it after invalidation? > Hello everyone! Please take a look at this issue, current implementation of EvictUnpinnedBuffer() IMO is erroneous - evicted buffers are lost permanently and will not be reused again -- Best regards, Maksim Milyutin --------------qXiBUNN3eSAeS2dDZcafQVSJ Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: 7bit

On 14.04.2024 21:16, Maksim Milyutin wrote:

On 07.04.2024 02:07, Thomas Munro wrote:

So this is the version I plan to commit.

+bool
+EvictUnpinnedBuffer(Buffer buf)
+{
...
+    /* This will return false if it becomes dirty or someone else pins it. */
+    result = InvalidateVictimBuffer(desc);
+
+    UnpinBuffer(desc);
+
+    return result;
+}


Hi, Thomas!

Should not we call at the end the StrategyFreeBuffer() function to add target buffer to freelist and not miss it after invalidation?


Hello everyone!

Please take a look at this issue, current implementation of EvictUnpinnedBuffer() IMO is erroneous - evicted buffers are lost permanently and will not be reused again

-- 
Best regards,
Maksim Milyutin
--------------qXiBUNN3eSAeS2dDZcafQVSJ--