Repository: GuillaumeGomez/sysinfo (language: rust)

Issue:
Free memory is wrong on Linux with gcroups v2
system: Linux container based on `debian:bookworm-slim`
sysinfo version: 0.30.6

The actual `cgroup` v2 readings deduct all the values in `/sys/fs/cgroup/memory.stat` from available memory in these lines https://github.com/GuillaumeGomez/sysinfo/blob/master/src/unix/linux/system.rs#L560-L562

This is causing wrong reporting on the available memory, as `memory.stat` includes values already counted in `memory.current`, plus values which are not inherent to available memory, eg:

```
root@testpod:/work# cat /sys/fs/cgroup/memory.max
7864320000
root@testpod:/work# cat /sys/fs/cgroup/memory.current
2481475584
root@testpod:/work# cat /sys/fs/cgroup/memory.stat
anon 2472849408
file 57344
kernel_stack 458752
pagetables 7061504
percpu 0
sock 4096
shmem 0
file_mapped 0
file_dirty 0
file_writeback 0
swapcached 0
anon_thp 0
file_thp 0
shmem_thp 0
inactive_anon 2472730624
active_anon 12288
inactive_file 4096
active_file 53248
unevictable 0
slab_reclaimable 371120
slab_unreclaimable 435552
slab 806672
workingset_refault_anon 0
workingset_refault_file 0
workingset_activate_anon 0
workingset_activate_file 0
workingset_restore_anon 0
workingset_restore_file 0
workingset_nodereclaim 0
pgfault 2503991
pgmajfault 0
pgrefill 0
pgscan 0
pgsteal 0
pgactivate 3
pgdeactivate 0
pglazyfree 0
pglazyfreed 0
thp_fault_alloc 0
thp_collapse_alloc 0
```

The free memory reported by sysinfo in this case is 425495718 which is clearly wrong.
I'm not sure why all `memory.stat` contents gets subtracted from the available memory.


Discussion / hints:

Fix patch:
diff --git a/src/unix/linux/system.rs b/src/unix/linux/system.rs
index 734e64547..61ed815e1 100644
--- a/src/unix/linux/system.rs
+++ b/src/unix/linux/system.rs
@@ -557,10 +557,6 @@ impl crate::CGroupLimits {
                 limits.free_swap = sys.swap_total.saturating_sub(swap_cur);
             }
 
-            read_table("/sys/fs/cgroup/memory.stat", ' ', |_key, value| {
-                limits.free_memory = limits.free_memory.saturating_sub(value);
-            });
-
             Some(limits)
         } else if let (Some(mem_cur), Some(mem_max)) = (
             // cgroups v1


Test patch: