Skip to content
6 changes: 3 additions & 3 deletions dragonfly-client-util/src/ratelimiter/bbr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -384,14 +384,14 @@ impl OverloadCollector {
fn is_memory_overloaded(&self) -> bool {
let used_percent = if self.is_running_in_container {
match self.memory.get_cgroup_stats(self.pid) {
Some(stats) => (stats.used_percent * 100.0).round() as u8,
Some(stats) => stats.used_percent.round() as u8,
None => {
warn!("container detected but cgroup memory stats unavailable, falling back to process stats");
(self.memory.get_process_stats(self.pid).used_percent * 100.0).round() as u8
self.memory.get_process_stats(self.pid).used_percent.round() as u8
}
}
} else {
(self.memory.get_process_stats(self.pid).used_percent * 100.0).round() as u8
self.memory.get_process_stats(self.pid).used_percent.round() as u8
};

self.memory_used_percent
Expand Down
10 changes: 4 additions & 6 deletions dragonfly-client-util/src/sysinfo/memory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,25 +146,23 @@ impl Memory {
if let Some(memory_controller) = cgroup.controller_of::<MemController>() {
let memory_stats = memory_controller.memory_stat();
let used_percent = if memory_stats.limit_in_bytes > 0 {
(memory_stats.usage_in_bytes as f64
/ memory_stats.limit_in_bytes as f64)
(memory_stats.stat.rss as f64 / memory_stats.limit_in_bytes as f64)
* 100.0
} else {
(memory_stats.usage_in_bytes as f64 / self.get_stats().total as f64)
* 100.0
(memory_stats.stat.rss as f64 / self.get_stats().total as f64) * 100.0
};

debug!(
"process {} cgroup memory limit: {} bytes, memory usage: {} bytes, used percent: {}%",
pid,
memory_stats.limit_in_bytes,
memory_stats.usage_in_bytes,
memory_stats.stat.rss,
used_percent,
);

return Some(CgroupMemoryStats {
limit: memory_stats.limit_in_bytes,
usage: memory_stats.usage_in_bytes,
usage: memory_stats.stat.rss,
used_percent: used_percent.clamp(0.0, 100.0),
});
}
Expand Down
Loading