Bug #79660 [NEW]: Shared memory is dirty in child proc after pcntl_fork
| From: | phpbugs at muglug dot com | Date: | Mon, 01 Jun 2020 14:17:14 +0000 |
| Subject: | Bug #79660 [NEW]: Shared memory is dirty in child proc after pcntl_fork | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-227260@lists.php.net to get a copy of this message | ||
From: phpbugs at muglug dot com
Operating system: Linux
PHP version: 7.4.6
Package: Performance problem
Bug Type: Bug
Bug description:Shared memory is dirty in child proc after pcntl_fork
Description:
------------
I have a cross-platform command-line application that uses pcntl_fork to
spawn child processes.
pcntl_fork's implementation is very simple â it's just a call to
fork(), which has copy-on-write behaviour (no memory should be
duplicated unless the program modifies it).
On Macs, memory appears to be shared effectively â it's only dirtied
if there is some change made to the data.
When the same script is run on Linux it appears that the shared memory
is dirtied instantly, which increases the cost of pcntl_fork both in
terms of memory (whicch is multiplied by the number of calls to that
function) and also time, as each call to pcntl_fork is more costly.
Test script:
---------------
<?php
$a = [];
for ($i = 0; $i < 1000000; $i++) {
$a[] = "$i";
}
$pid = pcntl_fork();
if ($pid == -1) {
die('could not fork');
} else if ($pid) {
// we are the parent
pcntl_wait($status); //Protect against Zombie children
} else {
echo shell_exec('cat /proc/' . posix_getpid() . '/smaps | grep
Shared_ | grep -v "0 kB"');
echo $a[0];
}
Expected result:
----------------
There should be no large areas of Shared_Dirty memory in the output,
since most memory should be shared.
--
Edit bug report at https://bugs.php.net/bug.php?id=79660&edit=1
--
Fix committed: https://bugs.php.net/fix.php?id=79660&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=79660&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=79660&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=79660&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=79660&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=79660&r=support
Expected behavior: https://bugs.php.net/fix.php?id=79660&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=79660&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=79660&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=79660&r=globals
PHP version support discontinued: https://bugs.php.net/fix.php?id=79660&r=phptooold
Daylight Savings: https://bugs.php.net/fix.php?id=79660&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=79660&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=79660&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=79660&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=79660&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=79660&r=mysqlcfg