Create a swapfile for your Linux server

You are not required to. If you wanted to play it safe, a 1 GB file should be more than sufficient and rarely used.

8 Likes

Hello ,

There is any sense to create 3 GB , 4GB SWAP for instance with 1 GB RAM . Any profits here ?(1% more better work is a profit )

You are better off investing in more physical RAM than a larger SWAP file.

4 Likes

Obviously you can create a swapfile any size you want. If it is not needed, it will just sit there merrily holding zeros. The disk space will simply be wasted.

So the trick is to size your swap large enough for the heaviest operation, which in Discourse should be the rebuild. Check memory usage on a rebuild to see how much is needed.

I think there are studies out there saying that very large swap files will not be useful because the CPU is gonna start thrashing way before that much swap is used.

EDIT: Searching on the net, it is recommended the swap to be no larger than 2 times physical RAM due to declining returns of adding more.

./discourse-setup will now create the swap file, so there is (usually) no reason to do it yourself. If you have a too-small swapfile you should delete it before running discourse-setup.

6 Likes

This is useful as a quickly grab-able recipe for adding swap files, but the use of sudo in the copy-paste script is inconsistent. Currently it only works if pasted in as root, and the sudo on some commands does nothing in that case. The use of sudo is a nice addition, but only if it’s done throughout.

This comment mostly won’t get read, so maybe the original post could be edited?

2 Likes

Sure I’ll remove it and put a notice at the top

You people often said that DO’s $5 droplet was enough for beginners, even when they gave just 10gb in 5 dollars (now they give 25 gb).

And I’ve 16gb hdd and 4gb ram on AWS. And my “uploads” and “backups” are in separate Amazon S3 bucket.
So I just have discourse instance (and 3 very just bare-bone wordpress sites).

And created 1 gb swap treading on this topic.

And yet I keep hitting hard disk space errors if I ever need to ‘rebuild’ the container.
Should I increase the hard disk size, or there is some other short term solution (I don’t often need to rebuild)? As it costs 2 dollar every 10 gb ssd space.

1 Like

25GB is really the minimum. DigitalOcean has offered 25GB on the $5 droplet for several years now, hence the recommendation.

2 Likes

I read the whole topic/all posts, but I couldn’t understand by full confidence whether the space used by swap file (if created by exact commands given in the OP) is permanently occupied, or it’ll be used only when its needed (priority shown in my swap file is just 10).

And, if created once, is there some simple command to turn off the swap completely (so that the disk space could be used by other processes)?

It’s permanently allocated.

You would need to disable swap and delete the swapfile to free up the space.

4 Likes