From 2bec254d89ff9266b2e688b15e34a3498da7c92c Mon Sep 17 00:00:00 2001 From: Oran Agra Date: Tue, 10 Jan 2023 08:40:40 +0200 Subject: 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. --- src/server.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'src/server.c') 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 -- cgit v1.2.1