At some point (https://bugs.webkit.org/show_bug.cgi?id=209186) the systemMemoryUsedAsPercentage() function of MemoryPressureMonitor was extended (WebKit/WebKit@c6a6f7b) to account for cgroup-based measurements so that WK processes associated to a cgroup with memory controller or ran inside the container are calculating the "sandbox" memory usage more precisely.
The above change works well when swap memory is not used, but it struggles when it's enabled.
Let's imagine the following scenario:
- WK processes are being run within container (hence associated to a cgroup with memory controller)
- memory limit is 400M (visible in
memory.limit_in_bytes)
- memory limit including swap is 600M (visible in
memory.memsw.limit_in_bytes)
- memory usage at the moment is 400M (visible in
memory.usage_in_bytes)
- memory usage including swap is 600M (visible in
memory.memsw.usage_in_bytes) because 200M is swapped out at the moment.
The problem with the above is - the current implementation will report 66.66% (400M/600M) memory usage because it does not use the memory.memsw.usage_in_bytes file at all. In other words - when calculating the percentage, the implementation accounts for swap memory in the denominator while it does not in the numerator.
In my opinion the above can be fixed two ways:
- By not using any
*.memsw.* files
- By accounting for swap memory properly i.e. reading
memory.memsw.usage_in_bytes for calculating current usage
- By using
memory.memsw.usage_in_bytes for calculating current usage while not using memory.memsw.limit_in_bytes for calculating overall limit (usage >100% would be allowed then)
I'm not sure what scenarios the author (Pablo Saavedra from Igalia) had in mind but in my opinion, the option (3) would be the best in practice as having anything swapped usually means severe performance degradation therefore there's no point delaying any memory pressure events in case we still have some swap space left.
@pgorszkowski-igalia could you please loop Pablo in?
At some point (https://bugs.webkit.org/show_bug.cgi?id=209186) the
systemMemoryUsedAsPercentage()function ofMemoryPressureMonitorwas extended (WebKit/WebKit@c6a6f7b) to account for cgroup-based measurements so that WK processes associated to a cgroup with memory controller or ran inside the container are calculating the "sandbox" memory usage more precisely.The above change works well when swap memory is not used, but it struggles when it's enabled.
Let's imagine the following scenario:
memory.limit_in_bytes)memory.memsw.limit_in_bytes)memory.usage_in_bytes)memory.memsw.usage_in_bytes) because 200M is swapped out at the moment.The problem with the above is - the current implementation will report
66.66% (400M/600M)memory usage because it does not use thememory.memsw.usage_in_bytesfile at all. In other words - when calculating the percentage, the implementation accounts for swap memory in the denominator while it does not in the numerator.In my opinion the above can be fixed two ways:
*.memsw.*filesmemory.memsw.usage_in_bytesfor calculating current usagememory.memsw.usage_in_bytesfor calculating current usage while not usingmemory.memsw.limit_in_bytesfor calculating overall limit (usage >100% would be allowed then)I'm not sure what scenarios the author (Pablo Saavedra from Igalia) had in mind but in my opinion, the option (3) would be the best in practice as having anything swapped usually means severe performance degradation therefore there's no point delaying any memory pressure events in case we still have some swap space left.
@pgorszkowski-igalia could you please loop Pablo in?