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.

January 27th, 2011 at 16:39
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**
January 27th, 2011 at 16:39
So thanks!
September 9th, 2011 at 11:40
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/
October 31st, 2011 at 11:16
> 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
January 11th, 2012 at 19:16
Thanks for the solution! Had no idea why it was working on one server and not another until I came across this page
February 7th, 2012 at 11:11
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.
March 31st, 2012 at 05:04
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.
March 31st, 2012 at 09:09
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.