How to check Swap file usage in Linux
February 21, 2022
The swap file will be used when the physical memory runs out. In order to check the operation of the Swap file, you need to artificially use up all the RAM. You don’t need to run many applications and open dozens of tabs in your web browser to do this, instead you can use stress testing tools like stress-ng.
See also:
- How to create or enlarge a Swap file in Kali Linux
- What happens if Linux runs out of RAM. Do I need a Swap file
Install stress-ng
To install stress-ng on Debian, Kali Linux, Linux Mint, Ubuntu and their derivatives, run the command:
sudo apt install stress-ng
To install stress-ng on Arch Linux, Manjaro, BlackArch and their derivatives, install pikaur and then run the command:
pikaur -S stress-ng
How to fill 110% of the free memory
An example of a command that will consume 10% more RAM than system has free RAM:
stress-ng --vm-bytes $(awk '/MemAvailable/{printf "%d\n", $2 * 1.1;}' < /proc/meminfo)k --vm-keep -m 1
After that, watch the memory consumption – you will see how the Swap file starts to be used.
On the command line, Swap file usage can be checked with the command:
swapon --show
Related articles:
- Dynamic swap files are created only when needed (100%)
- Swap file and swap partition in Arch Linux (BlackArch): what to choose and how to add Swap (72%)
- How to increase the swap partition in Linux Mint and Ubuntu. How to create a Swap file in Linux (72%)
- What happens if Linux runs out of RAM. Do I need a Swap file (58.8%)
- What is the difference between Suspend and Hibernate in Linux. Why is the Hibernation button missing? (58.8%)
- How to protect my website from bots (RANDOM - 50%)