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.
- 45
- 2
- 5
1 Answers
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):
root@s15:/home/doug/temp-k-git/linux# sync
root@s15:/home/doug/temp-k-git/linux# echo 3 > /proc/sys/vm/drop_caches
root@s15:/home/doug/temp-k-git/linux# free -m
total used free shared buff/cache available
Mem: 15719 88 15472 1 159 15343
Swap: 16085 35 16050
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:
root@s15:/home/doug/temp-k-git/linux# echo 1835000 > /sys/kernel/debug/tracing/buffer_size_kb
And check it:
root@s15:/home/doug/temp-k-git/linux# free -m
total used free shared buff/cache available
Mem: 15719 14476 858 1 385 730
Swap: 16085 35 16050
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):
root@s15:/home/doug/temp-k-git/linux# echo 1 > /sys/kernel/debug/tracing/buffer_size_kb
And check it:
root@s15:/home/doug/temp-k-git/linux# free -m
total used free shared buff/cache available
Mem: 15719 88 15470 1 160 15342
Swap: 16085 35 16050
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.
- 16,146