How to configure swap space for your Azure Ubuntu VM

It's been a long time since I've played with Linux. So, I'm learning again. The old way was to create a swap file with dd and swapon. I came across a nice article today on the modern way to do it. (yes, I'm starting to feel old). Mostly, it's the same, but a few new ways of tuning things.

In case you are interested, the echo lines are so I can see what I'm about to add when editing. After I move to the right place in the file, I paste again. It's just my way. Also makes it easier to see what I did when I dump my history.

Here is my history on how to add a 250GB swap partition.

    sudo fallocate -l 250M /swapfile
    ls -l /swapfile
    sudo chmod 600 /swapfile
    sudo mkswap /swapfile
    sudo swapon /swapfile
    sudo swapon -s
    free -m
    echo /swapfile   none    swap    sw    0   0
    sudo -e /etc/fstab
    cat /proc/sys/vm/swappiness
    sudo sysctl vm.swappiness=10
    cat /proc/sys/vm/swappiness
    echo vm.swappiness=10
    sudo -e /etc/sysctl.conf
    cat /proc/sys/vm/vfs_cache_pressure
    sudo sysctl vm.vfs_cache_pressure=50
    echo vm.vfs_cache_pressure = 50
    sudo -e /etc/sysctl.conf

The article from digital ocean is here