Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commite086b55

Browse files
committed
Don't trust signalfd() on illumos.
Since commit6a2a70a, we've used signalfd() to receive latch wakeupswhen building with WAIT_USE_EPOLL (default for Linux and illumos), andour traditional self-pipe when falling back to WAIT_USE_POLL (defaultfor other Unixes with neither epoll() nor kqueue()).Unexplained hangs and kernel panics have been reported on illumossystems, apparently linked to this use of signalfd(), leading illumosusers and build farm members to have to define WAIT_USE_POLL explicitlyas a work-around. A bug report exists athttps://www.illumos.org/issues/13700 but no fix is available yet.Let's provide a way for illumos users to go back to self-pipes withepoll(), like releases before 14, and choose that by default. No changefor Linux users. To help with development/debugging, macrosWAIT_USE_{EPOLL,POLL} and WAIT_USE_{SIGNALFD,SELF_PIPE} can be definedexplicitly to override the defaults.Back-patch to 14, where we started using signalfd().Reported-by: Japin Li <japinli@hotmail.com>Reported-by: Olaf Bohlen <olbohlen@eenfach.de> (off-list)Reviewed-by: Japin Li <japinli@hotmail.com>Discussion:https://postgr.es/m/MEYP282MB1669C8D88F0997354C2313C1B6CA9%40MEYP282MB1669.AUSP282.PROD.OUTLOOK.COM
1 parent4b0d21b commite086b55

File tree

1 file changed

+40
-18
lines changed

1 file changed

+40
-18
lines changed

‎src/backend/storage/ipc/latch.c

Lines changed: 40 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@
7272
#if defined(WAIT_USE_EPOLL)|| defined(WAIT_USE_POLL)|| \
7373
defined(WAIT_USE_KQUEUE)|| defined(WAIT_USE_WIN32)
7474
/* don't overwrite manual choice */
75-
#elif defined(HAVE_SYS_EPOLL_H)&& defined(HAVE_SYS_SIGNALFD_H)
75+
#elif defined(HAVE_SYS_EPOLL_H)
7676
#defineWAIT_USE_EPOLL
7777
#elif defined(HAVE_KQUEUE)
7878
#defineWAIT_USE_KQUEUE
@@ -84,6 +84,22 @@
8484
#error "no wait set implementation available"
8585
#endif
8686

