Re: Use pread and pwrite instead of lseek + write and read

Oskari Saarenmaa <os@ohmu.fi>

From: Oskari Saarenmaa <os@ohmu.fi>
To: Tom Lane <tgl@sss.pgh.pa.us>
Cc: pgsql-hackers@postgresql.org
Date: 2016-08-17T14:41:05Z
Lists: pgsql-hackers

Attachments

17.08.2016, 16:40, Tom Lane kirjoitti:
> Oskari Saarenmaa <os@ohmu.fi> writes:
>> On my laptop a simple pgbench run (scale 100, 15 minutes) shows a 1.5%
>> performance improvement.
>
> I would have hoped for a lot better result before anyone would propose
> that we should deal with all the portability issues this'll create.

AFAICT pread and pwrite are available on pretty much all operating 
systems released in 2000s; it was added to Linux in 1997.  Windows and 
HP-UX 10.20 don't have it, but we can just simulate it using lseek + 
read/write there without adding too much code.

>> A 1.5% performance improvement is small but
>> measurable - and IMV more importantly it allows us to drop more than 100
>> lines of backwards (compatible?) code; maybe we could start targeting
>> more recent platforms in v10?
>
> That's basically nonsense: we'll end up adding way more than that to
> deal with platforms that haven't got these APIs.

Attached an updated patch that adds a configure check and uses 
lseek+read/write instead pread/pwrite when the latter aren't available. 
The previous code ended up seeking anyway in most of the cases and 
pgbench shows no performance regression on my Linux box.

  8 files changed, 54 insertions(+), 168 deletions(-)

/ Oskari

Commits

  1. Use pg_pread() and pg_pwrite() for data files and WAL.