From: | Greg Stark <stark(at)mit(dot)edu> |
---|---|
To: | Jim Nasby <Jim(dot)Nasby(at)bluetreble(dot)com> |
Cc: | PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>, Merlin Moncure <mmoncure(at)gmail(dot)com>, Peter Geoghegan <pg(at)heroku(dot)com>, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Robert Haas <robertmhaas(at)gmail(dot)com> |
Subject: | Re: Clock sweep not caching enough B-Tree leaf pages? |
Date: | 2015-04-14 23:10:50 |
Message-ID: | CAM-w4HP5c+93R_g4edd8kvKZrQ60c=d+Wz56+p-L7D0SWdg+=A@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-hackers |
I've been meaning to write this since PGConf and now isn't a great time
since I'm on my phone but I think it's time.
The way the clock sweep algorithm is meant to be thought about is that it's
an approximate lru. Each usage count corresponds to an ntile of the lru. So
we don't know which buffer is least recently used but it must be in the set
of buffers with usage count 0 and that should be 1/nth of all the buffers.
In order for that property to be maintained though the usage count for some
buffer should be getting decremented every time we touch a buffer. That is,
every time we promote one buffer to the most recently moved ntile we should
be demoting some other buffer.
The way our cache works we promote when a buffer is accessed but we only
demote when a buffer is flushed. We flush a lot less often than we touch
buffers so it's not surprising that the cache ends up full of buffers that
are all in the "most recently used" section.
Now it's complicated by the fact that we aren't promoting buffers directly
to the most recently used ntile. We're incrementing the usage count by one.
That makes it more of a "least frequently used" list rather than a lru. I
think that's a mistake but I recall some debate about that when it first
went in.
From | Date | Subject | |
---|---|---|---|
Next Message | David Steele | 2015-04-14 23:12:41 | Re: Turning off HOT/Cleanup sometimes |
Previous Message | Jim Nasby | 2015-04-14 22:42:28 | Re: Clock sweep not caching enough B-Tree leaf pages? |