Commit Graph

635 Commits

Author SHA1 Message Date
David CARLIER
c082a331e2 POSIX_COMMIT_CHECKS adding for apple. (#284)
* POSIX_COMMIT_CHECKS adding for apple Intel
2021-02-23 14:51:02 +00:00
Matthew Parkinson
70e5f9653d Fix BSD usage of POSIX_COMMIT_CHECKS 2021-02-19 15:34:11 +00:00
Matthew Parkinson
60cd538c28 Change behaviour of USE_POSIX_COMMIT_CHECKS
The previous setting applied USE_POSIX_COMMIT_CHECKS to snmalloc if it
was a non-release build.  This caused issues in CCF virtual mode, as it
was being built in RelWithDebInfo.

This commit changes the flag to be applied less, but for tests to always
apply the setting independent of build type.

This means that when snmalloc is being used as a library, it will be
off, unless explicitly requested.
2021-02-19 15:34:11 +00:00
David CARLIER
ee470c535e Second batch for Mac M1 (mainly) changes proposal to make the whole
work more realibly, in both mono and multi thread contexts.
2021-02-11 20:10:05 +00:00
Matthew Parkinson
e3b3596e32 Remove an undefined behaviour
The initialisation had an awkward sequence that used undefined
behaviour. This fixes this.
2021-02-09 20:17:27 +00:00
Nathaniel Filardo
023290664d NFC: Front "deallocating start of an object" tests
Confirm that the client has given dealloc() a start-of-object pointer before
that pointer propagates very far (esp., before it enters the remote queues).

As these tests are not free, structure the code so that future interfaces can
skip over them if there's reason to be sure we're at the start of an object.
(On CHERI, for example, one could imagine using sealed pointers.)

For architectures with SSM/MTE, immediately after this test we can update the
memory granule to guard against double-frees; leave TODOs in place.
2021-02-09 19:15:40 +00:00
David CARLIER
0a868484db Mac M1 fix (#278)
The actual code works fine on the usual mac Intel however, some failures
occurs with some unit tests on the ARM h/w when zero'ing page ranges.
2021-02-09 14:38:54 +00:00
Matthew Parkinson
a3660c4069 Update to use a more efficient power of 2 check. (#274) 2021-01-27 11:58:41 +00:00
David Chisnall
db3580a9d8 Small tweaks to make the sandbox mode happy.
Allow replacing the type of GlobalVirtual at compile time.
Make that type a friend of Pool so that it can allocate things.
2021-01-13 17:10:13 +00:00
David Chisnall
c33f355736 Fix the sandbox use case and add a test. (#269)
Summary of changes:

- Add a new PAL that doesn't allocate memory, which can be used with a
  memory provider that is pre-initialised with a range of memory.
- Add a `NoAllocation` PAL property so that the methods on a PAL that 
  doesn't support dynamically reserving address space will never be
  called and therefore don't need to be implemented.
- Slightly refactor the memory provider class so that it has a narrower
  interface with LargeAlloc and is easier to proxy.
- Allow the address space manager and the memory provider to be
  initialised with a range of memory.

This may eventually also remove the need for (or, at least, simplify)
the Open Enclave PAL.

This commit also ends up with a few other cleanups:

 - The `malloc_useable_size` CMake test that checks whether the
   parameter is const qualified was failing on FreeBSD where this
   function is declared in `malloc_np.h` but where including
   `malloc.h` raises an error.  This should now be more robust.
 - The BSD aligned PAL inherited from the BSD PAL, which does not
   expose aligned allocation. This meant that it exposed both the
   aligned and non-aligned allocation interfaces and so happily
   accepted incorrect `constexpr` if blocks that expected one or 
   the other but accidentally required both to exist. The unaligned
   function is now deleted so the same failures that appear in CI should
   appear locally for anyone using this PAL.
2021-01-11 14:06:51 +00:00
David Chisnall
4837c82489 Fix external pagemap usage. (#221)
At some point in the refactoring, these were broken.
2021-01-08 13:21:37 +00:00
David Chisnall
c89f594b07 Add missing clang-format name. 2021-01-07 14:52:40 +00:00
David CARLIER
2dd63606af Sparc support proposal. (#264)
* Sparc support proposal.

* Tweaks from feedback.
Shift to integer/pointers cast like other archs.
Assembly reworks.
Note apparently reading the register once is sufficient to provoke
a pause in the cpu adding a clobber tough.
2021-01-05 16:28:22 +00:00
Nathaniel Filardo
975a2bd6db handle_dealloc_remote: restructure to avoid amplification when routing
When forwarding a Remote message, we can now operate entirely with local state:
access to our RemoteCache and the message itself.
2020-12-21 14:12:02 +00:00
Nathaniel Filardo
bf742cef84 handle_dealloc_remote{,_slow}: use Remote's sizeclass information
This removes a bunch of pointer math (which would need amplification) to find
and read the sizeclass from slab headers.
2020-12-21 14:12:02 +00:00
Nathaniel Filardo
7c04a9dad6 Remote: store the sizeclass, too
Squeeze some bits out of allocator IDs so that we can land the sizeclass in
each Remote object.  The intent is that, on StrictProvenance architectures like
CHERI, we will be able to route Remote messages through RemoteCache-s without
needing to amplify back to read the sizeclass metadata field out of the slab
headers.
2020-12-21 14:12:02 +00:00
Nathaniel Filardo
e9ed219fd8 ChunkMap: limit flat pagemap size
Presently, our flat pagemap can be configured to take...

                   32-bit AS    48-bit AS
USE_SMALL_CHUNKS     16 KiB        1 GiB
default               4 KiB      256 MiB
USE_LARGE_CHUNKS    256   B       16 MiB

At 1 GiB, we're already past the 512 MiB threshold imposed when
src/test/func/memory/memory.cc, when configured to TEST_LIMITED, probes the
effect of rlimit.

Instead, restrict flat pagemaps to at most 256 MiB of AS by default (override
by defining SNMALLOC_MAX_FLATPAGEMAP_SIZE), which forces the USE_SMALL_CHUNKS &
48-bit AS configuration to use the tree-based version.

While here, rename USE_FLATPAGEMAP to CHUNKMAP_USE_FLATPAGEMAP.
2020-12-16 15:57:19 +00:00
Nathaniel Filardo
c1d5f48797 Clarify ChunkMapSuperslabKind values 2020-12-16 15:57:19 +00:00
Nathaniel Filardo
b8b5f30513 mediumslab: limit header to min of page or slab
This had not been observed as an issue prior to
923705e514 because CMakeLists.txt had, until
then, been using EQUAL, not STREQUAL, to test for oe (and to then enable
USE_SMALL_CHUNKS).  This test would fail, and so the default SLAB_SIZE was
used.  Absent this min operation, the use of a whole page on a 64KiB page
causes a crash when using the largest medium size class, as, ultimately, size
classes are not based on page sizes, and so committing a whole page to the
header leaves too little room for that class.

See also 3d3b048776.
2020-12-16 15:57:19 +00:00
David Carlier
3e7ea1a85f Fix ARM 32 bits build, prfm is a 64 bits instruction. 2020-12-02 16:39:55 +00:00
David Carlier
08d0f42cc5 Solaris based system build fix.
malloc_usable_size or similar unsupported.
2020-11-27 15:26:37 +00:00
David Chisnall
2385eb2bc1 Separate out building and porting docs. (#260)
Fix omissions in the porting doc (`page_size` and C++20 concepts).
2020-11-10 13:33:45 +00:00
Matthew Parkinson
3ca29d6f50 Make POSIX COMMIT CHECKS mode fill memory
This simulates the pages being switched off with unexpected content, and
thus, when turned on we don't assume they have been unchanged.
2020-11-10 09:57:38 +00:00
Matthew Parkinson
01b282a5f3 Bug fix for using failing to initialise meta-data
If the Superslab meta-data is larger than an OS page, then the
subsequent pages could be decommited. This removes the skipped
initialisation in that case.
2020-11-10 09:57:38 +00:00
David Carlier
8990c34911 pass through Haiku build fix.
Haiku has a malloc_usable_size api but via the posix layer.
2020-10-16 15:57:12 +01:00
Robert Norton
0db4633ee7 Fix typo in macro definition for 16MiB shared library shim (#253).
This has been present since 4e1f5829a7 and resulted in the 16MiB shared library shim using the default 1MiB chunk size.
2020-10-12 15:27:59 +01:00
David Carlier
49b9856ed0 DragonFly support (userland).
- Close to OpenBSD as there is no malloc*size api nor arbritrary
 alignment support.
- Like FreeBSD, MAP_NORESERVE never had been implemented even tough
 still present in the header but not mentioned in the man page,
FreeBSD has reserved the value for another later usage seems
 DragonFly has just out of sync header.
2020-10-05 10:44:30 +01:00
Matthew Parkinson
923705e514 Natural alignment for USE_MALLOC (#248)
* Add concept of natural alignment to tests.

snmalloc naturally aligns blocks very heavily, so that
the largest power-of-two in the rounded size is the alignment.
This checks that in the test, and provides a method for
finding the natural alignment of a block.

* Improve USE_MALLOC to provide alignment

snmalloc provides a lot of alginment guarantees. This ensures that when
we pass through to the system allocator we still get those alignment
guarantees.

The commit also fixes the tests to work with USE_MALLOC, and builds a
set of unit tests for ctest to check behaviour.
2020-09-28 10:08:19 +01:00
Matthew Parkinson
f89f78ad46 Fix bug in pagemap when index has many levels
The pagemap was double incrementing the index level.  This did not
exhibit in any use case of the pagemap as it only used 0 or 1 level of
intermediate index for all current use cases.

This commit fixes the bug, and adds a test that uses the pagemap in a
different configuration that has multiple levels of intermediate index
node.
2020-09-24 11:10:30 +01:00
David Carlier
e615c33f7a Haiku debug build, rdynamic flag unsupported. 2020-09-14 09:43:18 +01:00
Matthew Parkinson
d3ecd66f73 Add constexpr annotation to align_up/down. 2020-09-11 14:08:01 +01:00
Nathaniel Filardo
17d5a3ed20 Update README.md PAL discussion w/ sprinkled "static" 2020-09-09 12:55:48 +01:00
Nathaniel Filardo
1e8d0bd743 MemoryProviderStateMixin is not a PAL 2020-09-09 12:55:48 +01:00
Nathaniel Filardo
d79a8184af AddressSpaceManager is not a PAL 2020-09-09 12:55:48 +01:00
Nathaniel Filardo
bf3c99d87f fully-static PALs 2020-09-09 12:55:48 +01:00
Nathaniel Filardo
cb1694f124 pal_windows: defer registration for low-mem until use
If we're going to explore fully-static PALs, then we shouldn't need a
constructor.
2020-09-09 12:55:48 +01:00
Nathaniel Filardo
3e21ea1f65 Add C++ concept for PAL
This will not be used unless the C++ standard version is raised to 20.  As
concepts and C++20 more generally are quite new, this does not do so.
Nevertheless, the use of concepts can improve the local development experience
as type mismatches are discovered earlier (at template invocation rather than
only during expansion).
2020-09-09 12:55:48 +01:00
Nathaniel Filardo
a3d54779c8 AddressSpaceManager: template parameter "PAL" not "Pal"
"Pal" is a global symbol for the current architecture's platform abstraction
layer class (see src/pal/pal.h); to be less confusing, don't shadow it with a
template parameter on the AddressSpaceManager class, and instead use "PAL" as
is done elsewhere for template arguments.
2020-09-09 12:55:48 +01:00
Nathaniel Filardo
82bc0e6852 ds/aba: make Cmp constructor explicit
For reasons unknown, this appeases MSVC using C++20.
2020-09-09 12:55:48 +01:00
Matthew Parkinson
77ebff6909 Added simple stats tracking memory usage (#241)
These statistics can be maintained with effectively zero cost to
realistic applications.  They do not track the precise amount of
memory used, but are an over-approximation.
2020-08-28 14:01:52 +01:00
Matthew Parkinson
234c0e2e8e Clang format 2020-08-26 17:51:46 +01:00
Matthew Parkinson
3adfe00f51 Missing 32bit case. 2020-08-26 17:51:46 +01:00
Matthew Parkinson
dc36849dd0 Reinstate staticcasts. 2020-08-26 17:51:46 +01:00
Matthew Parkinson
0728db1413 Fixes to ctz on Windows Clang. 2020-08-26 17:51:46 +01:00
David CARLIER
c171de9a89 Include the wait.h from the portable location
Build complains about wrong header inclusion with musl, sys/wait.h ough to be
 instead.

Co-authored-by: David Carlier <dcarlier@afilias.info>
2020-08-18 16:51:05 +01:00
Nathaniel Filardo
c9b023be23 FlatPagemap: Stop allocating way more space than needed
FlatPagemap computes the size of its internal `top` array as if it needed an
entry per byte, rather than an entry per instance of its template type T.  In
practice. T has always been uint8_t so far, so this hasn't mattered, but when
we use a larger type, suddenly FlatPagemap balloons to much larger than needed.
2020-08-05 13:59:55 +01:00
Matthew Parkinson
4e1f5829a7 Change default chunksize to 1MiB (#229)
This change makes the original 16MiB option not the common option.

It also changes the names of the defines to
  SNMALLOC_USE_LARGE_CHUNKS
  SNMALLOC_USE_SMALL_CHUNKS

The second should be set for Open Enclave configuration, and results in
256KiB chunk sizes.  The first being set builds the original 16MiB chunk
sizes.  If neither is set, then we default to 1MiB chunk sizes.
2020-07-09 13:22:32 +01:00
Schrodinger ZHU Yifan
8d1f3c3046 add limited test (#225)
* add limited test

* smaller allocation

* adjust test order

* CR, docs and QEMU
2020-07-08 20:38:54 +01:00
Matthew Parkinson
591b049585 Implement PAL backoff (#227)
The POSIX PAL and in some configurations the Windows PAL overallocate
address space. If address space has become exhausted then this can lead
to issues, where the PAL fails, even though there is enough aligned
address space to satisfy the underlying request.

This commit tries increasingly smaller overallocation sizes in an
attempt to succeed in more cases.
2020-07-08 16:17:33 +01:00
David CARLIER
c6197cb5f2 Illumos systems/Solaris support. (#226)
MAP_NORESERVE flag usage for memory over commit permitted only
 in the mmap context.
2020-07-08 15:35:28 +01:00