Add mremap and shmat/shmdt allocation tracking#556
Open
r1viollet wants to merge 1 commit into
Open
Conversation
Extends allocation tracking to cover memory allocation APIs that were previously missing: 1. mremap() - Remap/resize existing mmap regions - Tracks old region as deallocation + new region as allocation - Commonly used by allocators to grow large allocations (e.g., df-executor) 2. shmat()/shmdt() - System V shared memory attach/detach - Queries segment size via shmctl(IPC_STAT) on attach - Commonly used by databases (PostgreSQL, Oracle) and legacy IPC These APIs can bypass malloc/mmap hooks when called directly, leading to under-reporting of memory usage in allocation profiles. brk()/sbrk() are explicitly not instrumented (with comment explaining why): they manipulate the program break (heap boundary), not individual allocations, and would double-count if malloc uses them internally. Tests added in allocation_tracker-ut.cc for both mremap and shmat/shmdt.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Adds allocation tracking hooks for
mremap()and System V shared memory (shmat()/shmdt()).Why
These APIs can allocate or deallocate memory without going through malloc/mmap, leading to under-reporting in allocation profiles. Notable examples:
mremap()is used to grow large allocations (e.g., df-executor mmaps)shmat()/shmdt()are used by databases (PostgreSQL, Oracle) for System V shared memoryChanges
Instrumentation added (
src/lib/symbol_overrides.cc):mremap()- tracks old region as dealloc + new region as allocshmat()- queries segment size viashmctl(IPC_STAT)and tracks as allocshmdt()- tracks as deallocNot instrumented (with comment explaining why):
brk()/sbrk()- manipulate the program break, not individual allocations. Would double-count if malloc uses them internally, and have wrong semantics (heap boundary vs allocated objects).Tests added (
test/allocation_tracker-ut.cc):mremaptest viatest_reallocpatternshmat/shmdttest with IPC_PRIVATE segmentAll tests gated by weak symbol checks.
Verification
Unit tests pass for the new hooks. Full CI validation pending.