Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to allocate shared memory segment error #134

Closed
crabel opened this issue Sep 22, 2013 · 12 comments
Closed

Unable to allocate shared memory segment error #134

crabel opened this issue Sep 22, 2013 · 12 comments

Comments

@crabel
Copy link

@crabel crabel commented Sep 22, 2013

I currently see these errors in the logfile:

PHP Warning: PHP Startup: Unable to load dynamic library '/usr/lib64/php/modules/gd.so' - libjpeg.so.62: failed to map segment from shared object: Cannot allocate memory in Unknown on line 0
PHP Warning: PHP Startup: Unable to load dynamic library '/usr/lib64/php/modules/imagick.so' - libfftw3.so.3: failed to map segment from shared object: Cannot allocate memory in Unknown on line 0
PHP Warning: PHP Startup: Unable to load dynamic library '/usr/lib64/php/modules/intl.so' - libicudata.so.36: failed to map segment from shared object: Cannot allocate memory in Unknown on line 0
PHP Warning: PHP Startup: Unable to load dynamic library '/usr/lib64/php/modules/mysql.so' - libmysqlclient.so.18: failed to map segment from shared object: Cannot allocate memory in Unknown on line 0
PHP Warning: PHP Startup: Unable to load dynamic library '/usr/lib64/php/modules/mysqli.so' - libmysqlclient.so.18: failed to map segment from shared object: Cannot allocate memory in Unknown on line 0
PHP Warning: PHP Startup: Unable to load dynamic library '/usr/lib64/php/modules/pdo_mysql.so' - /usr/lib64/php/modules/pdo_mysql.so: failed to map segment from shared object: Cannot allocate memory in Unknown on line 0
PHP Warning: PHP Startup: Unable to load dynamic library '/usr/lib64/php/modules/pdo_sqlite.so' - /usr/lib64/php/modules/pdo_sqlite.so: failed to map segment from shared object: Cannot allocate memory in Unknown on line 0
PHP Warning: PHP Startup: Unable to load dynamic library '/usr/lib64/php/modules/phar.so' - /usr/lib64/php/modules/phar.so: failed to map segment from shared object: Cannot allocate memory in Unknown on line 0
PHP Warning: PHP Startup: Unable to load dynamic library '/usr/lib64/php/modules/wddx.so' - /usr/lib64/php/modules/wddx.so: failed to map segment from shared object: Cannot allocate memory in Unknown on line 0
PHP Warning: PHP Startup: Unable to load dynamic library '/usr/lib64/php/modules/xmlreader.so' - /usr/lib64/php/modules/xmlreader.so: failed to map segment from shared object: Cannot allocate memory in Unknown on line 0
PHP Warning: PHP Startup: Unable to load dynamic library '/usr/lib64/php/modules/xmlwriter.so' - /usr/lib64/php/modules/xmlwriter.so: failed to map segment from shared object: Cannot allocate memory in Unknown on line 0
PHP Warning: PHP Startup: Unable to load dynamic library '/usr/lib64/php/modules/xsl.so' - /usr/lib64/php/modules/xsl.so: failed to map segment from shared object: Cannot allocate memory in Unknown on line 0
Sun Sep 22 12:22:21 2013 (8552): Fatal Error Unable to allocate shared memory segment of 205520896 bytes: shmat: Cannot allocate memory (12)

This error repeats every couple of seconds:

Sun Sep 22 12:22:21 2013 (8554): Fatal Error Unable to allocate shared memory segment of 205520896 bytes: shmat: Cannot allocate memory (12)
PHP Warnings
Sun Sep 22 12:22:21 2013 (8556): Fatal Error Unable to allocate shared memory segment of 205520896 bytes: shmat: Cannot allocate memory (12)
PHP Warnings
Sun Sep 22 12:22:29 2013 (8558): Fatal Error Unable to allocate shared memory segment of 205520896 bytes: shmat: Cannot allocate memory (12)
PHP Warnings
Sun Sep 22 12:22:32 2013 (8562): Fatal Error Unable to allocate shared memory segment of 205520896 bytes: shmat: Cannot allocate memory (12)
PHP Warnings
Sun Sep 22 12:22:34 2013 (8565): Fatal Error Unable to allocate shared memory segment of 205520896 bytes: shmat: Cannot allocate memory (12)
PHP Warnings
Sun Sep 22 12:22:37 2013 (8567): Fatal Error Unable to allocate shared memory segment of 205520896 bytes: shmat: Cannot allocate memory (12)
...

