Skip to content

Commit

Permalink
Fine tune PTRACK_BUF_SIZE used for ptrack checkpoints.
Browse files Browse the repository at this point in the history
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
  • Loading branch information
ololobus committed Mar 31, 2021
1 parent d16e84b commit a8828ef
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
8 changes: 4 additions & 4 deletions engine.c
Original file line number Diff line number Diff line change
Expand Up @@ -430,7 +430,7 @@ ptrackCheckpoint(void)

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

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

j = 0;
Expand All @@ -449,10 +449,10 @@ ptrackCheckpoint(void)
/* Write if anythig left */
if ((i + 1) % PTRACK_BUF_SIZE != 0)
{
int writesz = sizeof(pg_atomic_uint64) * j;
size_t writesz = sizeof(pg_atomic_uint64) * j;

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

Expand Down
8 changes: 7 additions & 1 deletion engine.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,13 @@
/* Used for atomical crash-safe update of ptrack.map */
#define PTRACK_PATH_TMP "global/ptrack.map.tmp"

#define PTRACK_BUF_SIZE 1000
/*
* 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.
*/
#define PTRACK_BUF_SIZE ((uint64) 8000)

/* Ptrack magic bytes */
#define PTRACK_MAGIC "ptk"
Expand Down

0 comments on commit a8828ef

Please sign in to comment.