Migrating Blog to Hetzner Server and Creating Swap Space
Hello, it's me, the incompetent one.
I was able to migrate to the Hetzner server, but I was stuck with deno task lume. Then, while looking at top, I discovered that memory was exhausted.
So, I will create and mount virtual memory.
On 12/31...
Creating Swap Space
Although it's said not to use it, it's easy, so I'll go with this.
Conceptually, on the disk, you tell it to use from here to here with fallocate, then format it with mkswap to enable virtual memory usage, similar to building a filesystem with mkfs, and then use swapon to designate this as a Swap area, similar to mount. That's the image I have.
sudo fallocate -l 4G /swapfile
sudo chmod 600 /swapfile
sudo mkswap /swapfile
sudo swapon /swapfile
Check with free -h
$ free -h
total used free shared buff/cache available
Mem: 1.9Gi 736Mi 202Mi 4.3Mi 1.1Gi 1.2Gi
Swap: 4.0Gi 621Mi 3.4Gi
It's necessary for a barebones server...
Persistence
I will make the created swap file persistent by loading it at startup.
sudo echo "/swapfile none swap sw 0 0" >> /etc/fstab
It went through successfully.
It's already December 31st... What am I doing, I wonder... (;´д`)Toh-ho-ho…
A Little Explanation
For those wondering what swap space is in the first place:
Computers store data temporarily in something called RAM.
Incidentally, CPUs also have primary (L1) and secondary (L2) caches, but that's a lower-level topic and not something usually considered in programming.
In addition, there are directories like /tmp for storing temporary files as memory areas for programs. These are recorded on RAM and are very fast, but since RAM is volatile memory, they are erased upon power loss, i.e., reboot.
Programs are stored in the RAM area in this way, but if this area is exceeded, it becomes full and gets stuck. By creating the swap file area as a kind of fallback, you can offload data that cannot be written to RAM.
However, it is ultimately a virtual memory area, so it's an area that exists on disk, made to look like RAM.
It's created on an HDD if you have one, or on an SSD if you have one.
This is a bit of a hardware-oriented thought, but writing to RAM is originally meant to handle many files quickly, so it can put a load on the disk itself, shortening its lifespan, or increasing disk I/O. Therefore, the best solution is to load up on RAM.
But, I envy such a rich environment...
It's still the case that motherboards have 2 memory slots for low-end models and 4 for mid-range and above; that hasn't changed at all.