pgsql: Fix assorted portability issues with using msync() for data flus - Mailing list pgsql-committers

From Tom Lane
Subject pgsql: Fix assorted portability issues with using msync() for data flus
Date
Msg-id E1aqSAf-0003KH-Gs@gemulon.postgresql.org
Whole thread Raw
List pgsql-committers
Fix assorted portability issues with using msync() for data flushing.

Commit 428b1d6b29ca599c5700d4bc4f4ce4c5880369bf introduced the use of
msync() for flushing dirty data from the kernel's file buffers.  Several
portability issues were overlooked, though:

* Not all implementations of mmap() think that nbytes == 0 means "map
the whole file".  To fix, use lseek() to find out the true length.
Fix callers of pg_flush_data to be aware that nbytes == 0 may result
in trashing the file's seek position.

* Not all implementations of mmap() will accept partial-page mmap
requests.  To fix, round down the length request to whatever sysconf()
says the page size is.  (I think this is OK from a portability standpoint,
because sysconf() is required by SUS v2, and we aren't trying to compile
this part on Windows anyway.  Buildfarm should let us know if not.)

* On 32-bit machines, the file size might exceed the available free
address space, or even exceed what will fit in size_t.  Check for
the latter explicitly to avoid passing a false request size to mmap().
If mmap fails, silently fall through to the next implementation method,
rather than bleating to the postmaster log and giving up.

* mmap'ing directories fails on some platforms, and even if it works,
msync'ing the directory is quite unlikely to help, as for that matter are
the other flush implementations.  In pre_sync_fname(), just skip flush
attempts on directories.

In passing, copy-edit the comments a bit.

Stas Kelvich and myself

Branch
------
master

Details
-------
http://git.postgresql.org/pg/commitdiff/fa11a09fed2b6f483231608866a682ee3a376277

Modified Files
--------------
src/backend/storage/file/fd.c | 131 +++++++++++++++++++++++++++++-------------
1 file changed, 90 insertions(+), 41 deletions(-)


pgsql-committers by date:

Previous
From: Kevin Grittner
Date:
Subject: Re: [HACKERS] Re: pgsql: Avoid extra locks in GetSnapshotData if old_snapshot_threshold <
Next
From: Andres Freund
Date:
Subject: Re: [HACKERS] Re: pgsql: Avoid extra locks in GetSnapshotData if old_snapshot_threshold <