Bug->Doc #68631 [Opn->Ver]: opcache_invalidate always increases wasted memory
| From: | cmb@php.net | Date: | Thu, 08 Jul 2021 11:25:30 +0000 |
| Subject: | Bug->Doc #68631 [Opn->Ver]: opcache_invalidate always increases wasted memory | ||
| References: | 1 | Groups: | php.doc.bugs |
| Request: | Send a blank email to doc-bugs+get-18930@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=68631&edit=1
ID: 68631
Updated by: cmb@php.net
Reported by: iquito at gmx dot net
Summary: opcache_invalidate always increases wasted memory
-Status: Open
+Status: Verified
-Type: Bug
+Type: Documentation Problem
Package: opcache
Operating System: Debian Wheezy
PHP Version: 5.5.20
Block user comment: N
Private report: N
New Comment:
This is like OPcache is supposed to behave: for performance
reasons, invalidated files are never freed (there is no
defragmentation)[1], and as such reported as wasted memory.
[1] <http://blog.jpauli.tech/2015-03-05-opcache-html/>
Previous Comments:
------------------------------------------------------------------------
[2014-12-20 01:55:38] iquito at gmx dot net
Sorry, link was wrong, here is the correct link for categories.php: https://www.purplestar.com/categories.php
------------------------------------------------------------------------
[2014-12-20 01:53:08] iquito at gmx dot net
I tested some more and found out, that this bug occures infrequently, and the chances of occurence
are higher, if the invalidated script is used/included multiple times (included in a web
application, for example) before it is invalidated again, at least that is my theory. If the PHP
file is cached once and never used, opcache_invalidate does not increase wasted memory, at least I
cannot reproduce it that way.
Yet opcache_invalidate and the use of opcache do not have to be simultaneous. The most
"regular" results of an increase in wasted memory were with a website where a PHP file is
included in every page with multiple views per minute, and a cron job once a minute where some
scripts are invalidated. I also have a feeling that larger scripts increase the chances, but I am
not sure.
One PHP file which is included and produces this error quite regularly can be found on http://www.panaxis.ch/categories.php - to reproduce
I would recommend to load a website which includes that PHP file every 10 seconds, and invalidate
the file with opcache_invalidate every minute. With about that setup I reached 350MB of wasted space
in 3 hours, quite consistently.
Sorry for the imprecise description - I tried to find some method to make it 100% reproduceable, but
did not find a clear way. I hope somebody with inside knowledge of opcache reads this and got enough
information to know what causes this, or to know what to look for.
------------------------------------------------------------------------
[2014-12-19 17:04:06] iquito at gmx dot net
Description:
------------
When calling opcache_invalidate on a script which has not changed since being cached by opcache (and
$force is not set), the wasted memory in opcache statistics still increases.
I have a cron job which invalidates certain scripts every minute, as they can be changed at any time
and then need to be cached again as soon as possible. With the current implementation of
opcache_invalidate scenarios such as these lead to the opcache memory being filled within a short
time, triggering a restart of opcache and therefore slowing performance needlessly.
Test script:
---------------
Just call opcache_invalidate on a script which has not changed again and again, and check opcache
statistics for the increase in wasted memory.
Expected result:
----------------
According to the documentation, a script is only invalidated if the modification time of the script
is newer than the cached opcodes. Yet if the wasted memory increases, clearly something is happening
or being invalidated.
Actual result:
--------------
If opcache_invalidate is being called on a script which has not changed, opcache should not have any
changes - no invalidation, no increase in wasted memory, no action at all.
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=68631&edit=1