Re: Reducing the size of BufferTag & remodeling forks

From: Simon Riggs <simon(at)2ndQuadrant(dot)com>
To: Andres Freund <andres(at)anarazel(dot)de>
Cc: PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Reducing the size of BufferTag & remodeling forks
Date: 2015-09-12 12:12:26
Message-ID: CANP8+jL4NTXr=b+1iK9P=z_fhBxuW0=YW7jUA2bFJPsq-cuKnQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On 2 July 2015 at 14:36, Andres Freund <andres(at)anarazel(dot)de> wrote:

> Hi,
>
> I've complained a number of times that our BufferTag is ridiculously
> large:
> typedef struct buftag
> {
> RelFileNode rnode; /* physical relation identifier */
> ForkNumber forkNum;
> BlockNumber blockNum; /* blknum relative to begin of reln */
> } BufferTag;
>
> typedef struct RelFileNode
> {
> Oid spcNode; /* tablespace */
> Oid dbNode; /* database */
> Oid relNode; /* relation */
> } RelFileNode;
>
> that amounts to 20 bytes. That's problematic because we frequently have
> to compare or hash the entire buffer tag. Comparing 20bytes is rather
> branch intensive, and shows up noticably on profiles. It's also a
> stumbling block on the way to a smarter buffer mapping data structure,
> because it makes e.g. trees rather deep.
>
> The buffer tag is currently used in two situations:
>
> 1) Dealing with the buffer mapping, we need to identify the underlying
> file uniquely and we need the block number (8 bytes).
>
> 2) When writing out the a block we need, in addition to 1), have
> information about where to store the file. That requires the
> tablespace and database.
>
> You may know that a filenode (RelFileNode->relNode) is currently *not*
> unique across databases and tablespaces.
>

Why do we have to do buffer lookups using the full buffer tag?

Why not just use (relNode, blockNum) and resolve hash collisions, if any?

Your suggestion to avoid hashing the whole buffer tag was a good one.
Having a permanent table to produce a smaller tag is a fairly pessimistic
solution; why not just have an optimistic solution in memory instead?

--
Simon Riggs http://www.2ndQuadrant.com/
<http://www.2ndquadrant.com/>
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Amit Kapila 2015-09-12 12:24:21 Re: RFC: replace pg_stat_activity.waiting with something more descriptive
Previous Message Amit Kapila 2015-09-12 11:05:10 Re: RFC: replace pg_stat_activity.waiting with something more descriptive