←back to thread

804 points jryio | 1 comments | | HN request time: 0.215s | source
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 #
awesome_dude ◴[] No.45662628[source]
How do you get swap on a VPS?
replies(1): >>45663111 #
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 #
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 #
1. collinmanderson ◴[] No.45672114[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