Skip to content

Commit 499ebe0

Browse files
authored
feat(memory): Add MemPool Free with alignment (alibaba#74)
1 parent 1a4d325 commit 499ebe0

3 files changed

Lines changed: 18 additions & 3 deletions

File tree

include/paimon/memory/memory_pool.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,11 +74,26 @@ class PAIMON_EXPORT MemoryPool {
7474
///
7575
/// Releases a previously allocated memory block back to the pool.
7676
/// The size must match the size used during allocation.
77+
/// The alignment used during allocation is not provided, subclass should store it
78+
/// by themselves if needed.
7779
///
7880
/// @param p Pointer to the memory block to deallocate.
7981
/// @param size Size of the memory block (must match allocation size).
8082
virtual void Free(void* p, uint64_t size) = 0;
8183

84+
/// Deallocate memory back to the pool with specified alignment.
85+
///
86+
/// Releases a previously allocated memory block back to the pool.
87+
/// The size and alignment must match the values used during allocation.
88+
/// Subclass can override this method to optimize deallocation based on alignment.
89+
///
90+
/// @param p Pointer to the memory block to deallocate.
91+
/// @param size Size of the memory block (must match allocation size).
92+
/// @param alignment Alignment of the memory block (must match allocation alignment).
93+
virtual void Free(void* p, uint64_t size, uint64_t alignment) {
94+
Free(p, size);
95+
}
96+
8297
/// Get current memory usage.
8398
///
8499
/// Returns the amount of memory currently allocated from this pool.

src/paimon/common/utils/arrow/mem_utils.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,8 @@ class ArrowMemPoolAdaptor : public arrow::MemoryPool {
4646
return arrow::Status::OK();
4747
}
4848

49-
void Free(uint8_t* buffer, int64_t size, int64_t /*alignment=*/) override {
50-
pool_.Free(buffer, size);
49+
void Free(uint8_t* buffer, int64_t size, int64_t alignment) override {
50+
pool_.Free(buffer, size, alignment);
5151
stats_.DidFreeBytes(size);
5252
}
5353

src/paimon/global_index/lumina/lumina_memory_pool.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ class LuminaMemoryPool : public std::pmr::memory_resource {
4444
}
4545

4646
void do_deallocate(void* p, std::size_t bytes, std::size_t alignment) override {
47-
pool_->Free(p, bytes);
47+
pool_->Free(p, bytes, alignment);
4848
}
4949

5050
bool do_is_equal(const std::pmr::memory_resource& other) const noexcept override {

0 commit comments

Comments
 (0)