Commit Graph

614 Commits

Author SHA1 Message Date
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
Matthew Parkinson
5ebda5288d Add missing QEMU build flag. (#228) 2020-07-08 13:53:27 +01:00
David Chisnall
5199556263 Reduce code duplication. (#220)
* Reduce code duplication.

The Apple and Haiku PALs both had *almost* identical code to the POSIX
PAL, differing only in some small argument variables.  This is fragile
and easy to accidentally get out of sync.  For example, the changes to
`reserve_at_least` involved copying identical code into multiple PALs
and it's easy to accidentally miss one.

This change introduces two optional fields on POSIX-derived PALs:

 - `default_mmap_flags` allows a PAL to provide additional `MAP_*`
   flags to all `mmap` calls.
 - `anonymous_memory_fd` allows the PAL to override the default file
   descriptor used for memory mappings.

If a PAL does not provide these, default values are used.

Fixes #219
2020-06-30 13:33:50 +01:00
David CARLIER
4a3102fedb Haiku support proposal. (#218)
* Haiku support proposal.
Basic PAL implementation.
This platform does not support TLS modes.

* MAP_NORESERVE usage
2020-06-30 11:01:49 +01:00
Matthew Parkinson
94a2ba4eda Revert "fixes for mingw (#215)" (#216)
This reverts commit 8f6b8db4ed.
2020-06-23 09:40:06 +01:00
Schrodinger ZHU Yifan
8f6b8db4ed fixes for mingw (#215)
* fix mingw

* fix mingw malloc test
2020-06-23 07:05:06 +01:00
Matthew Parkinson
e16f2aff6f Add AddressSpaceManager (#214)
This change brings in a new approach to managing address space.
It wraps the Pal with a power of two reservation system, that
guarantees all returned blocks are naturally aligned to their size. It
either lets the Pal perform aligned requests, or over allocates and
splits into power of two blocks.
2020-06-22 12:36:40 +01:00
Matthew Parkinson
e393ac882f New configuration of slab sizes for OE. 2020-06-18 13:09:06 +01:00
Matthew Parkinson
26949de089 New PAL for open enclave
This changes the implementation of the open enclacve pal to support
aligned allocations.  This reduces the amount of memory required for
the initial reservation as the large allocator doesn't have to
overallocate to get alignment.
2020-06-18 13:09:06 +01:00
Theo Butler
61afa77898 Fix sizeclass rounding error 2020-06-08 07:55:32 +01:00
Matthew Parkinson
333190a27d Add some default initialisers. (#207)
* Add some default initialisers.
2020-05-29 17:12:00 +01:00
Anand Krishnamoorthi
c7736a2def OpenEnclave PAL: Store enclave heap base/end in inline variables. (#201)
PALOpenEnclave object is lazily constructed. I couldn't
figure out a straight-forward way to pass the heap bounds to
the constructor of PALOpenEnclave object.
As an alternative, store the bounds in inline static variables of
the PALOpenEnclave class and set them via static setup_initial_range
function.

- two_alloc_types/alloc1.cc
  Define oe_allocator_init to forward base, end values to
  PALOpenEnclave::setup_inital_range
- two_alloc_types/main.cc
  Use oe_allocator_init function to set up heap range.

- fixed_region/fixed_region.cc
  Initialize heap range via call to PALOpenEnclave::setup_inital_range.

Signed-off-by: Anand Krishnamoorthi <anakrish@microsoft.com>
2020-05-28 19:04:33 +01:00
Matthew Parkinson
4c22c5b02f Make binaries more compatible by default (#206)
* Make binaries more compatible by default

Turn `-march=native` off by default. This makes binaries more portable,
but may harm performance. However, fast paths look unaltered

* Change setting to on if specified.
2020-05-28 16:56:48 +01:00
Matthew Parkinson
2c9ab3096d Fix includes for the OE Pal.
The Pal should include address.h, this was masked as other Pals included
it, but are only included for simulating OE scenarios, rather than
the actual build for OE.
2020-05-27 13:42:32 +01:00
Matthew Parkinson
de0ab1dbe0 Remove iostream from ARM aal.
The ARM AAL was including `<iostream>`, this is unnecessary, and only
`<cstddef>` should be required for `size_t`.
2020-05-26 11:16:43 +01:00
Matthew Parkinson
b5c911fdf8 Merge pull request #185 from nwf/pal-page-size
Move OS_PAGE_SIZE to PAL, add Linux PowerPC w/ 64KiB pages
2020-05-26 09:43:15 +01:00
Nathaniel Filardo
37766588de Linux PowerPC port 2020-05-23 15:42:10 +00:00
Nathaniel Filardo
44e9abe888 Move OS_PAGE_SIZE to PAL 2020-05-23 15:42:10 +00:00
Nathaniel Filardo
b2ee1902dc AAL: add AalName and smallest_page_size 2020-05-23 15:42:10 +00:00
Nathaniel Filardo
3d3b048776 mediumslab: stop assuming page-alignedness of objects
With large pages (e.g. the 64K that Debian defaults to for ppc64), this
is a bit much to ask.  It's only not true for the bottom few medium size
classes, tho', as all sizes above 256K are multiples of 64K with the
current two mantissa bits size schedule.
2020-05-23 15:42:10 +00:00
Matthew Parkinson
87dfd41553 Improve code quality for alloc_size (#196)
* Improve code quality for alloc_size

* Made error noreturn.

* Update docs.

* Move annoation
2020-05-23 16:16:12 +01:00
Matthew Parkinson
fbbc2ddb76 Merge pull request #191 from nwf/aal-address_t
Allow the AAL to define address_t
2020-05-23 08:26:29 +01:00