Re: Hint Bits and Write I/O

From: "Florian G(dot) Pflug" <fgp(at)phlo(dot)org>
To: Simon Riggs <simon(at)2ndquadrant(dot)com>
Cc: pgsql-hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Hint Bits and Write I/O
Date: 2008-05-28 23:26:37
Message-ID: 483DEA2D.3010704@phlo.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers pgsql-patches

Simon Riggs wrote:
> Hmm, I think the question is: How many hint bits need to be set
> before we mark the buffer dirty? (N)
>
> Should it be 1, as it is now? Should it be never? Never is a long
> time. As N increases, clog accesses increase. So it would seem there
> is likely to be an optimal value for N.

After further thought, I begin to think that the number of times we set
a dirty hint-bit shouldn't influence the decision of whether to dirty
the page too much. Instead, we should look at the *age* of the last xid
which modified the tuple. The idea is that the clog pages showing the
status of "young" xids are far more likely to be cached that the pages
for "older" xids. This makes a lost hint-bit update much cheaper for
young than for old xids, because we probably won't waste any IO if we
have to set the hint-bit again later, because the buffer was evicted
from shared_buffers before being written out. Additionally, I think we
should put some randomness into the decision, to spread the IO caused by
hit-bit updates after a batch load.

All in all, I envision a formula like
chance_of_dirtying = min(1,
alpha
*floor((next_xid - last_modifying_xid)/clog_page_size)
/clog_buffers
)

This means that a hint-bit update never triggers dirtying if the last
modifying xid belongs to the same clog page as the next unused xid -
which sounds good, since that clog page gets touched on every commit and
abort, and therefore is cached nearly for sure.

For xids on older pages, the chance of dirtying grows (more aggresivly
for larger alpha values). For alpha = 1, a hint-bit update dirties a
buffer for sure only if the xid is older than clog_page_size*clog_buffers.

regards,
Florian Pflug

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Jonah H. Harris 2008-05-28 23:46:44 Re: intercepting WAL writes
Previous Message Tom Lane 2008-05-28 23:20:26 Re: BUG #4186: set lc_messages does not work

Browse pgsql-patches by date

  From Date Subject
Next Message Josh Berkus 2008-05-29 03:34:14 Re: [HACKERS] WITH RECURSIVE patch V0.1
Previous Message Tom Lane 2008-05-28 21:11:50 Re: pg_lzcompress patch for 8.3, 8.2 branch