Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:86303 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 44770 invoked from network); 19 May 2015 14:29:52 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 19 May 2015 14:29:52 -0000 Authentication-Results: pb1.pair.com header.from=rowan.collins@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=rowan.collins@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.212.182 as permitted sender) X-PHP-List-Original-Sender: rowan.collins@gmail.com X-Host-Fingerprint: 209.85.212.182 mail-wi0-f182.google.com Received: from [209.85.212.182] ([209.85.212.182:32904] helo=mail-wi0-f182.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 7F/C8-13816-FD84B555 for ; Tue, 19 May 2015 10:29:51 -0400 Received: by wicmx19 with SMTP id mx19so119168025wic.0 for ; Tue, 19 May 2015 07:29:48 -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=PHxIJ9vuuTH3g0QayGYp+jBnj8uCpuw1zFGi+2y6znk=; b=EMtrGX05WcMxhCyUH5CKW3gvq8s+WrouWkxUEYyPnRIOMkpmJp9TFyLN3hEIQGUzW8 5sCsKGoqltv8Co9RhovAK2H0fIU4yKgxxtCcY3HnQLPEhZ5NMJqVqslkol4v6UJfGSvP UvajPpMfCIp6/5jqktsgo3qJAVlnx6W8atq9oGBv2KaGlWc1kCjEwekv/BynmTTPxzpo oxBuFuD+zR/gbCgv0fxn6BzhkNNO/jYU2kLG/TZrMv3Rd1OeIOCUk5QBbOieWI9KThpv t/DNrj9+UM2zBWaEEJPngV+21ok+sWptu9ijfptH1xJEXxn6djFEzn+u13noBlDSs3Qa 0ckQ== X-Received: by 10.180.83.40 with SMTP id n8mr24421518wiy.57.1432045788839; Tue, 19 May 2015 07:29:48 -0700 (PDT) Received: from [192.168.0.159] ([62.189.198.114]) by mx.google.com with ESMTPSA id pd7sm13277231wjb.27.2015.05.19.07.29.47 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 19 May 2015 07:29:48 -0700 (PDT) Message-ID: <555B4889.7030808@gmail.com> Date: Tue, 19 May 2015 15:28:25 +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> <555A81FA.5080507@gmail.com> In-Reply-To: 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) Dan Ackroyd wrote on 19/05/2015 14:08: > * When gc_collect_cycles is called (and potentially other functions), > at the end of that function check whether the amount of memory being > used is less than reset level for each trigger. If so reduce the > current memory limit to the lowest trigger level. The only flaw I see in this approach is that the majority of memory deallocation is done transparently be the ref-counting mechanism, not any particular function, and the user should be able to trigger this manually. For instance, you might have an EntityRepository which caches all the entities it's loaded thus far in the script to save DB round trips, and calling clearCache() on this repository might free a significant amount of memory. It would probably make sense for the memory level to be checked against reset levels immediately after the low-memory callback returns, so that users can deliberately take advantage of such deallocations. However, that still leaves the case of that method being called during normal flow, and requiring a call to gc_collect_cycles just for the side-effect of resetting memory limits seems a bit odd. I don't know enough about the memory manager to know, but presumably at the moment memory_limit is checked on every allocation? Could a similar check be made on deallocation? Having multiple levels configured doesn't actually have any extra performance cost, except in the case where they are all passed at once - you just store the "current" level, and test whether you have reached the next level up or down. If a single deallocation drops you from 20MB to 2MB, you first register that the 16MB reset limit has been reached, and *only then* perform an extra check if the 8MB reset limit has also been reached. Regards, -- Rowan Collins [IMSoP]