apc_mmap: mmap failed: Cannot allocate memory

While trying to increase the size of the APC segment on my development machine I suddenly started getting “apc_mmap: mmap failed: Cannot allocate memory” in my error_log. This also made Apache angry, so it refused to return any pages while the error message was present.

After removing the apc.shm_size again, things went back to working as normal.

A bit of psychic debugging and reading phpinfo() output revealed the culprit:

Do NOT include a “M” specifier when providing a size for apc.shm_size. Leave it off. It will assume MBs anyways. This solved the issue.

This is in contrast with the manual page, where it has been documented with a default value of “32M”, while phpinfo() says “32”. This behaviour change with APC 3.1.4, so if your version is older than that you’ll have to use the format without the M.

11 thoughts on “apc_mmap: mmap failed: Cannot allocate memory”

  1. Mats. As soon as I saw your lifesaver I recalled I had seen this mentioned elsewhere and immediately it clicked … was the solution for me!
    It’s a real bummer … really tripped me up as i transferred php etc settings from a machine I thought was the same … same Ubuntu version etc etc.
    Another difference caught me out … I thought both machines were mmap compiled but the new machine would only accept **apc.mmap_file_mask=/dev/zero** and not **apc.mmap_file_mask=/tmp/apc.XXXXXX**

  2. > Do NOT include a “M” specifier when providing a size for apc.shm_size. Leave it off. It will assume MBs anyways. This solved the issue.

    YMMD! Thanks for this one!

    Teddai

  3. You are a star. I would never have worked this out and would have had another joyful day staring at logs and Top. I dedicate my stress free cup of Tea to you.

  4. Thanks so much!

    I got the same problem but it’s strange that the APC version 3.1.9 on Cent OS would not produce this problem while the 3.1.3 on Ubuntu would.

  5. The behaviour changed in 3.1.4, so 3.1.3 on Ubuntu require you to use the format without “M”, while 3.1.9 accepts the M notation.

  6. As of the most recent version of APC the suffix M or G is required. Not supplying one yields you a notice telling you this is a mistake.

  7. Also worth noting, I encountered this problem because the shm size I specified was larger than my system would allow.

Leave a Reply

Your email address will not be published. Required fields are marked *