Avoid SIGBUS on Linux when a DSM memory request overruns tmpfs.

Tom Lane <tgl@sss.pgh.pa.us>

Commit: 05297416f362b50985b3cd3473778fbb0842295d
Author: Tom Lane <tgl@sss.pgh.pa.us>
Date: 2017-09-25T20:09:20Z
Releases: 9.5.10
Avoid SIGBUS on Linux when a DSM memory request overruns tmpfs.

On Linux, shared memory segments created with shm_open() are backed by
swap files created in tmpfs.  If the swap file needs to be extended,
but there's no tmpfs space left, you get a very unfriendly SIGBUS trap.
To avoid this, force allocation of the full request size when we create
the segment.  This adds a few cycles, but none that we wouldn't expend
later anyway, assuming the request isn't hugely bigger than the actual
need.

Make this code #ifdef __linux__, because (a) there's not currently a
reason to think the same problem exists on other platforms, and (b)
applying posix_fallocate() to an FD created by shm_open() isn't very
portable anyway.

Back-patch to 9.4 where the DSM code came in.

Thomas Munro, per a bug report from Amul Sul

Discussion: https://postgr.es/m/1002664500.12301802.1471008223422.JavaMail.yahoo@mail.yahoo.com

Files

PathChange+/−
configure modified +1 −1
configure.in modified +1 −1
src/backend/storage/ipc/dsm_impl.c modified +52 −2
src/include/pg_config.h.in modified +3 −0
src/include/pg_config.h.win32 modified +3 −0

Discussion