Centos – (CentOS) Adding swap file failed

centosswap

Im trying adding swap file by following this guide:
http://www.redhat.com/docs/manuals/linux/RHL-8.0-Manual/custom-guide/s1-swap-adding.html

Everything is fine, but starting swapon /swapfile, I got this message:
swapon: /swapfile: Operation not permitted

Use sudo swapon /swapfile also not works, and I got this message:
audit_log_user_command(): Connection refused
swapon: /swapfile: Operation not permitted

After reboot, I use the same command.. also not works

Best Answer

This sounds like you are on a virtualized host based on openvz.

The "audit_log_user_command" error is common from a few version of openvz/virtuozzo that didn't patch a kernel bug that echo'd that out to the screen.

In this case, you cannot create swap, you are only allocated a certain amount of system memory. After you exceed this, you will be unable to allocate memory and get OOM kills depending on how frequently you attempt to spawn new processes near the barrier.