Minimal test case when Linux system does not have swap (or run sudo swapoff -a
before testing). Run following bash one-liner as normal user:
while true; do date; nice -20 stress --vm-bytes $(awk '/MemAvailable/{printf "%d\n", $2 + 4000;}' < /proc/meminfo)k --vm-keep -m 1 --timeout 10s; sleep 5s; done
and run following bash one-liner with high priority root shell (e.g. sudo nice -n -19 bash
):
while true; do NS=$(date '+%N' | sed 's/^0*//'); let "S=998000000 - $NS"; S=$(( S > 0 ? S : 0)); LC_ALL=C sleep "0.$S"; date --iso=ns; done
The high priority process is supposed to run date
every second as accurately as possible. However, even if this process is running with priority -19
, the background process running on priority 20
is able to cause major delays. It seems that there's no limit for the latency induced by the low priority background process because higher delays can be activated by increasing the stress --timeout
value.
Is there a way to limit maximum latency and automatically kill the stress
if needed to accomplish that? Increasing /proc/sys/vm/user_reserve_kbytes
or /proc/sys/vm/admin_reserve_kbytes
or /proc/sys/vm/min_free_kbytes
does not seem to help.
date
. As far as I can see it, the problem is memory starvation, not CPU starvation. – Mikko Rantalainen Feb 10 '18 at 19:15