Commit Graph

279 Commits

Author SHA1 Message Date
David Chisnall
2efcddfc3d Rework free list so that 0 is the placeholder.
This is needed because in some configurations the constructor for the
global placeholder is not called before the first allocation (i.e. when
other globals call the allocator in their constructor) and so we ended
up following a null pointer.
2019-07-05 14:20:24 +01:00
David Chisnall
14b5c57b55 Fix all of the tests. 2019-07-05 13:24:28 +01:00
David Chisnall
50695d07f8 Disable an always_inline with GCC in debug mode.
Most compilers are happy if you say always-inline but they can't.  GCC
will complain.  Here, we have two mutually recursive functions that are
marked as always inline.  In an optimised build, one is inlined into the
other and then becomes a tail-recursive function that should inline the
tail call.  Inlining the tail call can be done by simply jumping to the
start of the function and so everything is fine.  In a debug build, the
second transform doesn't happen and so we're left with a call to an
always-inline function.
2019-07-05 11:39:14 +01:00
David Chisnall
eefc9e49c5 Fix some duplicate inline warnings. 2019-07-05 11:39:01 +01:00
David Chisnall
1e65aafa06 Add missing fast-path annotations. 2019-07-05 09:42:07 +01:00
David Chisnall
6eeb273cbd Add -fomit-frame-pointer to CMakeLists for optimised builds. 2019-07-05 09:42:07 +01:00
David Chisnall
896b248c8c Fix undefined behaviour in FreeBSD PAL.
We were passing an argument less than 4K to the MAP_ALIGNED macro, which
caused an undefined shift.  The compiler helpfully propagated the undef
values back to earlier in the code and gave us some exciting nonsense.
2019-07-05 09:42:07 +01:00
David Chisnall
829d8e856b Tweak some tests to avoid the slowest path.
By caching the result of the first call to ThreadAlloc::get(), we were
always hitting a code path that should be hit once per thread in normal
operation.
2019-07-05 09:42:01 +01:00
David Chisnall
b8a5d7fca9 Lazily initialise TLS on slow paths.
Copying an idea from mimalloc, initialise the TLS variable to a global
allocator that doesn't own any memory and then lazily check when we hit
a slow path (which we always do when using the global allocator, because
it doesn't own any memory) if we are the global allocator and replace
it.

There is a slight complication compared to mimalloc's version of this
idea.  Snmalloc collects outgoing messages and it's possible for the
first operation in a thread to be a free of memory allocated by a
different thread.  We address this by initialising the queues with a
size value indicating that they are full and then do the lazy check when
about to insert a message that would make a queue full.  This will then
trigger lazy creation of an allocator.

Global initialisation doesn't work for the fake allocator, so skip most
of its constructor.
2019-07-05 09:41:32 +01:00
Matthew Parkinson
7dc30cc6fc Merge pull request #63 from microsoft/CI
Updated the syntax of the Azure pipelines file.
2019-07-02 18:04:58 +01:00
Matthew Parkinson
1f2b60ef65 Updated the syntax of the Azure pipelines file. 2019-07-02 17:27:47 +01:00
Matthew Parkinson
38f0b62e39 Merge pull request #62 from microsoft/opt
Optimise the fast path for alloc and dealloc
2019-07-02 17:06:01 +01:00
Matthew Parkinson
4cf19f3a4c Clangformat. 2019-07-02 16:18:03 +01:00
Matthew Parkinson
ea399660ce Fix for zero size allocations. 2019-07-02 15:58:19 +01:00
Matthew Parkinson
8970e70806 Clangformat 2019-07-02 15:44:10 +01:00
Matthew Parkinson
57e94b5824 Ensure id set on dummy deallocation. 2019-07-02 15:38:48 +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
daebe3f5e5 Remove constexpr steps. 2019-07-02 14:07:13 +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
b14735ff06 Fix clang format check. 2019-07-02 10:46:37 +01:00
Matthew Parkinson
0dbd10bd74 Minor alterations to slow path, and when to handle messages. 2019-07-01 17:06:04 +01:00
Matthew Parkinson
86fde10052 Minor changes to pagemap codegen 2019-07-01 17:05:24 +01:00
Matthew Parkinson
0453e43cc5 Typo 2019-07-01 15:23:01 +01:00
Matthew Parkinson
1b26c6d163 Updated differences 2019-07-01 15:11:39 +01:00
Matthew Parkinson
84c0117e54 Clang tidy. 2019-07-01 14:35:36 +01:00
Matthew Parkinson
9098b1c84f Only add Stats if passed to CMake. 2019-07-01 14:35:36 +01:00
Matthew Parkinson
187a016c39 Clang Tidy and Warnings 2019-07-01 14:35:36 +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
David Chisnall
c2780f99ed [FreeBSD] Fix a warning with GCC. 2019-07-01 14:35:35 +01:00
Matthew Parkinson
fb825dde09 Add an assert. 2019-07-01 14:35:35 +01:00
Matthew Parkinson
7a198cbda5 Aggressively optimise fast path for allocation
This change introduces a per small sizeclass free list.  That can be
used to access the free objects for that sizeclass with minimal
calculations being required.

It changes to a partial bump ptr.  We bump allocate a whole OS
page worth of objects at a go, so we don't switch as frequently
between bump and free list allocation.

The code for the fast paths has been restructured to minimise the
work required on the common case, and also it is all inlined for the
common case.

Allocating a zero sized object is moved off the fast path.  Ask for 1
byte if you want to be fast.
2019-07-01 14:35:35 +01:00
Matthew Parkinson
b0c1531221 Improved fast path for pagemap. 2019-07-01 14:35:35 +01:00
Matthew Parkinson
7f7704b6fc Made a size to sizeclass table. 2019-07-01 14:35:34 +01:00
Matthew Parkinson
7a8eaec2cc Made a sizecass_t to wrap the sizeclass
This is useful as codegen is nicer if we use size_t, but the semantics
is uint8_t, and is stored as that in many places in the metadata.
Ultimately should introduce a wrapper to check this invariant.
2019-07-01 14:30:05 +01:00
Matthew Parkinson
830b06a616 Add a couple of likely annotations. 2019-07-01 14:24:03 +01:00
Matthew Parkinson
90a0274743 Made TLS initial Exec.
This massively improves the TLS access at the expense of not being
dynamically loadable.
2019-07-01 14:24:03 +01:00
Matthew Parkinson
bb6b8e45c2 Merge pull request #61 from ricleite/readme_fix
Minor typo fixes in README
2019-06-27 17:49:15 +01:00
Ricardo Leite
ace91c7b2a Minor typo fixes in README 2019-06-27 16:45:06 +01:00
Matthew Parkinson
b033587ce8 Merge pull request #60 from microsoft/detect_cooruption
A few checks for easy corruptions
2019-06-12 16:14:43 +01:00
Matthew Parkinson
cc6a9775d6 Made checks on client have own macro. 2019-06-12 15:29:25 +01:00
Matthew Parkinson
7153f2169c Reverting separate compilation of new.cc. 2019-06-12 15:04:25 +01:00
Matthew Parkinson
be1898c4e8 Fixed warning. 2019-06-12 14:12:47 +01:00
Matthew Parkinson
d23a1ccbdf Make clangformat a macro to allow sharing. 2019-06-12 14:06:20 +01:00
Matthew Parkinson
5817978388 Make new.cc only compile once
Each test was compiling new.cc for every go.  This optimises that to
just compile it once.
2019-06-12 14:05:02 +01:00
Matthew Parkinson
88d9534453 CR Feedback + clangformat 2019-06-12 13:54:14 +01:00
Matthew Parkinson
a8dd065fd7 A few checks for easy corruptions
Will detect corruption caused by either
* Use-after-free
* Double-free
Neither is comprehensive.  Full temporal safety is not possible.
This just aids with debugging.
2019-06-06 13:31:25 +01:00