I deployed a hack to add swap space to a VPS that otherwise didn't allow me to use swapon
to create a file.
Prior to adding and executing the script, I followed the steps outlined here. and summarized below:
- First I create the swap file:
sudo dd if=/dev/zero of=/swapfile bs=1024 count=512k
- Then
sudo mkswap /swapfile
. - The next step would usually have been to do a
sudo swapon /swapfile
. However, the VPS I'm using doesn't jive with that, so I found this post. That claimed I could use the following script as a workaround.
See below:
#!/bin/bash
SWAP="${1:-512}"
NEW="$[SWAP*1024]"; TEMP="${NEW//?/ }"; OLD="${TEMP:1}0"
umount /proc/meminfo 2> /dev/null
sed "/^Swap\(Total\|Free\):/s,$OLD,$NEW," /proc/meminfo > /etc/fake_meminfo
mount --bind /etc/fake_meminfo /proc/meminfo
For more context, the process is described in detail in this answer. (It's mostly just spoon-feeding on running a bash script.)
All seems to be fine, however when I look in htop (or in free -m
for that matter); the memory usage remains at whatever value it was at when I executed the script and the used swap space remains at zero. This is regardless of whatever process I run on the server. My knowledge of what's going on in memory allocation is very limited (this is really my first time screwing around with it). Could anyone tell me if this makes sense, given the script I'm running, and why?