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 Responses to “apc_mmap: mmap failed: Cannot allocate memory”

  1. IainH Says:

    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. IainH Says:

    So thanks!

  3. oc666 Says:

    Linux has usually a default limit of 32MB per segment.
    Source: http://www.marcusnyberg.com/2011/06/20/segmentation-fault-11-core-dumped-in-php-on-freebsd/

  4. Teddai Says:

    > 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

  5. Andrew K Says:

    Thanks for the solution! Had no idea why it was working on one server and not another until I came across this page

  6. Stuart Laverick Says:

    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.

  7. Nguyen Duc Thuan Says:

    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.

  8. Mats Says:

    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.

  9. Jack Says:

    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.

  10. Jack Says:

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

  11. dREI Says:

    Thanks Mate!

    That did the trick.

    dREI

Leave a Reply