Re: Substituting Checksum Algorithm (was: Enabling Checksums)

From: Andres Freund <andres(at)2ndquadrant(dot)com>
To: Simon Riggs <simon(at)2ndQuadrant(dot)com>
Cc: Ants Aasma <ants(at)cybertec(dot)at>, Jeff Davis <pgsql(at)j-davis(dot)com>, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Florian Pflug <fgp(at)phlo(dot)org>, Robert Haas <robertmhaas(at)gmail(dot)com>, PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>, Greg Smith <greg(at)2ndquadrant(dot)com>, Bruce Momjian <bruce(at)momjian(dot)us>, Heikki Linnakangas <hlinnakangas(at)vmware(dot)com>
Subject: Re: Substituting Checksum Algorithm (was: Enabling Checksums)
Date: 2013-04-30 11:09:43
Message-ID: 20130430110943.GA25261@alap2.anarazel.de
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On 2013-04-30 11:55:29 +0100, Simon Riggs wrote:
> ISTM that we also need this patch to put memory barriers in place
> otherwise the code might be rearranged.
>
> --
> Simon Riggs http://www.2ndQuadrant.com/
> PostgreSQL Development, 24x7 Support, Training & Services

> --- a/src/backend/storage/page/bufpage.c
> +++ b/src/backend/storage/page/bufpage.c
> @@ -960,11 +960,14 @@ PageCalcChecksum16(Page page, BlockNumber blkno)
> * Save pd_checksum and set it to zero, so that the checksum calculation
> * isn't affected by the checksum stored on the page. We do this to
> * allow optimization of the checksum calculation on the whole block
> - * in one go.
> + * in one go. Memory barriers are required to avoid rearrangement here.
> */
> save_checksum = phdr->pd_checksum;
> + pg_memory_barrier();
> phdr->pd_checksum = 0;
> + pg_memory_barrier();
> checksum = checksum_block(page, BLCKSZ);
> + pg_memory_barrier();
> phdr->pd_checksum = save_checksum;
>
> /* mix in the block number to detect transposed pages */

Why? I am not sure which rearrangement you're fearing? In all cases
where there is danger of concurrent write access to the page we should
already be working on a copy?
Also, if we need a memory barrier I can only see a point in the 2nd
one. The first and third shouldn't ever be able to change anything since
we are only writing to local memory?

Greetings,

Andres Freund

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

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Ants Aasma 2013-04-30 11:23:35 Re: Substituting Checksum Algorithm (was: Enabling Checksums)
Previous Message Stephen Frost 2013-04-30 11:00:13 Re: Remaining beta blockers