Commit Graph

1177 Commits

Author SHA1 Message Date
Nathaniel Filardo
7fbca11527 0-length arrays in Buddy ranges (#672)
* backend_helpers: introduce NopRange

* Fix to Buddy MIN == MAX case

This fixes the 0-length arrays discussed (and made into assertion failures) in
the next commit.  This works because the Buddy's `MIN_SIZE_BITS` is instantiated
at `MIN_CHUNK_BITS`, and so we ensure that we instantiate the LargeBuddyRange
only with `max_page_chunk_size_bits` above `MIN_CHUNK_BITS`.

* Buddy range: assert that MAX > MIN

Now that the case leading to several 0-sized arrays in Buddy ranges, that then
cause gcc's -Warray-bounds to trip, has been removed, add a static assert so
that we can catch this with better error messages next time.
2024-09-09 12:25:51 -04:00
John Baldwin
fcad15456b aligned_alloc: Permit alignment values smaller than sizeof(uintptr_t) (#671)
posix_memalign() requires alignment values of at least
sizeof(uintptr_t), but aligned_alloc() does not.  memalign() regressed
to require larger alignment in commit
6cbc50fe2c.

Fixes #668
2024-08-27 22:16:19 +01:00
Matthew Parkinson
6af38acd94 Implement MCS Combining lock (#666)
* Added lambda lock primitive

* Implement MCS Combining lock

This is hybrid of Flat Combining and the MCS queue lock. It uses
the queue like the MCS queue lock, but each item additionally
contains a thunk to perform the body of the lock. This enables
other threads to perform the work than initially issued the request.

* Add a fast path flag

This update adds a fast path flag for the uncontended case. This
reduces the number of atomic operations in the uncontended case.

* CR feedback
2024-06-28 15:43:17 +01:00
Nathaniel Filardo
6bd6db5f61 Remove the SNMALLOC_USE_CXX17 C preprocessor symbol (#667)
* Revise search for no-unique-addres

* Remove SNMALLOC_USE_CXX17 as preprocessor symbol

Just test __cplusplus in the last place we were using it.
2024-06-28 10:19:32 -04:00
Matthew Parkinson
4620220080 Startup speed (#665)
* Refactor buddy allocator

Make it clearer the structure of add_block by pulling out remove_buddy.

* Give buddy a few elements so don't have to touch pagemap earlie on.

* Only use do and dont dump on pagemap

The do and dont dump calls were costings a lot during start up of snmalloc.  This reduces the times they are called to only be for the pagemap.
2024-06-26 21:34:22 +01:00
Nathaniel Filardo
835ab51863 msgpass benchmark and its refactoring dependencies (#659)
* NFC: split freelist_queue from remoteallocator

This lets us use freelists as message queues in contexts other than
the remoteallocator.  No functional change indended.

* freelist_queue: add and use destroy_and_iterate

* freelist: make backptr obfuscation key "tweakable"

* freelist: tweakable keys in forward direction, too

* test/perf/msgpass: ubench a producer-consumer app

Approximate a message-passing application as a set of producers, a set of
consumers, and a set of proxies that do both.  We'll use this for some initial
insight for https://github.com/microsoft/snmalloc/issues/634 but it seems worth
having in general.
2024-06-13 17:28:48 -04:00
Matthew Parkinson
2a7eabef6c Configurable client meta-data (#662)
This provide a way to configure snmalloc to provide per object meta-data that is out of band. This can be used to provide different mitigations on top of snmalloc, such as storing memory tags in a compressed form, or provide a miracle pointer like feature.

This also includes a couple of TSAN fixes as it wasn't fully on in CI.
2024-06-13 09:32:07 -04:00
Matthew Parkinson
2dba088d24 Refactor new/delete overrides (#660)
Produce static library that only overrides new and delete. This allows for a static library to be added that only overrides new and delete.
2024-06-06 10:23:12 +01:00
Nathaniel Filardo
846a926155 NFC: sizeclass: differentiate minimum step size and minimum allocation sizes (#651)
* Move sizeclass debugging code to sizeclass test

The sizeclass was already testing most of this, so just add the missing bits.
Forgo some tests whose failure would have implied earlier failures.

This moves the last dynamic call of size_to_sizeclass_const into tests
(and so, too, to_exp_mant_const).  sizeclasstable.h still contains a static
call to compute NUM_SMALL_SIZECLASSES from MAX_SMALL_SIZECLASS_SIZE.

* Remove unused to_exp_mant

Only its _const sibling is used, and little at that, now that almost everything
to do with sizes and size classes is table-driven.

* test/memcpy: trap, if we can, before exiting

This just means I don't need to remember to set a breakpoint on exit

* test/memcpy: don't assume sizeclass 0 is allocable

* test/memory: don't assume sizeclass 0 is allocable

* test/sizeclass: handle nonzero minimum sizeclasses

* sizeclass: distinguish min alloc and step size

Add support for a minimum allocation size that isn't the minimum step of
the sizeclass table.

* Expose MIN_ALLOC_{,STEP}_SIZE through cmake

* test/sizeclass: report MIN_ALLOC_{STEP_,}SIZE
2024-05-24 18:49:39 +01:00
Matthew Parkinson
b1d0d7dc78 Remove unnecessary assertion from aligned_alloc (#658)
With [DR460](https://open-std.org/JTC1/SC22/WG14/www/docs/summary.htm#dr_460) the undefined behaviour for size not being a multiple of alignment was remove.

The [N2072](http://www.open-std.org/jtc1/sc22/wg14/www/docs/n2072.htm) allows for this to return memory.

So we can remove this assert and keep the same conditions as memalign.
2024-05-23 16:07:01 +01:00
Javier Blazquez
d9bca64426 Add Windows ARM64 support (#656)
* Add Windows ARM64 support

* Add Windows ARM64/ARM64EC CI workflows
2024-04-10 06:31:10 +01:00
Nathaniel Wesley Filardo
b8e9e99cf0 NFC: Remove "Backend" from MetaEntry template arg
This parameter is in fact instantiated with FrontendSlabMetadata, so the use of
Backend here is confusing.
2024-01-05 17:29:08 +00:00
Nathaniel Wesley Filardo
24b79264df remotealloc: can_dequeue needs both domesticators
If we're running with the freelist_backward_edge mitigation turned on, then
we're going to follow the pointer, not just de-obfuscate it (in freelist's
atomic_read_next), so even if the queue heads are tame, we still need to
do this domestication.
2024-01-05 17:29:08 +00:00
Nathaniel Wesley Filardo
fffc9453bc remotealloc: make can_dequeue match its tin
The introduction of the remote stub back in
https://github.com/microsoft/snmalloc/pull/604 renamed this function from
`is_empty` but did not flip the return value to match.  Do so now.
2024-01-05 17:29:08 +00:00
Nathaniel Wesley Filardo
f3e470c3e4 realloc: ASSUME non-NULL source pointer for memcpy
NULL has size zero, which rounds up to zero, and so would have been handled.
2024-01-05 17:29:08 +00:00
Matthew Parkinson
640cacf90e Updated CI workaround. (#650)
https://github.com/actions/runner-images/issues/8659
2024-01-02 10:02:27 +00:00
Matthew Parkinson
3c3739ddaf Update NetBSD runner (#648) 2023-11-09 06:24:35 +00:00
Matthew Parkinson
a781f96211 FreeBSD CI. (#647) 2023-11-08 10:15:20 +00:00
Matthew Parkinson
7d88f4d638 Workaround runner issue. (#645) 2023-11-08 10:14:33 +00:00
Matthew Parkinson
f38ee89e72 Template construction of Pool elements (#641)
* Template construction of Pool elements

The Pool class is used by verona-rt.  The recent changes made this
less nice to consume as an API.

This change makes the construction logic a template parameter to the
Pool. This enables standard allocation to be used from Verona.

* Drop parameter from acquire

Pool::acquire took a list of parameters to initialise the object that it
constructed.  But if this was serviced from the pool, the parameter
would be ignored.  This is not an ideal API.

This PR removes the ability to pass a parameter.
2023-10-03 13:59:23 +00:00
Matthew Parkinson
5543347543 Startup improvements (#639)
* Benchmark for testing startup performance.

* Make pool pass spare space to pooled item

The pool will result in power of 2 allocations as it doesn't have a
local state when it is initially set up.

This commit passes this extra space to the constructor of the pooled
type, so that it can be feed into the freshly created allocator.

Co-authored-by: Nathaniel Wesley Filardo <nfilardo@microsoft.com>
2023-09-28 14:53:39 +01:00
David Chisnall
126e77f2a5 Add a default constructor to seqset nodes. (#636)
This allows them to exist as fields without invalidating the set.

This should make it possible to remove the undefined behaviour in the
creation of FrontendSlabMetadata, which is currently created via a
reinterpret_cast from a different-typed allocation.
FrontendSlabMetadata has a SeqSet::Node field that is in an unspecified
state on construction and which is valid only when inserted into a
SeqSet.
2023-09-18 10:15:49 +00:00
Matthew Parkinson
2a7670eb82 Add C++17 version for Mac. (#635) 2023-09-18 09:37:56 +01:00
Zhang
6b8f3338c7 Fix #631 (#633)
* Fix #631

Add wrapper override for the Windows variant of maloc_usable_size : _msize

Co-authored-by: Matthew Parkinson <mjp41@users.noreply.github.com>
2023-09-14 11:04:12 +00:00
Matthew A Johnson
35eef33099 Adding an option to disable TLS (#632)
Signed-off-by: Matthew A Johnson <matjoh@microsoft.com>
2023-09-13 10:17:10 +00:00
Matthew Parkinson
7b597335ae Disable empty static prefix for Windows. (#629) 2023-08-25 14:17:04 +01:00
Matthew Parkinson
c2e4a12e21 Using exclusive mode prefetch (#627)
* Using exclusive mode prefetch

The prefetching is always used to move the cache line to the current
core for writing.  This change makes it use exclusive mode prefetch
and enables it as a feature flag for x64.

* Debug platform for BSDs

* CI fixes

* More CI

* Update ARM prefetch

* Update x64 prefetch default
2023-08-09 07:15:37 +01:00
Matthew Parkinson
6cbc50fe2c Factor out libc code into a header. (#624)
* Factor out libc code into a header.

This pulls the main definitions of the various libc malloc functions
into a header for easier use and inclusion in other projects.

* Clang-tidy fixes.

* Clang-tidy fixes really.

* More code quality changes

* Minor fix

* Clangformat
2023-08-09 07:15:09 +01:00
Matthew Parkinson
9d4466093a Move to clang-format 15 (#621)
The current version requires clang-format-9.  This now getting hard to get.
This commit moves it to the clang-format-15, which is the latest in 22.04.

Also, updates clang-tidy to 15 as well.
2023-07-18 11:24:07 +01:00
Matthew Parkinson
cdfedd8718 Update README.md (#622) 2023-07-17 15:09:36 +01:00
Matthew Parkinson
dc1268886a Improve CMake slightly (#620)
* Prefix build testing flag with SNMALLOC

* Only add clangformat target is testing enabled.
2023-06-28 11:42:19 +01:00
Matthew Parkinson
95bad423a7 Correct order of test based on #618 (#619) 2023-06-20 12:16:45 -04:00
Matthew Parkinson
ce489cfffe Conditional range (#617)
* Make a conditional range

This range allows for a contained range to be disabled at runtime.
This allows for thread local caching to be disabled if the initial fixed
size heap is below a threshold.
2023-06-20 12:00:34 -04:00
David CARLIER
d9f5bd0500 pass through enable malloc build for dragonflybsd. (#614) 2023-05-30 21:25:59 +01:00
Matthew Parkinson
55376aa006 Move key_global into RemoteAllocator (#608)
There was a mis-compilation in a Verona configuration that lead to
two instances of key_global existing.  This change moves it inside
a struct that seems to fix the issue.

The rest of the changes are limiting the use of key_global as both
RemoteCache and RemoteAllocator must use the same configuration,
so there is no need to take the key_global as a parameter.
2023-04-26 17:24:16 +01:00
Matthew Parkinson
7b3a2b3fc1 Made pool reuse a queue (#612)
So allocator churn will cause remote queues to be visited.
2023-04-26 15:08:30 +01:00
Matthew Parkinson
365553e67f Remove 18.04 (#613) 2023-04-25 21:08:04 +01:00
Julien Maffre
e3f636544f Update BUILDING.md (#611) 2023-04-19 17:06:55 +01:00
Axel PASCON
7f368bd6da Fix broken link in PORTING.md (#610) 2023-04-07 20:08:37 +01:00
Matthew Parkinson
1077be0e50 Update GuardedMemcpy.md 2023-03-27 10:51:34 +01:00
Matthew Parkinson
d8f174c717 Minor perf (#607)
* Prefetch on traversing remote queue

* Make pointer function fast path

* Only try to form blocks of MIN_BITS
2023-03-24 10:54:54 +00:00
Matthew Parkinson
8e3f6c96e8 Optimise buddy allocator to not search too high (#606)
The buddy allocator doesn't need to look at sizes above the current
highest size. This commit tracks the highest block that is stored in the
buddy allocator.
2023-03-24 09:16:09 +00:00
Matthew Parkinson
0620825df7 Add a fast path to ensure_init (#605) 2023-03-24 09:15:45 +00:00
Matthew Parkinson
798f2fa367 Remote stub (#604)
* Alter is_empty

* Use a stub in remoteallocator

Rather than allocating a sizeclass use a stub.  This change adds a
branch on enqueue.
2023-03-24 09:15:28 +00:00
Matthew Parkinson
ccca98a709 Factor checks under separate feature flags. (#587)
All the checks and mitigations have been placed under feature flags.
These can be controlled by defining

  SNMALLOC_CHECK_CLIENT_MITIGATIONS

This can take a term that represents the mitigations that should be enabled.
E.g.
  -DSNMALLOC_CHECK_CLIENT_MITIGATIONS=nochecks+random_pagemap

The CMake uses this to build numerous versions of the LD_PRELOAD library and
tests to allow individual features to be benchmarked.

Co-authored-by: Nathaniel Wesley Filardo <nfilardo@microsoft.com>
2023-03-23 13:41:02 +00:00
David CARLIER
848db74cfc AAL disable __builtin_readcyclecounter on macOs arm64. (#601)
Fix perf-content* tests.
2023-03-13 12:38:18 +00:00
Saar Amar
959531b6e3 Update GuardedMemcpy.md (#602)
Fix the signature of `memcpy`.
2023-03-07 10:32:40 +00:00
Matthew Parkinson
6066cbaafb Alter glibc override to work with RTL_DEEPBIND (#598)
When using dlopen with RTL_DEEPBIND the LD_PRELOAD used
by the majority of allocators does not work as both libc
and snmallocs allocators can be called by various dso.

This patch uses GLIBC's __malloc_hook to override the allocator
as well as LD_PRELOAD.  This means that all libraries will
call snmalloc when performing allocation.
2023-02-27 14:30:55 +00:00
EAirPeter
8fa861758f Fix incorrect aligned_size invocations in operator overrides (#597) 2023-02-27 13:46:39 +00:00
Matthew Parkinson
c304ddfcdb Remove OpenBSD from CI (#599) 2023-02-27 13:43:20 +00:00