Thread: Re: [HACKERS] Automatic free space map filling

Re: [HACKERS] Automatic free space map filling

From
ITAGAKI Takahiro
Date:
"Zeugswetter Andreas DCP SD" <ZeugswetterA@spardat.at> wrote:

> Ok, we cannot reuse a dead tuple. Maybe we can reuse the space of a dead
> tuple by reducing the tuple to it's header info.

Attached patch realizes the concept of his idea. The dead tuples will be
reduced to their headers are done by bgwriter.

This patch is incomplete, so please discuss in the thread on HACKERS.

---
ITAGAKI Takahiro
NTT Cyber Space Laboratories


Attachment

Re: [HACKERS] Automatic free space map filling

From
Simon Riggs
Date:
On Thu, 2006-03-09 at 15:53 +0900, ITAGAKI Takahiro wrote:
> "Zeugswetter Andreas DCP SD" <ZeugswetterA@spardat.at> wrote:
>
> > Ok, we cannot reuse a dead tuple. Maybe we can reuse the space of a dead
> > tuple by reducing the tuple to it's header info.
>
> Attached patch realizes the concept of his idea. The dead tuples will be
> reduced to their headers are done by bgwriter.
>
> This patch is incomplete, so please discuss in the thread on HACKERS.

I'm interested in this patch but you need to say more about it. I get
the general idea but it would be useful if you could give a full
description of what this patch is trying to do and why.

Thanks,

Best Regards, Simon Riggs


Re: [HACKERS] Automatic free space map filling

From
ITAGAKI Takahiro
Date:
Simon Riggs <simon@2ndquadrant.com> wrote:

> > "Zeugswetter Andreas DCP SD" <ZeugswetterA@spardat.at> wrote:
> > > Ok, we cannot reuse a dead tuple. Maybe we can reuse the space of a dead
> > > tuple by reducing the tuple to it's header info.
> >
> > Attached patch realizes the concept of his idea. The dead tuples will be
> > reduced to their headers are done by bgwriter.
>
> I'm interested in this patch but you need to say more about it. I get
> the general idea but it would be useful if you could give a full
> description of what this patch is trying to do and why.

OK, I try to explain the patch. Excuse me for a long writing.


* Purpose
  The basic idea is just "reducing the dead tuple to it's header info",
suggested by Andreas. This is a lightweight per-page sweeping to reduce
the consumption of free space map and the necessity of VACUUM; i.e,
normal VACUUM is still needed occasionally.

  I think it is useful on heavy-update workloads. It showed 5-10% of
performance improvement on DBT-2 after 9 hours running *without* vacuum.
I don't know whether it is still effective with well-scheduled vacuum.

* Why does bgwriter do vacuum?
  Sweeping has cost, so non-backend process should do. Also, the page worth
vacuum are almost always dirty, because tuples on the page are just updated
or deleted. Bgwriter treats dirty pages, so I think it is a good place for
sweeping.

* Locking
  We must take super-exclusive-lock of the pages before vacuum. In the patch,
bgwriter tries to take exclusive-lock before it writes a page, and does
vacuum only if the lock is super-exclusive. Otherwise, it gives up and
writes the pages normally. This is an optimistic way, but I assume the
possibility is high because the most pages written by bgwriter are least
recently used (LRU).

* Keep the headers
  We cannot remove dead tuples completely in per-page sweep, because
references to the tuples from indexes still remains. We might keep only
line pointers (4 bytes), but it might lead line-pointer-bloat problems,
(http://archives.postgresql.org/pgsql-hackers/2006-03/msg00116.php).
so the headers (4+32 byte) should be left.

* Other twists and GUC variables in the patch
- Bgwriter cannot access the catalogs, so I added BM_RELATION hint bit
  to BufferDesc. Only relation pages will be swept. This is enabled by
  GUC variable 'bgvacuum_relation'.
- I changed bgwriter_lru_maxpages to be adjusted automatically. Backends
  won't do vacuum not to disturb their processing, so bgwriter should write
  most of dirty pages. ('bgvacuum_autotune')
- After sweepping, the page will be added to free space map. I made a simple
  replacement algorithm of free space map, that replaces the page with least
  spaces near the added one. ('bgvacuum_fsm')

* Issues
- If WAL is produced by sweeping a page, writing the page should be pended
  for a while, because flushing the WAL is needed before writing the page.
- Bgwriter writes pages in 4 contexts, background-writes for LRU, ALL,
  checkpoint and shutdown. In current patch, pages are swept in 3 contexts
  except shutdown, but it may be better to do only on LRU.

* Related discussions
- Real-Time Vacuum Possibility (Rod Taylor)
    http://archives.postgresql.org/pgsql-hackers/2005-03/msg00518.php
    | have the bgwriter take a look at the pages it has, and see if it can do
    | any vacuum work based on pages it is about to send to disk
- Pre-allocated free space for row updating (like PCTFREE) (Satoshi Nagayasu)
    http://archives.postgresql.org/pgsql-hackers/2005-08/msg01135.php
    | light-weight repairing on a single page is needed to maintain free space
- Dead Space Map (Heikki Linnakangas)
    http://archives.postgresql.org/pgsql-hackers/2006-02/msg01125.php
    | vacuuming pages one by one as they're written by bgwriter


Thank you for reading till the last.
I'd like to hear your comments.

---
ITAGAKI Takahiro
NTT Cyber Space Laboratories



Re: [HACKERS] Automatic free space map filling

From
Simon Riggs
Date:
On Mon, 2006-03-13 at 17:38 +0900, ITAGAKI Takahiro wrote:
> Simon Riggs <simon@2ndquadrant.com> wrote:
>
> > > "Zeugswetter Andreas DCP SD" <ZeugswetterA@spardat.at> wrote:
> > > > Ok, we cannot reuse a dead tuple. Maybe we can reuse the space of a dead
> > > > tuple by reducing the tuple to it's header info.
> > >
> > > Attached patch realizes the concept of his idea. The dead tuples will be
> > > reduced to their headers are done by bgwriter.
> >
> > I'm interested in this patch but you need to say more about it. I get
> > the general idea but it would be useful if you could give a full
> > description of what this patch is trying to do and why.
>
> OK, I try to explain the patch. Excuse me for a long writing.

OK. I'll take a look at this, thanks.

Best Regards, Simon Riggs


Re: [HACKERS] Automatic free space map filling

From
Bruce Momjian
Date:
Added to TODO list with URL.

---------------------------------------------------------------------------

ITAGAKI Takahiro wrote:
> "Zeugswetter Andreas DCP SD" <ZeugswetterA@spardat.at> wrote:
>
> > Ok, we cannot reuse a dead tuple. Maybe we can reuse the space of a dead
> > tuple by reducing the tuple to it's header info.
>
> Attached patch realizes the concept of his idea. The dead tuples will be
> reduced to their headers are done by bgwriter.
>
> This patch is incomplete, so please discuss in the thread on HACKERS.
>
> ---
> ITAGAKI Takahiro
> NTT Cyber Space Laboratories
>

[ Attachment, skipping... ]

>
> ---------------------------(end of broadcast)---------------------------
> TIP 4: Have you searched our list archives?
>
>                http://archives.postgresql.org

--
  Bruce Momjian   http://candle.pha.pa.us
  EnterpriseDB    http://www.enterprisedb.com

  + If your life is a hard drive, Christ can be your backup. +