llvm-project/compiler-rt/lib
Kostya Kortchinsky bebdab63e8 [scudo][standalone] Correct releaseToOS behavior
Summary:
There was an issue in `releaseToOSMaybe`: one of the criteria to
decide if we should proceed with the release was wrong. Namely:

```
const uptr N = Sci->Stats.PoppedBlocks - Sci->Stats.PushedBlocks;
if (N * BlockSize < PageSize)
  return; // No chance to release anything.
```

I meant to check if the amount of bytes in the free list was lower
than a page, but this actually checks if the amount of **in use** bytes
was lower than a page.

The correct code is:

```
const uptr BytesInFreeList =
  Region->AllocatedUser -
  (Region->Stats.PoppedBlocks - Region->Stats.PushedBlocks) * BlockSize;
if (BytesInFreeList < PageSize)
  return 0; // No chance to release anything.
```

Consequences of the bug:
- if a class size has less than a page worth of in-use bytes (allocated
  or in a cache), reclaiming would not occur, whatever the amount of
  blocks in the free list; in real world scenarios this is unlikely to
  happen and be impactful;
- if a class size had less than a page worth of free bytes (and enough
  in-use bytes, etc), then reclaiming would be attempted, with likely
  no result. This means the reclaiming was overzealous at times.

I didn't have a good way to test for this, so I changed the prototype
of the function to return the number of bytes released, allowing to
get the information needed. The test added fails with the initial
criteria.

Another issue is that `ReleaseToOsInterval` can actually be 0, meaning
we always try to release (side note: it's terrible for performances).
so change a `> 0` check to `>= 0`.

Additionally, decrease the `CanRelease` threshold to `PageSize / 32`.
I still have to make that configurable but I will do it at another time.

Finally, rename some variables in `printStats`: I feel like "available"
was too ambiguous, so change it to "total".

Reviewers: morehouse, hctim, eugenis, vitalybuka, cferris

Reviewed By: morehouse

Subscribers: delcypher, #sanitizers, llvm-commits

Tags: #llvm, #sanitizers

Differential Revision: https://reviews.llvm.org/D68471

llvm-svn: 373930
2019-10-07 17:37:39 +00:00
..
BlocksRuntime [compiler-rt] Test commit: remove some trailing white spaces. 2017-08-25 19:36:30 +00:00
asan [compiler-rt] Use GetNextInstructionPc in signal handlers 2019-10-02 21:20:37 +00:00
builtins Fix int to bool errors exposed due to r372612. 2019-09-24 02:59:02 +00:00
cfi Improve error message when '=' is missing in {ASAN,...}_OPTIONS. 2019-06-15 01:37:14 +00:00
crt [compiler-rt][crt] make test case nontrivial in check_cxx_section_exists 2019-09-16 21:47:47 +00:00
dfsan [compiler-rt] Remove some cpplint filters 2019-09-12 02:20:36 +00:00
fuzzer [libFuzzer] Remove lazy counters. 2019-10-01 22:49:06 +00:00
gwp_asan Add GWP-ASan fuzz target to compiler-rt/tools. 2019-08-27 18:28:07 +00:00
hwasan hwasan: Compatibility fixes for short granules. 2019-09-27 01:02:10 +00:00
interception [compiler-rt] Remove some cpplint filters 2019-09-12 02:20:36 +00:00
lsan [compiler-rt] Use GetNextInstructionPc in signal handlers 2019-10-02 21:20:37 +00:00
msan [compiler-rt] Use GetNextInstructionPc in signal handlers 2019-10-02 21:20:37 +00:00
profile Revert "clang-misexpect: Profile Guided Validation of Performance Annotations in LLVM" 2019-09-11 09:16:17 +00:00
safestack compiler-rt: Rename .cc file in lib/{interception/tests,safestack} to .cpp 2019-08-01 13:56:52 +00:00
sanitizer_common compiler-rt: use __GLIBC_PREREQ for SANITIZER_INTERCEPT_GETRANDOM 2019-10-04 00:38:07 +00:00
scudo [scudo][standalone] Correct releaseToOS behavior 2019-10-07 17:37:39 +00:00
stats compiler-rt: Rename .cc file in lib/{dfsan,stats,ubsan_minimal} to .cpp 2019-08-01 12:41:23 +00:00
tsan [compiler-rt] Use GetNextInstructionPc in signal handlers 2019-10-02 21:20:37 +00:00
ubsan [compiler-rt] Use GetNextInstructionPc in signal handlers 2019-10-02 21:20:37 +00:00
ubsan_minimal compiler-rt: Rename .cc file in lib/{dfsan,stats,ubsan_minimal} to .cpp 2019-08-01 12:41:23 +00:00
xray Re-land "[compiler-rt] Migrate llvm::make_unique to std::make_unique" 2019-08-15 14:57:44 +00:00
CMakeLists.txt Reland "[compiler-rt] Simple crtbegin.o and crtend.o implementation" 2019-04-30 18:13:22 +00:00