3

A team member has created a swapfile on one of our machines which needed more swap. And he created it on a filesystem on SSD. While our servers are not swapping a lot and probably safe to keep the swap file on the SSD with its finite write-cycles, I am curious to know what happens if SWAP partition fails on a server that is using the swap (say the SWAP drive died).

  • Is a SWAP partition failure on a running machine catastrophic? Or it will be treated just like someone had issued a swapoff -a albeit without all the flushing of buffers and cache.

  • I am assuming that the program that has its pages on SWAP may crash.

  • If I am to reboot a machine with a failed SWAP, would commenting out the swap entries in fstab would suffice to prevent being stuck at boot? Can I just add a new swap partition and update the fstab entries and it will reboot as if nothing had happend?

4

I'm assuming you're using linux here, partly because of the mention of swapoff -a but it's advisable to be explicit about this, either in the text of your question and/or via tags.

A swap failure will generate a memory fault in the process that had its memory paged out to the swap device, i.e. that process will be killed.

Rebooting a system with a failed swap device will simply give an error when the swapon is executed but the system will continue on without that swap device. You can then use another swap device either directly with swapon /dev/whatever and/or edit /etc/fstab and reboot and/or swapon -a.

Note you can also use a file as swap device:

# create a large enough file (1GB here)
dd if=/dev/zero of=/var/SWAPFILE bs=1024k count=1024
# write swap signature to the file so that the kernel recognizes it
mkswap /var/SWAPFILE
# activate it
swapon /var/SWAPFILE
| improve this answer | |

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.