Commit Graph

85 Commits

Author SHA1 Message Date
Nathaniel Filardo
12111ae7d3 ds/cdllist: factor out next to base classes
Choose between implementations based on aal's requirement of strict
provenance.
2020-05-21 12:43:38 +00:00
Nathaniel Filardo
3f32f37e60 Eliminate pointer_cast()
Since we anticipate address_t not carrying provenance on CHERI, but
rather being vaddr_t there, it doesn't make sense to offer conversion
back to a provenance-carrying pointer.

Thankfully, there is not much to be done here: the uses were few and
could be replaced with the vocabulary of other pointer operations in
ds/address.h
2020-05-19 14:53:55 +00:00
Matthew Parkinson
a9cfc3a2b4 Various minor changes to aid compiling with std14 (#182)
These changes make the code compile in clang10 with -std14.
2020-05-07 15:02:31 +01:00
Paul Liétar
0f5cc165e8 Don't require 16-byte CAS on x86. (#173)
* Don't require 16-byte CAS on x86.

We only need to CAS 2 pointers, which is always possible on x86.

* Fix the way the Image variable is referenced.

* Replace failOnStderr by `set -eo pipefail` on Linux.

The x86 image doesn't have clangformat, which causes cmake to print a
warning on the stderr. Exit codes should be enough to detect failure.

* Use x86 images from snmallocciteam.

* clang-format
2020-04-16 07:33:02 +01:00
Matthew Parkinson
fe8b8a0891 Improved assume defines. 2020-04-13 08:33:52 +01:00
Matthew Parkinson
cf9c2eb9d9 Addressing OE linking issues when built with GCC (#167)
* Use C++17 inline statics

This leads to better codegen in GCC, and fixes some linking issues in OE.

* Detect GCC and OE combination and fall-back to lock based ABA.

* clangformat
2020-04-10 13:49:39 +01:00
Paul Liétar
6f697e06ef Add missing closing > 2020-04-10 12:54:09 +02:00
Paul Liétar
1ccb808a18 Fix clang-tidy warning and CR comments. 2020-04-10 12:36:36 +02:00
Paul Liétar
794a5912c7 Replace uses of std::function by function_ref. 2020-04-09 15:47:11 +02:00
Paul Liétar
89523a96bd Add back the peek methods to ABA. (#165)
These are used by the Verona runtime.
2020-04-09 14:13:57 +01:00
Matthew Parkinson
74657d9dbc Defensive code for alloc/dealloc during TLS teardown (#161)
* Defensive code for alloc/dealloc during TLS teardown

If an allocation or deallocation occurs during TLS teardown, then it is
possible for a new allocator to be created and then this is leaked. On
the mimalloc-bench mstressN benchmark this was observed leading to a
large memory leak.

This fix, detects if we are in the TLS teardown phase, and if so,
the calls to alloc or dealloc must return the allocator once they have
perform the specific operation.

Uses a separate variable to represent if a thread_local's destructor has
run already.  This is used to detect thread teardown to put the
allocator into a special slow path to avoid leaks.

* Added some printing first operation to track progress

* Improve error messages on posix

Flush errors, print assert details, and present stack traces.

* Detect incorrect use of pool.

* Clang format.

* Replace broken LL/SC implementation

LL/SC implementation was broken, this replaces it with
a locking implementation. Changes the API to support LL/SC
for future implementation on ARM.

* Improve TLS teardown.

* Make std::function fully inlined.

* Factor out PALLinux stack trace.

* Add checks for leaking allocators.

* Add release build of Windows Clang
2020-04-07 15:37:26 +01:00
Matthew Parkinson
d900e29424 Improve slow path performance for allocation (#143)
* Remote dealloc refactor.

* Improve remote dealloc

Change remote to count down to 0, so fast path does not need a constant.

Use signed value so that branch does not depend on addition.

* Inline remote_dealloc

The fast path of remote_dealloc is sufficiently compact that it can be
inlined.

* Improve fast path in Slab::alloc

Turn the internal structure into tail calls, to improve fast path.
Should be no algorithmic changes.

* Refactor initialisation to help fast path.

Break lazy initialisation into two functions, so it is easier to codegen
fast paths.

* Minor tidy to statically sized dealloc.

* Refactor semi-slow path for alloc

Make the backup path a bit faster.  Only algorithmic change is to delay
checking for first allocation. Otherwise, should be unchanged.

* Test initial operation of a thread

The first operation a new thread takes is special.  It results in
allocating an allocator, and swinging it into the TLS.  This makes
this a very special path, that is rarely tested.  This test generates
a lot of threads to cover the first alloc and dealloc operations.

* Correctly handle reusing get_noncachable

* Fix large alloc stats

Large alloc stats aren't necessarily balanced on a thread, this changes
to tracking individual pushs and pops, rather than the net effect
(with an unsigned value).

* Fix TLS init on large alloc path

* Add Bump ptrs to allocator

Each allocator has a bump ptr for each size class.  This is no longer
slab local.

Slabs that haven't been fully allocated no longer need to be in the DLL
for this sizeclass.

* Change to a cycle non-empty list

This change reduces the branching in the case of finding a new free
list. Using a non-empty cyclic list enables branch free add, and a
single branch in remove to detect the empty case.

* Update differences

* Rename first allocation

Use needs initialisation as makes more sense for other scenarios.

* Use a ptrdiff to help with zero init.

* Make GlobalPlaceholder zero init

The GlobalPlaceholder allocator is now a zero init block of memory.
This removes various issues for when things are initialised. It is made read-only
to we detect write to it on some platforms.
2020-03-31 09:17:53 +01:00
Matthew Parkinson
ecef894525 Increase Remote batch size (#158)
* Increase Remote batch size

The remote batch size has not changed since the fast path optimisations.
The optimisations mean we are checking the queue considerably less
often, so the batch should be larger.  This has a dramatic improvement
on performance on a few of the mimalloc microbenchmarks.

It is set to 4096 as this should cover the worse case scenario of only
remote deallocation at 16 bytes for the 2^16 slab size.

* Fixes for Clang-10

Clang-10 outputs a warning for calling alignment intrinsic with an
alignment of 1. At add constexpr to handle this case.
2020-03-30 13:40:09 +01:00
David Carlier
55f1237df9 Few build tweaks. 2020-03-17 12:16:21 +00:00
David Carlier
2d4f2c3867 AAL, basic arm implementation proposal. 2020-03-13 08:09:14 +00:00
Amaury Chamayou
8e3efcb1dc Assert not going through the PAL (#140)
* Assert not going through the PAL

* Make it more difficult to assert() accidentally
2020-03-11 15:58:44 +00:00
Alex
beb99ddc38 Extra helper functions for dllist (#139)
* More helpful functions for dllist
2020-03-11 10:07:29 +00:00
SchrodingerZhu
8077c66a8e format bits 2020-03-08 22:50:34 +08:00
SchrodingerZhu
65de3c41bc fix mingw 2020-03-08 22:13:49 +08:00
Matthew Parkinson
b79448b6b5 Update src/ds/defines.h
Clang format
2020-03-04 17:59:13 +00:00
Matthew Parkinson
9dc689762c Apply suggestions from code review 2020-03-04 17:44:54 +00:00
Amaury Chamayou
acbcbce597 replace assert with SNMALLOC_ASSERT 2020-03-04 16:57:44 +00:00
Matthew Parkinson
b756ca08a7 Address GCC8 warning
The bootstrapping allocator needs to perform a memcpy to bypass the
removed move constructors on std::atomic.  This is safe as there is no
concurrency at this point, but GCC is unhappy with this.

This commit moves CI to GCC8 and disables this warning for that line.
2020-03-01 20:48:03 +00:00
Matthew Parkinson
c9da18a145 Improve Debug test speed.
Removed some very expensive debug checks off the fast path
of deallocation.
2020-02-06 13:05:40 +00:00
Matthew Parkinson
053b5a30ef Minor code tidying. 2020-01-29 16:37:46 +00:00
Matthew Parkinson
0affc069cf Make snmalloc build on Windows with Clang
Fixes a few places where Clang complains about Windows specific code,
and also uses macros supported by Clang on Windows.  A few places
separating platform and compiler specific code, as MSVC and WIN32 were
used interchangably previously.
2020-01-26 19:46:18 +00:00
Nathaniel Filardo
ef40f1cf1d Replace "AAL" type with "Aal" to parallel "Pal" 2019-12-04 16:56:28 +00:00
Nathaniel Filardo
997ebc5065 ds/aba: rename ::load to ::ptr
`load` does not load (`read` and `compare_exchange` do) so give it a
different name.  For the cases where `ptr` was previously the pointer we
were guarding, rename it to `raw`.
2019-11-26 15:50:22 +00:00
Nathaniel Filardo
263d735d0c ds/address: add dynamic pointer_align_up 2019-11-26 15:50:22 +00:00
Nathaniel Filardo
83c467eb92 ds/address: add pointer diff function
And use it rather than open-coding subtraction of two address_cast-s.
2019-11-26 15:50:22 +00:00
Nathaniel Filardo
ef7985510c address.h: add pointer alignment functions
More explicit than address_cast and bitwise and
2019-11-26 15:37:52 +00:00
Nathaniel Filardo
20e804728b Move bits::is_aligned_block to address.h
And chase consequences
2019-11-26 15:33:09 +00:00
Nathaniel Filardo
2af4c64698 Improve commentary 2019-11-26 14:58:47 +00:00
David Chisnall
0b2b4d68a2 Revert "Add type confusion protection to the default memory provider."
This reverts commit d56201e28d.
2019-09-12 17:16:48 +01:00
David Chisnall
d56201e28d Add type confusion protection to the default memory provider. 2019-08-13 17:30:37 +01:00
David Chisnall
6dbe24da2e [NFC] Replace HEADER_GLOBAL with inline (C++17).
HEADER_GLOBAL was using non-standard attributes to achieve what C++17
now permits with a keyword.  Use the standard formulation.

Update the README to note that gcc is still not recommended, but because
of its poor codegen for 128-bit atomic compare and exchange, rather than
because it doesn't support the attribute used for HEADER_GLOBAL.
2019-08-13 17:30:37 +01:00
Matthew Parkinson
280c2ae25c Refactor ThreadAlloc
Made common code between the Libc and C++ based releasing of allocators
part of a parent class, which each implementation subclasses.
2019-07-15 17:49:40 +01:00
David Chisnall
d83828c537 [NFC] Appease clang-tidy. 2019-07-10 11:22:24 +01:00
David Chisnall
7eabea01d6 Add an Architecture Abstraction Layer.
Currently, we support one architecture, but this provides a layer for
adding other architectures without adding more nested `#ifdef`s.

Fixes #42
2019-07-10 10:42:59 +01:00
David Chisnall
e594377b8a Pull out the #defines from bits. 2019-07-09 13:16:45 +01:00
Matthew Parkinson
d1db6d07ad Use a queue of slabs for free lists
This commit changes the strategy for finding a free list from
a stack to a queue.  This tends to avoid the slow path considerably more.
It has some memory overheads.

TOOD:  We should move the bump allocation data out of the metaslab and
into the allocator.  At the moment, the slab contains the bump allocation
data, we should move this into the allocator, as it only ever has one slab
it is bump allocating from per sizeclass.
2019-07-05 17:04:55 +01:00
Matthew Parkinson
54879fbb4a Make GCC happy with inline 2019-07-02 15:38:28 +01:00
Matthew Parkinson
b74116e209 Fixes 2019-07-02 14:58:13 +01:00
Matthew Parkinson
eb4e28e8d0 CR Feedback
Removed stub from message queue, and use an actual allocation.
2019-07-02 14:08:05 +01:00
Matthew Parkinson
fdcbcf7016 Add prefetch to mpscq. 2019-07-02 14:07:42 +01:00
Matthew Parkinson
d4e94d9c49 Minor changes to mpscq fast path. 2019-07-02 14:07:13 +01:00
Matthew Parkinson
621b7e6b9a Clang format. 2019-07-02 10:51:18 +01:00
Matthew Parkinson
3c7d122dea Add macro for ASSUME and FAST_PATH/SLOW_PATH
Fixes GCC warning that was incorrect using an ASSUME.

Made fast path and slow path Macros so we can add additional attributes.
2019-07-01 14:35:36 +01:00
Matthew Parkinson
830b06a616 Add a couple of likely annotations. 2019-07-01 14:24:03 +01:00
Matthew Parkinson
b8bcfc0798 Made the statistics print atexit
Fixed some statistics and made them automatically print atexit.
2019-05-16 11:43:44 +01:00