Re: Use pg_pwritev_with_retry() instead of write() in dir_open_for_write() to avoid partial writes?
| От | Andres Freund |
|---|---|
| Тема | Re: Use pg_pwritev_with_retry() instead of write() in dir_open_for_write() to avoid partial writes? |
| Дата | |
| Msg-id | 20230211224424.r25uw4rsv6taukxk@awork3.anarazel.de обсуждение исходный текст |
| Ответ на | Re: Use pg_pwritev_with_retry() instead of write() in dir_open_for_write() to avoid partial writes? (Bharath Rupireddy <bharath.rupireddyforpostgres@gmail.com>) |
| Ответы |
Re: Use pg_pwritev_with_retry() instead of write() in dir_open_for_write() to avoid partial writes?
|
| Список | pgsql-hackers |
Hi,
On 2022-11-01 08:32:48 +0530, Bharath Rupireddy wrote:
> +/*
> + * pg_pwrite_zeros
> + *
> + * Writes zeros to a given file. Input parameters are "fd" (file descriptor of
> + * the file), "size" (size of the file in bytes).
> + *
> + * On failure, a negative value is returned and errno is set appropriately so
> + * that the caller can use it accordingly.
> + */
> +ssize_t
> +pg_pwrite_zeros(int fd, size_t size)
> +{
> + PGAlignedBlock zbuffer;
> + size_t zbuffer_sz;
> + struct iovec iov[PG_IOV_MAX];
> + int blocks;
> + size_t remaining_size = 0;
> + int i;
> + ssize_t written;
> + ssize_t total_written = 0;
> +
> + zbuffer_sz = sizeof(zbuffer.data);
> +
> + /* Zero-fill the buffer. */
> + memset(zbuffer.data, 0, zbuffer_sz);
I previously commented on this - why are we memseting a buffer on every call
to this? That's not at all free.
Something like
static const PGAlignedBlock zerobuf = {0};
would do the trick. You do need to cast the const away, to assign to
iov_base, but that's not too ugly.
Greetings,
Andres Freund
В списке pgsql-hackers по дате отправления: