by hnechochamber2 · 4y ago · 0 comments
$ dd if=/dev/zero of=/swapfile bs=1G count=250 status=progress
$ chmod 600 /swapfile
$ mkswap -U clear /swapfile
$ swapon /swapfile $ ( umask 077; dd if=/dev/zero of=/swapfile bs=1G count=250 status=progress )
$ mkswap /swapfile
$ swapon /swapfileIt's simply because it's an easy way to create a file of a certain size that most Linux users would be familiar with.
The quicker way (and possibly more "proper" way) is to use fallocate, but who has even heard of that vs dd ?
You're also likely to get less write amplification if your swap file is continuous.
Of course with all the layers of indirection it's a numbers game, you don't know if your file system allocates adjacent inodes, and you don't know how your SSD will remap the blocks. But all else being equal, trying to make the file as sequential as possible seems preferable.