27 Commits

Author SHA1 Message Date
Fabio D'Urso
4b189961c5
[scudo] Use MemMap in BufferPool and RegionPageMap (#66788) 2023-09-28 16:34:41 +02:00
Vitaly Buka
2bfcecf4d4 [NFC][scudo] Fix "comparison of integers of different signs" 2023-09-27 09:23:03 -07:00
Fabio D'Urso
76a5602fd0
[scudo] Always express sizes in terms of element count in BufferPool (#66896)
This fixes the issue that resulted in getBuffer interpreting its
argument as a number of elements and getDynamicBuffer interpreting it
as a number of bytes.
2023-09-27 15:57:57 +02:00
Christopher Ferris
e2a9d3f851
[scudo] Remove AndroidSvelteConfig. (#66444)
This config is not actually used anywhere and it is not used on Android.
Since it does not test anything not tested elsewhere, remove it.

Remove the size class data associated with this config too.
2023-09-18 13:57:55 -07:00
Christopher Ferris
af41f79f40 [scudo] Clean up tests.
Modify the tests so that all clang warnings can be turned up to high.

Fix all places flagged by -Wconversion.

Fix a few unused variables not marked with UNUSED.

For the memtag testing, only compile some tests for 64 bit since
compiling them on 32 bit leads to warnings/errors. All of the tests
are already skipped on 32 bit OSes, so this will not affect any
real tests.

Reviewed By: Chia-hungDuan

Differential Revision: https://reviews.llvm.org/D155749
2023-07-20 14:02:40 -07:00
Chia-hung Duan
11ea40cff5 [scudo] releaseToOSMaybe can fail if it can't allocate PageMap
PageMap is allocated with MAP_ALLOWNOMEM if there's no static buffer
left. So it can be failed and return nullptr without any assertion
triggered. Instead of crashing in the releaseToOSMaybe in the middle,
just return and let the program handles the page failure.

Reviewed By: cferris

Differential Revision: https://reviews.llvm.org/D151379
2023-05-25 18:07:55 +00:00
Chia-hung Duan
6fb70a8a60 [scudo] Fix missing one block in range marking
When a range contains only one block, we may not mark the pages touched
by the block as can-be-released. This happens in the last group and if
it only contains single block.

Also enhance the existing tests and add a new test for testing the last
block.

Differential Revision: https://reviews.llvm.org/D149866
2023-05-05 14:55:18 +00:00
Fabio D'Urso
248ee65ac6 [scudo] Test ScudoReleaseTest.BufferPool with a buffer pool allocated on the heap
The previous code resulted in 252 KiB being allocated on the stack,
which caused a stack overflow on Fuchsia.

Reviewed By: Chia-hungDuan

Differential Revision: https://reviews.llvm.org/D146229
2023-03-16 18:13:43 +00:00
Chia-hung Duan
c514198e4d [scudo] Adjust page map buffer size
Given the memory group, we are unlikely to need a huge page map to
record entire region. This CL reduces the size of default page map
buffer from 2048 to 512 and increase the number of static buffers to 2.

Reviewed By: cferris

Differential Revision: https://reviews.llvm.org/D144754
2023-03-08 21:19:43 +00:00
Chia-hung Duan
657d297a92 [scudo] Simplify markFreeBlocks
With memory group, we always mark the free blocks from the same region.
Therefore, we don't need to calculate the offset from base and determine
the region index. Also improve the way we deal with the last block in
the region so that the loop body is simpler.

Reviewed By: cferris

Differential Revision: https://reviews.llvm.org/D143303
2023-03-07 21:55:04 +00:00
Chia-hung Duan
5b9d6097e7 Reland D144920 "[scudo] Only prepare PageMap entry for partial region
This reverts commit daaef4c49954cb04ea1831615e0876865a29a08a.

Differential Revision: https://reviews.llvm.org/D144920
2023-03-06 16:38:18 +00:00
Chia-hung Duan
daaef4c499 Revert "Revert "Revert "[scudo] Only prepare PageMap entry for partial region"""
ScudoReleaseTest.ReleaseFreeMemoryToOSAndroid failed on Fuchsia

This reverts commit c6ef6bbd8d964028ee6c2f03441604d7a7ba5375.
2023-03-02 20:37:55 +00:00
Chia-hung Duan
c6ef6bbd8d Revert "Revert "[scudo] Only prepare PageMap entry for partial region""
Fixed the bug in merging BatchGroups back to the FreeList. Added DCHECKs
to ensure the order of BatchGroups

This reverts commit 387452ec591c81def6d8869b23c2ab2f1c56f999.

Reviewed By: cferris

Differential Revision: https://reviews.llvm.org/D144920
2023-02-28 16:55:48 +00:00
Chia-hung Duan
387452ec59 Revert "[scudo] Only prepare PageMap entry for partial region"
This reverts commit 0a0b6fa4fbdf3bdeb300ddd58859f66b714b8bdf.
2023-02-27 21:12:28 +00:00
Chia-hung Duan
0a0b6fa4fb [scudo] Only prepare PageMap entry for partial region
This reduces the size of PageMap and we are more likely to use the
static local buffer. Note that now this is only supported for single
region case, i.e. on SizeClassAllocator64. For SizeClassAllocator32,
it needs a different way to save the PageMap.

Differential Revision: https://reviews.llvm.org/D142659
2023-02-27 18:49:10 +00:00
Chia-hung Duan
a78805f3cb [scudo] Mark all blocks in a range without visiting each of them
When all the blocks in the group are known to be used, we should just
mark the pages in the range as all counted instead of visiting each of
them. This will reduce the time of marking free blocks especially for
smaller size class.

Reviewed By: cferris

Differential Revision: https://reviews.llvm.org/D141958
2023-02-23 23:26:03 +00:00
Chia-hung Duan
a9269773eb [scudo] Improve the uses of roundUpTo/roundDownTo/isAligned
The implementations of those functions require the rounding target to be
power-of-two. It's better to add a debugging check to avoid misuse.
Besides, add a general verion of those three to accommadate non
power-of-two cases.

Also change the name to roundUp/roundDown/isAligned

Reviewed By: cferris, cryptoad

Differential Revision: https://reviews.llvm.org/D142658
2023-02-15 23:44:44 +00:00
Chia-hung Duan
a1e325ce7c [scudo] Lazy initialize the PageMap while page releasing
We allocate the page map before knowing if there're groups can be
released. This may result in many redundant map()/unmap() operations if
there's no page to release.

Make the page map be lazy initialized.

Differential Revision: https://reviews.llvm.org/D136873
2022-10-28 20:29:17 +00:00
Chia-hung Duan
56dafd024c [scudo] Add PageReleaseContext to convey page usage status.
PageReleaseContext contains all the information needed for determing if
a page can be released. Splitting out the context increases the flexibility
of heterogenous free lists in the future. Also rename PackedCounterArray to
PageMap.

Reviewed By: cryptoad, cferris

Differential Revision: https://reviews.llvm.org/D133895
2022-10-13 23:35:06 +00:00
Chia-hung Duan
0fb2aeef53 Use u16 to store Count/MaxCount
The Count/MaxCount used in TransferBatch and PerClass can be fit in u16 in
current configurations and it's also reasonable to have a u16 limit. The
spare 16 bits will be used for additional status like pages mapping
status in a TransferBatch.

Reviewed By: cryptoad, cferris, vitalybuka

Differential Revision: https://reviews.llvm.org/D133145
2022-10-13 23:35:06 +00:00
Kostya Kortchinsky
2c56776a31 [scudo][standalone] Compact pointers for Caches/Batches
This CL introduces configuration options to allow pointers to be
compacted in the thread-specific caches and transfer batches. This
offers the possibility to have them use 32-bit of space instead of
64-bit for the 64-bit Primary, thus cutting the size of the caches
and batches by nearly half (and as such the memory used in size
class 0). The cost is an additional read from the region information
in the fast path.

This is not a new idea, as it's being used in the sanitizer_common
64-bit primary. The difference here is that it is configurable via
the allocator config, with the possibility of not compacting at all.

This CL enables compacting pointers in the Android and Fuchsia default
configurations.

Differential Revision: https://reviews.llvm.org/D96435
2021-02-25 12:14:38 -08:00
Kostya Kortchinsky
bd5ca4f0ed [scudo][standalone] Skip irrelevant regions during release
With the 'new' way of releasing on 32-bit, we iterate through all the
regions in between `First` and `Last`, which covers regions that do not
belong to the class size we are working with. This is effectively wasted
cycles.

With this change, we add a `SkipRegion` lambda to `releaseFreeMemoryToOS`
that will allow the release function to know when to skip a region.
For the 64-bit primary, since we are only working with 1 region, we never
skip.

Reviewed By: hctim

Differential Revision: https://reviews.llvm.org/D86399
2020-08-25 07:41:02 -07:00
Kostya Kortchinsky
998334da2b [scudo][standalone] Change the release loop for efficiency purposes
Summary:
On 32-b, the release algo loops multiple times over the freelist for a size
class, which lead to a decrease in performance when there were a lot of free
blocks.

This changes the release functions to loop only once over the freelist, at the
cost of using a little bit more memory for the release process: instead of
working on one region at a time, we pass the whole memory area covered by all
the regions for a given size class, and work on sub-areas of `RegionSize` in
this large area. For 64-b, we just have 1 sub-area encompassing the whole
region. Of course, not all the sub-areas within that large memory area will
belong to the class id we are working on, but those will just be left untouched
(which will not add to the RSS during the release process).

Reviewers: pcc, cferris, hctim, eugenis

Subscribers: llvm-commits, #sanitizers

Tags: #sanitizers

Differential Revision: https://reviews.llvm.org/D83993
2020-07-24 10:35:49 -07:00
Kostya Kortchinsky
c753a306fd [scudo][standalone] Various improvements wrt RSS
Summary:
This patch includes several changes to reduce the overall footprint
of the allocator:
- for realloc'd chunks: only keep the same chunk when lowering the size
  if the delta is within a page worth of bytes;
- when draining a cache: drain the beginning, not the end; we add pointers
  at the end, so that meant we were draining the most recently added
  pointers;
- change the release code to account for an freed up last page: when
  scanning the pages, we were looking for pages fully covered by blocks;
  in the event of the last page, if it's only partially covered, we
  wouldn't mark it as releasable - even what follows the last chunk is
  all 0s. So now mark the rest of the page as releasable, and adapt the
  test;
- add a missing `setReleaseToOsIntervalMs` to the cacheless secondary;
- adjust the Android classes based on more captures thanks to pcc@'s
  tool.

Reviewers: pcc, cferris, hctim, eugenis

Subscribers: #sanitizers, llvm-commits

Tags: #sanitizers, #llvm

Differential Revision: https://reviews.llvm.org/D75142
2020-02-26 12:25:43 -08:00
Kostya Kortchinsky
0d3d4d3b0f [scudo][standalone] Make tests work on Fuchsia
Summary:
This CL makes unit tests compatible with Fuchsia's zxtest. This
required a few changes here and there, but also unearthed some
incompatibilities that had to be addressed.

A header is introduced to allow to account for the zxtest/gtest
differences, some `#if SCUDO_FUCHSIA` are used to disable incompatible
code (the 32-bit primary, or the exclusive TSD).

It also brought to my attention that I was using
`__scudo_default_options` in different tests, which ended up in a
single binary, and I am not sure how that ever worked. So move
this to the main cpp.

Additionally fully disable the secondary freelist on Fuchsia as we do
not track VMOs for secondary allocations, so no release possible.

With some modifications to Scudo's BUILD.gn in Fuchsia:
```
[==========] 79 tests from 23 test cases ran (10280 ms total).
[  PASSED  ] 79 tests
```

Reviewers: mcgrathr, phosek, hctim, pcc, eugenis, cferris

Subscribers: srhines, jfb, #sanitizers, llvm-commits

Tags: #sanitizers, #llvm

Differential Revision: https://reviews.llvm.org/D70682
2019-11-27 09:17:40 -08:00
Kostya Kortchinsky
6f2de9cbb3 [scudo][standalone] Consolidate lists
Summary:
This is a clean patch using the last diff of D69265, but using git
instead of svn, since svn went ro and arc was making my life harded
than it needed to be.

I was going to introduce a couple more lists and realized that our
lists are currently a bit all over the place. While we have a singly
linked list type relatively well defined, we are using doubly linked
lists defined on the fly for the stats and for the secondary blocks.

This CL adds a doubly linked list object, reorganizing the singly list
one to extract as much of the common code as possible. We use this
new type in the stats and the secondary. We also reorganize the list
tests to benefit from this consolidation.

There are a few side effect changes such as using for iterator loops
that are, in my opinion, cleaner in a couple of places.

Reviewers: hctim, morehouse, pcc, cferris

Reviewed By: hctim

Subscribers: jfb, #sanitizers, llvm-commits

Tags: #sanitizers, #llvm

Differential Revision: https://reviews.llvm.org/D69516
2019-10-28 09:34:36 -07:00
Nico Weber
3fa3831830 compiler-rt: Rename .cc file in lib/scudo/standalone/tests to .cpp
Like r367463, but for scudo/standalone/tests.

With this, all files in compiler-rt/lib have extension cpp.

llvm-svn: 367569
2019-08-01 14:38:49 +00:00