Commit Graph

176 Commits

Author SHA1 Message Date
Nathaniel Filardo
7ed80e7244 Report error on pagemap ABI mismatch 2019-11-25 15:22:53 +00:00
Nathaniel Filardo
d5b478ecb3 Deconflate "Pagemap" objects
There are two things calling themselves pagemaps:

- the src/mem/pagemap.h objects of that name

- the SuperslabMap object gets called a PageMap inside the Allocator

Rename the latter to chunkmap, with appropriate case and snake,
everywhere, and pull it out to its own file (chunkmap.h).

The default implementation of a chunkmap is a purely static object, but
we nevertheless instantiate it per allocator, so that other
implementations can use stateful instances when interposing on the
mutation methods.  Note that the "get" method, however, must remain
static to support the interface required by Allocator objects.
2019-11-21 15:35:56 +00:00
Nathaniel Filardo
3b2f521c46 allocstats: assert count doesn't go negative 2019-11-14 22:59:02 +00:00
Nathaniel Filardo
574700318e debug_is_empty: don't dealloc() free space
We know that these are small objects and that they have already had
their cache friendly offsets applied, so jump in to the dealloc path
futher down, below the stats calls.

Split small_dealloc_offseted into a wrapper around the core to avoid
inlining too much into the debug function.

While here, move the handling of the Remote objects into its own block
so that `p` is out of scope thereafter.

Fixes https://github.com/microsoft/snmalloc/issues/98
2019-11-14 22:59:02 +00:00
Matthew Parkinson
97c87f2e91 Merge pull request #96 from microsoft/usemalloc_fix
Modified pass through
2019-11-14 14:48:58 +00:00
Matthew Parkinson
7a3f0eb50b Clang format 2019-11-14 14:23:56 +00:00
Matthew Parkinson
4046417f25 Fix cache friendly offset. 2019-11-14 14:02:50 +00:00
Matthew Parkinson
74cc475787 Code review feedback. 2019-11-14 13:34:57 +00:00
Matthew Parkinson
14383614e0 Clang tidy 2019-11-14 13:04:24 +00:00
Matthew Parkinson
c2799f6ec8 Make debug_check_empty not use statistics
Debug_check_empty now empties the free lists, and checks it empties all the
queues in the allocator.  This does not require statistic tracking to
work anymore.

This additionally can check internal regression that cause leaks that
are not the clients fault.
2019-11-14 12:55:23 +00:00
Matthew Parkinson
23b4230f6a Fixed leak in free list.
If the first call to alloc uses the minimum size class, then we end up
leaking a whole page of allocations. We fill the small_fast_free_list,
in a call to build the message_queue. But this means the
small_fast_free_list[0] is not empty.  But the code was staying on the
slow path, and overwriting it.
2019-11-14 12:50:53 +00:00
Matthew Parkinson
3d0ba82b8d Modified pass through
If we are using USE_MALLOC pass through, then ThreadAlloc::get() can
cause an allocation inside snmalloc still, as it builds the thread
local allocator, which allocs a single stub allocator, using
the underlying allocator. This means that ASAN would detect a
leak in a client, even though the client program has none.

This change stops us ever allocating allocators, if we are passing
through calls to an underlying allocator.
2019-11-13 15:34:36 +00:00
Matthew Parkinson
f214abde3f Typo in assertion. 2019-09-30 13:43:32 +01:00
David Chisnall
6188667476 Revert the change to make the pool global type safe.
This adds lazy initialization, which adds a conditional branch on some
hot paths.

Fixes #93
2019-09-12 17:33:59 +01: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
Matthew Parkinson
ae05ed4dfd default_memory_provider is a function now. 2019-08-15 11:38:44 +01:00
Matthew Parkinson
e7f9b6e0d9 Add missing UNUSED 2019-08-15 10:52:07 +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
David Chisnall
bbf016bac8 Merge pull request #84 from microsoft/bug-fix
Bug fix
2019-08-13 16:57:21 +01:00
David Chisnall
d2dc653af2 Make the pagemap global typed.
The pagemap global is now an inline static of a template class, so that
we will see different symbols for the different types.

