Bug #75368 [Com]: mmap/munmap trashing on unlucky allocations
| From: | spam2 at rhsoft dot net | Date: | Fri, 13 Oct 2017 12:10:48 +0000 |
| Subject: | Bug #75368 [Com]: mmap/munmap trashing on unlucky allocations | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-211671@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=75368&edit=1
ID: 75368
Comment by: spam2 at rhsoft dot net
Reported by: nikic@php.net
Summary: mmap/munmap trashing on unlucky allocations
Status: Closed
Type: Bug
Package: Scripting Engine problem
PHP Version: 7.0.24
Block user comment: N
Private report: N
New Comment:
thank you!
this seems to make a big difference for phpdoc on my workstation when the KDE session which seems to
have small memory leaks is running a long time - phpdoc sometimes takes ages for no reason
same run, only the php-cli binary changed while currently the memleak/fragmentation is not so high
after 12 hours but a noticeable change
17/17 [============================] 100% 12.553s ..
17/17 [============================] 100% 6.488s ..
Previous Comments:
------------------------------------------------------------------------
[2017-10-13 11:03:06] dmitry@php.net
Automatic comment on behalf of dmitry@zend.com
Revision: http://git.php.net/?p=php-src.git;a=commit;h=397f5cb687f4f31cb0dec85ba5a87237394ca12d
Log: Fixed bug #75368 (mmap/munmap trashing on unlucky allocations)
------------------------------------------------------------------------
[2017-10-13 06:46:34] laruence@php.net
it may still be triggered by i = 94 * 2 if you cache one chunk
------------------------------------------------------------------------
[2017-10-12 19:53:59] nikic@php.net
Description:
------------
It may happen that memory is allocated and freed in such a way that the allocation mmaps a new ZMM
chunk and the deallocation immediately unmaps it again.
The attached script demonstrates this issues. It will execute quickly up to a certain point (for me
on master i=94) and then hang for a while. strace shows that during this time a sequence of mmap,
madvise and munmap is repeated many times:
mmap(NULL, 2097152, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f3927400000
madvise(0x7f3927400000, 2097152, MADV_HUGEPAGE) = 0
munmap(0x7f3927400000, 2097152) = 0
This issue may be fixed by ensuring we always cache at least one chunk.
Test script:
---------------
<?php
$bigArray = range(0, 256 * 1024 - 1);
var_dump(memory_get_usage(true) / (1024*1024));
$array = [];
for ($i = 0; $i < 1024; $i++) {
echo "$i\n";
$array[] = range(0, 1023);
for ($j = 0; $j < 16 * 1024; $j++) {
$x = range(0, 1023);
unset($x);
}
}
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=75368&edit=1