Re: EINTR in ftruncate()
Thomas Munro <thomas.munro@gmail.com>
From: Thomas Munro <thomas.munro@gmail.com>
To: Andres Freund <andres@anarazel.de>
Cc: Alvaro Herrera <alvherre@alvh.no-ip.org>, Pg Hackers <pgsql-hackers@lists.postgresql.org>
Date: 2022-07-06T20:56:33Z
Lists: pgsql-hackers
On Thu, Jul 7, 2022 at 8:39 AM Andres Freund <andres@anarazel.de> wrote: > On 2022-07-06 21:29:41 +0200, Alvaro Herrera wrote: > > On 2022-Jul-05, Andres Freund wrote: > > > > > I think we'd be better off disabling at least some signals during > > > dsm_impl_posix_resize(). I'm afraid we'll otherwise just find another > > > variation of these problems. I haven't checked the source of ftruncate, but > > > what Thomas dug up for fallocate makes it pretty clear that our current > > > approach of just retrying again and again isn't good enough. It's a bit more > > > obvious that it's a problem for fallocate, but I don't think it's worth having > > > different solutions for the two. > > > > So what if we move the retry loop one level up? As in the attached. > > Here, if we get EINTR then we retry both syscalls. > > Doesn't really seem to address the problem to me. posix_fallocate() > takes some time (~1s for 3GB roughly), so if we signal at a higher rate, > we'll just get stuck. > > I hacked a bit on a test program from Thomas, and it's pretty clearly > that with a 5ms timer interval you'll pretty much not make > progress. It's much easier to get fallocate() to get interrupted than > ftruncate(), but the latter gets interrupted e.g. when you do a strace > in the "wrong" moment (afaics SIGSTOP/SIGCONT trigger EINTR in > situations that are retried otherwise). > > So I think we need: 1) block most signals, 2) a retry loop *without* > interrupt checks. Yeah. I was also wondering about wrapping the whole function in PG_SETMASK(&BlockSig), PG_SETMASK(&UnBlockSig), but also leaving the while (rc == EINTR) loop there (without the check for *Pending variables), only because otherwise when you attach a debugger and continue you'll get a spurious EINTR and it'll interfere with program execution. All blockable signals would be blocked *except* SIGQUIT, which means that fast shutdown/crash will still work. It seems nice to leave that way to interrupt it without resorting to SIGKILL.
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