Re: can while loop in ClockSweepTick function be kind of infinite loop in some cases?

2023-01-11 Thread 斯波隼斗
Hi, Thank you for your quick reply I misunderstood the logic of pg_atomic_compare_exchange_u32, so the loop cannot be infinite. > I wonder if we should make ->nextVictimBuffer a 64bit atomic. At the time the changes went in we didn't (or rather, couldn't) rely on it, but these days we could. I

Re: can while loop in ClockSweepTick function be kind of infinite loop in some cases?

2023-01-10 Thread Andres Freund
Hi, On 2023-01-10 13:11:35 -0500, Robert Haas wrote: > On Tue, Jan 10, 2023 at 12:40 PM Andres Freund wrote: > > > 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

Re: can while loop in ClockSweepTick function be kind of infinite loop in some cases?

2023-01-10 Thread Robert Haas
On Tue, Jan 10, 2023 at 12:40 PM Andres Freund wrote: > > 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

Re: can while loop in ClockSweepTick function be kind of infinite loop in some cases?

2023-01-10 Thread Andres Freund
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

can while loop in ClockSweepTick function be kind of infinite loop in some cases?

2023-01-10 Thread 斯波隼斗
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