This is an archive of the discontinued LLVM Phabricator instance.

[sanitizer] Minor 32-bit primary improvements
ClosedPublic

Authored by cryptoad on May 9 2018, 12:09 PM.

Details

Summary

For the 32-bit TransferBatch:

  • SetFromArray callers have bounds count, so relax the CHECK to DCHECK;
  • same for Add;
  • mark CopyToArray as const;

For the 32-bit Primary:

  • {Dea,A}llocateBatch are only called from places that check class_id, relax the CHECK to DCHECK;
  • same for AllocateRegion;
  • remove GetRegionBeginBySizeClass that is not used;
  • use a local variable for the random shuffle state, so that the compiler can use a register instead of reading and writing to the SizeClassInfo at every iteration;

For the 32-bit local cache:

  • pass the count to drain instead of doing a Min everytime which is at times superfluous.

Diff Detail

Repository
rL LLVM

Event Timeline

cryptoad created this revision.May 9 2018, 12:09 PM
Herald added subscribers: Restricted Project, delcypher, kubamracek. · View Herald TranscriptMay 9 2018, 12:09 PM

And I forgot:

  • the SizeClassInfo mutex should be a StaticSpinMutex since it's zero initialized and doesn't need to be "constructed";
alekseyshl added inline comments.May 15 2018, 2:17 PM
lib/sanitizer_common/sanitizer_allocator_local_cache.h
183 ↗(On Diff #145981)

Drain(c, allocator, class_id, c->count / 2); is the same, but reads a bit easier, more logical ("drain half of the elements").

192 ↗(On Diff #145981)

Why the loop, why don't we drain the class in one call?

Drain(c, allocator, i, c->count);

We used to have to have a loop because of the Drain API, but now we can specify the number of elements to drain.

lib/sanitizer_common/sanitizer_allocator_primary32.h
305 ↗(On Diff #145981)

Add a comment why you need a local variable here, otherwise someone will "optimize" it back later or, better yet, add a local variable in RandomShuffle and let the compiler do its job generating the best code possible.

cryptoad updated this revision to Diff 146921.May 15 2018, 2:38 PM
cryptoad marked 2 inline comments as done.

Addressing a couple of comments from Aleksey.

cryptoad added inline comments.May 15 2018, 2:38 PM
lib/sanitizer_common/sanitizer_allocator_local_cache.h
192 ↗(On Diff #145981)

Since the TransferBatch that we are using can only hold max_count / 2, we can't directly drain count.
I could change it to something like if count > max_count / 2 then we can drain max_count / 2, then drain count elements.

alekseyshl added inline comments.May 15 2018, 3:15 PM
lib/sanitizer_common/sanitizer_allocator_local_cache.h
192 ↗(On Diff #145981)

Ah, I see.

This restriction was not obvious before and it is even more obfuscated now. Was Min() call in Drain so taxing that it is worth complicating the already not so easy to follow logic of the code? If it is not, I'd rather not change the code. If it is though, well, do it, but add a DCHECK to Drain to document the restriction of this API: DCHECK_LE(count, c->max_count / 2); and ignore my previous comment, Drain(c, allocator, class_id, c->max_count / 2);

cryptoad added inline comments.May 15 2018, 3:21 PM
lib/sanitizer_common/sanitizer_allocator_local_cache.h
192 ↗(On Diff #145981)

Yeah you are right it's not worth it. I'll revert this part to its original state.

cryptoad updated this revision to Diff 146937.May 15 2018, 3:23 PM

The changes to the local cache were not worth doing. Reverting those.

alekseyshl accepted this revision.May 15 2018, 3:55 PM
This revision is now accepted and ready to land.May 15 2018, 3:55 PM
This revision was automatically updated to reflect the committed changes.