Commit Graph

602 Commits

Author SHA1 Message Date
Daniel Micay
086eb1fee4 at a final spacing class of 1 slot size classes 2019-04-10 16:32:24 -04:00
Daniel Micay
7a89a7b8c5 support for slabs with 1 slot for largest sizes 2019-04-10 16:26:49 -04:00
Daniel Micay
b31e8dacb1 document extended size classes 2019-04-10 08:42:32 -04:00
Daniel Micay
6c31f6710a support extended range of small size classes 2019-04-10 08:31:51 -04:00
Daniel Micay
1b34fd4a69 enable 4 arenas by default 2019-04-10 08:12:59 -04:00
Daniel Micay
d5f18c47b3 micro-optimize initialization with arenas 2019-04-10 08:07:24 -04:00
Daniel Micay
62c73d8b41 harden thread_arena check 2019-04-10 07:40:29 -04:00
Daniel Micay
d5c00b4d0d disable current in-place growth code path for now 2019-04-09 19:20:34 -04:00
Daniel Micay
d5c1bca915 use round-robin assignment to arenas
The initial implementation was a temporary hack rather than a serious
implementation of random arena selection. It may still make sense to
offer it but it should be implemented via the CSPRNG instead of this
silly hack. It would also make sense to offer dynamic load balancing,
particularly with sched_getcpu().

This results in a much more predictable spread across arenas. This is
one place where randomization probably isn't a great idea because it
makes the benefits of arenas unpredictable in programs not creating a
massive number of threads. The security benefits of randomization for
this are also quite small. It's not certain that randomization is even a
net win for security since it's not random enough and can result in a
more interesting mix of threads in the same arena for an attacker if
they're able to attempt multiple attacks.
2019-04-09 16:54:14 -04:00
Daniel Micay
9a0de626fc move stats accounting to utility functions 2019-04-09 03:57:44 -04:00
Daniel Micay
02bfcc3b75 chacha: add constant for number of rounds 2019-04-09 01:29:35 -04:00
Daniel Micay
cef7368b3c disable unusable readability-magic-numbers lint
This wouldn't be worth using even if it had a whole bunch of heuristics
like ignoring expressions in static_assert, ignoring repeated patterns
like assigning different things to sequential array indexes, etc.
2019-04-09 00:58:06 -04:00
Daniel Micay
295bfbde94 disable bugprone-too-small-loop-variable lint
This has too many false positives since it doesn't permit comparisons
against constants where the compiler can verify it doesn't overflow.
2019-04-09 00:55:16 -04:00
Daniel Micay
8b2b9d940a chacha: use C99 variable declaration style
This further aligns the code style with the rest of the project and
fixes the clang-tidy readability-isolate-declaration lint triggered by
declaring all of these variables together.
2019-04-09 00:18:17 -04:00
Daniel Micay
9453332e57 remove redundant else block 2019-04-09 00:06:17 -04:00
Daniel Micay
922c741915 it already supports Bionic, musl and glibc 2019-04-07 18:13:26 -04:00
Daniel Micay
a4cff7a960 factor out slab memory_set_name into label_slab 2019-04-07 18:02:56 -04:00
Daniel Micay
ef90f404a6 add sanity check for stats option 2019-04-07 09:06:03 -04:00
Daniel Micay
e0891c8cfc implement the option of large size classes
This extends the size class scheme used for slab allocations to large
allocations. This drastically improves performance for many real world
programs using incremental realloc growth instead of using proper growth
factors. There are 4 size classes for every doubling in size, resulting
in a worst case of ~20% extra virtual memory being reserved and a huge
increase in performance for pathological cases. For example, growing
from 4MiB to 8MiB by calling realloc in increments of 32 bytes will only
need to do work beyond looking up the size 4 times instead of 1024 times
with 4096 byte granularity.
2019-04-07 08:52:17 -04:00
Daniel Micay
7a7126e780 add infrastructure for a larger guard size option 2019-04-07 06:07:09 -04:00
Daniel Micay
c68de6141d factor out duplicated code in malloc/realloc 2019-04-07 05:48:10 -04:00
Daniel Micay
ce36d0c826 split out allocate_large function 2019-04-07 05:44:09 -04:00
Daniel Micay
3d18fb8074 implement Android M_PURGE mallopt via malloc_trim 2019-04-07 03:35:26 -04:00
Daniel Micay
4f08e40fe5 move thread sealing implementation 2019-04-07 00:50:26 -04:00
Daniel Micay
55891357ff clean up the exported API section of the code 2019-04-07 00:36:53 -04:00
Daniel Micay
0651c819e3 clarify hardened_malloc extensions section 2019-04-07 00:34:13 -04:00
Daniel Micay
491ce6b0b1 no need to provide valloc and pvalloc on Android 2019-04-07 00:31:09 -04:00
Daniel Micay
1eed432b9a limit more glibc cruft to that environment 2019-04-07 00:30:05 -04:00
Daniel Micay
ec8fb347ed document CONFIG_STATS 2019-04-07 00:10:22 -04:00
Daniel Micay
beaa39a5a3 move to only supporting current generation AOSP 2019-04-06 23:46:35 -04:00
Daniel Micay
27a4c883ce extend stats with nmalloc and ndalloc 2019-04-06 23:19:03 -04:00
Daniel Micay
e94fe50a0d include zero byte size class in stats
The allocations don't consume any actual memory, but it does still use
up the virtual memory assigned to the size class and requires metadata.
2019-04-06 22:43:56 -04:00
Daniel Micay
712748aaa8 add implementation of Android mallinfo extensions
These are used internally by Bionic to implement malloc_info.
2019-04-06 22:39:01 -04:00
Daniel Micay
0f107cd2a3 only provide malloc_info stub for glibc
This has a proper implementation in Bionic outside of the malloc
implementation via the extended mallinfo API.
2019-04-06 22:01:12 -04:00
Daniel Micay
350d0e5fd2 add real mallinfo implementation for Android
Android Q uses the mallinfo implementation in the ART GC:

