Re: Lowering the default wal_blocksize to 4K

From: Thomas Munro <thomas(dot)munro(at)gmail(dot)com>
To: Robert Haas <robertmhaas(at)gmail(dot)com>
Cc: Andres Freund <andres(at)anarazel(dot)de>, Matthias van de Meent <boekewurm+postgres(at)gmail(dot)com>, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, pgsql-hackers(at)postgresql(dot)org, Heikki Linnakangas <hlinnaka(at)iki(dot)fi>
Subject: Re: Lowering the default wal_blocksize to 4K
Date: 2023-10-11 20:47:29
Message-ID: CA+hUKG+HHAG6dYkjjJNaRk38K5e9ucaoPoyBeOHDUcMS+48s7g@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Thu, Oct 12, 2023 at 9:27 AM Thomas Munro <thomas(dot)munro(at)gmail(dot)com> wrote:
> On Thu, Oct 12, 2023 at 9:05 AM Robert Haas <robertmhaas(at)gmail(dot)com> wrote:
> > But if we do want to keep those cross-checks, why not take what Thomas
> > proposed a little further and move all of xlp_sysid, xlp_seg_size, and
> > xlp_xlog_blcksz into XLOG_CHECKPOINT_REDO? Then long and short page
> > headers would become identical.
>
> FTR that's exactly what I was trying to say.

And to be extra double explicit, the point of that is to kill the
'div' instruction that Andres was complaining about, because now the
division depends only on compile time constants so it can be done with
multiplication and bitswizzling tricks. For example, when X is a
variable I get:

*a = n / X;
0x0000000000000003 <+3>: mov %rdi,%rax
0x0000000000000006 <+6>: xor %edx,%edx
0x0000000000000008 <+8>: divq 0x0(%rip) # 0xf <f+15>
0x0000000000000011 <+17>: mov %rax,(%rsi)

*b = n % X;
0x000000000000000f <+15>: xor %edx,%edx
0x0000000000000014 <+20>: mov %rdi,%rax
0x0000000000000017 <+23>: divq 0x0(%rip) # 0x1e <f+30>
0x000000000000001e <+30>: mov %rdx,(%rcx)

... but when it's the constant 8192 - 24 I get:

*a = n / X;
0x0000000000000000 <+0>: movabs $0x2018120d8a279db7,%rax
0x000000000000000d <+13>: mov %rdi,%rdx
0x0000000000000010 <+16>: shr $0x3,%rdx
0x0000000000000014 <+20>: mul %rdx
0x0000000000000017 <+23>: shr $0x7,%rdx
0x000000000000001b <+27>: mov %rdx,(%rsi)

*b = n % X;
0x000000000000001e <+30>: imul $0x1fe8,%rdx,%rdx
0x0000000000000025 <+37>: sub %rdx,%rdi
0x0000000000000028 <+40>: mov %rdi,(%rcx)

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Alena Rybakina 2023-10-11 21:01:37 Re: A new strategy for pull-up correlated ANY_SUBLINK
Previous Message Thomas Munro 2023-10-11 20:27:33 Re: Lowering the default wal_blocksize to 4K