Skip to content

Fix object pool size reporting under ASan - #3739

Open
chenBright wants to merge 1 commit into
apache:masterfrom
chenBright:fix-object-pool-total-size
Open

chenBright wants to merge 1 commit into
apache:masterfrom
chenBright:fix-object-pool-total-size

Conversation

@chenBright

Copy link
Copy Markdown
Contributor

What problem does this PR solve?

Issue Number:

Related PR: #3737

Problem Summary:

ObjectPoolInfo::total_size uses sizeof(T), omitting alignment padding in ASan object-pool slots.

For example, allocating one char with the default configuration reports 256 bytes, although the block's slot array occupies 2048 bytes.

What is changed and the side effects?

Changed:

Calculate total_size using sizeof(BlockItem) to include slot alignment padding.

Side effects:

  • Performance effects:

  • Breaking backward compatibility:


Check List:

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.

🟢 Approval recommended

The review found no active issues, and the change is supported by targeted tests covering allocation, cleanup, and ASan versus non-ASan size calculations.

No open issues 🎉

What changed in this PR

This PR fixes how ObjectPoolInfo::total_size is calculated in bRPC's object pool. The old formula used sizeof(T), which left out the alignment padding that AddressSanitizer (ASan) adds to each slot. As a result, the reported size was too small under ASan. For example, one char with the default settings reported 256 bytes, but the block's slot array actually takes 2048 bytes. The fix uses sizeof(BlockItem), the real slot size, so the reported size matches the memory in use.

Changes:

  • total_size in ObjectPool::describe_objects now multiplies by sizeof(BlockItem) instead of sizeof(T).
  • Unit tests check total_size after allocating, returning, and clearing objects. They also check the expected size for a char under ASan (2048 bytes) and without ASan (256 bytes).
File Description
src/​butil/​object_pool_inl.h Changes the total_size formula to use sizeof(BlockItem), which includes slot alignment padding.
test/​object_pool_unittest.cpp Adds checks for total_size across allocation and cleanup, and a test for the char case with and without ASan.

Review effort: Lite

@chenBright
chenBright requested a review from wasphin November 13, 2026 03:06
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.

2 participants