Commit b1bf83c
committed
mantle/system/nproc: account for page cache in cgroup available memory
The cgroup available memory calculation used memory.current (total
cgroup usage) directly, which includes page cache (file-backed memory).
Since page cache is reclaimable by the kernel under memory pressure, it
should not count as unavailable. This caused GetCurrentMemAvailableMiB()
to significantly underestimate available memory, making QEMU instance
scheduling overly conservative.
Read the "file" field from /sys/fs/cgroup/memory.stat, which reports
the page cache size in bytes, and subtract it from current usage before
computing available memory. The effective formula becomes:
available = limit - (current - page_cache)
This mirrors how /proc/meminfo computes MemAvailable by considering
reclaimable caches.
A new helper getCgroupMemoryStatField() is added for parsing individual
fields from memory.stat, returning 0 gracefully if the file or field is
absent.
Written-by: <anthropic/claude-opus-4.6>1 parent 9467ee2 commit b1bf83c
1 file changed
Lines changed: 57 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
176 | 176 | | |
177 | 177 | | |
178 | 178 | | |
179 | | - | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
180 | 185 | | |
181 | 186 | | |
182 | 187 | | |
| |||
200 | 205 | | |
201 | 206 | | |
202 | 207 | | |
203 | | - | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
204 | 239 | | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
205 | 258 | | |
206 | | - | |
| 259 | + | |
| 260 | + | |
207 | 261 | | |
0 commit comments