Commit Graph

64 Commits

Author SHA1 Message Date
David Chisnall
d0fefb8641 Don't always refer to the global pagemap.
If you're creating a new allocator and the pagemap comes from a library
that exports the pagemap accessor function but not the pagemap symbol,
you need to be able to replace this.
2019-04-10 11:57:02 +01:00
David Chisnall
a93f43fd2f Add some type safety to other pagemap accesses.
Introduce a descriptor for the pagemap config and check that the source
descriptor is compatible with the destination type.
2019-04-09 15:52:38 +01:00
rschust
51fbdf3a44 ZeroMem should not be a part of pal_consts.h 2019-04-09 13:56:22 +01:00
rschust
71900ef947 Created pal_consts.h. New exported functions are now prefixed with "snmalloc_". 2019-04-09 13:56:22 +01:00
rschust
f0d18760fe Exporting the global pagemap and the default memory provider's reserve function in order to support shared allocators 2019-04-09 13:56:22 +01:00
David Chisnall
45a31e75d1 Add some comments. 2019-02-25 12:54:16 +00:00
David Chisnall
6a5359b177 Pull aligned allocation out of the PAL.
The PAL can now advertise that it supports aligned allocation.  If it
does not, then the memory provider will do the alignment for it.

This change still leaves the PAL responsible for systematic testing, but
it should now be much easier to lift that out.
2019-02-25 12:54:16 +00:00
David Chisnall
d6e89b7c60 Fix Matt's code review comments. 2019-02-25 11:27:53 +00:00
David Chisnall
01bd77b356 Remove some ugly templated things.
Replace them with some very simple constexpr things.  This is what the
code used to look like, but it appears that I fundamentally
misunderstood why it didn't work.  This version should be a lot more
maintainable.
2019-02-25 11:27:53 +00:00
David Chisnall
4036e54879 [NFC] clang-format. 2019-02-25 11:27:53 +00:00
David Chisnall
1892538ad1 Clean up PAL feature detection API. 2019-02-25 11:27:53 +00:00
David Chisnall
5adba34d60 Make clang happy. 2019-02-25 11:27:53 +00:00
David Chisnall
a24e6270cc Provide a generic PAL feature detection mechanism.
We can support up to 64 optional features, currently only one is used.
2019-02-25 11:27:53 +00:00
David Chisnall
80630a359f Clean up interface to the low memory notifications.
- Rename MemoryProviderState to PAL to reflect what is now is.
 - Hide calls to the PAL's low memory functions behind something that
   returns a default value if they're not implemented.
2019-02-25 11:27:53 +00:00
David Chisnall
e2a12802d5 Hide the low memory notification PAL code. 2019-02-25 11:27:53 +00:00
David Chisnall
f6349092c9 Remove debugging define.
This was enabled so CI would run it.  It probably should be enabled for
some testing, but via CMake, not like this.
2019-02-25 11:27:53 +00:00
David Chisnall
6af4c97726 Explicitly qualify a method.
Either clang or cl has a bug: cl accepts the unqualified (inherited)
method name, clang rejects it.  Both accept the qualified name.
2019-02-25 11:27:53 +00:00
David Chisnall
71cfb6da1e [NFC] clangformat 2019-02-25 11:27:53 +00:00
David Chisnall
e5d330ec7a Fix the tests. 2019-02-25 11:27:53 +00:00
David Chisnall
66cec23b23 Initial cut at a lazy decommit strategy.
This does not deallocate memory until the OS tells us that we are short
on memory, then tries to decommit all of the cached chunks (except for
the first page, used for the linked lists).

Nowhere near enough testing to commit to master yet!
2019-02-25 11:27:53 +00:00
Matthew Parkinson
d588e8ecb1 Updated to match documentation. 2019-02-19 15:00:55 +00:00
Matthew Parkinson
aac2b9212e Merge pull request #21 from plietar/smart-next
Place the next pointer at a different place on every object.
2019-02-19 09:04:23 +00:00
Paul Liétar
ffe496dd18 Address review comments. 2019-02-18 21:29:32 +00:00
Paul Liétar
4ac3421487 Place the next pointer at a different place on every object.
This limits the collision in cache buckets, especially for larger objects.
2019-02-18 14:22:50 +00:00
David Chisnall
c47eed1922 Tweaks to end bounds checking.
Introduce a `OnePastEnd` option for the pointer immediately after the
end of the allocation.  This simplifies some of the logic in callers,
where they wants to say 'is base + length safe to use?'.

