Commit Graph

1261 Commits

Author SHA1 Message Date
Matthew Parkinson
d4c7e01cd7 Pass continuations for success and failure cases (#788)
This PR provides a templated parameter to the allocation routines. This can be used to add special behaviour in
both the successful allocation behaviour, and in the failing
to allocate cases.

The intent of this is two enable two future features
* set_new_handler - so that the failure case doesn't just set ENOMEM, and return nullptr.  But can handle both the Windows and C++ versions of (_)set_new_handler.
* The success handler can be used to add checking, zeroing and in the future storing precise size information in metadata for each allocation.
2025-07-03 20:05:52 +01:00
Matthew Parkinson
012138e29f Small sizeclass lookup improvement, (#777)
* Fix off by one in deciding where to switch from small to large.
* Improve codegen on Windows by making it simpler for compiler to remove a redundant branch
2025-07-01 12:02:10 +01:00
Matthew Parkinson
2d33e4f33b Adjust func-memory test to be shorter. (#780)
Some CI pipelines were occasionally timing out due to the func-memory
test taking too long. This change reduces the number of iterations
from 100 to 50 for each test run, which should help avoid timeouts
while still providing sufficient coverage.

It also adds some debug output to indicate the time taken for each test.
2025-07-01 11:01:53 +01:00
Matthew Parkinson
9d29d828b8 Index cache by build run (#779) 2025-07-01 11:01:12 +01:00
Matthew Parkinson
76c67a3ee3 Drop Win2019 from CI (#778) 2025-07-01 09:18:07 +00:00
Matthew Parkinson
9a3d12a724 Make Secondary Allocator a template parameter (#774)
This refactors the use of the Secondary Allocator, so that out of tree implementations can be used.
2025-06-30 21:23:07 +01:00
Neil Monday
e600bf1b38 Release all pagemap reservations at the very end of the program or DLL (#773)
* Release all pagemap reservations at the very end of the program or DLL


Co-authored-by: Neil Monday <neil.monday@amd.com>
Co-authored-by: Matthew Parkinson <mjp41@users.noreply.github.com>
2025-06-30 13:15:49 +00:00
Mark Johnston
890bcf94a6 Remove tests for experimental jemalloc ABIs (#770)
Commit 5680cf6dc6e2 ("jemalloc: don't expose 3.0 compat symbols") in
FreeBSD src removes the default symbols for allocm() and friends, so
this test no longer links.  Compatibility is stil provided for programs
linking against FBSD_1.3, but here it seems easier to simply stop
referencing them.
2025-06-30 14:06:29 +01:00
Matthew Parkinson
16d96b9f8c Fix CI (#776)
This PR updates to aspects of the CI to fix blocked PRs:

It moves the Bazel CI into its own set of actions, so failure can be isolated from other tasks.
Updates the clang-cl version used in CI for self-vendored build as it was failing with the default.
2025-06-30 13:57:07 +01:00
Matthew Parkinson
0064c01b82 Improving handling first allocation being for TLS (#767)
* handle reentrancy during initialization

* use finialization list if possible

* Add test for reentrancy of C++ destructors and allocation

* Add test for reentrancy of setspecific

* Add new mode for directly calling __cxa_thread_atexit_impl

---------

Co-authored-by: Schrodinger ZHU Yifan <yifanzhu@rochester.edu>
2025-05-07 19:28:37 +01:00
Jaya Kasa
a63f0c1ac3 feat: add support for bazel (#759) 2025-05-07 09:09:44 +01:00
Matthew Parkinson
6325edefcf Remove 20.04 from CI (#768)
* Remove 20.04 as no longer supported.
* Remove PowerPC due to existing issues with updated QEMU.
2025-04-28 15:11:21 +01:00
Matthew Parkinson
b8e28be14b Fix bug in pool sort (#765)
The pool sort routine is used by Verona's systematic testing.  There was a bug introduced in #612 that could corrupt the list when a sort occured.

This is not used by snmalloc and the test coverage was insufficient to expose the bug.

This PR fixes the bug, and improves test coverage.
2025-04-10 10:25:24 +01:00
Will Brown
e6bf8570d0 [Rust] add support for optionally compiling libc functions (#763)
* add SNMALLOC_RUST_LIBC_API option
2025-04-03 13:56:41 +01:00
Jeff Sooknarine
59987ca908 Header-only build fix for WIN32_LEAN_AND_MEAN redefinition (#764)
When using snmalloc as header-only library in a project that globally defines `WIN32_LEAN_AND_MEAN`, there is a compile error for macro redefinition.

Guard the pal_windows.h define.
2025-04-01 21:16:55 +00:00
Matthew Parkinson
80bdcd999f CI: Cancel inflight checks on a new push. (#760) 2025-03-21 17:58:54 +00:00
Matthew Parkinson
dff1057db2 Refactor representation of thread local state. (#751)
* Lift checking for init to ThreadAlloc

The check init code was tightly integrated into LocalAllocator.  This commit pull that code out into ThreadAlloc, and passes a template parameter into the remaining LocalAllocator to perform the relevant TLS manipulations.  This removes some of the awkward layering around register_clean_up.

* Reduce size of test due to failures.

Fully disable lotsofthreads test

Need to investigate if the test is unreliable, or we have actually
regressed perf.  A quick mimalloc-bench didn't show any regressions.

* Simplify message queue initialisation

This introduces one additional branch on when processing a batch of messages, but it is likely to only be hit when a lot of messages are processed.

* Patch Domestication test.

* Refactor CoreAlloc/LocalAlloc

This combines the notion of CoreAlloc, LocalAlloc and LocalCache into a single class.  Previously, these were separated so that a more complex structure would be stored directly in the TLS.  This however, proved to be bad for compatibility if the allocator is part of the libc implementation.

This commit collapses all the stages of the allocator into a single class. This simplifies the sequencing and overall is a nice reduction in complexity.

* Re-enable lots of threads test.

* Reenable concept using alternative lazy checking for concepts.

* Self code review
2025-03-21 15:13:32 +00:00
Matthew Parkinson
3348bf9e56 Fix test when using GWP-Asan (#758) 2025-03-17 15:37:54 +00:00
Matthew Parkinson
a106a2e69d Refactor check_bounds (#756)
This changes the shape of check_bounds to take a continuation to call if the bounds check succeeds.  This is designed to allow for easily wrapping existing code with a bounds check, e.g.

```
void* memcpy(void* dest, const void* src, size_t n) {
  return check_bounds(dest, n, [&] {
    return memcpy_impl(dest, src, n);
  });
}
```
2025-03-14 16:09:09 +00:00
Trithek
dfda7a8442 Fixed pagemap reservations for a fixed-region use-case using the default PAL (#757)
* Made reserve_range do the correct thing when a fixed range configuration was used

* Corrected the check for out-of-bounds
2025-03-13 10:20:43 +00:00
Matthew Parkinson
ccc03ce0fc Protection against fork (#735)
If a thread forks, while another thread is holding an snmalloc lock, then the allocator could stop working.

This patch attempts to protect against the cases of this. There is one case that is not covered. If a fork occurs during the very first allocation. This can result in the installation of the fork handler racing with the fork, and all bets are off.
2025-03-04 13:44:59 +00:00
Matthew Parkinson
c2e22ccb79 Prevent internal errno setting escaping to the client. (#754) 2025-02-28 11:12:22 +00:00
Matthew Parkinson
06df9dd9e1 Update realloc(p,0) semantics. (#753)
* Factor out small sizeclass check

* Update realloc(p,0) semantics

This commit changes the behaviour of realloc(p,0) to be free(p) if p!=nullptr, and malloc(0) if p== nullptr.
2025-02-27 15:20:31 +00:00
Matthew Parkinson
6622dc584e Bug fixes (#752)
* Fix overflow by alignment

* Bug fix: Ensure bytes_free is the total

The bytes freed was not added to the total, but
overrode it.  This meant it never fired. This
commit fixes that.
2025-02-27 08:52:50 +00:00
Matthew Parkinson
5f7baef755 Refactor: Remove unused features and functions, and move most allocator operations to a global namespace. (#750)
* Factor out explicit Config type

Instead of using snmalloc::Alloc::Config, expose snmalloc::Config, which is then used to derive the allocator type.

* Move globalalloc to front end.

* Remove unneed template parameter from global snmalloc functions.

* Remove SNMALLOC_PASS_THROUGH

VeronaRT now has an abstraction layer which can easily replace the allocator.
Having such a complex integration still in snmalloc does not make sense.

* Take some global functions off of local alloc.

* Drop comparison overloads on atomic Capptr.

Performing a comparison on two atomic ptr is a complex operation, and should not be implicit.  The memory model order and such things needs to be considered by the caller.

* Remove function_ref and use templates

The implementation prefers to use templates over the function_ref.  This now only exists in the Pal for a currently unused feature.

* Removing function_ref reduces stl needs.

* Remove use of __is_convertible to support older g++

* Inline function that is only used once.

* Remove unused function

* Restrict ThreadAlloc usage to globalalloc

This commit introduces various inline functions on snmalloc:: that perform allocation/deallocation using the thread local allocator.

They remove all usage from a particular test.

* Move cheri checks to own file.

* Refactor is_owned checks.

* Move alloc_size and check_size to globalalloc.

* Minor simplification of dealloc path

* Fix up is_owned to take a config

* Improve usage of scoped allocator.

* Handle Config_ in globalalloc.
2025-02-22 19:53:27 +00:00
Matthew Parkinson
6d50141e35 build: Fix nothrow include. (#749) 2025-02-14 12:50:18 +00:00
Matthew Parkinson
0cd9ccf170 CI: Refresh Targets (#748)
Add newer platforms to CI.
* ubuntu-24.04-arm
* windows-2021
* windows-2025
2025-02-13 09:47:36 +00:00
Neil Monday
ef4748289d Windows: Remove exception handler for pagemap on unloading (#746)
Co-authored-by: Neil Monday <neil.monday@amd.com>
2025-02-12 15:38:54 +00:00
Matthew Parkinson
a3fe420af2 Fix HAS_EXCEPTION on Windows. (#743) 2025-02-05 16:54:51 +00:00
Matthew Parkinson
b3efd49c9a Mistaken commit of message_once (#741) 2025-02-05 11:16:41 +00:00
Schrodinger ZHU Yifan
16b96245f6 Enable a seconary allocator support (e.g. GWP-Asan) (#737) 2025-02-05 09:03:11 +00:00
Matthew Parkinson
32495fd42d Multiple Pals could return spuriously from wake on address (#739)
* Add stress test benchmark

Co-authored-by: Alexander Nadeau <wareya@gmail.com>

* Add defensive code against spurious wakeup

This commit checks that wait_on_address has not returned spuriously.

* pal: spurious wake up.

The code in the Pal for wake on address was incorrectly assuming the operation returning success meant it had actually changed.  The specification allows for spurious wake ups.

This change makes the Pals recheck for a change.

---------

Co-authored-by: Alexander Nadeau <wareya@gmail.com>
2025-02-04 18:44:02 +00:00
Matthew Parkinson
e3e558472d Update CMakeLists.txt (#734)
* Handle platforms that have `_GLIBCXX_ASSERTIONS`, which require the stdlib++ to be included.
* Stop override of memcpy with FORTIFY_SOURCE enabled
* Add to .gitignore
* Add data for graphs in release notes.
* Minor tidy on CMake.
2025-01-23 13:36:08 +00:00
Jean-Michaël Celerier
aa07749f46 pal_windows.h: missing <cerrno> for ENOMEM on MinGW (#733)
Co-authored-by: Matthew Parkinson <mjp41@users.noreply.github.com>
2025-01-21 09:25:11 +00:00
Schrodinger ZHU Yifan
229c6d04fe remove extra puts definitions (#731)
LGTM, thanks.
2025-01-16 10:31:31 +00:00
Matthew Parkinson
0fbc325a0a Fix merge issue for out of data CI run. (#730) 2025-01-10 08:37:33 +00:00
Matthew Parkinson
9e632047de Add Windows Support for Lazy Commit of page map (#727)
The Pagemap can potentially be accessed where there is no direct
knowledge of the location.  On platforms with lazy commit this can
be handled by the OS faulting in a zero page.  Here we modify the
Windows PAL to add an exception handler that will commit pages
in the read only range, i.e. the page map.  We still require explicit
notify_using to be able to modify the pagemap.
2025-01-09 17:57:52 +00:00
Schrodinger ZHU Yifan
0111a410a2 [proxy](7/n) self vendor array and algorithm headers (#722)
* [proxy](7/n) proxy array and algorithm headers

* [wip] address CRs

* undo comment

* format

* fix build

* simplify macro dispatching
2025-01-09 13:49:22 +00:00
Schrodinger ZHU Yifan
0027f02396 [proxy](6/n) self-vendor utility headers (#721) 2025-01-09 10:25:35 +00:00
Schrodinger ZHU Yifan
e874617d8e [proxy](5/n) use c headers instead of c++ headers (#720) 2025-01-09 09:45:24 +00:00
Neil Monday
6a3c5750bd Changing DEBUG constexpr to Debug to avoid collision with any #define DEBUG that may exist in other projects. (#729)
Co-authored-by: Neil Monday <neil.monday@amd.com>
2025-01-08 17:13:26 +00:00
Schrodinger ZHU Yifan
d1c65c2852 [proxy](4/n) use customised placement-new (#719)
* [proxy](4/n) use customized placement-new

* fix
2025-01-08 06:38:23 +00:00
Matthew Parkinson
046c5ac766 Limit remote batch size (#724)
When processing a remote batch, the system will process every single message that was available at the start of processing.
This can lead to a long pause time if there have been a considerable number of frees to this thread.

This commit introduces a new mechanism to only process messages up to a limit of 1MiB. The limit is configurable using CMake.

Choosing too small a limit can cause freeing to never catch up with the incoming messages.
2025-01-07 14:29:34 +00:00
Matthew Parkinson
35c5c6038c Remove dependencies from Singleton and FlagLock (#725)
* Move get_tid() to ds_core.

* Rewrite Singleton to only use Aal.

* Move data structure to be usable from the Pal.
2025-01-07 14:28:57 +00:00
Schrodinger ZHU Yifan
8c6474d05a [proxy](3/n) remove chrono dependency for windows (#718)
* [proxy](3/n) remove chrono dependency for windows

* minor fixes
2025-01-07 13:40:57 +00:00
Schrodinger ZHU Yifan
2cc74eac10 [proxy](2/n) provide proxy layers for type traits (#717)
* [proxy](2/n) provide proxy layers for type traits

* fix after rebasing
2025-01-06 17:07:49 +00:00
Matthew Parkinson
7db1f243cc CI issues (#726)
* Remove unneeded workaround.

* Update Clang version in cross compile for latest

* Explicitly install libc++ in CI
2025-01-06 08:53:28 +00:00
Schrodinger ZHU Yifan
feff2e8151 [proxy](1/n) start self-vendored STL with atomic (#715)
* [proxy] start self-vendored STL

* address CR
2025-01-03 07:49:32 +00:00
David CARLIER
fb29a5e085 PALSolaris AlignedAllocation feature implementation attempt. (#723) 2025-01-02 14:11:58 +00:00
David CARLIER
515b97d996 PALOpenBSD implement WaitOnAddress feature attempt. (#716) 2025-01-02 09:07:46 +00:00