Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:86299 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 83919 invoked from network); 19 May 2015 00:21:18 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 19 May 2015 00:21:18 -0000 Authentication-Results: pb1.pair.com smtp.mail=rowan.collins@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=rowan.collins@gmail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 74.125.82.44 as permitted sender) X-PHP-List-Original-Sender: rowan.collins@gmail.com X-Host-Fingerprint: 74.125.82.44 mail-wg0-f44.google.com Received: from [74.125.82.44] ([74.125.82.44:32799] helo=mail-wg0-f44.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 47/90-13816-EF18A555 for ; Mon, 18 May 2015 20:21:18 -0400 Received: by wgjc11 with SMTP id c11so44592532wgj.0 for ; Mon, 18 May 2015 17:21:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=message-id:date:from:user-agent:mime-version:to:subject:references :in-reply-to:content-type:content-transfer-encoding; bh=E+YIsaI9g7w/WCxCy+/j7X0I6K1GE2b+sNrBtzNqkno=; b=K9iyfaQYDf8nt3h1rIlUanPnhfOTlEW36vll+Y8anYVWcTCqwCoEmOdC2mD+7kFNp9 sXKYvFCX8dkSuHPDaFCg5uGd62fh0mqWCYeIV3gW5Ty7NOzRWTHot6feBF8Rtk4D7iPg kJPc2wmMvOjHChJECcQ6dOyTbhNFy/hubGrIiKzmVGBd7hQHV1F2N5TGoS9577BrB9TX hhrhcIa/yrd9w0oqamABhBT/hpaXYbe7sMsywk47T+19vz2RBkZOOjijYPGwHt+L1ODx 7Dz4alNqWyXEvoexrO/8n7Zrq0XneGrEGyY8Q67l/ZtqrD0Pdb6+iwH0sXZnVZuKpuWz xF4w== X-Received: by 10.180.216.40 with SMTP id on8mr3881091wic.55.1431994875632; Mon, 18 May 2015 17:21:15 -0700 (PDT) Received: from [192.168.0.5] (cpc68956-brig15-2-0-cust215.3-3.cable.virginm.net. [82.6.24.216]) by mx.google.com with ESMTPSA id qs2sm19151529wjc.31.2015.05.18.17.21.14 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 18 May 2015 17:21:14 -0700 (PDT) Message-ID: <555A81FA.5080507@gmail.com> Date: Tue, 19 May 2015 01:21:14 +0100 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:31.0) Gecko/20100101 Thunderbird/31.6.0 MIME-Version: 1.0 To: internals@lists.php.net References: <55567DD2.1090608@gmx.de> <555A70C1.9000409@gmx.de> In-Reply-To: <555A70C1.9000409@gmx.de> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Subject: Re: [PHP-DEV] trigger GC before memory limit is exhausted From: rowan.collins@gmail.com (Rowan Collins) On 19/05/2015 00:07, Christoph Becker wrote: >> As Rasmus suggested[1], in an issue linked through #60982, a simple >> >way to solve this would be to have both a soft and hard limit for >> >memory, and to allow the soft-limit to be a user callback, which could >> >call gc_collect_cycles, or not as the user desired. > What happens if the soft limit is exhausted, but the GC can free only a > little memory? That might trigger the GC shortly afterwards again and > again. A user would have to carefully adjust the soft limit > dynamically, to work around this problem. Then again, it might be > better than the current situation. Apart from chewing CPU cycles, would that actually be a problem? The soft-limit callback would presumably be responsible for doing one of two things: gracefully terminating the request (the "pretty error page" use case) or reducing the used amount of memory (the "trigger GC" use case). If the memory usage was still over the soft limit when the callback ends, the engine could terminate as though the hard limit was reached. Rather than adding a soft limit, you could say that we are adding an additional reserve of memory only accessible to the memory-out callback. If the callback freed at least some memory, the engine could execute at least one instruction before the soft limit was reached a second time, triggering the callback again. In the worst case, a loop could repeatedly push usage over the limit, triggering the callback repeatedly like a tick function; however, one of the following would then have to happen: - the oscillation could continue for a while, but the loop or the whole program eventually finish normally, just a bit slower than normal - if the net amount of memory freed by the callback was slightly higher than the net amount allocated after it returned, the memory usage would slowly decline, breaking out of the oscillation once it dropped below the soft limit - if the amount of memory freed was lower than the amount allocated, the memory usage would slowly grow, eventually reaching the hard limit - if the amount of memory freed and allocated was consistently identical, the oscillation could continue and cause the program to hit the execution timeout Dynamically adjusting the limit would be no help, because if you're that hard up against the limit, your only hope is to gracefully end the process anyway. -- Rowan Collins [IMSoP]