Skip to content

Commit a8828ef

Browse files
committed
Fine tune PTRACK_BUF_SIZE used for ptrack checkpoints.
8k of 64 bit LSNs is 64 KB, which looks like a reasonable buffer size for disk writes. On fast NVMe SSD it gives around 20% increase in ptrack checkpoint speed compared to PTRACK_BUF_SIZE == 1000, i.e. 8 KB writes. Also use proper types for writesz and PTRACK_BUF_SIZE while on it
1 parent d16e84b commit a8828ef

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed

engine.c

+4-4
Original file line numberDiff line numberDiff line change
@@ -430,7 +430,7 @@ ptrackCheckpoint(void)
430430

431431
if (j == PTRACK_BUF_SIZE)
432432
{
433-
int writesz = sizeof(buf); /* Up to ~2 GB for buffer size seems
433+
size_t writesz = sizeof(buf); /* Up to ~2 GB for buffer size seems
434434
* to be more than enough, so never
435435
* going to overflow. */
436436

@@ -439,7 +439,7 @@ ptrackCheckpoint(void)
439439
* takes into account all paddings for us.
440440
*/
441441
ptrack_write_chunk(ptrack_tmp_fd, &crc, (char *) buf, writesz);
442-
elog(DEBUG5, "ptrack checkpoint: i " UINT64_FORMAT ", j " UINT64_FORMAT ", writesz %d PtrackContentNblocks " UINT64_FORMAT,
442+
elog(DEBUG5, "ptrack checkpoint: i " UINT64_FORMAT ", j " UINT64_FORMAT ", writesz %zu PtrackContentNblocks " UINT64_FORMAT,
443443
i, j, writesz, (uint64) PtrackContentNblocks);
444444

445445
j = 0;
@@ -449,10 +449,10 @@ ptrackCheckpoint(void)
449449
/* Write if anythig left */
450450
if ((i + 1) % PTRACK_BUF_SIZE != 0)
451451
{
452-
int writesz = sizeof(pg_atomic_uint64) * j;
452+
size_t writesz = sizeof(pg_atomic_uint64) * j;
453453

454454
ptrack_write_chunk(ptrack_tmp_fd, &crc, (char *) buf, writesz);
455-
elog(DEBUG5, "ptrack checkpoint: final i " UINT64_FORMAT ", j " UINT64_FORMAT ", writesz %d PtrackContentNblocks " UINT64_FORMAT,
455+
elog(DEBUG5, "ptrack checkpoint: final i " UINT64_FORMAT ", j " UINT64_FORMAT ", writesz %zu PtrackContentNblocks " UINT64_FORMAT,
456456
i, j, writesz, (uint64) PtrackContentNblocks);
457457
}
458458

engine.h

+7-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,13 @@
3131
/* Used for atomical crash-safe update of ptrack.map */
3232
#define PTRACK_PATH_TMP "global/ptrack.map.tmp"
3333

34-
#define PTRACK_BUF_SIZE 1000
34+
/*
35+
* 8k of 64 bit LSNs is 64 KB, which looks like a reasonable
36+
* buffer size for disk writes. On fast NVMe SSD it gives
37+
* around 20% increase in ptrack checkpoint speed compared
38+
* to PTRACK_BUF_SIZE == 1000, i.e. 8 KB writes.
39+
*/
40+
#define PTRACK_BUF_SIZE ((uint64) 8000)
3541

3642
/* Ptrack magic bytes */
3743
#define PTRACK_MAGIC "ptk"

0 commit comments

Comments
 (0)