summaryrefslogtreecommitdiff
path: root/src/server.c
diff options
context:
space:
mode:
authorOran Agra <oran@redislabs.com>2023-01-10 08:40:40 +0200
committerGitHub <noreply@github.com>2023-01-10 08:40:40 +0200
commit2bec254d89ff9266b2e688b15e34a3498da7c92c (patch)
treefdd239369e4e847693c9e43459a252e52b8d88e2 /src/server.c
parenteef29b68a2cd94de1f03aa1b7891af75f5cabae2 (diff)
downloadredis-2bec254d89ff9266b2e688b15e34a3498da7c92c.tar.gz
Make sure that fork child doesn't do incremental rehashing (#11692)
Turns out that a fork child calling getExpire while persisting keys (and possibly also a result of some module fork tasks) could cause dictFind to do incremental rehashing in the child process, which is both a waste of time, and also causes COW harm.
Diffstat (limited to 'src/server.c')
-rw-r--r--src/server.c11
1 files changed, 7 insertions, 4 deletions
diff --git a/src/server.c b/src/server.c
index f01e7382d..ae83ec25c 100644
--- a/src/server.c
+++ b/src/server.c
@@ -622,13 +622,15 @@ int incrementallyRehash(int dbid) {
* as we want to avoid resizing the hash tables when there is a child in order
* to play well with copy-on-write (otherwise when a resize happens lots of
* memory pages are copied). The goal of this function is to update the ability
- * for dict.c to resize the hash tables accordingly to the fact we have an
+ * for dict.c to resize or rehash the tables accordingly to the fact we have an
* active fork child running. */
void updateDictResizePolicy(void) {
- if (!hasActiveChildProcess())
- dictEnableResize();
+ if (server.in_fork_child != CHILD_TYPE_NONE)
+ dictSetResizeEnabled(DICT_RESIZE_FORBID);
+ else if (hasActiveChildProcess())
+ dictSetResizeEnabled(DICT_RESIZE_AVOID);
else
- dictDisableResize();
+ dictSetResizeEnabled(DICT_RESIZE_ENABLE);
}
const char *strChildType(int type) {
@@ -6496,6 +6498,7 @@ int redisFork(int purpose) {
server.in_fork_child = purpose;
setupChildSignalHandlers();
setOOMScoreAdj(CONFIG_OOM_BGCHILD);
+ updateDictResizePolicy();
dismissMemoryInChild();
closeChildUnusedResourceAfterFork();
/* Close the reading part, so that if the parent crashes, the child will