diff options
author | antirez <antirez@gmail.com> | 2014-11-12 10:43:32 +0100 |
---|---|---|
committer | antirez <antirez@gmail.com> | 2014-11-12 10:43:32 +0100 |
commit | 3ef0876b95a6ff342bc348f5603ae282265f0ca1 (patch) | |
tree | ad38f64bfecc6f4ede1fb48a24b4c16ab37e1640 /src/latency.c | |
parent | bb7fea0d5ca7b3a53532338e8654e409014c1194 (diff) | |
download | redis-3ef0876b95a6ff342bc348f5603ae282265f0ca1.tar.gz |
THP detection / reporting functions added.
Diffstat (limited to 'src/latency.c')
-rw-r--r-- | src/latency.c | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/src/latency.c b/src/latency.c index b7845ca29..2e239571a 100644 --- a/src/latency.c +++ b/src/latency.c @@ -56,6 +56,32 @@ dictType latencyTimeSeriesDictType = { dictVanillaFree /* val destructor */ }; +/* ------------------------- Utility functions ------------------------------ */ + +#ifdef __linux__ +/* 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) { + char buf[1024]; + + FILE *fp = fopen("/sys/kernel/mm/transparent_hugepage/enabled","r"); + if (!fp) return 0; + if (fgets(buf,sizeof(buf),fp) == NULL) { + fclose(fp); + return 0; + } + fclose(fp); + return (strstr(buf,"[never]") == NULL) ? 1 : 0; +} + +/* Report the amount of AnonHugePages in smap, in bytes. If the return + * value of the function is non-zero, the process is being targeted by + * THP support, and is likely to have memory usage / latency issues. */ +int THPGetAnonHugePagesSize(void) { + return zmalloc_get_smap_bytes_by_field("AnonHugePages:"); +} +#endif + /* ---------------------------- Latency API --------------------------------- */ /* Latency monitor initialization. We just need to create the dictionary |