cherry-pick zstd fix + add guc for off changes#158
cherry-pick zstd fix + add guc for off changes#158visill merged 14 commits intoMDB_6_25_STABLE_YEZZEYfrom
Conversation
gpdb uses zstd to compress workfiles, but it can't control memory allocation within zstd. Meanwhile, zstd allocates as much memory as it needs which results in ambiguous error message in a case of memory exhaustion and can make OOM killer stop gpdb processes with force. This patch forces zstd to use our custom allocator which can keep track of allocated memory. Since this zstd feature is experimental and its api can change, we also had to link zstd statically.
Smyatkin-Maxim
left a comment
There was a problem hiding this comment.
There is a leak that needs to be fixed.
IMO The perfect solution would be to make MemoryContext a member of BufFile. Then create context when we create BufFile and drop the context when we close BufFile.
The problem is that we need to pass this context somehow to custommem, BUT I see that there is a member named opaque in ZSTD_customMem. I didn't find any documentation on how to use it, but I believe you can do something like customMem.opaque = (void *)file_buf->memory_context; and use this context from customAlloc and customFree.
This way you get rid of global context (which can't be even made static), and get rid of the leak.
Smyatkin-Maxim
left a comment
There was a problem hiding this comment.
LGTM now, feel free to squash and merge
* ADBDEV-3774 Use custom allocators for zstd (#566) gpdb uses zstd to compress workfiles, but it can't control memory allocation within zstd. Meanwhile, zstd allocates as much memory as it needs which results in ambiguous error message in a case of memory exhaustion and can make OOM killer stop gpdb processes with force. This patch forces zstd to use our custom allocator which can keep track of allocated memory. Since this zstd feature is experimental and its api can change, we also had to link zstd statically. * Add GUC --------- Co-authored-by: Dennis Kovalenko <kds@arenadata.io>
* ADBDEV-3774 Use custom allocators for zstd (#566) gpdb uses zstd to compress workfiles, but it can't control memory allocation within zstd. Meanwhile, zstd allocates as much memory as it needs which results in ambiguous error message in a case of memory exhaustion and can make OOM killer stop gpdb processes with force. This patch forces zstd to use our custom allocator which can keep track of allocated memory. Since this zstd feature is experimental and its api can change, we also had to link zstd statically. * Add GUC --------- Co-authored-by: Dennis Kovalenko <kds@arenadata.io>
* ADBDEV-3774 Use custom allocators for zstd (#566) gpdb uses zstd to compress workfiles, but it can't control memory allocation within zstd. Meanwhile, zstd allocates as much memory as it needs which results in ambiguous error message in a case of memory exhaustion and can make OOM killer stop gpdb processes with force. This patch forces zstd to use our custom allocator which can keep track of allocated memory. Since this zstd feature is experimental and its api can change, we also had to link zstd statically. * Add GUC --------- Co-authored-by: Dennis Kovalenko <kds@arenadata.io>
* ADBDEV-3774 Use custom allocators for zstd (#566) gpdb uses zstd to compress workfiles, but it can't control memory allocation within zstd. Meanwhile, zstd allocates as much memory as it needs which results in ambiguous error message in a case of memory exhaustion and can make OOM killer stop gpdb processes with force. This patch forces zstd to use our custom allocator which can keep track of allocated memory. Since this zstd feature is experimental and its api can change, we also had to link zstd statically. * Add GUC --------- Co-authored-by: Dennis Kovalenko <kds@arenadata.io>
Here are some reminders before you submit the pull request
make installcheck