fallocate -l 4G /swapfile
chmod 600 /swapfile
mkswap /swapfile
swapon /swapfile
swapon: /swapfile: swapon failed: Invalid argument
echo “/swapfile swap swap sw 0 0” >> /etc/fstab
echo “vm.swappiness = 10” >>/etc/sysctl.conf
echo “vm.vfs_cache_pressure = 50” >> /etc/sysctl.conf
The problem with fallocate(1) is that it uses filesystem ioctls to make the allocation fast and effective, the disadvantage is that it does not physically allocate the space but swapon(2) syscall requires a real space. Reference : https://bugzilla.redhat.com/show_bug.cgi?id=1129205
I had faced this issue earlier with my box too. So instead of using fallocate, I had used dd as per the link suggests
sudo dd if=/dev/zero of=/swapfile count=4096 bs=1MiB
Recent Comments