You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hello, sorry for writing here what is actually not an issue, but a question, however AFAIK the Jemalloc mailing list is no longer active. Jemalloc 4.0.3 is used in recent Redis releases. Over the last months we got sporadic crash reports related to a file, ziplist.c that is almost the same for years at this point. So I read the changelog of Jemalloc to understand if we are using something that contains problems that could cause a memory corruption. My feeling is that Redis is the only big user of Jemalloc 4.0.3 since later new improved releases were released at a fast speed and we are now at 4.4.x. I'm going to upgrade in the next days as well, however reading the change log I cannot find any critical bug involving 4.0.3 related to the basic API we use: malloc/realloc/calloc/free. I wonder if this is correct, or if you are aware of non trivial bugs that could be present in such a release that could explain the sporadic corruptions we are seeing. Thank you.
I'm unaware of any malloc/calloc/realloc/free issues in 4.0.3 through 4.4.0, but if you have a semi-reproducible crash case, we may be able to narrow down the cause of the bug (whether in jemalloc or redis) by enabling some of jemalloc's debugging facilities.
Is redis 3433 an example of the issue you're investigating? One random thought is that perhaps malloc/calloc/realloc is returning NULL due to being out of memory.
P.S. This is the proper forum for asking questions; no apology needed.
Thanks @jasone I really appreciate your reply. Yes, https://github.com/antirez/redis/issues/3433 is exactly one of those cases. It is not possible for allocators to return NULL in Redis because we wrap Jemalloc in zmalloc.c that aborts on OOM. Basically Redis crashes on out of memory, it is a condition that is avoided by the maxmemory directive that will free stuff or report errors when the limit is reached. Or if this configuration is lacking, we abort the server completely.
P.S. Ora Agra, one of my colleagues at Redis Labs, implemented, using Jemalloc, a run-time defragmentation procedure that was merged into Redis 4.0. In order to do that we had to add a (very small) new function to jemalloc that given a piece of memory returned by malloc(), returns metrics to understand if the allocation is contributing to fragmentation. If so, we reallocate it using MALLOCX_TCACHE_NONE and fix the references. With this trick Oran was able to provide remarkable results. In workloads fragmenting jemalloc we are able, by enabling on-demand the defragmentation routine and then purging the memory, to return to a sane fragmentation level. So we'll try to open an issue in order to understand if the function that reports the hints about the allocation could be added to the Jemalloc code base. It's a small function, but you know much better if/how to implement it of course, so we'll go for an issue describing the use case instead of a PR. Thank you I'm closing this issue and continuing with the auditing of ziplist.c in the hope to find bugs.
@antirez, I was thinking about the defragmentation procedure you mentioned, and realized that a very simple way to achieve similar results would be to move-reallocate all small objects. This would cause nearly optimal dense packing into the oldest runs, and allow all the drained runs to be reclaimed.
@jasone yes, that's exactly what we are doing (I think), but before moving an allocation, the @oranagra implementation checks if the reallocation is actually allocated with a given bin/run utilization ratio that makes it a good candidate for reallocation, in order to save some work. Large or huge bins are never reallocated. Maybe @oranagra could provide more insights.
Activity
jasone commentedon Jan 17, 2017
I'm unaware of any malloc/calloc/realloc/free issues in 4.0.3 through 4.4.0, but if you have a semi-reproducible crash case, we may be able to narrow down the cause of the bug (whether in jemalloc or redis) by enabling some of jemalloc's debugging facilities.
Is redis 3433 an example of the issue you're investigating? One random thought is that perhaps malloc/calloc/realloc is returning
NULLdue to being out of memory.P.S. This is the proper forum for asking questions; no apology needed.
antirez commentedon Jan 17, 2017
Thanks @jasone I really appreciate your reply. Yes, https://github.com/antirez/redis/issues/3433 is exactly one of those cases. It is not possible for allocators to return
NULLin Redis because we wrap Jemalloc inzmalloc.cthat aborts on OOM. Basically Redis crashes on out of memory, it is a condition that is avoided by themaxmemorydirective that will free stuff or report errors when the limit is reached. Or if this configuration is lacking, we abort the server completely.antirez commentedon Jan 17, 2017
P.S. Ora Agra, one of my colleagues at Redis Labs, implemented, using Jemalloc, a run-time defragmentation procedure that was merged into Redis 4.0. In order to do that we had to add a (very small) new function to jemalloc that given a piece of memory returned by malloc(), returns metrics to understand if the allocation is contributing to fragmentation. If so, we reallocate it using
MALLOCX_TCACHE_NONEand fix the references. With this trick Oran was able to provide remarkable results. In workloads fragmenting jemalloc we are able, by enabling on-demand the defragmentation routine and then purging the memory, to return to a sane fragmentation level. So we'll try to open an issue in order to understand if the function that reports the hints about the allocation could be added to the Jemalloc code base. It's a small function, but you know much better if/how to implement it of course, so we'll go for an issue describing the use case instead of a PR. Thank you I'm closing this issue and continuing with the auditing ofziplist.cin the hope to find bugs.jasone commentedon Jan 18, 2017
@antirez, I was thinking about the defragmentation procedure you mentioned, and realized that a very simple way to achieve similar results would be to move-reallocate all small objects. This would cause nearly optimal dense packing into the oldest runs, and allow all the drained runs to be reclaimed.
antirez commentedon Jan 18, 2017
@jasone yes, that's exactly what we are doing (I think), but before moving an allocation, the @oranagra implementation checks if the reallocation is actually allocated with a given bin/run utilization ratio that makes it a good candidate for reallocation, in order to save some work. Large or huge bins are never reallocated. Maybe @oranagra could provide more insights.
oranagra commentedon Jan 18, 2017
Hi, i started a new discussion about it in issue #566