Flushing the swap

I had a script which I was developing that ran away on the memory and the swap space ended up at 96% utilization instead of the normal 5-45% utilization.

I have now fixed the script but the swap space utilization still remains high in the red at 96%.

I know that on other Linux distros (including CentOS), I have successfully run the command swapoff -a && swapon -a to fix this situation; however in NethServer I get the error message “swapoff: /dev/mapper/VolGroup-lv_swap: swapoff failed: Cannot allocate memory”

Is there a quick and easy way to flush the swap space in NethServer without the need to restart the entire box?

Works in the same way as on CentOS. The problem you’re getting may be due to overcommited memory.

You can try dropping the cache (although not recommended in production).

To see information on current memory:
cat /proc/meminfo

To drop cache memory:
sync; echo 3 > /proc/sys/vm/drop_caches

You can try other (safer) values instead of 3:

The values for drop_caches:
1 invalidates and frees page cache.
2 frees unused slab cache.
3 frees page+slab cache.

After a minute or two you can check the memory freed an set drop_caches to defaults:
echo 0 > /proc/sys/vm/drop_caches