Skip to content

slog: buffer allocation on-demand#1024

Open
pfyao1101 wants to merge 1 commit into
oceanbase:developfrom
pfyao1101:fix/issue-999
Open

slog: buffer allocation on-demand#1024
pfyao1101 wants to merge 1 commit into
oceanbase:developfrom
pfyao1101:fix/issue-999

Conversation

@pfyao1101

@pfyao1101 pfyao1101 commented Jul 12, 2026

Copy link
Copy Markdown

Task Description

Closes #999.

ObStorageLoggerManager previously pre-allocated 128 standard slog buffers during initialization. Each buffer is 8 KB, causing more than 1 MB of StorageLoggerM memory 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

  • Initialize only the fixed queue used to manage standard slog buffers during startup.
  • Allocate an 8 KB standard slog buffer when the free buffer queue is empty.
  • Preserve LOG_FILE_ALIGN_SIZE address alignment for newly allocated buffers.
  • Protect concurrent arena allocation with ObSpinLockGuard.
  • Reuse released standard buffers through the existing fixed queue.
  • Allocate the slog item before its buffer so that MAX_CONCURRENT_ITEM_CNT remains the concurrency limit.
  • Roll back the allocated item and buffer if a later allocation or initialization step fails.
  • Add unit tests covering lazy allocation, address alignment, buffer reuse, and the maximum concurrency limit.

Passed Regressions

The following relevant tests passed:

  • test_storage_logger_manager: 4/4 passed
  • test_storage_log_read_write: 8/8 passed
  • test_storage_log_replay: 3/3 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_SIZE using upper_align, preserving the existing buffer alignment requirement.

Release Note

Reduce slog startup memory usage by allocating standard 8 KB slog buffers on-demand.

@CLAassistant

CLAassistant commented Jul 12, 2026

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@pfyao1101 pfyao1101 marked this pull request as ready for review July 12, 2026 07:37
Copilot AI review requested due to automatic review settings July 12, 2026 07:37

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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_CNT as 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.

Comment on lines +240 to +243
log_buffer = reinterpret_cast<char *>(upper_align(
reinterpret_cast<int64_t>(raw_buffer),
ObLogConstants::LOG_FILE_ALIGN_SIZE));
ret = OB_SUCCESS;

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Change standard slog buffer allocation from pre-allocated to on-demand

3 participants