Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit b5d0f8e

Browse files
committed
Allow parent's WaitEventSets to be freed after fork().
An epoll fd belonging to the parent should be closed in the child. A kqueue fd is automatically closed by fork(), but we should still adjust our counter. For poll and Windows systems, nothing special is required. On all systems we free the memory. No caller yet, but we'll need this if we start using WaitEventSet in the postmaster as planned. Reviewed-by: Andres Freund <andres@anarazel.de> Discussion: https://postgr.es/m/CA%2BhUKG%2BZ-HpOj1JsO9eWUP%2Bar7npSVinsC_npxSy%2BjdOMsx%3DGg%40mail.gmail.com
1 parent 1f0019d commit b5d0f8e

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

src/backend/storage/ipc/latch.c

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -869,6 +869,23 @@ FreeWaitEventSet(WaitEventSet *set)
869869
pfree(set);
870870
}
871871

872+
/*
873+
* Free a previously created WaitEventSet in a child process after a fork().
874+
*/
875+
void
876+
FreeWaitEventSetAfterFork(WaitEventSet *set)
877+
{
878+
#if defined(WAIT_USE_EPOLL)
879+
close(set->epoll_fd);
880+
ReleaseExternalFD();
881+
#elif defined(WAIT_USE_KQUEUE)
882+
/* kqueues are not normally inherited by child processes */
883+
ReleaseExternalFD();
884+
#endif
885+
886+
pfree(set);
887+
}
888+
872889
/* ---
873890
* Add an event to the set. Possible events are:
874891
* - WL_LATCH_SET: Wait for the latch to be set

src/include/storage/latch.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,7 @@ extern void ShutdownLatchSupport(void);
175175

176176
extern WaitEventSet *CreateWaitEventSet(MemoryContext context, int nevents);
177177
extern void FreeWaitEventSet(WaitEventSet *set);
178+
extern void FreeWaitEventSetAfterFork(WaitEventSet *set);
178179
extern int AddWaitEventToSet(WaitEventSet *set, uint32 events, pgsocket fd,
179180
Latch *latch, void *user_data);
180181
extern void ModifyWaitEvent(WaitEventSet *set, int pos, uint32 events, Latch *latch);

0 commit comments

Comments
 (0)