I want to stress memory for certain time duration. I am checking memory usage with vmstat -s
and using tail /dev/zero
command but tail /dev/zero
times out in about 60s and it fills out memory randomly. I want to have available free memory 5% for 180 seconds.
One could use the kernel trace buffer as a way to reduce available memory left for the system and/or user. Example, using my system with 16 gigabytes and 8 CPUs:
First flush memory, giving our starting point (note that I am running as root):
Now, calculate and allocate the memory to the kernel trace buffer: 5% of 15719 megabytyes is 786 megabytes. Starting from 15472 megabytyes, Then 14686 megabyytes need to be used. The kernel trace buffer is per CPU, in my case 8 CPUs, so 1835 megabytes per CPU. Allocate:
And check it:
You can observe that it resulted in 5.46% of memory still available (tweek the allocation, if needed). Once you have done whatever testing, then you can de-allocate the kernel trace buffer with (0 does not work):
And check it:
If you want the time to be 180 seconds, then bundle up the above into a script with a 180 second sleep time. However, you will still have to check the available number as your starting point.