Issue #84 showed that it's possible to compile two compilation units
with different pagemaps, link them together, and have them attempt to
interpret the global pagemap as two different types.  This change should
make that impossible.

Also make the `pagemap()` function static so that it can be used from
static functions, avoiding other things that directly reference the
global pagemap.
2019-08-13 14:24:50 +01:00
Matthew Parkinson
dd3feb948c Deal with wrap around in statistics. 2019-08-13 13:43:20 +01:00
Matthew Parkinson
bef2fb94d8 Clangformat 2019-08-13 13:27:33 +01:00
Matthew Parkinson
e6b4efd980 Don't apply changes to GlobalPlaceholder. 2019-08-13 13:04:29 +01:00
Matthew Parkinson
cbb1063e82 Fix up checking for empty to account for stub messages. 2019-08-13 13:03:06 +01:00
Paul Liétar
7047cda8ed Fix warning about shadowing. 2019-07-17 14:13:44 +01:00
Paul Liétar
a5379b24d5 Add remove_cache_friendly_offset calls in a few places that were missing it. 2019-07-17 13:14:59 +01:00
David Chisnall
ab8ec72738 Merge pull request #71 from microsoft/tls-2
Improved ThreadAlloc::get API
2019-07-16 11:25:27 +01:00
David Chisnall
d3f5dcefe4 Fix the libc hook.
Friend declarations to `extern "C"` functions must have a forward
declaration with the correct signature.
2019-07-16 10:55:29 +01:00
Matthew Parkinson
a2a47d9a50 Clang-tidy 2019-07-15 20:08:16 +01:00
Matthew Parkinson
1b0923e141 Clang-tidy 2019-07-15 19:51:11 +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
89a296aaaa Merge pull request #70 from microsoft/pagemap-splice
Add two APIs that are missing from the flat pagemap.
2019-07-15 15:11:09 +01:00
Matthew Parkinson
df1896d55f Improved ThreadAlloc::get API
Made the API so that get always returns an initialised Alloc*.  Added
new fast path that doesn't perform checking, but can lead to very slow
behaviour if called and reused.
2019-07-15 15:02:47 +01:00
David Chisnall
5e9727c8ca [NFC] clang format. 2019-07-15 15:01:45 +01:00
David Chisnall
31267f9d85 Add two APIs that are missing from the flat pagemap. 2019-07-15 13:39:03 +01:00
Matthew Parkinson
4ce371f936 Tidy TLS implementation. 2019-07-12 16:45:04 +01:00
Matthew Parkinson
33ff935aee Remove infinite loop from adding message queue check
Adding a handle_message_queue here lead to an infinite loop.
2019-07-10 20:11:05 +01:00
Matthew Parkinson
45f47499c5 Improved pal_supports 2019-07-10 20:11:05 +01:00
Matthew Parkinson
23b3e35d6e Add comment about inlining choices. 2019-07-10 20:11:04 +01:00
Matthew Parkinson
c6178322b0 Minor 2019-07-10 20:11:04 +01:00
Matthew Parkinson
9fd238d5fa Move remote dealloc to slow path
It is only ever called in a tail position, so slow path means it is just
a jump, but improves the local deallocation fast path's codegen
considerably.
2019-07-10 20:11:04 +01:00
Matthew Parkinson
e240dd279a Use FlatPageMap on OS with lazy commit
If the operating system will allocate private pages on demand for the
pagemap then use the FlatPageMap by default as it generates better code
for deallocation.
2019-07-10 20:11:03 +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
c35a3941fe Merge pull request #65 from microsoft/queue_of_slabs
Use a queue of slabs for free lists
2019-07-08 20:53:06 +01:00
David Chisnall
3a0cdc05a5 Fix on macOS.
Fixes an issue where the global placeholder allocator was being
released.
2019-07-08 19:24:56 +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
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
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