slog: buffer allocation on-demand#1024
Conversation
There was a problem hiding this comment.
Pull request overview
This PR updates ObStorageLoggerManager to stop pre-allocating the 128 standard (8KB) slog buffers at startup and instead allocate them on-demand when a standard-size slog item is first requested, while keeping the existing concurrency cap and reuse behavior.
Changes:
- Switch standard slog buffer pool initialization to only set up the fixed free-queue; allocate new 8KB buffers lazily when the queue is empty.
- Preserve
MAX_CONCURRENT_ITEM_CNTas the concurrency limiter by allocating the slog item before the standard buffer and adding rollback on failure. - Add/adjust unit tests to validate lazy allocation, alignment, reuse, and max concurrency behavior.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| unittest/storage/slog/test_storage_logger_manager.cpp | Updates and expands tests to assert zero pre-allocation, alignment, reuse, and max-concurrency behavior under lazy buffer allocation. |
| src/storage/slog/ob_storage_logger_manager.h | Updates internal APIs and adds a spin lock member to guard concurrent arena allocations. |
| src/storage/slog/ob_storage_logger_manager.cpp | Implements lazy standard buffer allocation, changes allocation order to preserve concurrency limits, and adds rollback logic on failures. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| log_buffer = reinterpret_cast<char *>(upper_align( | ||
| reinterpret_cast<int64_t>(raw_buffer), | ||
| ObLogConstants::LOG_FILE_ALIGN_SIZE)); | ||
| ret = OB_SUCCESS; |
There was a problem hiding this comment.
I initially tried using allocator_.alloc_aligned(NORMAL_LOG_ITEM_SIZE, LOG_FILE_ALIGN_SIZE), but the alignment unit test showed that the returned address was not always 4 KB aligned.
ObArenaAllocator::alloc_aligned() delegates to PageArena::_alloc_aligned(). When the current page does not have enough space and the allocator extends or allocates a new page, that path may return cur_page_->alloc(sz) without applying the alignment offset again.
The explicit padding and upper_align are therefore intentional to guarantee the required 4 KB alignment. The buffers are allocated only on-demand, reused through the free queue, and bounded by the 128 slog items.
Task Description
Closes #999.
ObStorageLoggerManagerpreviously pre-allocated 128 standard slog buffers during initialization. Each buffer is 8 KB, causing more than 1 MB ofStorageLoggerMmemory to be allocated even when no slog write is performed.This change allocates standard slog buffers on-demand while preserving the existing buffer size, alignment, concurrency limit, reuse semantics, and error behavior.
Solution Description
LOG_FILE_ALIGN_SIZEaddress alignment for newly allocated buffers.ObSpinLockGuard.MAX_CONCURRENT_ITEM_CNTremains the concurrency limit.Passed Regressions
The following relevant tests passed:
Upgrade Compatibility
This change does not change any public API, slog file format, standard buffer size, alignment requirement, or maximum concurrency limit. No upgrade or migration action is required.
Other Information
Standard slog buffers are aligned to
LOG_FILE_ALIGN_SIZEusingupper_align, preserving the existing buffer alignment requirement.Release Note
Reduce slog startup memory usage by allocating standard 8 KB slog buffers on-demand.