This is an archive of the discontinued LLVM Phabricator instance.

[NFC][lsan] Use hash table to track root regions
ClosedPublic

Authored by vitalybuka on May 31 2023, 12:08 AM.

Details

Summary

This avoid O(N) in __lsan_unregister_root_region.

Diff Detail

Event Timeline

vitalybuka created this revision.May 31 2023, 12:08 AM
Herald added a project: Restricted Project. · View Herald TranscriptMay 31 2023, 12:08 AM
Herald added a subscriber: Enna1. · View Herald Transcript
vitalybuka requested review of this revision.May 31 2023, 12:08 AM
Herald added a project: Restricted Project. · View Herald TranscriptMay 31 2023, 12:08 AM
Herald added a subscriber: Restricted Project. · View Herald Transcript

This avoid O(N^2) in __lsan_unregister_root_region.

O(N) ?

Is there a pessimistic case where size(root_regions) is in the scale of 1000+ ?

vitalybuka edited the summary of this revision. (Show Details)May 31 2023, 12:14 PM

This avoid O(N^2) in __lsan_unregister_root_region.

O(N) ?

Yes. N^2 is for entire app

Is there a pessimistic case where size(root_regions) is in the scale of 1000+ ?

Yes, it should make a difference of 1000+ but I don't know such examples. But it should be possible.
I was debugging perf regression and suspected this place.
But the real reason was request calls MemoryMappingLayout which is already fixed.

MaskRay accepted this revision.May 31 2023, 8:33 PM

Thanks!

compiler-rt/lib/lsan/lsan_common.cpp
524–536

Add a space after using RootRegions.

Add a comment like // A map that contains (region, count) pairs. Regions are non-overlapping.

528

We can just use alignas instead of ALIGNED.

Actually, static RootRegions *regions = new RootRegions();. The function-local static variable is constructed when executed for the first time.

#include <assert.h>
#include <stdio.h>

struct A {
  A() { puts("a"); }
  ~A() { assert(0); }
};

static A& foo() {
  puts("foo");
  static A *a = new A;
  return *a;
}

int main() {
  puts("main");
  foo();
  foo();
}
This revision is now accepted and ready to land.May 31 2023, 8:33 PM
MaskRay added inline comments.May 31 2023, 8:34 PM
compiler-rt/lib/lsan/lsan_common.cpp
524–536

Sorry, I mean add a blank line after using RootRegions

vitalybuka marked 2 inline comments as done.

update

vitalybuka added inline comments.May 31 2023, 9:32 PM
compiler-rt/lib/lsan/lsan_common.cpp
524–536

Add a space after using RootRegions.

Add a comment like // A map that contains (region, count) pairs. Regions are non-overlapping.

when in practice they should not be overlapping, we didn't enforce that before, I don't see good reason to enforce now.
this is one of reasons I use that algorithm

528

we don't have cxa_guard for static
BTW, maybe you have ideas how to easily get this without linking libc++

This revision was automatically updated to reflect the committed changes.