Bug #66442 [NEW]: Memory leaks after Interned String Pool exhaustion
| From: | Terry at ellisons dot org dot uk | Date: | Wed, 08 Jan 2014 18:24:59 +0000 |
| Subject: | Bug #66442 [NEW]: Memory leaks after Interned String Pool exhaustion | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-183650@lists.php.net to get a copy of this message | ||
From: Terry at ellisons dot org dot uk
Operating system: N/A
PHP version: master-Git-2014-01-08 (Git)
Package: opcache
Bug Type: Bug
Bug description:Memory leaks after Interned String Pool exhaustion
Description:
------------
The SHM Interned Strings pool is sized by the
opcache.interned_strings_buffer INI parameter. However, there is no
guarantee that -- especially for large OPcaches supporting a lot of
modules -- that the interned strings pool might not fill. OPcache is
then supposed to degrade gracefully into using non-interned memory for
overflow strings that would otherwise have been allocated to SHM.
I decided to exercise these code paths within the tests environment by
the following mod:
--- a/ZendAccelerator.c
+++ b/ZendAccelerator.c
@@ -2492,6 +2495,11 @@ static int zend_accel_init_shm(TSRMLS_D)
# if ZEND_EXTENSION_API_NO > PHP_5_5_X_API_NO
orig_interned_empty_string = CG(interned_empty_string);
CG(interned_empty_string) = accel_new_interned_string("",
sizeof(""), 0 TSRMLS_CC);
+# if 1 //TERRY
+ /* Q&D patch to force interned string pool exhaustion */
+ ZCSG(interned_strings_end) = CG(interned_strings_top)+128;
+ CG(interned_strings_end) = ZCSG(interned_strings_end);
+# endif
# endif
# endif
This set the strings end point to 128 above the top after initialising
the SHM with existing interned strings. This means in practice that the
pool will "fill" after only a few string inserts and any remaining
string will be handled by the "pool full" path.
When I do this, I get a lot of memory leaks. The following is a simple
example:
Test script:
---------------
<?php
$c = get_declared_classes();
?>
run with the above patch in OPcache , with and without OPcache enabled.
Expected result:
----------------
The failover to non-SHM overflow should be silent. No errors should be
raised.
Actual result:
--------------
$ php56 -d opcache.enable=0 /tmp/test.php
$ php56 -d opcache.enable=1 -d opcache.enable_cli=1 /tmp/test.php
[Wed Jan 8 18:21:11 2014] Script: '/tmp/test.php'
/.../Zend/zend_API.c(1461) : Freeing 0x7F3162054110 (23 bytes),
script=/tmp/test.php
Last leak repeated 41 times
=== Total 42 memory leaks detected ===
Footnote. This highlights that Sysadmins need to able to query capacity
/ usage information on all fixed size pools and tables.
--
Edit bug report at https://bugs.php.net/bug.php?id=66442&edit=1
--
Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=66442&r=trysnapshot54
Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=66442&r=trysnapshot55
Try a snapshot (trunk): https://bugs.php.net/fix.php?id=66442&r=trysnapshottrunk
Fixed in SVN: https://bugs.php.net/fix.php?id=66442&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=66442&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=66442&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=66442&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=66442&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=66442&r=support
Expected behavior: https://bugs.php.net/fix.php?id=66442&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=66442&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=66442&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=66442&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=66442&r=php4
Daylight Savings: https://bugs.php.net/fix.php?id=66442&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=66442&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=66442&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=66442&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=66442&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=66442&r=mysqlcfg