From: | Andres Freund <andres(at)anarazel(dot)de> |
---|---|
To: | 斯波隼斗 <shibahayaton(at)gmail(dot)com> |
Cc: | pgsql-hackers(at)lists(dot)postgresql(dot)org |
Subject: | Re: can while loop in ClockSweepTick function be kind of infinite loop in some cases? |
Date: | 2023-01-10 17:39:46 |
Message-ID: | 20230110173946.33r7jzxy6geu5qvt@awork3.anarazel.de |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-hackers |
Hi,
On 2023-01-11 01:25:06 +0900, 斯波隼斗 wrote:
> This question is about ClockSweepTick function and the code is below.
> https://github.com/postgres/postgres/blob/24d2b2680a8d0e01b30ce8a41c4eb3b47aca5031/src/backend/storage/buffer/freelist.c#L146-L165
>
> The value of expected, NBuffers, wrapped variable is fixed in the while
> loop, so that when the value of expected variable is not equal to
> StrategyControl->nextVictimBuffer, CAS operation fails and the while loop
> will be run kind-of infinitely.
> It is possible for this problem to occur when ClockSweepTick function is
> concurrently called and nextVictimBuffer is incremented by other process
> before CAS operation in the loop (ex: in this case, the value of expected
> variable is NBuffers+1 while the value of nextVictimBuffer variable is
> NBuffers+2. so CAS operation fails)
> I think. `expected = originalVictim + 1;` line should be in while loop
> (before acquiring spin lock) so that, even in the case above, expected
> variable is incremented for each loop and CAS operation will be successful
> at some point.
> Is my understanding correct? If so, I will send PR for fixing this issue.
Yes, I think your understanding might be correct. Interesting that this
apparently has never occurred.
Yes, please send a patch.
Thanks,
Andres
From | Date | Subject | |
---|---|---|---|
Next Message | Aleksander Alekseev | 2023-01-10 17:42:31 | Re: Add 64-bit XIDs into PostgreSQL 15 |
Previous Message | Mark Dilger | 2023-01-10 17:26:53 | Re: Transparent column encryption |