Vectored IO in XLogWrite() - Mailing list pgsql-hackers

From Melih Mutlu
Subject Vectored IO in XLogWrite()
Date
Msg-id CAGPVpCQr1yk6p1ZJguacosuqP+OLjXR2EX9yH3tmhM8VQK=smA@mail.gmail.com
Whole thread Raw
Responses Re: Vectored IO in XLogWrite()
List pgsql-hackers
Hi hackers,

I was looking into XLogWrite() and saw the below comment. It cannot really circle back in wal buffers without needing to call pg_write() since next pages wouldn't be contiguous in memory. So it needs to write whenever it reaches the end of wal buffers.

  /*
* Dump the set if this will be the last loop iteration, or if we are
* at the last page of the cache area (since the next page won't be
* contiguous in memory), or if we are at the end of the logfile
* segment.
*/

I think that we don't have the "contiguous pages" constraint when writing anymore as we can do vectored IO. It seems unnecessary to write just because XLogWrite() is at the end of wal buffers.
Attached patch uses pg_pwritev() instead of pg_pwrite() and tries to write pages in one call even if they're not contiguous in memory, until it reaches the page at startidx.

After quickly experimenting the patch and comparing the number of write calls, the patch's affect can be more visible when wal_buffers is quite low as it's more likely to circle back to the beginning. When wal_buffers is set to a decent amount, the patch only saves a few write calls. But I wouldn't expect any regression introduced by the patch (I may be wrong here), so I thought it may be worth to consider.

I appreciate any feedback on the proposed change. I'd also be glad to benchmark the patch if you want to see how it performs in some specific cases since I've been struggling with coming up a good test case.

Regards,
--
Melih Mutlu
Microsoft
Attachment

pgsql-hackers by date:

Previous
From: Amul Sul
Date:
Subject: Re: Support specify tablespace for each merged/split partition
Next
From: Peter Eisentraut
Date:
Subject: Remove hardcoded hash opclass function signature exceptions