Don't initialize page in {vm,fsm}_extend(), not needed
authorAndres Freund <[email protected]>
Wed, 5 Apr 2023 15:19:39 +0000 (08:19 -0700)
committerAndres Freund <[email protected]>
Wed, 5 Apr 2023 15:19:39 +0000 (08:19 -0700)
The read path needs to be able to initialize pages anyway, as relation
extensions are not durable. By avoiding initializing pages, we can, in a
future patch, extend the relation by multiple blocks at once.

Using smgrextend() for {vm,fsm}_extend() is not a good idea in general, as at
least one page of the VM/FSM will be read immediately after, always causing a
cache miss, requiring us to read content we just wrote.

Discussion: https://postgr.es/m/20230301223515[email protected]

src/backend/access/heap/visibilitymap.c
src/backend/storage/freespace/freespace.c

index 11e6d0d479f8aa7f41a7bf90f41294608c5e0c95..114d1b42b3e47120168bdb9b18cce50f9b70b298 100644 (file)
@@ -622,11 +622,9 @@ static void
 vm_extend(Relation rel, BlockNumber vm_nblocks)
 {
    BlockNumber vm_nblocks_now;
-   PGAlignedBlock pg;
+   PGAlignedBlock pg = {0};
    SMgrRelation reln;
 
-   PageInit((Page) pg.data, BLCKSZ, 0);
-
    /*
     * We use the relation extension lock to lock out other backends trying to
     * extend the visibility map at the same time. It also locks out extension
@@ -662,8 +660,6 @@ vm_extend(Relation rel, BlockNumber vm_nblocks)
    /* Now extend the file */
    while (vm_nblocks_now < vm_nblocks)
    {
-       PageSetChecksumInplace((Page) pg.data, vm_nblocks_now);
-
        smgrextend(reln, VISIBILITYMAP_FORKNUM, vm_nblocks_now, pg.data, false);
        vm_nblocks_now++;
    }
index 3e9693b293ba319b4a018aa0f48aaa14b09ee469..90c529958e7fdc12908e6d620f100c948aa55a3d 100644 (file)
@@ -608,10 +608,9 @@ static void
 fsm_extend(Relation rel, BlockNumber fsm_nblocks)
 {
    BlockNumber fsm_nblocks_now;
-   PGAlignedBlock pg;
+   PGAlignedBlock pg = {0};
    SMgrRelation reln;
 
-   PageInit((Page) pg.data, BLCKSZ, 0);
 
    /*
     * We use the relation extension lock to lock out other backends trying to
@@ -649,8 +648,6 @@ fsm_extend(Relation rel, BlockNumber fsm_nblocks)
    /* Extend as needed. */
    while (fsm_nblocks_now < fsm_nblocks)
    {
-       PageSetChecksumInplace((Page) pg.data, fsm_nblocks_now);
-
        smgrextend(reln, FSM_FORKNUM, fsm_nblocks_now,
                   pg.data, false);
        fsm_nblocks_now++;