You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Fix the attempted allocation size in OOM error messages
The sizes reported in the error messages previously didn't match the sizes that
were actually checked against the memory limit. This can result in confusing
error reports, because the reported size often tends to be much smaller than
the actual chunk allocation size used in accounting.
Consider the following example script:
<?php
$foo = [];
while (true) {
var_dump(memory_get_usage());
$foo[] = new stdClass();
}
Executing the script as
sapi/cli/php -dmemory_limit=5145728 oom.php
results in:
int(3833360)
int(3833440)
int(3833520)
Fatal error: Allowed memory size of 5145728 bytes exhausted at
php-src/Zend/zend_objects_API.c:136 (tried to allocate 524320 bytes) in
php-src/oom.php on line 5
With each iteration the actual memory usage grows by 80 bytes. The error
message reports roughly 512 KiB of additional usage, possibly for an array
resizing, but even for those additional 512 KiB the last observed memory usage
does not exceed the memory limit of 5145728 Bytes.
This is because actually a chunk of 2 MiB is going to be allocated and that is
what is checked. The following output was created with this patch applied:
int(3833360)
int(3833440)
int(3833520)
Fatal error: Allowed memory size of 5145728 bytes exhausted at
php-src/Zend/zend_objects_API.c:136 (tried to allocate 2097152 bytes)
in php-src/oom.php on line 5
With the fixed output the attempted allocation clearly exceeds the memory
limit.
In a further change the error message could possibly be adjusted to also report
the current memory usage instead of just the limit + the attempted allocation.
0 commit comments