c220f98180
1575267302
2019-04-06 20:54:26 -04:00
Daniel Micay
7acebaa837 overhaul glibc compatibility workarounds 2019-03-26 01:45:57 -04:00
Daniel Micay
df9650fe64 conditionally include threads.h 2019-03-26 01:28:27 -04:00
Daniel Micay
98deb9de52 relabel malloc read-only after init data 2019-03-25 20:34:10 -04:00
Daniel Micay
fc8f2c3b60 move pthread_atfork wrapper to util header 2019-03-25 17:16:52 -04:00
Daniel Micay
b5187a0aff only use __register_atfork hack for old glibc 2019-03-25 17:16:22 -04:00
Daniel Micay
494cc5ec50 update README now that arenas are implemented 2019-03-25 16:18:01 -04:00
Daniel Micay
c5e911419d add initial implementation of arenas 2019-03-25 14:59:50 -04:00
Daniel Micay
55769496dc move hash_page to pages.h 2019-03-25 14:54:22 -04:00
Daniel Micay
13de480bde rename quarantine bitmap field for clarity 2019-03-24 20:24:40 -04:00
Daniel Micay
3d142eb4c2 relabel large allocation guards when shrinking 2019-03-23 23:01:12 -04:00
Daniel Micay
64dfd23f7b relabel purged slabs 2019-03-23 22:59:59 -04:00
Daniel Micay
178ec6e3f9 relabel quarantined large allocation regions 2019-03-23 22:57:19 -04:00
Daniel Micay
6e67106882 label malloc slab region gaps 2019-03-23 22:54:56 -04:00
Daniel Micay
1d62075291 label allocate_aligned_pages mappings 2019-03-23 22:29:04 -04:00
Daniel Micay
c8b948e202 enable C++17 support when available 2019-03-23 19:46:54 -04:00