I have noticed these errors first last Monday, Tuesday evening they stopped and reapeared yesterday afternoon. The weird thing is, everything seems to work. No 500 internal server errors or something, nobody complains.

I don't understand why I get these errors. My config:

opcache.memory_consumption=196
opcache.enable=1
opcache.use_cwd=1
opcache.validate_timestamp=0
opcache.revalidate_freq=180 ; seconds
opcache.revalidate_path=0
opcache.dups_fix=0
opcache.log_verbosity_level=1
opcache.interned_strings_buffer=8
opcache.max_accelerated_files=4000
opcache.max_wasted_percentage=25
opcache.consistency_checks=0
opcache.force_restart_timeout=60
opcache.blacklist_filename=
opcache.fast_shutdown=1
opcache.enable_cli=1
opcache.enable_file_override=1
opcache.optimization_level=0xfffffbbf
opcache.enable_slow_optimizations=1

Server is CentOS5.9 with PHP 5.4.19

Maybe I don't understand correctly what Zend optimizer does. I thought that it allocates the cache once at startup and later just reattaches. Why should it try to allocate that amout again? Or is the error message misleading?

According to phpinfo Zend seems to work: (I just restarted, it usually caches about 1500 files after a couple of days)
Opcode Caching Up and Running
Optimization Enabled
Startup OK
Shared memory model mmap
Cache hits 1587373
Cache misses 1459
Used memory 110901784
Free memory 88870072
Wasted memory 5749040
Cached scripts 1139
Cached keys 1358
Max keys 7963
OOM restarts 0
Hash keys restarts 0
Manual restarts 0

Any ideas how I could find out what happens?

@fulopattila122
Copy link

@fulopattila122 fulopattila122 commented Sep 23, 2013

Are you on a virtual server? It usually happens in virtual environments

@crabel
Copy link
Author

@crabel crabel commented Sep 23, 2013

I think, my server is a real box., but I am not 100% sure. It's difficult to tell nowadays. ;) At least virt-what doesn't return anything.

Interestingly the errors stopped again three hours ago, for now reason I can fathom.

@typomedia
Copy link

@typomedia typomedia commented Nov 7, 2013

I have the same problem and I am in a openvz environment. Any idea?

Edit: I'm running PHP now with the APC accelerator in openvz.

Edit: Had some trouble with APC and WP Super Cache. I'm using xcache now.

@TerryE
Copy link

@TerryE TerryE commented Nov 9, 2013

What I found interesting about this one is that your info report gives Shared memory model mmap, and that the the no_memory_bailout() error was reported on the SHM allocator.

However looking at the code, this is because the zend_shared_alloc_startup() routine loops around the allocators detected during configure and tries each in turn. The SHM one is the last in the list and therefore reported. The issue is that the shmat() (and mmap) can't allocate the 196Mb requested. This is also consistent with the "failed to map segment from shared object: Cannot allocate memory" reports. This sounds like a general system memory exhaustion, or perhaps the PHP process hitting a per-process memory limit. Without a repeatable test, it will be extremely difficult to track down or even to determine if it is even a PHP or OPcache bug at all.

@Neo1975
Copy link

@Neo1975 Neo1975 commented Nov 13, 2013

In my case if use this configuration

opcache.memory_consumption=86

I have the same error. But is the same if I use APC, so I don't think is a problem of OpCache.

I also incresed memory_limit of PHP and linux shared memory limit.

kernel.shmmax
kernel.shmall

but nothing.... Now I'm thinking that is a problem of OpenVZ.
If someone solved this problem, please share the solution.

@lazy404
Copy link

@lazy404 lazy404 commented Nov 13, 2013

check /proc/user_beancounters for allocation failures,

You are likelly hitting shared memory limit (shmpages)

@Neo1975
Copy link

@Neo1975 Neo1975 commented Nov 13, 2013

php -i give the follow error:

Thu Nov 14 01:53:43 2013 (1864): Fatal Error Unable to allocate shared memory segment of 134217728 bytes: mmap: No space left on device (28)

