# Forum Unusable due to "Can’t save in background: fork: Cannot allocate memory”

**URL:** https://meta.discourse.org/t/forum-unusable-due-to-can-t-save-in-background-fork-cannot-allocate-memory/57781
**Category:** Self-hosting
**Created:** [2월 22, 2017, 12:17오후 UTC](https://meta.discourse.org/t/forum-unusable-due-to-can-t-save-in-background-fork-cannot-allocate-memory/57781 "2017-02-22T12:17:56Z")
**Posts on this page:** 14
**Page:** 1

<div class="post-metadata">

### Author: ![Goosy](https://avatars.discourse-cdn.com/v4/letter/g/db5fbb/32.png) [@Goosy](https://meta.discourse.org/u/Goosy)
#### Post date: [2월 22, 2017, 12:17오후 UTC](https://meta.discourse.org/t/forum-unusable-due-to-can-t-save-in-background-fork-cannot-allocate-memory/57781/1 "2017-02-22T12:17:57Z")

</div>

I’m using a 2GB Digital Ocean Droplet and I keep getting 500 errors when users are trying to post new comments.

I checked the server logs and I see them full of these 2 lines:

44:M 22 Feb 12:10:04.079 \* 1 changes in 900 seconds. Saving…  
44:M 22 Feb 12:10:04.079 # Can’t save in background: fork: Cannot allocate memory

Also, when I ssh into my droplet, I see that memory consumption is at 82%.

I tried updating everything to latest, resetting the machine, but nothing helps on the long run. It works ok for a bit an then starts throwing the errors again.

---

<div class="post-metadata">

### Author: ![pfaffman](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/pfaffman/32/120154_2.png) [@pfaffman](https://meta.discourse.org/u/pfaffman)
#### Post date: [2월 22, 2017, 1:46오후 UTC](https://meta.discourse.org/t/forum-unusable-due-to-can-t-save-in-background-fork-cannot-allocate-memory/57781/2 "2017-02-22T13:46:33Z")

</div>

Do you have swap configured? How big is your database?

---

<div class="post-metadata">

### Author: ![Goosy](https://avatars.discourse-cdn.com/v4/letter/g/db5fbb/32.png) [@Goosy](https://meta.discourse.org/u/Goosy)
#### Post date: [2월 22, 2017, 3:22오후 UTC](https://meta.discourse.org/t/forum-unusable-due-to-can-t-save-in-background-fork-cannot-allocate-memory/57781/3 "2017-02-22T15:22:41Z")

</div>

@pfaffman No swap configured. I remember that when I deployed the forum 2 years ago it was required only for 1GB instances. Should I have swap?

The forum has 6.9k posts and I have 18.1 GB free on the server. Hope this info is enough, Otherwise, how can I check the db size?

---

<div class="post-metadata">

### Author: ![pfaffman](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/pfaffman/32/120154_2.png) [@pfaffman](https://meta.discourse.org/u/pfaffman)
#### Post date: [2월 22, 2017, 3:26오후 UTC](https://meta.discourse.org/t/forum-unusable-due-to-can-t-save-in-background-fork-cannot-allocate-memory/57781/4 "2017-02-22T15:26:02Z")

</div>

The memory requirements have increased in the past couple years.

I’d see if swap space would solve your problem:

> <https://github.com/discourse/discourse_docker/blob/master/discourse-setup#L87-L93>

---

<div class="post-metadata">

### Author: ![Goosy](https://avatars.discourse-cdn.com/v4/letter/g/db5fbb/32.png) [@Goosy](https://meta.discourse.org/u/Goosy)
#### Post date: [2월 22, 2017, 3:50오후 UTC](https://meta.discourse.org/t/forum-unusable-due-to-can-t-save-in-background-fork-cannot-allocate-memory/57781/5 "2017-02-22T15:50:09Z")

</div>

Ok, I’ve made a swap now. Will update this after seeing how it goes. Thanks for the suggestion!

---

<div class="post-metadata">

### Author: ![codinghorror](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/codinghorror/32/110067_2.png) [@codinghorror](https://meta.discourse.org/u/codinghorror)
#### Post date: [2월 23, 2017, 1:19오전 UTC](https://meta.discourse.org/t/forum-unusable-due-to-can-t-save-in-background-fork-cannot-allocate-memory/57781/6 "2017-02-23T01:19:16Z")

</div>

Even 1GB works fine, _provided you have 2GB of swap_, over a series of years running Discourse.

There are sometimes brief periods (usually during upgrades; it is strange to hear about this during regular use) where memory needs to be a bit larger.

It is definitely interesting to hear that no swap at all is affecting 2GB RAM instances cc @sam

---

<div class="post-metadata">

### Author: ![Goosy](https://avatars.discourse-cdn.com/v4/letter/g/db5fbb/32.png) [@Goosy](https://meta.discourse.org/u/Goosy)
#### Post date: [2월 23, 2017, 11:53오전 UTC](https://meta.discourse.org/t/forum-unusable-due-to-can-t-save-in-background-fork-cannot-allocate-memory/57781/7 "2017-02-23T11:53:06Z")

</div>

@pfaffman The swap file seems to have fixed the issue so far. Thanks again!  
@codinghorror Let me know if you would like me to provide any other details that could be helpful in case you would like to investigate the possible cause. And thanks all for this great platform!

Btw, this is what I get now when running “free -h”  
 ![](https://global.discourse-cdn.com/meta/optimized/3X/3/2/3278840dc92aba1fd7d223e61280a83cc93a9c24_2_690x59.png)

The swap used memory has been increasing in size since yesterday. Maybe there is some memory leak?

---

<div class="post-metadata">

### Author: ![codinghorror](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/codinghorror/32/110067_2.png) [@codinghorror](https://meta.discourse.org/u/codinghorror)
#### Post date: [2월 23, 2017, 12:58오후 UTC](https://meta.discourse.org/t/forum-unusable-due-to-can-t-save-in-background-fork-cannot-allocate-memory/57781/8 "2017-02-23T12:58:13Z")

</div>

Is your site very busy? What does the /about page show for stats? It’s possible your site is just very popular and thus needs more resources.

---

<div class="post-metadata">

### Author: ![Iceman](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/iceman/32/181309_2.png) [@Iceman](https://meta.discourse.org/u/Iceman)
#### Post date: [11월 10, 2017, 11:06오후 UTC](https://meta.discourse.org/t/forum-unusable-due-to-can-t-save-in-background-fork-cannot-allocate-memory/57781/9 "2017-11-10T23:06:12Z")

</div>

Hi,

Sorry to bring this up from Februrary but whanted to ask if it’s normal to have intermittent Error 500 with ~80% memory usage (like the OP).

The site is under heavy usage, but just wanted to know if there is some kind of “estimations” for a correlation Users/VolumeOfTraffic - Memory.

I saw that a “Swap” was recommended, pardon my ignorance, but how do you achieve that, it’s recommended? Or is like removing the incorporated Rate Limiter (which was not recommended by Sam)

I’m running the latest version of Discourse.

---

<div class="post-metadata">

### Author: ![codinghorror](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/codinghorror/32/110067_2.png) [@codinghorror](https://meta.discourse.org/u/codinghorror)
#### Post date: [11월 10, 2017, 11:09오후 UTC](https://meta.discourse.org/t/forum-unusable-due-to-can-t-save-in-background-fork-cannot-allocate-memory/57781/10 "2017-11-10T23:09:26Z")

</div>

If you search the #howto category here there is a topic about adding swap. Running without swap is definitely not recommened, unless you have well over 2GB of RAM on your server already allocated to Discourse.

---

<div class="post-metadata">

### Author: ![pfaffman](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/pfaffman/32/120154_2.png) [@pfaffman](https://meta.discourse.org/u/pfaffman)
#### Post date: [11월 11, 2017, 12:45오전 UTC](https://meta.discourse.org/t/forum-unusable-due-to-can-t-save-in-background-fork-cannot-allocate-memory/57781/11 "2017-11-11T00:45:16Z")

</div>

> [@Iceman](#):
>
> The site is under heavy usage,

That doesn’t mean anything. How many page views per day/week/month?

You need enough RAM for your database to fit in memory. How big is your database, or how many posts are there?

How much RAM do you have? How fast is the CPU? Where are you hosted?

---

<div class="post-metadata">

### Author: ![ondrej](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/ondrej/32/198804_2.png) [@ondrej](https://meta.discourse.org/u/ondrej)
#### Post date: [5월 17, 2019, 4:50오후 UTC](https://meta.discourse.org/t/forum-unusable-due-to-can-t-save-in-background-fork-cannot-allocate-memory/57781/12 "2019-05-17T16:50:52Z")

</div>

I am also getting 500 error as a member on other forum

---

<div class="post-metadata">

### Author: ![pfaffman](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/pfaffman/32/120154_2.png) [@pfaffman](https://meta.discourse.org/u/pfaffman)
#### Post date: [5월 17, 2019, 6:30오후 UTC](https://meta.discourse.org/t/forum-unusable-due-to-can-t-save-in-background-fork-cannot-allocate-memory/57781/13 "2019-05-17T18:30:44Z")

</div>

There are many reasons that might happen. If you’re not the admin of the forum, there’s nothing you can do.

If you are the admin, then you can check memory and disk space and see if you have any broken plugins.

---

<div class="post-metadata">

### Author: ![riking](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/riking/32/170938_2.png) [@riking](https://meta.discourse.org/u/riking)
#### Post date: [10월 5, 2020, 10:51오전 UTC](https://meta.discourse.org/t/forum-unusable-due-to-can-t-save-in-background-fork-cannot-allocate-memory/57781/15 "2020-10-05T10:51:09Z")

</div>


