-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Free cached chunks when the requested memory limit is above real usage. #8053
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks very reasonable to me. Thank you!
It might be worthwhile to port this to PHP-8.0.
Very useful to have this as part of Wouldn't it also make sense to add something similar to |
|
This was not obvious to me. But if the shutdown takes the memory limit on startup into account, then there is indeed no issue. edit, other thought: And TIL that statistics (an average) are being kept on resource usage between requests. That would explain why my tests (from #7745 (comment)) showed a gradual increase/decrease in allocated memory at the start of a request. |
Merged into PHP-8.0 and above via c035298 |
Unfortunately this doesn't appear to be fixed, I was getting random but rare allowed memory exceeded in production (running 8.1.7 php-fpm on Linux), which I could not reproduce by repeating the requests (which run the same code and database queries). It runs past the memory limit in different places in my code (but usually memcached->get() or PDO->execute/fetch calls), this problem only manifested it self under higher than normal traffic, and the code hasn't changed that much. I did added extra breadcrumbs at start of request with I then logged memory_get_usage for all requests per process id, and most of them have 2mb at the start of requests, but some of them would start with higher memory usage, which drops in subsequent requests. After digging I landed on #7745 (comment)
I've also dumped /proc/self/smaps, and the only big map it shows is /dev/zero. |
@xPaw I think that log shows the expected behaviour. As Dmitry mentioned, php does not return all memory to the system after a request. It keeps the average peak memory allocated. This "real" memory is then reported on the next request (correctly since the fix of #7745). I would guess that the more accurate |
Yeah I did think about it more yesterday, and I double checked requests for how much memory my code was using, since it's deterministic (same request fetches same data) it doesn't quite make sense why only very few rare requests would run past the limit. |
Attempt to fix the problem mentioned at #7745