cat /proc/user_beancounters
Version: 2.5
uid resource held maxheld barrier limit failcnt
445: kmemsize 14096574 25306704 800514055920 800514055920 0
lockedpages 0 4613 5002 10024 4
privvmpages 120023 386696 8524288 1024288 0
shmpages 1314 22738 22848 1200042 765
dummy 0 0 0 0 0
numproc 87 160 1024 2048 0
physpages 22707 265110 0 9223372036854775807 0
vmguarpages 0 0 1024288 2024288 0
oomguarpages 22707 265111 1024288 2024288 0
numtcpsock 18 45 5400 5400 0
numflock 19 316 1024 2048 0
numpty 1 4 1024 2048 0
numsiginfo 0 150 1024 2048 0
tcpsndbuf 326752 2400960 4414800000 988301622 0
tcprcvbuf 294912 9830528 4414800000 988301622 0
othersockbuf 471872 1125504 1126080 2097152 1397
dgramrcvbuf 0 46464 262144 262144 0
numothersock 252 332 2097152 4097152 0
dcachesize 735237 4619081 883409920 993409920 0
numfile 2455 4732 99312 99312 0
dummy 0 0 0 0 0
dummy 0 0 0 0 0
dummy 0 0 0 0 0
numiptent 10 196 10244 16084 0

cat /etc/sysctl.conf

kernel.sem=250 256000 32 1024
kernel.shmmax=1073741824
kernel.shmall=3774873
kernel.msgmax=65535
kernel.msgmnb=65535

free -m
total used free shared buffers cached
Mem: 7955 466 7489 0 0 0
-/+ buffers/cache: 466 7489
Swap: 859 0 859

ipcs -l

------ Limiti della memoria condivisa --------
max number of segments = 4096
max seg size (kbytes) = 1048576
max total shared memory (kbytes) = 15099492
dimensione min seg (byte) = 1

------ Limiti di semaforo --------
numero max di matrici = 1024
numero max di semafori per matrice = 250
numero max di semafori su tutto il sistema = 256000
numero max opz. per chiamata semop = 32
valore max del semaforo = 32767

------ Messaggi: limiti --------
numero max di code su tutto il sistema = 16
dimensione max del messaggio (byte) = 65535
dimensione massima predefinita della coda (byte) = 65535

any idea?

@TerryE
Copy link

@TerryE TerryE commented Nov 14, 2013

@Neo1975, the issue that you have is that you are trying to allocate an OPcache SMA of 132Mb in an OpenVZ container where your max shmpages is just over 22K (= 88 Mb). VMs still have limits. You've hit one. You need to change them or live within them.

This really belongs on a support forum and not an OPcache issue, though perhaps some advisory in the OPcache docs might help others.

@typomedia
Copy link

@typomedia typomedia commented Nov 14, 2013

You are right - it's not an opcache issue!

You can try to reduce you memory consumption in your opcache.ini. For example:

opcache.memory_consumption=64

@Neo1975
Copy link

@Neo1975 Neo1975 commented Nov 15, 2013

For other people that can fit this type of problem (on google I can found very few post about this) if the problem still persists over change shmmax and you have a VPS contact your provider, they have to change a set.

Thanks.

@crabel
Copy link
Author

@crabel crabel commented May 12, 2014

I had some time now to look into the matter (in case somebody wonders: Not so important application and no problems except those log file entries). In my case the problem was not related to a virtual server or something:

Please note that: opcache.enable_cli=1 was enabled
Each call to our php application checks if a maintenance tasks is to start. Not sure of the exact reasoning behind that implementation, but passthru() is used to execute the maintenance code in the shell. And that produces above errors.

In my case, the problem was basically "fixed" by setting opcache.enable_cli=0

@crabel crabel closed this May 12, 2014
@wenchangming211
Copy link

@wenchangming211 wenchangming211 commented Jul 20, 2017

Could you tell me how to solve the problem?

Request Method: GET
http://192.168.111.142/
1.8
ImportError
/usr/local/lib/python2.7/lib-dynload/future_builtins.so: failed to map segment from shared object: Cannot allocate memory
/usr/local/lib/python2.7/site-packages/reportlab/init.py in , line 31
/usr/local/bin/uwsgi
2.7.13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
7 participants
You can’t perform that action at this time.