Scale up as you grow — whether you're running one virtual machine or ten thousand.

From GPU-powered inference and Kubernetes to managed databases and storage, get everything you need to build, scale, and deploy intelligent applications.

This textbox defaults to using Markdown to format your answer.
You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!
Thank you for this tutorial.
When I try the $ sudo swapon /swapfile command I get the following error:
swapon: /swapfile: swapon failed: Invalid argument
Any ideas?
Erik
Nice tutorial!
Is 4GB too much for a swap? For what I can see, you are using the same number from your physical memory.
How about the recommendation to use half of your RAM for swap? Is it valid?
Cheers
Hi Josh, Thanks for this useful tutorial.
I’ve done all the steps and eveything seems to work fine. The only difference is that I got this warning message when doing
mkswap: /swapfile: warning: don’t erase bootbits sectors on whole disk. Use -f to force.
For those experiencing swapon failed: Invalid argument here is a workaround.
CentOS7 defaults to using XFS, which fallocate has issues with creating files without holes
The workaround is to use dd instead of falllocate, so the fallocate call above would be replaced with:
dd if=/dev/zero of=/swapfile count=4096 bs=1MiB
Thanks, this was very helpful. It was my guide for this Ansible Playbook. I hope it is useful for someone.
---
# need to be root
- debug: msg="{{ ansible_memtotal_mb }}M swapfile size"
- stat: path=/swapfile
register: swap
- debug: var=swap.stat.exists
- command: fallocate -l {{ ansible_memtotal_mb }}M /swapfile
when: swap.stat.exists == false
- file: path=/swapfile mode=0600
when: swap.stat.exists == false or (swap.stat.exists == true and swap.stat.mode != 0600)
- command: mkswap /swapfile
when: swap.stat.exists == false
- command: swapon /swapfile
when: swap.stat.exists == false
- lineinfile: dest=/etc/fstab
regexp='^/swapfile'
line='/swapfile none swap sw 0 0'
when: swap.stat.exists == false
- sysctl: name=vm.swappiness value=1 state=present
/swapfile swap swap sw 0 0
/swapfile none swap sw 0 0
/swapfile none swap defaults 0 0
Which of these is more accurate?
Thank you Josh for this nice tutorial. Worked as expected.
Btw, if I already have a swap file of 1GB and I needed more like 4GB what should I do ?
It is for another machine.
Thanks again.
I’m also getting swapon failed: Invalid argument with both sudo dd if=/dev/zero of=/swapfile count=4096 bs=1MiB and sudo fallocate -l 4G /swapfile I’m using CentOS 7, this question may explain the problem http://superuser.com/questions/539287/swapon-failed-invalid-argument-on-a-linux-system-with-btrfs-filesystem “Invalid argument” should be read as “Your filesystem do not support swap file”