v1-0001-Use-static-const-variable-to-avoid-memset-calls-i.patch
application/x-patch
Filename: v1-0001-Use-static-const-variable-to-avoid-memset-calls-i.patch
Type: application/x-patch
Part: 1
Patch
Format: format-patch
Series: patch v1-0001
Subject: Use static const variable to avoid memset calls in pg_pwrite_zeros
| File | + | − |
|---|---|---|
| src/common/file_utils.c | 4 | 6 |
From adc5ea83fb6726a5d8a1f3b87d6b3b03550c7fcb Mon Sep 17 00:00:00 2001
From: Bharath Rupireddy <bharath.rupireddyforpostgres@gmail.com>
Date: Sun, 12 Feb 2023 10:55:09 +0000
Subject: [PATCH v1] Use static const variable to avoid memset calls in
pg_pwrite_zeros
---
src/common/file_utils.c | 10 ++++------
1 file changed, 4 insertions(+), 6 deletions(-)
diff --git a/src/common/file_utils.c b/src/common/file_utils.c
index 4dae534152..cd15cc2fdb 100644
--- a/src/common/file_utils.c
+++ b/src/common/file_utils.c
@@ -539,7 +539,8 @@ pg_pwritev_with_retry(int fd, const struct iovec *iov, int iovcnt, off_t offset)
ssize_t
pg_pwrite_zeros(int fd, size_t size)
{
- PGAlignedBlock zbuffer; /* worth BLCKSZ */
+ /* Zero-filled buffer worth BLCKSZ. */
+ static const PGAlignedBlock zbuffer = {0};
size_t zbuffer_sz;
struct iovec iov[PG_IOV_MAX];
int blocks;
@@ -548,15 +549,12 @@ pg_pwrite_zeros(int fd, size_t size)
ssize_t written;
ssize_t total_written = 0;
- zbuffer_sz = sizeof(zbuffer.data);
-
- /* Zero-fill the buffer. */
- memset(zbuffer.data, 0, zbuffer_sz);
+ zbuffer_sz = BLCKSZ;
/* Prepare to write out a lot of copies of our zero buffer at once. */
for (i = 0; i < lengthof(iov); ++i)
{
- iov[i].iov_base = zbuffer.data;
+ iov[i].iov_base = (void *) (unconstify(PGAlignedBlock *, &zbuffer)->data);
iov[i].iov_len = zbuffer_sz;
}
--
2.34.1