Unverified Commit 1221f7cd authored by Yossi Gottlieb's avatar Yossi Gottlieb Committed by GitHub
Browse files

Improve setup operations order after fork. (#9365)

The order of setting things up follows some reasoning: Setup signal
handlers first because a signal could fire at any time. Adjust OOM score
before everything else to assist the OOM killer if memory resources are
low.

The trigger for this is a valgrind test failure which resulted with the
child catching a SIGUSR1 before initializing the handler.
parent 08c46f2b
...@@ -5845,7 +5845,6 @@ void setupChildSignalHandlers(void) { ...@@ -5845,7 +5845,6 @@ void setupChildSignalHandlers(void) {
act.sa_flags = 0; act.sa_flags = 0;
act.sa_handler = sigKillChildHandler; act.sa_handler = sigKillChildHandler;
sigaction(SIGUSR1, &act, NULL); sigaction(SIGUSR1, &act, NULL);
return;
} }
/* After fork, the child process will inherit the resources /* After fork, the child process will inherit the resources
...@@ -5875,11 +5874,17 @@ int redisFork(int purpose) { ...@@ -5875,11 +5874,17 @@ int redisFork(int purpose) {
int childpid; int childpid;
long long start = ustime(); long long start = ustime();
if ((childpid = fork()) == 0) { if ((childpid = fork()) == 0) {
/* Child */ /* Child.
*
* The order of setting things up follows some reasoning:
* Setup signal handlers first because a signal could fire at any time.
* Adjust OOM score before everything else to assist the OOM killer if
* memory resources are low.
*/
server.in_fork_child = purpose; server.in_fork_child = purpose;
dismissMemoryInChild();
setOOMScoreAdj(CONFIG_OOM_BGCHILD);
setupChildSignalHandlers(); setupChildSignalHandlers();
setOOMScoreAdj(CONFIG_OOM_BGCHILD);
dismissMemoryInChild();
closeChildUnusedResourceAfterFork(); closeChildUnusedResourceAfterFork();
} else { } else {
/* Parent */ /* Parent */
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment