Re: EINTR in ftruncate()
Andres Freund <andres@anarazel.de>
From: Andres Freund <andres@anarazel.de>
To: Thomas Munro <thomas.munro@gmail.com>
Cc: Chris Travers <chris.travers@gmail.com>, Pg Hackers <pgsql-hackers@lists.postgresql.org>
Date: 2022-07-01T22:17:22Z
Lists: pgsql-hackers
Hi, On 2022-07-02 09:52:33 +1200, Thomas Munro wrote: > On Sat, Jul 2, 2022 at 9:06 AM Andres Freund <andres@anarazel.de> wrote: > > On 2022-07-01 13:29:44 -0700, Andres Freund wrote: > > Chris, do you have any additional details about the machine that lead to this > > change? OS version, whether it might have been swapping, etc? > > > > I wonder if what happened is that posix_fallocate() used glibc's fallback > > implementation because the kernel was old enough to not support fallocate() > > for tmpfs. Looks like support for fallocate() for tmpfs was added in 3.5 > > ([1]). So e.g. a rhel 6 wouldn't have had that. > > With a quick test program on my Linux 5.10 kernel I see that an > SA_RESTART signal handler definitely causes posix_fallocate() to > return EINTR (can post trivial program). > > A drive-by look at the current/modern kernel source supports this: > shmem_fallocate returns -EINTR directly (not -ERESTARTSYS, which seems > to be the Linux-y way to say you want EINTR or restart as > appropriate?), and it also undoes all partial progress too (not too > surprising), which would explain why a perfectly timed machine gun > stream of signals from our recovery conflict system can make an > fallocate retry loop never terminate, for large enough sizes. Yea :( And even if we fix recovery to not do douse other processes in signals quite that badly, there are plenty other sources of signals that can arrive at a steady clip. So I think we need to do something to defuse this another way. Ideas: 1) do the fallocate in smaller chunks, thereby making it much more likely to complete between two signal deliveries 2) block signals while calling posix_fallocate(). That won't work for everything (e.g. rapid SIGSTOP/SIGCONT), but that's not something we'd send ourselves, so whatever. 3) 1+2 4) ? Greetings, Andres Freund
Commits
-
Provide sigaction() for Windows.
- b28ac1d24db4 16.0 landed
-
Emulate sigprocmask(), not sigsetmask(), on Windows.
- c94ae9d827a3 16.0 landed
-
Make dsm_impl_posix_resize more future-proof.
- d3b0884c0708 10.22 landed
- 3f2344d4aee1 11.17 landed
- 1661c40b9deb 12.12 landed
- c75b6b454ea1 13.8 landed
- c412c60b91ac 14.5 landed
- 91377a4559d8 15.0 landed
- 3b8d23a3e14f 16.0 landed
-
Don't clobber postmaster sigmask in dsm_impl_resize.
- e26024bea9e9 10.22 landed
- 74a9ee034829 11.17 landed
- a05f40ef874b 12.12 landed
- 17aa39da50c5 13.8 landed
- 8383645592de 14.5 landed
- a715c20043c1 15.0 landed
- 80845b7c0b2c 16.0 landed
-
Create a distinct wait event for POSIX DSM allocation.
- 7bae3bbf62d6 16.0 landed
-
Remove redundant ftruncate() for POSIX DSM memory.
- 712704d3539e 16.0 landed
-
Block signals while allocating DSM memory.
- 4518c798b2b9 16.0 landed
- c4a617ea117e 15.0 landed
- 2019e6ecfa26 14.5 landed
- e73fe6e828d1 13.8 landed
- ff78bf796d80 12.12 landed
- 39683c69a03e 11.17 landed
- 53cfe403c9d2 10.22 landed
-
Remove dsm_resize() and dsm_remap().
- 3c60d0fa231f 12.0 cited
-
XLOG (also known as WAL -:)) Bootstrap/Startup/Shutdown.
- 47937403676d 7.1.1 cited