Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:107308 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 83239 invoked from network); 24 Sep 2019 09:22:19 -0000 Received: from unknown (HELO php-smtp3.php.net) (208.43.231.12) by pb1.pair.com with SMTP; 24 Sep 2019 09:22:19 -0000 Received: from php-smtp3.php.net (localhost [127.0.0.1]) by php-smtp3.php.net (Postfix) with ESMTP id F11512CD539 for ; Tue, 24 Sep 2019 00:01:08 -0700 (PDT) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on php-smtp3.php.net X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,FREEMAIL_FROM, HTML_MESSAGE,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE, URIBL_BLOCKED autolearn=no autolearn_force=no version=3.4.2 X-Spam-ASN: AS15169 209.85.128.0/17 X-Spam-Virus: No Received: from mail-qt1-f175.google.com (mail-qt1-f175.google.com [209.85.160.175]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by php-smtp3.php.net (Postfix) with ESMTPS for ; Tue, 24 Sep 2019 00:01:08 -0700 (PDT) Received: by mail-qt1-f175.google.com with SMTP id x5so915627qtr.7 for ; Tue, 24 Sep 2019 00:01:08 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:reply-to :from:date:message-id:subject:to:cc; bh=P7/HeNjZrvgjSNpCVDkMXYFXCpp4uVI18UPreDTyIvE=; b=azL38jKI6a/AENEMx4+9KWsXN2Szj9gAEk/ew2f/r+tfMrVpa2+Sw/vJ6hSjL+sfGT eVxF9UjQpYXCMIwFJck9SXWsBLfhavbCzBTUezGFFffZompKPR3PRf9EyQ8B38Rl6nUI LXtLSOrLE8wso9HkT3myA9ZpLlZrywDh97ZrLK82nCxPVHH6CzxJIaAF3SC1GvqlmH4D BuH/D5tZazyFWFLRMPCKyxZyFrViiUBtvtq/tVG0rXGpxVP1gNrHPt++z4WjRzYzPwEf WRi37rXyrQsbiLwgQ3GAY998lQ+brWXt2MY+3c7RqR5riyLySa8R39h2mFb9cXzHOmsj JOFg== X-Gm-Message-State: APjAAAWYsxfkPAl67Dy/OKgiuSvpicDP2/6L4oP+Nk94NFdtUSRkkY6x w0BgQSSWgy/nkaaOOVZGSTXmBM5LhU2y3SUlXjA= X-Google-Smtp-Source: APXvYqztifksJxcA+YeliXoRzBy2b439GUSek5dg7ivTjMTxe9viHCSNMKt3jYmj+9LWMWtwarojd8RMmQQyXwYckY0= X-Received: by 2002:a05:6214:444:: with SMTP id cc4mr1250161qvb.132.1569308467763; Tue, 24 Sep 2019 00:01:07 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: Reply-To: bishop@php.net Date: Tue, 24 Sep 2019 03:00:42 -0400 Message-ID: To: Peter Stalman Cc: "internals@lists.php.net" Content-Type: multipart/alternative; boundary="000000000000c39f7505934719ac" X-Envelope-From: Subject: Re: [PHP-DEV] Shutdown Memory Allowance (aka Soft Memory Limit) From: bishop@php.net (Bishop Bettini) --000000000000c39f7505934719ac Content-Type: text/plain; charset="UTF-8" On Tue, Sep 24, 2019 at 2:26 AM Peter Stalman wrote: > When PHP runs out of memory, a fatal error is triggered and whatever > shutdown > functions or error handlers take over. > > However, in the case of error logging, or just logging in general, there > often > needs to be additional memory used to accommodate the final logging > process. > > This can sort of be accomplished in userland a few ways: > > 1. Pre-allocating memory in a variable, such as the Yii2 error handler > (http://bit.ly/2kLnpd2), but this requires wasting memory on every > request. > > 2. Continuously checking the memory usage, but this increases code > complexity > needlessly and also wastes resources with constant checking. > > 3. A second process with its own memory allowance, but this also increases > complexity and transferring the required data for logging would require > serialization without using additional memory. I'm not sure how this > would be > accomplished. > > So I would like to suggest an option for setting a shutdown memory > allowance, > which would be the amount of additional memory allowed to be used by any > registered error handlers or shutdown functions. > > I think a C implementation of this in PHP would be far more efficient than > the > userland implementionations I mentioned. > Memory parachutes help when against a hard limit, but I'm not sure they're applicable in the soft limit scenario you describe. When the OOM condition fires, PHP resets its soft tracking of memory. You are free to allocate as much on the stack of the shutdown function, up to the soft limit again. Here[1] we see the shutdown function called because of OOM, then we allocate a local variable that consumes less than the soft limit (which is ok), while here[2] we see the shutdown function itself is constrained to the soft limit (it's killed b/c of OOM). Perhaps I am misunderstanding the scenario. Could you elaborate further, perhaps provide a concrete example demonstrating where a parachute would be needed? [1]:https://3v4l.org/bXMlX [2]:https://3v4l.org/HDkRc --000000000000c39f7505934719ac--