Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:60375 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 74256 invoked from network); 30 Apr 2012 10:33:39 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 30 Apr 2012 10:33:39 -0000 Authentication-Results: pb1.pair.com header.from=theanomaly.is@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=theanomaly.is@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.217.170 as permitted sender) X-PHP-List-Original-Sender: theanomaly.is@gmail.com X-Host-Fingerprint: 209.85.217.170 mail-lb0-f170.google.com Received: from [209.85.217.170] ([209.85.217.170:55085] helo=mail-lb0-f170.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 9E/6A-13197-18A6E9F4 for ; Mon, 30 Apr 2012 06:33:39 -0400 Received: by lbgc1 with SMTP id c1so820699lbg.29 for ; Mon, 30 Apr 2012 03:33:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; bh=Lu8ikYm6u+TqYnHEm862GMcEYupRiOxUl5fapJgLHaU=; b=VIEQpWr3TCyQbpd3wqsY91870Dy8S8bQUmhQ8sMpEeImwVIByebb1UTdsR3oy/eYh4 VyKFtbEmNL6OdE4kq1GJ0Z8vl4YHoxAIsX/FVZLw8S/fulzihOz2l4KfaW5ExbdOYz4e Zi6MUAi3F/ZHI11ESNyrMNJ47huFctq0j9ojSBknsDlC4Asf0BQ5zcRubiPTEHT60JFk LiQJhfwh3hhuyVCFJ/eMgrgOBGAyBfZymL26e8UaKcbwVBh8s+FoDAPOX3s+3x58+DCf U2eDtP5Kn3fPcMVzROzboghVSbfAY860WYxFwkTQ3tGWdFjyRYaKQ1IzD5fKTDoNIpSz Axcw== MIME-Version: 1.0 Received: by 10.112.32.39 with SMTP id f7mr9706954lbi.74.1335782014357; Mon, 30 Apr 2012 03:33:34 -0700 (PDT) Received: by 10.112.100.227 with HTTP; Mon, 30 Apr 2012 03:33:34 -0700 (PDT) In-Reply-To: <002701cd26b5$1cd0bb70$56723250$@thetaphi.de> References: <4F9E2173.50005@garfieldtech.com> <000e01cd269a$06f15230$14d3f690$@php.net> <002701cd26b5$1cd0bb70$56723250$@thetaphi.de> Date: Mon, 30 Apr 2012 06:33:34 -0400 Message-ID: To: Uwe Schindler Cc: Pierre Joye , Uwe Schindler , Larry Garfield , internals@lists.php.net Content-Type: text/plain; charset=ISO-8859-1 Subject: Re: [PHP-DEV] readfile() memory usage From: theanomaly.is@gmail.com (Sherif Ramadan) > 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.