Skip hole in log_newpage

Lists: pgsql-hackers
From: Heikki Linnakangas <hlinnakangas(at)vmware(dot)com>
To: PostgreSQL-development <pgsql-hackers(at)postgreSQL(dot)org>
Subject: Skip hole in log_newpage
Date: 2013-12-03 11:03:41
Message-ID: 529DBA8D.3050405@vmware.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

The log_newpage function, used to WAL-log a full copy of a page, is
missing the trick we normally use for full-page images to leave out the
unused space on the block. That's pretty trivial to implement, so we should.

The place where this matters the most is when building a new B-tree
index. When wal_level > minimal, all pages in the created index are
logged with log_newpage, and by default we leave 10% free space on index
pages. So implementing this reduces the amount of WAL generated by index
creation by roughly 10%.

Anyone see a problem with this?

- Heikki

Attachment Content-Type Size
log_newpage_hole-1.patch text/x-diff 15.1 KB

From: Andres Freund <andres(at)2ndquadrant(dot)com>
To: Heikki Linnakangas <hlinnakangas(at)vmware(dot)com>
Cc: PostgreSQL-development <pgsql-hackers(at)postgreSQL(dot)org>
Subject: Re: Skip hole in log_newpage
Date: 2013-12-03 11:37:22
Message-ID: 20131203113722.GA25860@awork2.anarazel.de
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Hi,

On 2013-12-03 13:03:41 +0200, Heikki Linnakangas wrote:
> The log_newpage function, used to WAL-log a full copy of a page, is missing
> the trick we normally use for full-page images to leave out the unused space
> on the block. That's pretty trivial to implement, so we should.
>
> The place where this matters the most is when building a new B-tree index.
> When wal_level > minimal, all pages in the created index are logged with
> log_newpage, and by default we leave 10% free space on index pages. So
> implementing this reduces the amount of WAL generated by index creation by
> roughly 10%.

Sounds like a good idea to me.

> Anyone see a problem with this?

I haven't looked thoroughly through all callsites, but shouldn't the
vacuumlazy callsite use std = true?

Greetings,

Andres Freund

--
Andres Freund http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Training & Services


From: Heikki Linnakangas <hlinnakangas(at)vmware(dot)com>
To: Andres Freund <andres(at)2ndquadrant(dot)com>
Cc: PostgreSQL-development <pgsql-hackers(at)postgreSQL(dot)org>
Subject: Re: Skip hole in log_newpage
Date: 2013-12-03 11:57:04
Message-ID: 529DC710.1080803@vmware.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On 12/03/2013 01:37 PM, Andres Freund wrote:
> I haven't looked thoroughly through all callsites, but shouldn't the
> vacuumlazy callsite use std = true?

Well, it's logging an empty page, ie. a page full of zeros. I'm not sure
if you'd consider that a "standard" page. Like the backup-block code in
xlog.c, log_newpage actually makes a full page image without the hole if
pd_lower == 0, even if you pass std = 'true', so the end result is the same.

- Heikki


From: Andres Freund <andres(at)2ndquadrant(dot)com>
To: Heikki Linnakangas <hlinnakangas(at)vmware(dot)com>
Cc: PostgreSQL-development <pgsql-hackers(at)postgreSQL(dot)org>
Subject: Re: Skip hole in log_newpage
Date: 2013-12-03 12:03:28
Message-ID: 20131203120328.GA29581@awork2.anarazel.de
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On 2013-12-03 13:57:04 +0200, Heikki Linnakangas wrote:
> On 12/03/2013 01:37 PM, Andres Freund wrote:
> >I haven't looked thoroughly through all callsites, but shouldn't the
> >vacuumlazy callsite use std = true?
>
> Well, it's logging an empty page, ie. a page full of zeros. I'm not sure if
> you'd consider that a "standard" page. Like the backup-block code in xlog.c,
> log_newpage actually makes a full page image without the hole if pd_lower ==
> 0, even if you pass std = 'true', so the end result is the same.

Hm. It should have been PageInit()ed and thus have sensible
pd_lower/upper, right? Otherwise we'd have entered thePageIsNew() branch
above it.
It's obviously not critical, but it seems like a shame to write 8kb when
it's not necessary.

Greetings,

Andres Freund

--
Andres Freund http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Training & Services


From: Heikki Linnakangas <hlinnakangas(at)vmware(dot)com>
To: Andres Freund <andres(at)2ndquadrant(dot)com>
Cc: PostgreSQL-development <pgsql-hackers(at)postgreSQL(dot)org>
Subject: Re: Skip hole in log_newpage
Date: 2013-12-03 12:20:17
Message-ID: 529DCC81.6050905@vmware.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On 12/03/2013 02:03 PM, Andres Freund wrote:
> On 2013-12-03 13:57:04 +0200, Heikki Linnakangas wrote:
>> On 12/03/2013 01:37 PM, Andres Freund wrote:
>>> I haven't looked thoroughly through all callsites, but shouldn't the
>>> vacuumlazy callsite use std = true?
>>
>> Well, it's logging an empty page, ie. a page full of zeros. I'm not sure if
>> you'd consider that a "standard" page. Like the backup-block code in xlog.c,
>> log_newpage actually makes a full page image without the hole if pd_lower ==
>> 0, even if you pass std = 'true', so the end result is the same.
>
> Hm. It should have been PageInit()ed and thus have sensible
> pd_lower/upper, right? Otherwise we'd have entered thePageIsNew() branch
> above it.
> It's obviously not critical, but it seems like a shame to write 8kb when
> it's not necessary.

Ah, you're right. I was thinking that that is the PageIsNew() branch,
but it's not.

- Heikki


From: Robert Haas <robertmhaas(at)gmail(dot)com>
To: Heikki Linnakangas <hlinnakangas(at)vmware(dot)com>
Cc: PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Skip hole in log_newpage
Date: 2013-12-03 12:55:45
Message-ID: CA+TgmoZ1iKMH4ErvVCghLfAtWy8AKH2gafV9uVo3bqENXo-e4w@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Tue, Dec 3, 2013 at 6:03 AM, Heikki Linnakangas
<hlinnakangas(at)vmware(dot)com> wrote:
> The log_newpage function, used to WAL-log a full copy of a page, is missing
> the trick we normally use for full-page images to leave out the unused space
> on the block. That's pretty trivial to implement, so we should.
>
> The place where this matters the most is when building a new B-tree index.
> When wal_level > minimal, all pages in the created index are logged with
> log_newpage, and by default we leave 10% free space on index pages. So
> implementing this reduces the amount of WAL generated by index creation by
> roughly 10%.
>
> Anyone see a problem with this?

Looks good to me.

--
Robert Haas
EnterpriseDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company


From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Heikki Linnakangas <hlinnakangas(at)vmware(dot)com>
Cc: PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Skip hole in log_newpage
Date: 2013-12-03 14:54:42
Message-ID: 10684.1386082482@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Heikki Linnakangas <hlinnakangas(at)vmware(dot)com> writes:
> The log_newpage function, used to WAL-log a full copy of a page, is
> missing the trick we normally use for full-page images to leave out the
> unused space on the block. That's pretty trivial to implement, so we should.

> Anyone see a problem with this?

+1. Don't forget to bump the WAL version identifier.

regards, tom lane