"Cannot allocate memory" during setup


(Kuba Orlik) #1

When running discourse setup, I get a lot of such messages:

155:M 08 Sep 14:11:51.916 * 10 changes in 300 seconds. Saving...
155:M 08 Sep 14:12:05.407 # Can't save in background: fork: Cannot allocate memory
155:M 08 Sep 14:12:16.034 * 10 changes in 300 seconds. Saving...
155:M 08 Sep 14:12:31.907 # Can't save in background: fork: Cannot allocate memory
155:M 08 Sep 14:12:41.454 * 10 changes in 300 seconds. Saving...
155:M 08 Sep 14:12:57.993 # Can't save in background: fork: Cannot allocate memory
155:M 08 Sep 14:13:10.906 * 10 changes in 300 seconds. Saving...
155:M 08 Sep 14:13:27.200 # Can't save in background: fork: Cannot allocate memory
155:M 08 Sep 14:13:40.634 * 10 changes in 300 seconds. Saving...
155:M 08 Sep 14:13:50.437 # Can't save in background: fork: Cannot allocate memory
155:M 08 Sep 14:14:01.302 * 10 changes in 300 seconds. Saving...

What does it mean? Is there something I should reconfigure?


(Joshua Rosenfeld) #2

Can you share more of the console logs? Also, how much memory is on your server, and do you have swap set up?


(Kuba Orlik) #3

I’m running the setup on a VPS with 2GB of RAM. The logs are very long, would you like me to share the entire thing or just a specific part?


(Joshua Rosenfeld) #4

Everything would be fine - just be sure to redact any sensitive info, like passwords or API keys if they’re in the logs.


(Kuba Orlik) #5

Well, it’s been running for quite some time, but here’s how far it’s gotten until now:

log.txt (519.8 KB)


(Joshua Rosenfeld) #6

Hmm…digging through the logs I noticed this line:

could not fork autovacuum worker process: Cannot allocate memory

Which was recently reported here:

However, there the issue was 1 GB or RAM, where you have 2. Perhaps @codinghorror or someone with more install experience than I could assist…


(Jeff Atwood) #7

Make sure you have a 2GB swap file.


(Jay Pfaffman) #8

@kuba-orlik, you said you ran discourse setup. If you ran . /disourse-setup, it should have configured swap for you. Is that what you did? Does free show swap?


(Kuba Orlik) #9

I did use the ./discourse-setup method. It doesn’t seem to have configured swap for me:

             total       used       free     shared    buffers     cached
Mem:       2009404    1534120     475284       5508      54028     843600
-/+ buffers/cache:     636492    1372912
Swap:            0          0          0

Should I had provided the script with some additional arguments?


(Rafael dos Santos Silva) #10

It tries to set up swap on the beginning, maybe it failed. See our topic on the #howto category about setting up swap afterwards.


(Kuba Orlik) #11

Are you sure the ./discourse-setup script should set up swap? We’ve set up a few discourse instances using this method and neither of the machines have swap set up…


(Jay Pfaffman) #12

I mis-remembered. discourse-setup does set up swap, but only when there is less than 2GB of ram.

@codinghorror, it sounds like I should update discourse-setup to create swap if there is less than 4GB of ram. You want that PR?

Also, @mpalmer says:

Have memory requirements increased?


(Jay Pfaffman) #13

Also INSTALL-cloud.md no longer includes instructions for setting up swap (since discourse-setup does it).

@kuba-orlik, here’s how to set up 2GB of swap:

install -o root -g root -m 0600 /dev/null /swapfile
dd if=/dev/zero of=/swapfile bs=1k count=2048k
mkswap /swapfile
swapon /swapfile
echo "/swapfile       swap    swap    auto      0       0" | tee -a /etc/fstab
sysctl -w vm.swappiness=10
echo vm.swappiness = 10 | tee -a /etc/sysctl.conf

(Jeff Atwood) #14

Clarification. 2GB or less of RAM. so <= not <.


(Jay Pfaffman) #15

Oh. That’s not what the text of the echos says. This PR fixes the -le and changes the text of the echos.


(Jeff Atwood) #16

It is something of a new change, but recent Ruby / Rails versions have ballooned the memory required for rebuilds a fair bit…


(Jay Pfaffman) #17

But you still think that 1GB is enough for a site to run?

Here’s my site that’s been up for only three days and had virtually no use or traffic. I don’t think I’ve done an update since I rebooted last.

pfaffman@discourse:~$ free
             total       used       free     shared    buffers     cached
Mem:       1017880     906440     111440      90956       2800     155972
-/+ buffers/cache:     747668     270212
Swap:      2097148     727356    1369792

(Jeff Atwood) #18

Yes, it is. The rebuild process is extremely memory intensive in a way that normal site running, is not.

Remember the computer’s job is to use all memory available, not let it sit idle doing nothing.


(Kuba Orlik) #19

Is this policy also reflected in how Discourse functions on a daily basis (not during rebuilds)?


(Jeff Atwood) #20

Well, Discourse requires 1GB RAM minimum because it has a lot of stuff going on:

  • Postgres database
  • Sidekiq
  • Ruby and Rails
  • Redis
  • Unicorn webserver processes

and so on. It’s a big, complex app that is built for the next 10 years (now the next seven years).