Bug #78076 [Com]: Opcache greatly increases memory usage.
| From: | turchanov at farpost dot com | Date: | Sun, 25 Apr 2021 02:25:23 +0000 |
| Subject: | Bug #78076 [Com]: Opcache greatly increases memory usage. | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-233565@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=78076&edit=1
ID: 78076
Comment by: turchanov at farpost dot com
Reported by: tyler dot bannister at remote-learner dot net
Summary: Opcache greatly increases memory usage.
Status: Verified
Type: Bug
Package: opcache
Operating System: Centos 7.4.1708
PHP Version: 7.2.18
Assigned To: dmitry
Block user comment: N
Private report: N
New Comment:
Are there any plans to fix this?
This bug effectively prevents us from using OPCache in "cli" mode. Using file_cache_only=1
seems very logical/practical for cli mode. And we hit memory_limit due to this bug.
An alternative - 'file_cache_only=0', means that every running cli php will have its own
private SHM cache of 200M (yes, we cache a lot!). This incurs a HUGE memory waste.
Previous Comments:
------------------------------------------------------------------------
[2020-03-31 08:22:23] dmitry@php.net
Unfortunately the fix proposed at https://github.com/php/php-src/pull/5321 is
incorrect. It causes use-after-free and following crash.
Opcache in file_cache_only mode uses CG(arena) to store data loaded from file cache by the end of
request. This is done by design, because all the functions and classes loaded from file cache are
kept by the end of request anyway. The only part that is not necessary after the include() finishes
- main op_array. In general, it should be possible to detect if file_cache contains only main
op_array, then copy all relevant parts to emalloc()-ed process memory and then deallocate buffer.
However, this is not an easy fix.
------------------------------------------------------------------------
[2020-03-29 22:18:49] thedinosaurmail at gmail dot com
The following pull request has been associated:
Patch Name: fix bug 78076
On GitHub: https://github.com/php/php-src/pull/5321
Patch: https://github.com/php/php-src/pull/5321.patch
------------------------------------------------------------------------
[2020-02-18 14:58:20] cmb@php.net
I can confirm the reported behavior (PHP 7.3 and 7.4 on Windows 10).
------------------------------------------------------------------------
[2019-05-28 16:06:47] tyler dot bannister at remote-learner dot net
I've continued testing the problem, and on the command line I was able to stop the memory
explosion in my test script by setting opcache.file_cache_only=0.
However, I only enabled that setting in the first place to deal with the problem of running out of
memory with the Moodle installer. So the issue isn't exclusive to having file_cache_only
enabled, but maybe that setting makes the problem worse?
The minimal number of non-default settings to replicate (on my now Centos 7.6.1810 with PHP 7.3.5
system) seems to be:
opcache.enable=1
opcache.enable_cli=1
opcache.file_cache="/var/lib/php/cli-opcache"
opcache.file_cache_only=1
I was also able to replicate the problem on Ubuntu 18.04.2 with PHP 7.2.17:
Opcache enabled with opcache.file_cache_only enabled:
Starting Memory:389008
Ending Memory:7860232
Opcache enabled with opcache.file_cache_only disabled:
Starting Memory:388432
Ending Memory:388432
Opcache disabled:
Starting Memory:389992
Ending Memory:390144
------------------------------------------------------------------------
[2019-05-28 15:43:12] tyler dot bannister at remote-learner dot net
PHP 7.28 actual output:
Opcache enabled:
Starting Memory:385248
Ending Memory:7856480
Opcache disabled:
Starting Memory:386104
Ending Memory:386232
PHP 7.3.5 actual output:
Opcache enabled:
Starting Memory:389112
Ending Memory:8450224
Opcache disabled:
Starting Memory:389904
Ending Memory:390088
------------------------------------------------------------------------
The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at
https://bugs.php.net/bug.php?id=78076
--
Edit this bug report at https://bugs.php.net/bug.php?id=78076&edit=1