Re: Page replacement algorithm in buffer cache

From: Amit Kapila <amit(dot)kapila(at)huawei(dot)com>
To: "'Atri Sharma'" <atri(dot)jiit(at)gmail(dot)com>
Cc: "'Pg Hackers'" <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Page replacement algorithm in buffer cache
Date: 2013-03-22 10:33:39
Message-ID: 007801ce26e8$b86e0810$294a1830$@kapila@huawei.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Friday, March 22, 2013 12:00 PM Atri Sharma wrote:
>
>
> Sent from my iPad
>
> On 22-Mar-2013, at 11:28, Amit Kapila <amit(dot)kapila(at)huawei(dot)com> wrote:
>
> > On Friday, March 22, 2013 10:22 AM Atri Sharma wrote:
> >> Hello all,
> >>
> >> Sorry if this is a naive question.
> >>
> >> I was going through Greg Smith's slides on buffer
> >>
> cache(http://www.westnet.com/~gsmith/content/postgresql/InsideBufferCac
> >> he.pdf).
> >> When going through the page replacement algorithm that we use i.e.
> >> clocksweep algorithm, I felt a potential problem in our current
> >> system.
> >>
> >> Specifically, when a new entry is allocated in the buffer, it's
> >> USAGE_COUNT is set to 1. On each sweep of the algorithm, the
> >> USAGE_COUNT is decremented and an entry whose USAGE_COUNT becomes
> >> zero is replaced.
> >
> > Yes, it is replaced but in the next clock sweep pass, not immediately
> after
> > making 0.
> > So till the time of next pass if nobody accesses the buffer and all
> other
> > buffers have higher count, it can be replaced.
> > Also the buffer, it has returned for which the usage count becomes 1,
> it
> > will come to reduce the usage count only in next pass.
> > So in whole, I think it needs 2 passes for a freshly returned buffer
> to be
> > re-used incase no one uses it again.
> >
> > With Regards,
> > Amit Kapila.
> >
>
> Hmm,so in the second pass,it gets replaced,right?
Yes.

> I think that if the initialization of USAGE_COUNT starts at the maximum
> allowed value instead of one, we can have a better solution to this
> problem.

So what is your idea, if you start at maximum, what we will do for further
accesses to it?
Why do you want to give more priority to just loaded page?

> Another,more complex solution could be to introduce an ageing factor as
> well.

With Regards,
Amit Kapila.

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Atri Sharma 2013-03-22 10:45:52 Re: Page replacement algorithm in buffer cache
Previous Message Heikki Linnakangas 2013-03-22 09:39:13 Re: Let's invent a function to report lock-wait-blocking PIDs