I ran swapon -s on a VPS that I’m using and discovered that there’s a swap partition pointing at /dev/null.

# swapon -s
Filename        Type        Size    Used    Priority
/dev/null       partition   262144  0       -1

Does this mean that there isn’t any actual swap, and that anything that’s swapped out will be lost? Is this better/worse than not having any swap at all?

The output of df -h:

# df -h
Filesystem         Size  Used Avail Use% Mounted on
/dev/ploop63064p1   20G  1.3G   18G   7% /
none               128M  4.0K  128M   1% /dev
none               4.0K     0  4.0K   0% /sys/fs/cgroup
none                26M   40K   26M   1% /run
none               5.0M     0  5.0M   0% /run/lock
none               128M     0  128M   0% /run/shm
none               100M     0  100M   0% /run/user

The output of cat /etc/fstab:

# cat /etc/fstab
proc  /proc       proc    defaults    0    0
none  /dev/pts    devpts  rw,gid=5,mode=620    0    0
none  /run/shm    tmpfs   defaults    0    0

The output of cat /proc/sys/vm/swappiness:

# cat /proc/sys/vm/swappiness
  • What is the output of df -h? Feb 5 '15 at 22:47
  • Edited question to include df -h output.
    – Alex Grin
    Feb 6 '15 at 1:04
  • Thanks. Helpful. What is the output of cat /proc/sys/vm/swappiness? Feb 6 '15 at 1:51
  • It's 60. I tried changing that but it looks like the VPS provider has that locked down.
    – Alex Grin
    Feb 6 '15 at 14:33

This could all boil down to some virtual hosting infrastructure environments simply not needing a swap file/partition setup at all. Why? I am unsure of how different virtual host infrastructure environments are setup to deal with “out of memory” conditions and paging; I imagine the host OS in some cases handles conditions like that in a more efficient way than the guest OS could on it’s own?

For example, looking at this post here as well as this post here it seems that Chef requires a swap file and setting it to /dev/null as a commonly accepted—yet kludgy—solution to effectively “neutralize” a swap file/partition setup for some virtual private server deployments.

Additionally, it seems like your systems “swapiness” would have to be set to 0 for a setup like this to work. You can confirm this by checking it via this command:

cat /proc/sys/vm/swappiness

As explained on this Wikipedia entry, “swapiness” can be set anywhere in the range of 0 to 100:

Swappiness can be set to values between 0 and 100 inclusive. A low value causes the kernel to avoid swapping, a higher value causes the kernel to try to use swap space. The default value is 60, and for most desktop systems, setting it to 100 may affect the overall performance, whereas setting it lower (even 0) may decrease response latency.

And common values presented are:

  • vm.swappiness = 0: The kernel will swap only to avoid an out of memory condition.
  • vm.swappiness = 60: The default value.
  • vm.swappiness = 100: The kernel will swap aggressively.

Which tells me that your VPS might have some system settings in place to avoid serious out of memory conditions caused by the loss swap. So my next suggestion would be to contact your VPS provider and ask for some clarification. To read up more on how one virtual hosting provider advises on how best to use a swap file/partition, check out this post from DigitalOcean.

  • I checked the swappiness and it's set to 60. I tried to change it, but I think the VPS provider is blocking that.
    – Alex Grin
    Feb 6 '15 at 14:35
  • @lyoshenka Well, I don’t think you need to change that. On my Amazon EC2 VPS, there is no swap file saved; the output of swapon -s is simply null. Meaning in some VPS environments, it seems you don’t need a swap. Why? Unclear. But I recommend you should contact your VPS support team to get clarification. Feb 8 '15 at 21:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.