Should I increase the swap file from 2GB?

AI-generated summary

In a discussion about whether a 2GB swap file is sufficient for a Discourse installation on a Hetzner server with 4GB RAM, users offer varied perspectives. alltiagocom shares screenshots showing memory usage during and after a rebuild, noting peak RAM use briefly hit 1GB and later stabilized around 1.6GB, with CPU cores occasionally hitting 80%. merefield suggests monitoring with htop during builds and later confirms the setup is sufficient [10]. Rubi initially confuses swapfile with swap partition but clarifies swapfiles are modern defaults. NateDhaliwal confirms the auto-created swap is indeed a file and believes 2GB is adequate unless other services run concurrently. Jagster notes that heavy plugin or AI usage may require more. alltiagocom clarifies they used default install scripts and have minimal plugins. merefield recommends sysstat for more precise logging, while Ed_S advocates vmstat 5 for capturing peak memory pressure in a scrollable log — crucial for diagnosing failures. alltiagocom appreciates the tips and saves them for future reference. Overall, consensus leans toward 2GB swap being sufficient for this setup, especially with light plugin use.

I recently installed Discourse again, but in Hetzner servers. Now I have 4GB of RAM and 40GB of space. By default it created the 2GB swap file

image

Is that enough?

Watch it using htop during a build. Probably enough.

Which Linux distro did you use for the install on the servers?

I would have recommended using a swapfile instead of a swap partition.

Swapfiles are the default nowadays on most distros and are more flexible in terms of adjusting the swappiness.

I don’t believe a swap partition was mentioned?

I think 2GB swap + 4GB RAM is enough. I don’t think you’d need more swap unless you’re running other stuff on your server as well.

My apologies, you are correct.

Should have made sure to drink more coffee before replying :wink:

It depends how much there in plugins in use, AI etc. For me 4+2 wasn’t enough.

I’m not an expert so I just took some screenshot along the way:

SCR-20251221-ilhi

SCR-20251221-imkv

This was right after it completed:

SCR-20251221-imvf

Then, I let it run for a little bit longer, because I was seeing the 0 and 1 bars (I’ assuming those are the cores?) both hitting around 80% and I wanted to see if that was just temporary:

SCR-20251221-ince

SCR-20251221-infh

SCR-20251221-inoo

SCR-20251221-inzv

Does this help?

For the most part, the Mem was no higher than maybe 500M, average. During the rebuild the highest it went was maybe 1GB or so, but very briefly. Only after the rebuild stopped did it go to those values of 1.6GB or so.

And even now, after it stopped for a few minutes, I’m still seeing this, so I wonder if that’s normal?

image

@NateDhaliwal and @Rubi I didn’t do anything myself, it created it automatically, so I’m assuming it’s swapfile? I just followed the official instructions to install and let it do its thing. Hope that clarifies?

@Jagster I don’t have a lot of stuff. No AI, at least not that I installed anything myself, and other than the native plugins, I only have 3 that I installed, along with Components, which are probably 20 or less, but I don’t think those are that relevant?

Yep, it is a swapfile. IIRC a change was made earlier this year to create a swapfile if under 5GB RAM (I think it used to be 1 GB?).

Clearly enough, plenty of spare capacity, you are good to go :+1:

I might give this a go myself next time. Do you just open a separate terminal window and type htop? Any recommended options? I’ll do an internet search for more general information about it.

Yes. But note this is not a fine tool. It’s obvious here 2GB is enough but If you want a more accurate peak of swap use you might investigate sysstat and logging. I’ll leave you to research that.

Awesome! Thank you for your feedback and for the htop command, which I wasn’t aware of. Saved it to my notes.

For myself, I’d not use htop but instead vmstat 5 because that leaves a clear text log of what it saw (every 5 seconds). That’s handy because you can scroll back, or search for the worst moment. The worst moment is what matters, really, especially if it causes failure. The average situation (during a rebuild) isn’t informative. With a tool like htop you could easily miss seeing the peak, and once it’s past you can’t review.

I’ve posted before about vmstat and explained how to interpret the output.

Thank you. I’m very new to this whole thing, so I always add these “nuggets” and save them to my notes. Appreciate it!