Commit 72a5b18
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 inactive 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 "inactive_file" field from /sys/fs/cgroup/memory.stat, which
reports the page cache size that can be reclaimed easily in bytes, and
subtract it from current usage before computing available memory. The
effective formula becomes:
available = limit - (current - inactive_file)
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 486c64b commit 72a5b18
1 file changed
Lines changed: 60 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 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
180 | 188 | | |
181 | 189 | | |
182 | 190 | | |
| |||
200 | 208 | | |
201 | 209 | | |
202 | 210 | | |
203 | | - | |
| 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 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
204 | 242 | | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
205 | 261 | | |
206 | | - | |
| 262 | + | |
| 263 | + | |
207 | 264 | | |
0 commit comments