Also restructure some of the other logic somewhat.
2019-02-15 20:05:00 +01:00
Matthew Parkinson
5e149b083f One more constexpr 2019-02-15 17:43:27 +00:00
Matthew Parkinson
8698f87018 Added some constexpr to some ifs. 2019-02-15 16:12:38 +00:00
Matthew Parkinson
ac8e5e4e5b Fix comment to represent current PAL API. 2019-02-15 09:24:01 +00:00
Matthew Parkinson
adeecfb0f1 Added bug fix to alignment of using. 2019-02-14 20:08:04 +00:00
Paul Liétar
79b432ddab Fix the condition on when to allocate a new block.
Previously we would pretty much always allocate a new block for each
allocator, making them 16MiB aligned.
2019-02-12 12:47:22 +00:00
Matthew Parkinson
731757b29c Merge pull request #13 from Microsoft/matt-refactor
Simplification around remote allocation
2019-02-06 11:25:07 +00:00
Matthew Parkinson
f3897dd3e0 Code review feedback. 2019-02-05 16:57:09 +00:00
Matthew Parkinson
83c55fe5da Simplify remote allocator.
Don't store the sizeclass, as we can find it easily, and already are
going to touch though cache lines in the common case.
2019-02-05 13:27:19 +00:00
Matthew Parkinson
122a5de811 Refactor code to correctly handle low bits of allocator ID. 2019-02-05 13:11:55 +00:00
theodus
85cf5dd097 Avoid unnecessary allocation from realloc 2019-02-02 14:47:06 -05:00
Matthew Parkinson
ec59820970 Use placement new instead of init for metaslab. 2019-01-25 19:46:24 +00:00
Matthew Parkinson
06ff1ffe0a Renamed zero to init for metaslab. 2019-01-25 16:38:10 +00:00
Matthew Parkinson
e5c40c1231 Remove an auto as not correctly inferred. 2019-01-24 11:48:02 +00:00
Matthew Parkinson
d5fb7150a3 Clang format 2019-01-24 11:39:19 +00:00
Matthew Parkinson
294efe8e03 Hardening access to meta data
Introduce a wrapper that ensure various fields of meta data, represent
valid indexes into the the address space, and not beyond the current
slab/superslab.
2019-01-24 11:39:18 +00:00
Matthew Parkinson
2083b29c9b Remove a raw pointer usage
Metaslab can be handled as as ref, rather than a raw pointer.
2019-01-24 11:39:18 +00:00
Matthew Parkinson
e30c94cb2a Apply ModArray to Metaslab data
Prevent bugs accessing outside the Slabs meta data.
2019-01-24 11:39:18 +00:00
Matthew Parkinson
745a2a53d1 Clang format 2019-01-22 17:18:54 +00:00
Matthew Parkinson
cb70aa3f7f Restricted another array to bounds. 2019-01-22 11:19:57 +00:00
Matthew Parkinson
18dd15c2c0 Minor restructuring to move static_assert 2019-01-22 11:19:57 +00:00
Matthew Parkinson
bb5027b454 Harden sizeclass table
If a sizeclass in the metadata is corrupted, then this can be used to
force an index beyond the end of these tables. This extends the tables
to the next power of two, and uses a mask on the index, so they are
always either a valid piece of data, or zero.
2019-01-22 11:19:57 +00:00
Matthew Parkinson
94f8b886a0 Remove union in metaslab
The union in Metaslab provides no benefit in size, as the single byte
it effectively saves will be removed due to padding.

By removing the union, we get stronger properties over sizeclass, and
remove an out-of-bounds access.
2019-01-18 21:11:01 +00:00
David Chisnall
20b84b9810 Merge pull request #7 from Microsoft/mjp41/refactor
Fixes remote and pagemap
2019-01-18 17:11:25 +00:00
Matthew Parkinson
c1e23c497f Made alignment a template parameter. 2019-01-18 17:00:10 +00:00
Matthew Parkinson
07b19d43cb Merge pull request #4 from Microsoft/fbsdlibc
Merge changes required for using snmalloc in FreeBSD libc
2019-01-18 16:08:51 +00:00