From: | Bharath Rupireddy <bharath(dot)rupireddyforpostgres(at)gmail(dot)com> |
---|---|
To: | Andres Freund <andres(at)anarazel(dot)de> |
Cc: | Michael Paquier <michael(at)paquier(dot)xyz>, Alvaro Herrera <alvherre(at)alvh(dot)no-ip(dot)org>, Nathan Bossart <nathandbossart(at)gmail(dot)com>, Thomas Munro <thomas(dot)munro(at)gmail(dot)com>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org> |
Subject: | Re: Use pg_pwritev_with_retry() instead of write() in dir_open_for_write() to avoid partial writes? |
Date: | 2023-02-12 14:29:00 |
Message-ID: | CALj2ACWdYgO+EOwT7FYEbc1Ui7KkCnVRSYmFjTO3S8EadeL_VQ@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-hackers |
On Sun, Feb 12, 2023 at 4:14 AM Andres Freund <andres(at)anarazel(dot)de> wrote:
>
> > +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.
Thanks for looking at it. We know that we don't change the zbuffer in
the function, so can we avoid static const and have just a static
variable, like the attached
v1-0001-Use-static-variable-to-avoid-memset-calls-in-pg_p.patch? Do
you see any problem with it?
FWIW, it comes out like the attached
v1-0001-Use-static-const-variable-to-avoid-memset-calls-i.patch with
static const.
--
Bharath Rupireddy
PostgreSQL Contributors Team
RDS Open Source Databases
Amazon Web Services: https://aws.amazon.com
Attachment | Content-Type | Size |
---|---|---|
v1-0001-Use-static-variable-to-avoid-memset-calls-in-pg_p.patch | application/x-patch | 1.2 KB |
v1-0001-Use-static-const-variable-to-avoid-memset-calls-i.patch | application/x-patch | 1.4 KB |
From | Date | Subject | |
---|---|---|---|
Next Message | Mark Dilger | 2023-02-12 14:48:29 | Re: Transparent column encryption |
Previous Message | Andrew Dunstan | 2023-02-12 14:16:25 | Re: run pgindent on a regular basis / scripted manner |