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


Reply via email to