Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:60379 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 2994 invoked from network); 30 Apr 2012 17:15:36 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 30 Apr 2012 17:15:36 -0000 Authentication-Results: pb1.pair.com smtp.mail=larry@garfieldtech.com; spf=permerror; sender-id=unknown Authentication-Results: pb1.pair.com header.from=larry@garfieldtech.com; sender-id=unknown Received-SPF: error (pb1.pair.com: domain garfieldtech.com from 66.111.4.25 cause and error) X-PHP-List-Original-Sender: larry@garfieldtech.com X-Host-Fingerprint: 66.111.4.25 out1-smtp.messagingengine.com Received: from [66.111.4.25] ([66.111.4.25:39339] helo=out1-smtp.messagingengine.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 22/1E-13197-7B8CE9F4 for ; Mon, 30 Apr 2012 13:15:36 -0400 Received: from compute3.internal (compute3.nyi.mail.srv.osa [10.202.2.43]) by gateway1.nyi.mail.srv.osa (Postfix) with ESMTP id 2547C20DCC for ; Mon, 30 Apr 2012 13:15:33 -0400 (EDT) Received: from frontend2.nyi.mail.srv.osa ([10.202.2.161]) by compute3.internal (MEProxy); Mon, 30 Apr 2012 13:15:33 -0400 DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d= messagingengine.com; h=message-id:date:from:mime-version:to :subject:references:in-reply-to:content-type :content-transfer-encoding; s=smtpout; bh=1AAJDC3n6PGCTGO6MsTvbG WaeZQ=; b=qe6wNGhmd+/xSQQS3wkbjQJIdx/Dj6JzaQ8votaaC3GI248zkCLfTd /W8//vNtH1AbC8E2/M4zOs6tE3MdQbWpiKEGK++ftP0yt9Ow2m/wgZoEQ24ZlXFV RUsQ+0TVaRoNxC6XGGMmjCjKJVQLYqv+SUQj6nqQ0DZ3s0lnJshJU= X-Sasl-enc: OvzE6YmZeSPins36E/f6ndMc58GIS+ZZLUQFZYtsWYw4 1335806132 Received: from garfield.local (unknown [209.41.114.202]) by mail.messagingengine.com (Postfix) with ESMTPSA id E433F4827CD for ; Mon, 30 Apr 2012 13:15:32 -0400 (EDT) Message-ID: <4F9EC8B4.3040600@garfieldtech.com> Date: Mon, 30 Apr 2012 12:15:32 -0500 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.7; rv:11.0) Gecko/20120327 Thunderbird/11.0.1 MIME-Version: 1.0 To: internals@lists.php.net References: <4F9E2173.50005@garfieldtech.com> <000e01cd269a$06f15230$14d3f690$@php.net> <002701cd26b5$1cd0bb70$56723250$@thetaphi.de> In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Subject: Re: [PHP-DEV] readfile() memory usage From: larry@garfieldtech.com (Larry Garfield) Thanks all. So it sounds like the answer is: 1) readfile() has always been memory-safe as far as PHP is concerned. 2) Because it uses mmap(), GFL trying to understand its memory usage from top. 3) Operating systems have gotten better at such things in the past decade. 4) So given #2 and #3, the "readfile() will kill your memory, don't use it" line is a persistent urban legend that belongs on Snopes as debunked. Looping on fread() for performance is a red herring. Is that an accurate summary? If so, I will blog my benchmark results and this conversation. --Larry Garfield On 4/30/12 5:33 AM, Sherif Ramadan wrote: >> Mmapping of course uses memory, but the memory used here is not from PHP's >> memory manager, it's memory that's already used for the O/S cache. The >> memory mapping used here does not enforce loading the file contents into O/S >> cache; it just gets a virtual address into the O/S cache. If the actual file >> contents are not yet in O/S cache, the O/S will hit a page fault and load >> the pages into memory. Apache Server uses the same mechanism to serve files. >> >> Maybe the "user confusion" about memory usage comes from that fact (they see >> lots of *virtual* memory used by PHP when viewed in top). I know this user >> confusion from my work in the Apache Lucene/Solr project, where one option >> (used on 64 bit operating systems) is to memory-map the whole Lucene >> full-text index. Users then see hundreds of Gigabytes of "virtual memory" >> usage in TOP / Windows Task Manager and are afraid of running their machine >> out of memory. This is always hard to explain to people that are not used to >> the term "virtual memory". >> > > > That's a very good point and a detailed look at the stack can show > some of the underlying mechanics coming from readfile and how its > pretty much is just implemented like fpassthru delegating a stream, as > you said. > > http://i.imgur.com/PWiTv.png > > >> >>> About php memory usage, one has to use an external tools to actually see >> this >>> memory usage as it is not managed by the zend memory manager. >> >> Of course... >> > > Also, running valgrind and taking a closer look at what memory blocks > PHP is allocating here it can be better determined what's leaking and > what isn't, of course... > > http://pastebin.com/LSQcUsBL > > > I can certainly attest to users being deceived by memory readings in > top in the past. It can be very deceiving if you think look at what > free memory top or `free` shows you especially after some huge > allocation. There's a clear difference here though between the Zend > memory manager allocating these blocks in PHP and what's going on with > readfile. The memory the system knows is available to it isn't being > tied up in this case. >