The combined allocator rounds up the requested size with regard to the
alignment, which makes sense when being serviced by the primary as it comes
with alignment guarantees, but not with the secondary. For the rare case of
large alignments, it wastes memory, and entices unnecessarily large fields for
the Scudo header. With this patch, we pass the non-alignement-rounded-up size
to the secondary, and adapt the Scudo code for this change.
Details
- Reviewers
kcc alekseyshl - Commits
- rG2defe4d9a19d: [sanitizer] Do not use the alignment-rounded-up size when using the secondary
rCRT289088: [sanitizer] Do not use the alignment-rounded-up size when using the secondary
rL289088: [sanitizer] Do not use the alignment-rounded-up size when using the secondary
Diff Detail
- Repository
- rL LLVM
Event Timeline
lib/sanitizer_common/sanitizer_allocator_combined.h | ||
---|---|---|
62 ↗ | (On Diff #80326) | sanitizer_allocator_secondary.h adds alignment to the size prior to allocation and align the result properly. |
64 ↗ | (On Diff #80326) | If the allocation comes from the secondary, it's mmap backed and it's zero'd out, and we don't need to clear the memory again. |
lib/sanitizer_common/sanitizer_allocator_combined.h | ||
---|---|---|
62 ↗ | (On Diff #80326) | Understood, but this check feels a bit arbitrary now (to me, that is). Before your change it matched well with the similar if statement adjusting 'size', now it is puzzling why, while both allocators accept the alignment as a parameter, the resulting pointer is expected to be aligned only when alignment is greater than 8? |
64 ↗ | (On Diff #80326) | Ah, right, there's '&& from_primary' check... Then it seems to make sense to push 'cleared' flag down to allocators, since the particular allocator knows better the current state of the memory block. Anyway, not for this patch. |
lib/sanitizer_common/sanitizer_allocator_combined.h | ||
---|---|---|
62 ↗ | (On Diff #80326) | I agree it's a bit obscure, all the more since the primary doesn't take the alignment as parameter, but is expected to produced a 2^x aligned chunked when requested 2^x bytes (https://github.com/llvm-mirror/compiler-rt/blob/master/lib/sanitizer_common/sanitizer_allocator_combined.h#L20). |
LGTM
lib/sanitizer_common/sanitizer_allocator_combined.h | ||
---|---|---|
62 ↗ | (On Diff #80326) | Well, in the context of this patch, not much. Maybe a comment why if this is enforced only when alignment > 8? And primary allocator does care about alignment, although indirectly, in CanAllocate call. |
Added comments to the combined allocator Allocate to make clearer the expected behavior.