diff options
author | zhenwei pi <pizhenwei@bytedance.com> | 2020-10-27 21:04:18 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-10-27 15:04:18 +0200 |
commit | a9c06021498444b8d785066a2fae7d49693721dc (patch) | |
tree | 6c866042c5d85a0355b06c76a0c0d74369ac5382 /src/latency.c | |
parent | 825fe7bd23051d804ebbe2f4be5ad67a7e4769bb (diff) | |
download | redis-a9c06021498444b8d785066a2fae7d49693721dc.tar.gz |
Disable THP if enabled (#7381)
In case redis starts and find that THP is enabled ("always"), instead
of printing a log message, which might go unnoticed, redis will try to
disable it (just for the redis process).
Note: it looks like on self-bulit kernels THP is likely be set to "always" by default.
Some discuss about THP side effect on Linux:
according to http://www.antirez.com/news/84, we can see that
redis latency spikes are caused by linux kernel THP feature.
I have tested on E3-2650 v3, and found that 2M huge page costs
about 0.25ms to fix COW page fault.
Add a new config 'disable-thp', the recommended setting is 'yes',
(default) the redis tries to disable THP by prctl syscall. But
users who really want THP can set it to "no"
Thanks to Oran & Yossi for suggestions.
Signed-off-by: zhenwei pi <pizhenwei@bytedance.com>
Diffstat (limited to 'src/latency.c')
-rw-r--r-- | src/latency.c | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/src/latency.c b/src/latency.c index 6148543c8..c661c5d6d 100644 --- a/src/latency.c +++ b/src/latency.c @@ -59,6 +59,7 @@ dictType latencyTimeSeriesDictType = { /* ------------------------- Utility functions ------------------------------ */ #ifdef __linux__ +#include <sys/prctl.h> /* Returns 1 if Transparent Huge Pages support is enabled in the kernel. * Otherwise (or if we are unable to check) 0 is returned. */ int THPIsEnabled(void) { @@ -73,6 +74,21 @@ int THPIsEnabled(void) { fclose(fp); return (strstr(buf,"[always]") != NULL) ? 1 : 0; } + +/* since linux-3.5, kernel supports to set the state of the "THP disable" flag + * for the calling thread. PR_SET_THP_DISABLE is defined in linux/prctl.h */ +int THPDisable(void) { + int ret = -EINVAL; + + if (!server.disable_thp) + return ret; + +#ifdef PR_SET_THP_DISABLE + ret = prctl(PR_SET_THP_DISABLE, 1, 0, 0, 0); +#endif + + return ret; +} #endif /* Report the amount of AnonHugePages in smap, in bytes. If the return |