Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:39115 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 23681 invoked from network); 20 Jul 2008 14:58:46 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 20 Jul 2008 14:58:46 -0000 Authentication-Results: pb1.pair.com header.from=rasmus@lerdorf.com; sender-id=unknown Authentication-Results: pb1.pair.com smtp.mail=rasmus@lerdorf.com; spf=permerror; sender-id=unknown Received-SPF: error (pb1.pair.com: domain lerdorf.com from 204.11.219.139 cause and error) X-PHP-List-Original-Sender: rasmus@lerdorf.com X-Host-Fingerprint: 204.11.219.139 mail.lerdorf.com Received: from [204.11.219.139] ([204.11.219.139:45723] helo=mail.lerdorf.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 31/04-33537-4A253884 for ; Sun, 20 Jul 2008 10:58:45 -0400 Received: from [192.168.200.148] (c-24-6-219-206.hsd1.ca.comcast.net [24.6.219.206]) (authenticated bits=0) by mail.lerdorf.com (8.14.3/8.14.3/Debian-5) with ESMTP id m6KEweR2018731 for ; Sun, 20 Jul 2008 07:58:40 -0700 Message-ID: <488352A0.5060101@lerdorf.com> Date: Sun, 20 Jul 2008 07:58:40 -0700 User-Agent: Thunderbird/3.0a2pre (Macintosh; 2008071516) MIME-Version: 1.0 To: PHP Developers Mailing List Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Greylist: Sender succeeded SMTP AUTH authentication, not delayed by milter-greylist-3.0 (mail.lerdorf.com [204.11.219.139]); Sun, 20 Jul 2008 07:58:42 -0700 (PDT) Subject: Syscall Optimization From: rasmus@lerdorf.com (Rasmus Lerdorf) On most requests we end up with a getcwd() followed by a chdir() to the same directory and then a second chdir() to the same directory at the end of the request: getcwd("/var/www", 4095) = 14 chdir("/var/www") = 0 ... request is processed ... chdir("/var/www") = 0 which comes from this code in main.c: if ((primary_file->type == ZEND_HANDLE_FILENAME || primary_file->type == ZEND_HANDLE_STREAM) && primary_file->filename) { VCWD_GETCWD(old_cwd, OLD_CWD_SIZE-1); VCWD_CHDIR_FILE(primary_file->filename); } ... if (old_cwd[0] != '\0') { VCWD_CHDIR(old_cwd); } free_alloca(old_cwd, use_heap); We probably can't get rid of the second chdir() since we should preserve our sandbox and leave the process in the same state that we started in and all sorts of things along the way could theoretically have changed the cwd. But we should be able to get rid of that first chdir() when the directory we want to change to is the same as old_cwd. Perhaps a new macro to not break other code using it? VCWD_GETCWD_CHDIR_FILE(primary_file->filename, old_cwd, OLD_CWD_SIZE-1) And have this macro only do the chdir if the directories are different. -Rasmus