-
Notifications
You must be signed in to change notification settings - Fork 7.8k
php-fpm: free(): invalid pointer when used with jemalloc #11133
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
Comments
Possible duplicate of #10670 |
Yes this is indeed the same LD_PRELOAD problem, see #10670 (comment) |
Ok, this is means what it is not possible to use jemalloc with php-fpm at all? May be in this case, php-fpm can detect jemalloc substitution of glibc malloc, and write graceful error message to user? Because error message "free(): invalid pointer" is not user friendly and looks like php internal bug loke double free or something like this. Or this is not php bug at all, but this is jemalloc bug, and this bug should be fixed in jemalloc code? If this is jemalloc bug - issue about it should be open it the jemalloc bug tracker ? |
Right now it is indeed not possible to use the LD_PRELOAD hack to override the allocator. As a workaround you could try to get rid of the RTLD_DEEPBIND option in your build of PHP, but this will most likely cause issues with 3rd party libraries that define the same global symbols.
I'm not sure if that's possible to do in a reliable way. There are usages of LD_PRELOAD that do not involve allocators that work.
It's more of a limitation in how these alternative allocators are injected. Any application that uses RTLD_DEEPBIND to load its libraries can break. In the past jemalloc used a workaround that allowed it to be used with RTLD_DEEPBIND, but glibc removed support for that workaround recently. It would probably be possible to add a configuration option to PHP to allow overriding the allocator at configure+compile time, but even then using LD_PRELOAD to override the allocator will not work. |
Why do you try to use jemalloc with FPM in the first place? From what I remember it claims to be more scallable so it probably make sense in multithreaded apps but there are no threads in FPM so what would be the actual advantage? |
Yes, you are right, jemalloc is very good for Percona Server for MySQL (compiled statically) or for Redis (also compiled statically). It was my mistake - I think what if jemalloc is good for Percona Server for MySQL and Redis - this is means what jemalloc will be good for every other software, so I enable jemalloc via /etc/ld.so.preload for all programs, and got crashes for php-fpm. Now I realized my mistake and stop trying to use jemalloc for each program in the system. |
So maybe it's not just better for multithreaded apps as Redis is single threaded and mentions better fragmentation here but it's mem intensive app so it's more likely it needs better allocator. PHP uses it's own allocator for program run that is optimized for PHP execution so it is less likely there will be significant improvement. FPM uses libc allocator for non request related usage (e.g. master process) so it might get some improvements but not sure if there will be any visible impact as the amount of new allocations is much smaller compare to databases. |
As I can see from
Ok, Jakub thank you for detailed explanation, now I completely understand my mistake and stop trying to use jemalloc with php-fpm. BTW, not only php-fpm, but nginx also has use its own, very effective memory allocator, which gives it a high speed of work. |
Description
The following code:
Resulted in this output:
But I expected this output instead:
PHP Version
PHP 8.2.5
Operating System
Rocky Linux 9.1
The text was updated successfully, but these errors were encountered: