Thread: Increase of buffers usage count by bgwriter

Increase of buffers usage count by bgwriter

From
ITAGAKI Takahiro
Date:
Hi Hackers,

I found that bgwriter increments usage count of buffers when it writes
the buffers. I feel this behavior is strange, because the behavior of
bgwriter will affect buffer management strategy.
When backends write LRU dirty buffers, they are replaced immediately.
However, when bgwriter writes dirty buffer, the replacement is postponed
until the next rotation of CLOCK.


If the behavior is not intended, another UnpinBuffer that doesn't
increase the buffers usage count will be needed.
Otherwise, bgwriter should do behavior that looks like VACUUM, 
using StrategyHintVacuum(true).


I'll appreciate any comments.
Thanks,
---
ITAGAKI Takahiro
NTT Cyber Space Laboratories



Re: Increase of buffers usage count by bgwriter

From
Tom Lane
Date:
ITAGAKI Takahiro <itagaki.takahiro@lab.ntt.co.jp> writes:
> I found that bgwriter increments usage count of buffers when it writes
> the buffers. I feel this behavior is strange, because the behavior of
> bgwriter will affect buffer management strategy.

Good point --- we probably don't want it to do that.

> If the behavior is not intended, another UnpinBuffer that doesn't
> increase the buffers usage count will be needed.
> Otherwise, bgwriter should do behavior that looks like VACUUM, 
> using StrategyHintVacuum(true).

I think it might be sufficient to not increment usage_count when
UnpinBuffer's "trashOK" parameter is false --- that's what
SyncOneBuffer passes, so it'd fix the issue for bgwriter activity,
and arguably all the other call sites that pass false also don't
want the count to increment.

(Probably need a different name for trashOK ...)

Comments?
        regards, tom lane


Re: Increase of buffers usage count by bgwriter

From
Tom Lane
Date:
I wrote:
> ITAGAKI Takahiro <itagaki.takahiro@lab.ntt.co.jp> writes:
>> I found that bgwriter increments usage count of buffers when it writes
>> the buffers. I feel this behavior is strange, because the behavior of
>> bgwriter will affect buffer management strategy.

> I think it might be sufficient to not increment usage_count when
> UnpinBuffer's "trashOK" parameter is false --- that's what
> SyncOneBuffer passes, so it'd fix the issue for bgwriter activity,
> and arguably all the other call sites that pass false also don't
> want the count to increment.

I've committed a change along this line.  Thanks for the suggestion!
        regards, tom lane