Hi, On Tue, Jan 28, 2025 at 2:17 AM Arkadiy Kulev <e...@ethaniel.com> wrote:
> Hello everyone, > > I’d like to propose adding a new configuration directive, tentatively > called *pm.max_memory*, to PHP-FPM. This directive would allow > administrators to specify a per-child memory usage limit, after which the > PHP-FPM child process would gracefully exit or restart. > I think it's reasonable as an additional protection and a bit nicer than pm.max_requests. However, implementation might be tricky. > Implementation Details and Challenges > > I am not proposing to implement this feature myself—I’m more of a sysadmin > and don’t have the necessary C knowledge to patch php-src. However, here > are some thoughts on what the implementation might involve: > > 1. *Measuring memory usage:* Likely via getrusage(), mallinfo() (on > some platforms), or reading from /proc/self/statm on Linux. > > This wouldn't really work because FPM does not control the script during execution and would have to check it out after each allocation which is not really viable. > > - *System-level OOM or cgroups:* This approach can kill the entire > pool or container, which is often more disruptive than recycling a single > worker. > > I think this is really the only way that I can see to make it work reliably. We have got already an old feature request for that: https://bugs.php.net/bug.php?id=70605 . There was even a PR https://github.com/php/php-src/pull/2440 but it was using unmaintained lib and cgroup v1. We should use something cgroup v2 based but it is not a small job to add it. Anyway you can create a GitHub feature request for this so it doesn't get forgotten and maybe one day there will a better PR that can be accepted. Cheers Jakub