fix(memtrack): track successful posix_memalign allocations#470
Open
not-matthias wants to merge 2 commits into
Conversation
not-matthias
marked this pull request as ready for review
July 24, 2026 11:58
Greptile SummaryAdds dedicated
Confidence Score: 5/5The PR appears safe to merge because no eligible blocking failures remain. No blocking failure remains. Important Files Changed
|
Merging this PR will not alter performance
|
posix_memalign was attached to the shared memalign uprobe handler, but
its ABI is inverted relative to memalign/aligned_alloc: it returns int 0
on SUCCESS (nonzero errno on failure) and delivers the pointer through
the memptr out-parameter rather than the return register. The shared
handler skipped any call returning 0 (treating a NULL malloc-style
return as failure), so every successful posix_memalign call was dropped,
undercounting the reported heap footprint. It also read the size from
PARM2 (alignment) instead of PARM3.
Add a dedicated posix_memalign uprobe/uretprobe pair that captures the
memptr out-parameter (PARM1) and size (PARM3) on entry, keeps calls
returning 0, and reads the allocated pointer back from *memptr via
bpf_probe_read_user on return.
Fold the regression case into the existing c_tests rstest table
(posix_memalign_test) instead of a standalone test file; the snapshot
asserts AlignedAlloc { size: 768 } followed by Free.
Add a posix_memalign_einval case to the c_tests rstest table. The fixture calls posix_memalign with alignment 3 (not a power-of-two multiple of sizeof(void*)), which returns EINVAL and allocates nothing, then does a real malloc/free. The snapshot asserts only Malloc/Free, proving the uretprobe drops the failing call (ret != 0) while tracking stays live for subsequent allocations.
not-matthias
force-pushed
the
cod-3238-memtrack-drops-all-successful-posix_memalign-allocations
branch
from
July 24, 2026 12:08
8071d34 to
b9aeda1
Compare
not-matthias
changed the base branch from
main
to
cod-3231-support-disabling-allocator-tracking
July 24, 2026 12:08
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.
Problem
posix_memalignwas attached to the sharedmemalignuprobe handler (UPROBE_ARG_RET), which assumes the standard allocator ABI. Butposix_memalign(void** memptr, size_t alignment, size_t size)is inverted:int 0on success (nonzero errno on failure), not a pointer.memptrout-parameter, not the return register.PARM3(PARM2is the alignment).The shared handler gated success on a non-NULL return and used the return register as the address. Since successful
posix_memalignreturns0, every successful allocation was treated as a failure and silently dropped.Fix
Dedicated uprobe/uretprobe pair for
posix_memalign:memptr(PARM1) andsize(PARM3) keyed by tid.RC == 0, reads the address back from*memptrviabpf_probe_read_user, then submits an aligned-alloc event.Test
Added
posix_memalign_testto the existing rstest table intests/c_tests.rswith a fixture + snapshot confirming the allocation is now tracked.