This is an archive of the discontinued LLVM Phabricator instance.

[sanitizer] Allocator local cache improvements
ClosedPublic

Authored by cryptoad on Feb 2 2018, 9:53 AM.

Details

Summary

Here are a few improvements proposed for the local cache:

  • InitCache always read from per_class_[1] in the fast path. This was not ideal as we are working with per_class_[class_id]. The latter offers the same property we are looking for (eg: max_count != 0 means initialized), so we might as well use it and keep our memory accesses local to the same per_class_ element. So change InitCache to take the current PerClass as an argument. This also makes the fast-path assembly of Deallocate a lot more compact;
  • Change the 32-bit Refill & Drain functions to mimic their 64-bit counterparts, by passing the current PerClass as an argument. This saves some array computations;
  • As far as I can tell, InitCache has no place in Drain: it's either called from Deallocate which calls InitCache, or from the "upper" Drain which checks for c->count to be greater than 0 (strictly). So remove it there.
  • Move the stats_ updates to after we are done with the per_class_ accesses in an attempt to preserve locality once more;
  • Change some CHECK to DCHECK: I don't think the ones changed belonged in the fast path and seemed to be overly cautious failsafes;
  • Mark some variables as const.

The overall result is cleaner more compact fast path generated code, and some
performance gains with Scudo (and likely other Sanitizers).

Diff Detail

Event Timeline

cryptoad created this revision.Feb 2 2018, 9:53 AM
Herald added subscribers: Restricted Project, delcypher, kubamracek. · View Herald TranscriptFeb 2 2018, 9:53 AM
cryptoad updated this revision to Diff 132617.Feb 2 2018, 9:55 AM

Remove an extraneous CHECK.

alekseyshl accepted this revision.Feb 5 2018, 10:05 AM
This revision is now accepted and ready to land.Feb 5 2018, 10:05 AM
This revision was automatically updated to reflect the committed changes.