diff options
author | Ivan Shapovalov <intelfx@intelfx.name> | 2022-12-27 05:16:54 +0400 |
---|---|---|
committer | BenBE <BenBE@geshi.org> | 2023-04-23 16:00:17 +0200 |
commit | 71f5a80d9e312375eff28d2fbb7d8add81f6793c (patch) | |
tree | 94fff570e9f040d961a46059d6155b4abff865b6 /linux/LinuxProcessList.c | |
parent | 0c8df5f9939cfed393a3740a77ef588ad636bb87 (diff) |
Linux: implement zswap support
On Linux, use zswap to populate "compressed memory" metrics added in the
previous commit.
Fixes #104.
Diffstat (limited to 'linux/LinuxProcessList.c')
-rw-r--r-- | linux/LinuxProcessList.c | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/linux/LinuxProcessList.c b/linux/LinuxProcessList.c index a3472c53..2ecdefc3 100644 --- a/linux/LinuxProcessList.c +++ b/linux/LinuxProcessList.c @@ -1733,6 +1733,7 @@ errorReadingProcess: } static inline void LinuxProcessList_scanMemoryInfo(ProcessList* this) { + LinuxProcessList *lpl = (LinuxProcessList *)this; memory_t availableMem = 0; memory_t freeMem = 0; memory_t totalMem = 0; @@ -1743,6 +1744,8 @@ static inline void LinuxProcessList_scanMemoryInfo(ProcessList* this) { memory_t swapCacheMem = 0; memory_t swapFreeMem = 0; memory_t sreclaimableMem = 0; + memory_t zswapCompMem = 0; + memory_t zswapOrigMem = 0; FILE* file = fopen(PROCMEMINFOFILE, "r"); if (!file) @@ -1787,6 +1790,10 @@ static inline void LinuxProcessList_scanMemoryInfo(ProcessList* this) { break; } break; + case 'Z': + tryRead("Zswap:", zswapCompMem); + tryRead("Zswapped:", zswapOrigMem); + break; } #undef tryRead @@ -1812,6 +1819,8 @@ static inline void LinuxProcessList_scanMemoryInfo(ProcessList* this) { this->totalSwap = swapTotalMem; this->usedSwap = swapTotalMem - swapFreeMem - swapCacheMem; this->cachedSwap = swapCacheMem; + lpl->zswap.usedZswapComp = zswapCompMem; + lpl->zswap.usedZswapOrig = zswapOrigMem; } static void LinuxProcessList_scanHugePages(LinuxProcessList* this) { @@ -1870,6 +1879,24 @@ static void LinuxProcessList_scanHugePages(LinuxProcessList* this) { closedir(dir); } +static inline void LinuxProcessList_scanZswapInfo(LinuxProcessList *this) { + long max_pool_percent = 0; + int r; + char buf[256]; + + r = xReadfile("/sys/module/zswap/parameters/max_pool_percent", buf, 256); + if (r <= 0) { + return; + } + max_pool_percent = strtol(buf, NULL, 10); + if (max_pool_percent < 0 || max_pool_percent > 100) { + return; + } + + this->zswap.totalZswapPool = this->super.totalMem * max_pool_percent / 100; + /* the rest of the metrics are set in LinuxProcessList_scanMemoryInfo() */ +} + static inline void LinuxProcessList_scanZramInfo(LinuxProcessList* this) { memory_t totalZram = 0; memory_t usedZramComp = 0; @@ -2222,6 +2249,7 @@ void ProcessList_goThroughEntries(ProcessList* super, bool pauseProcessUpdate) { LinuxProcessList_scanHugePages(this); LinuxProcessList_scanZfsArcstats(this); LinuxProcessList_scanZramInfo(this); + LinuxProcessList_scanZswapInfo(this); double period = LinuxProcessList_scanCPUTime(super); |