87+
/*
88+
* By default, we use a self-pipe with poll() and a signalfd with epoll(), if
89+
* available. We avoid signalfd on illumos for now based on problem reports.
90+
* For testing the choice can also be manually specified.
91+
*/
92+
#if defined(WAIT_USE_POLL)|| defined(WAIT_USE_EPOLL)
93+
#if defined(WAIT_USE_SELF_PIPE)|| defined(WAIT_USE_SIGNALFD)
94+
/* don't overwrite manual choice */
95+
#elif defined(WAIT_USE_EPOLL)&& defined(HAVE_SYS_SIGNALFD_H)&& \
96+
!defined(__illumos__)
97+
#defineWAIT_USE_SIGNALFD
98+
#else
99+
#defineWAIT_USE_SELF_PIPE
100+
#endif
101+
#endif
102+
87103
/* typedef in latch.h */
88104
structWaitEventSet
89105
{
@@ -146,12 +162,12 @@ static WaitEventSet *LatchWaitSet;
146162
staticvolatilesig_atomic_twaiting= false;
147163
#endif
148164

149-
#ifdefWAIT_USE_EPOLL
165+
#ifdefWAIT_USE_SIGNALFD
150166
/* On Linux, we'll receive SIGURG via a signalfd file descriptor. */
151167
staticintsignal_fd=-1;
152168
#endif
153169

154-
#if defined(WAIT_USE_POLL)
170+
#ifdefWAIT_USE_SELF_PIPE
155171
/* Read and write ends of the self-pipe */
156172
staticintselfpipe_readfd=-1;
157173
staticintselfpipe_writefd=-1;
@@ -164,7 +180,7 @@ static void latch_sigurg_handler(SIGNAL_ARGS);
164180
staticvoidsendSelfPipeByte(void);
165181
#endif
166182

167-
#if defined(WAIT_USE_POLL)|| defined(WAIT_USE_EPOLL)
183+
#if defined(WAIT_USE_SELF_PIPE)|| defined(WAIT_USE_SIGNALFD)
168184
staticvoiddrain(void);
169185
#endif
170186

@@ -190,7 +206,7 @@ static inline int WaitEventSetWaitBlock(WaitEventSet *set, int cur_timeout,
190206
void
191207
InitializeLatchSupport(void)
192208
{
193-
#if defined(WAIT_USE_POLL)
209+
#if defined(WAIT_USE_SELF_PIPE)
194210
intpipefd[2];
195211

196212
if (IsUnderPostmaster)
@@ -264,7 +280,7 @@ InitializeLatchSupport(void)
264280
pqsignal(SIGURG,latch_sigurg_handler);
265281
#endif
266282

267-
#ifdefWAIT_USE_EPOLL
283+
#ifdefWAIT_USE_SIGNALFD
268284
sigset_tsignalfd_mask;
269285

270286
/* Block SIGURG, because we'll receive it through a signalfd. */
@@ -316,15 +332,15 @@ ShutdownLatchSupport(void)
316332
LatchWaitSet=NULL;
317333
}
318334

319-
#if defined(WAIT_USE_POLL)
335+
#if defined(WAIT_USE_SELF_PIPE)
320336
close(selfpipe_readfd);
321337
close(selfpipe_writefd);
322338
selfpipe_readfd=-1;
323339
selfpipe_writefd=-1;
324340
selfpipe_owner_pid=InvalidPid;
325341
#endif
326342

327-
#if defined(WAIT_USE_EPOLL)
343+
#if defined(WAIT_USE_SIGNALFD)
328344
close(signal_fd);
329345
signal_fd=-1;
330346
#endif
@@ -341,9 +357,12 @@ InitLatch(Latch *latch)
341357
latch->owner_pid=MyProcPid;
342358
latch->is_shared= false;
343359

344-
#if defined(WAIT_USE_POLL)
360+
#if defined(WAIT_USE_SELF_PIPE)
345361
/* Assert InitializeLatchSupport has been called in this process */
346362
Assert(selfpipe_readfd >=0&&selfpipe_owner_pid==MyProcPid);
363+
#elif defined(WAIT_USE_SIGNALFD)
364+
/* Assert InitializeLatchSupport has been called in this process */
365+
Assert(signal_fd >=0);
347366
#elif defined(WAIT_USE_WIN32)
348367
latch->event=CreateEvent(NULL, TRUE, FALSE,NULL);
349368
if (latch->event==NULL)
@@ -405,9 +424,12 @@ OwnLatch(Latch *latch)
405424
/* Sanity checks */
406425
Assert(latch->is_shared);
407426

408-
#if defined(WAIT_USE_POLL)
427+
#if defined(WAIT_USE_SELF_PIPE)
409428
/* Assert InitializeLatchSupport has been called in this process */
410429
Assert(selfpipe_readfd >=0&&selfpipe_owner_pid==MyProcPid);
430+
#elif defined(WAIT_USE_SIGNALFD)
431+
/* Assert InitializeLatchSupport has been called in this process */
432+
Assert(signal_fd >=0);
411433
#endif
412434

413435
if (latch->owner_pid!=0)
@@ -617,7 +639,7 @@ SetLatch(Latch *latch)
617639
return;
618640
elseif (owner_pid==MyProcPid)
619641
{
620-
#if defined(WAIT_USE_POLL)
642+
#if defined(WAIT_USE_SELF_PIPE)
621643
if (waiting)
622644
sendSelfPipeByte();
623645
#else
@@ -904,9 +926,9 @@ AddWaitEventToSet(WaitEventSet *set, uint32 events, pgsocket fd, Latch *latch,
904926
{
905927
set->latch=latch;
906928
set->latch_pos=event->pos;
907-
#if defined(WAIT_USE_POLL)
929+
#if defined(WAIT_USE_SELF_PIPE)
908930
event->fd=selfpipe_readfd;
909-
#elif defined(WAIT_USE_EPOLL)
931+
#elif defined(WAIT_USE_SIGNALFD)
910932
event->fd=signal_fd;
911933
#else
912934
event->fd=PGINVALID_SOCKET;
@@ -2023,7 +2045,7 @@ GetNumRegisteredWaitEvents(WaitEventSet *set)
20232045
returnset->nevents;
20242046
}
20252047

2026-
#if defined(WAIT_USE_POLL)
2048+
#if defined(WAIT_USE_SELF_PIPE)
20272049

20282050
/*
20292051
* SetLatch uses SIGURG to wake up the process waiting on the latch.
@@ -2074,7 +2096,7 @@ sendSelfPipeByte(void)
20742096

20752097
#endif
20762098

2077-
#if defined(WAIT_USE_POLL)|| defined(WAIT_USE_EPOLL)
2099+
#if defined(WAIT_USE_SELF_PIPE)|| defined(WAIT_USE_SIGNALFD)
20782100

20792101
/*
20802102
* Read all available data from self-pipe or signalfd.
@@ -2090,7 +2112,7 @@ drain(void)
20902112
intrc;
20912113
intfd;
20922114

2093-
#ifdefWAIT_USE_POLL
2115+
#ifdefWAIT_USE_SELF_PIPE
20942116
fd=selfpipe_readfd;
20952117
#else
20962118
fd=signal_fd;
@@ -2108,7 +2130,7 @@ drain(void)
21082130
else
21092131
{
21102132
waiting= false;
2111-
#ifdefWAIT_USE_POLL
2133+
#ifdefWAIT_USE_SELF_PIPE
21122134
elog(ERROR,"read() on self-pipe failed: %m");
21132135
#else
21142136
elog(ERROR,"read() on signalfd failed: %m");
@@ -2118,7 +2140,7 @@ drain(void)
21182140
elseif (rc==0)
21192141
{
21202142
waiting= false;
2121-
#ifdefWAIT_USE_POLL
2143+
#ifdefWAIT_USE_SELF_PIPE
21222144
elog(ERROR,"unexpected EOF on self-pipe");
21232145
#else
21242146
elog(ERROR,"unexpected EOF on signalfd");

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp