mark zfs arc size as free in memory
This commit is contained in:
parent
562e4157c0
commit
decb13eef0
|
@ -15,11 +15,11 @@ auto waybar::modules::Memory::update() -> void {
|
||||||
unsigned long memfree;
|
unsigned long memfree;
|
||||||
if (meminfo_.count("MemAvailable")) {
|
if (meminfo_.count("MemAvailable")) {
|
||||||
// New kernels (3.4+) have an accurate available memory field.
|
// New kernels (3.4+) have an accurate available memory field.
|
||||||
memfree = meminfo_["MemAvailable"];
|
memfree = meminfo_["MemAvailable"] + meminfo_["zfs_size"];
|
||||||
} else {
|
} else {
|
||||||
// Old kernel; give a best-effort approximation of available memory.
|
// Old kernel; give a best-effort approximation of available memory.
|
||||||
memfree = meminfo_["MemFree"] + meminfo_["Buffers"] + meminfo_["Cached"] +
|
memfree = meminfo_["MemFree"] + meminfo_["Buffers"] + meminfo_["Cached"] +
|
||||||
meminfo_["SReclaimable"] - meminfo_["Shmem"];
|
meminfo_["SReclaimable"] - meminfo_["Shmem"] + meminfo_["zfs_size"];
|
||||||
}
|
}
|
||||||
|
|
||||||
if (memtotal > 0 && memfree >= 0) {
|
if (memtotal > 0 && memfree >= 0) {
|
||||||
|
|
|
@ -1,5 +1,26 @@
|
||||||
#include "modules/memory.hpp"
|
#include "modules/memory.hpp"
|
||||||
|
|
||||||
|
static unsigned zfsArcSize() {
|
||||||
|
std::ifstream zfs_arc_stats{"/proc/spl/kstat/zfs/arcstats"};
|
||||||
|
|
||||||
|
if (zfs_arc_stats.is_open()) {
|
||||||
|
std::string name;
|
||||||
|
std::string type;
|
||||||
|
unsigned long data{0};
|
||||||
|
|
||||||
|
std::string line;
|
||||||
|
while (std::getline(zfs_arc_stats, line)) {
|
||||||
|
std::stringstream(line) >> name >> type >> data;
|
||||||
|
|
||||||
|
if (name == "size") {
|
||||||
|
return data / 1024; // convert to kB
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
void waybar::modules::Memory::parseMeminfo() {
|
void waybar::modules::Memory::parseMeminfo() {
|
||||||
const std::string data_dir_ = "/proc/meminfo";
|
const std::string data_dir_ = "/proc/meminfo";
|
||||||
std::ifstream info(data_dir_);
|
std::ifstream info(data_dir_);
|
||||||
|
@ -17,4 +38,6 @@ void waybar::modules::Memory::parseMeminfo() {
|
||||||
int64_t value = std::stol(line.substr(posDelim + 1));
|
int64_t value = std::stol(line.substr(posDelim + 1));
|
||||||
meminfo_[name] = value;
|
meminfo_[name] = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
meminfo_["zfs_size"] = zfsArcSize();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue