[PATCH] D68471: [scudo][standalone] Correct releaseToOS behavior

Kostya Kortchinsky via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Oct 4 10:10:27 PDT 2019


cryptoad created this revision.
cryptoad added reviewers: morehouse, hctim, eugenis, vitalybuka, cferris.
Herald added subscribers: Sanitizers, delcypher.
Herald added projects: LLVM, Sanitizers.

There was an issues 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.

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".


Repository:
  rCRT Compiler Runtime

https://reviews.llvm.org/D68471

Files:
  lib/scudo/standalone/primary32.h
  lib/scudo/standalone/primary64.h
  lib/scudo/standalone/tests/primary_test.cpp

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D68471.223242.patch
Type: text/x-patch
Size: 9532 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20191004/9a464c8b/attachment.bin>


More information about the llvm-commits mailing list