This is an archive of the discontinued LLVM Phabricator instance.

[sanitizer] Size class map & local cache improvements
ClosedPublic

Authored by cryptoad on Feb 8 2018, 1:38 PM.

Details

Summary
  • Reland rL324263, this time allowing for a compile-time decision as to whether or not use the 32-bit division. A single test is using a class map covering a maximum size greater than 4GB, this can be checked via the template parameters, and allows SizeClassAllocator64PopulateFreeListOOM to pass;
  • MaxCachedHint is always called on a class id for which we have already computed the size, but we still recompute Size(class_id). Change the prototype of the function to work on sizes instead of class ids. This also allows us to get rid of the kBatchClassID special case. Update the callers accordingly;
  • InitCache and Drain will start iterating at index 1: index 0 contents are unused and can safely be left to be 0. Plus we do not pay the cost of going through an UNLIKELY in MaxCachedHint, and touching memory that is otherwise not used;
  • const some variables in the areas modified;
  • Remove an spurious extra line at the end of a file.

Diff Detail

Event Timeline

cryptoad created this revision.Feb 8 2018, 1:38 PM
Herald added subscribers: Restricted Project, delcypher, kubamracek. · View Herald TranscriptFeb 8 2018, 1:38 PM
dberris accepted this revision.Feb 8 2018, 9:28 PM
dberris added a subscriber: dberris.

LGTM

This revision is now accepted and ready to land.Feb 8 2018, 9:28 PM
alekseyshl added inline comments.Feb 9 2018, 11:24 AM
lib/sanitizer_common/sanitizer_allocator_local_cache.h
101

Does

c->class_size = Allocator::ClassIdToSize(i);
c->max_count = 2 * SizeClassMap::MaxCachedHint(c->class_size);

lead to less optimal code?

223–224

I think we should either use size everywhere in this function or assign c->class_size first and then use it everywhere.

cryptoad added inline comments.Feb 9 2018, 12:22 PM
lib/sanitizer_common/sanitizer_allocator_local_cache.h
101

It leads to almost exactly the same asm (at least for x64).
Do you prefer yours?

cryptoad added inline comments.Feb 9 2018, 12:25 PM
lib/sanitizer_common/sanitizer_allocator_local_cache.h
234

If keeping the size construct, I can use size instead of c->class_size here.

alekseyshl accepted this revision.Feb 9 2018, 2:21 PM
alekseyshl added inline comments.
lib/sanitizer_common/sanitizer_allocator_local_cache.h
101

Yep, mine is more concise.

234

Please do

cryptoad updated this revision to Diff 133693.Feb 9 2018, 2:56 PM
cryptoad marked 3 inline comments as done.

Replacing a c->class_size by size.

cryptoad marked 3 inline comments as done.Feb 9 2018, 3:00 PM
cryptoad added inline comments.
lib/sanitizer_common/sanitizer_allocator_local_cache.h
101

After discussion, having a const uptr size looks safer to prevent a potential refetching. So this will stay as is.

alekseyshl added inline comments.Feb 9 2018, 3:00 PM
lib/sanitizer_common/sanitizer_allocator_local_cache.h
101

As discussed offline, let's keep the current version and switch to 'size' in InitCache.

This revision was automatically updated to reflect the committed changes.
cryptoad marked an inline comment as done.