Use pread and pwrite instead of lseek + write and read - Mailing list pgsql-hackers

From Oskari Saarenmaa
Subject Use pread and pwrite instead of lseek + write and read
Date
Msg-id a86bd200-ebbe-d829-e3ca-0c4474b2fcb7@ohmu.fi
Whole thread Raw
Responses Re: Use pread and pwrite instead of lseek + write and read  (Victor Wagner <vitus@wagner.pp.ru>)
Re: Use pread and pwrite instead of lseek + write and read  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-hackers
Hi,

The Uber blog post, among other things, pointed out that PG uses lseek +
read instead of pread.  I didn't see any discussion around that and my
Google searches didn't find any posts about pread / pwrite for the past
10 years.

With that plus the "C++ port" thread in mind, I was wondering if it's
time to see if we could do better by just utilizing newer C and POSIX
features.

The attached patch replaces FileWrite and FileRead with FileWriteAt and
FileReadAt and removes most FileSeek calls.  FileSeek is still around so
we can find the end of a file, but it's not used for anything else.

On my laptop a simple pgbench run (scale 100, 15 minutes) shows a 1.5%
performance improvement.  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?

Obviously this patch needs some more work before it could be merged, and
we probably still need a fallback for some platforms without pread and
pwrite (afaik Windows doesn't implement them.)

/ Oskari

Attachment

pgsql-hackers by date:

Previous
From: Andrew Borodin
Date:
Subject: Re: WIP: Covering + unique indexes.
Next
From: Magnus Hagander
Date:
Subject: Re: [RFC] Change the default of update_process_title to off