From 6b282f62c358122467b5ac362efffd828c3070db Mon Sep 17 00:00:00 2001 From: Abhijat Malviya Date: Fri, 29 Mar 2024 13:43:07 +0530 Subject: [PATCH] compression/storage: Use preallocated lz4 blocks (cherry picked from commit 34860a98f53c9276775ab45885ab4fa869bb6fa6) --- src/v/compression/internal/lz4_frame_compressor.cc | 12 +++++++----- src/v/compression/lz4_decompression_buffers.h | 1 + 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/src/v/compression/internal/lz4_frame_compressor.cc b/src/v/compression/internal/lz4_frame_compressor.cc index dece3b2aae0c9..236244692dae8 100644 --- a/src/v/compression/internal/lz4_frame_compressor.cc +++ b/src/v/compression/internal/lz4_frame_compressor.cc @@ -10,9 +10,8 @@ #include "compression/internal/lz4_frame_compressor.h" #include "bytes/bytes.h" +#include "compression/lz4_decompression_buffers.h" #include "static_deleter_fn.h" -#include "units.h" -#include "vassert.h" #include @@ -59,9 +58,12 @@ using lz4_decompression_ctx = std::unique_ptr< &LZ4F_freeDecompressionContext>>; static lz4_decompression_ctx make_decompression_context() { - LZ4F_dctx* c = nullptr; - LZ4F_errorCode_t code = LZ4F_createDecompressionContext(&c, LZ4F_VERSION); - check_lz4_error("LZ4F_createDecompressionContext error: {}", code); + LZ4F_dctx* c = LZ4F_createDecompressionContext_advanced( + lz4_decompression_buffers_instance().custom_mem_alloc(), LZ4F_VERSION); + if (c == nullptr) { + throw std::runtime_error("Failed to initialize decompression context"); + } + return lz4_decompression_ctx(c); } diff --git a/src/v/compression/lz4_decompression_buffers.h b/src/v/compression/lz4_decompression_buffers.h index fce743022f8a4..d8b96805c3fbd 100644 --- a/src/v/compression/lz4_decompression_buffers.h +++ b/src/v/compression/lz4_decompression_buffers.h @@ -81,6 +81,7 @@ class lz4_decompression_buffers { size_t deallocs{0}; size_t pass_through_allocs{0}; size_t pass_through_deallocs{0}; + bool operator==(const stats&) const = default; }; void allocated() { _allocation_stats.allocs += 1; }