Most active commenters
  • awesome_dude(6)
  • justsomehnguy(4)
  • ahepp(3)

←back to thread

804 points jryio | 19 comments | | HN request time: 0s | source | bottom
Show context
speedgoose ◴[] No.45661785[source]
Looking at the htop screenshot, I notice the lack of swap. You may want to enable earlyoom, so your whole server doesn't go down when a service goes bananas. The Linux Kernel OOM killer is often a bit too late to trigger.

You can also enable zram to compress ram, so you can over-provision like the pros'. A lot of long-running software leaks memory that compresses pretty well.

Here is how I do it on my Hetzner bare-metal servers using Ansible: https://gist.github.com/fungiboletus/794a265cc186e79cd5eb2fe... It also works on VMs.

replies(15): >>45661833 #>>45662183 #>>45662569 #>>45662628 #>>45662841 #>>45662895 #>>45663091 #>>45664508 #>>45665044 #>>45665086 #>>45665226 #>>45666389 #>>45666833 #>>45673327 #>>45677907 #
1. awesome_dude ◴[] No.45662628[source]
How do you get swap on a VPS?
replies(1): >>45663111 #
2. justsomehnguy ◴[] No.45663111[source]
Search "linux enable swap in a file"

    To enable a swap file in Linux, first create the swap file using a command like sudo dd if=/dev/zero of=/swapfile bs=1G count=1 for a 1GB file. Then, set it up with sudo mkswap /swapfile and activate it using sudo swapon /swapfile. To make it permanent, add /swapfile swap swap defaults 0 0 to your /etc/fstab file.
replies(2): >>45663117 #>>45663334 #
3. awesome_dude ◴[] No.45663117[source]
Strongly suggest you try doing that on a VPS, then report back
replies(2): >>45663205 #>>45663268 #
4. ahepp ◴[] No.45663205{3}[source]
What do you think is going to happen? I tested it out on an ec2 instance just now and it seems to have worked as one would expect.
replies(2): >>45663613 #>>45666456 #
5. justsomehnguy ◴[] No.45663268{3}[source]
https://news.ycombinator.com/item?id=45007821

And that was like... two years ago? 1GB of RAM and actually ~700MB usable before I found the proper magik incantations to really disable kdump.

Also have used 1GB machines for literally years.

Strongly suggest you shouldn't strongly suggest.

replies(1): >>45663625 #
6. collinmanderson ◴[] No.45663334[source]
Yes. I think might also need to chmod 600 /swapfile. I do this on all my VPS, especially helps for small VPS with only 1GB ram:

   fallocate -l 1G /swapfile
   chmod 600 /swapfile
   mkswap /swapfile
   swapon /swapfile
Works really well with no problems that I've seen. Really helps give a bit more of a buffer before applications get killed. Like others have said, with SSD the performance hit isn't too bad.
replies(2): >>45664144 #>>45672114 #
7. awesome_dude ◴[] No.45663613{4}[source]
EC2 != VPS
replies(2): >>45665189 #>>45677481 #
8. awesome_dude ◴[] No.45663625{4}[source]
Uh.. your link... doesn't show how a VPS can have SWAP enabled

You do understand what's being discussed... right?

replies(1): >>45663739 #
9. justsomehnguy ◴[] No.45663739{5}[source]
Literally up the chain: https://news.ycombinator.com/item?id=45663111

Or you have a very peculiar understanding what 'VPS' means.

replies(1): >>45664617 #
10. awesome_dude ◴[] No.45664144{3}[source]
IME SWAP has been explicitly disabled by the VPS providers.

Partly it's a money thing (they want to sell you RAM), partly it's so that the shared disk isn't getting thrashed by multiple VPS

replies(1): >>45666094 #
11. awesome_dude ◴[] No.45664617{6}[source]
https://en.wikipedia.org/wiki/Virtual_private_server

As I said earlier

https://news.ycombinator.com/threads?id=awesome_dude#4566311...

replies(1): >>45674279 #
12. cmpxchg8b ◴[] No.45665189{5}[source]
They both offer virtualized guests under a hypervisor host. EC2 does have more offload specialization hardware but for the most part they are functionally equivalent, unless I'm missing something...
13. efreak ◴[] No.45666094{4}[source]
Get better VPS then. Openvz and other kernel paravirtualization have limits, go for Xen or KVM instead (Xen has paravirtualization as well, but I'm not sure how much it's actually used). Full virtualization (implemented by Xen and KVM) do not allow you to prevent swap from being used.
14. Zekio ◴[] No.45666456{4}[source]
well once you "need" that swap, it will be writing pages across the network due to the storage being external to the physical server, so the latency is terrible
replies(2): >>45666737 #>>45677456 #
15. kassner ◴[] No.45666737{5}[source]
Put swap on the “instance store” disk, not EBS.
16. collinmanderson ◴[] No.45672114{3}[source]
I forgot to mention what the parent comment said, yes, need to put something like this in /etc/fstab:

/swapfile swap swap sw 0 0

or via ansible:

    mount:
      src: "/swapfile"
      name: "swap"
      fstype: "swap"
      opts: "sw"
      passno: "0"
      dump: "0"
      state: present
17. justsomehnguy ◴[] No.45674279{7}[source]
Hello, it's the year 2025 here. If you use OpenVZ-like ancient shit - it's on you.

So no, VPS is a proper virtualization for a 15 years. And with a proper virtualization you have the full control.

18. ahepp ◴[] No.45677456{5}[source]
Latency of swap is always terrible in comparison to RAM. RAM vs disk is already something ~1000x right? I've never characterized EBS vs trad ssd, but I would be surprised if it's more than 10x.

I don't think using swap as "emergency RAM" makes a lot of sense in 2025. The arguments in favor of swap which I find convincing are about allowing the system to evict low use pages which otherwise would not be evictable.

19. ahepp ◴[] No.45677481{5}[source]
What VPS do you think this would cause problems on? Why?