php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #75368 mmap/munmap trashing on unlucky allocations
Submitted: 2017-10-12 19:53 UTC Modified: 2017-10-13 06:46 UTC
From: nikic@php.net Assigned:
Status: Closed Package: Scripting Engine problem
PHP Version: 7.0.24 OS:
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: nikic@php.net
New email:
PHP Version: OS:

 

 [2017-10-12 19:53 UTC] 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);
    }
}


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2017-10-13 06:46 UTC] laruence@php.net
it may still be triggered by i = 94 * 2 if you cache one chunk
 [2017-10-13 11:03 UTC] 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 11:03 UTC] dmitry@php.net
-Status: Open +Status: Closed
 [2017-10-13 12:10 UTC] spam2 at rhsoft dot net
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 ..
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Oct 04 09:01:27 2024 UTC