Use pread and pwrite instead of lseek + write and read
Oskari Saarenmaa <os@ohmu.fi>
From: Oskari Saarenmaa <os@ohmu.fi>
To: pgsql-hackers@postgresql.org
Date: 2016-08-17T07:58:09Z
Lists: pgsql-hackers
Attachments
- use-pread-pwrite.patch (application/x-patch) patch
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
Commits
-
Use pg_pread() and pg_pwrite() for data files and WAL.
- c24dcd0cfd94 12.0 landed