Commit Graph

53 Commits

Author SHA1 Message Date
Matthew Parkinson
621b7e6b9a Clang format. 2019-07-02 10:51:18 +01:00
Matthew Parkinson
0dbd10bd74 Minor alterations to slow path, and when to handle messages. 2019-07-01 17:06:04 +01:00
Matthew Parkinson
9098b1c84f Only add Stats if passed to CMake. 2019-07-01 14:35:36 +01:00
Matthew Parkinson
187a016c39 Clang Tidy and Warnings 2019-07-01 14:35:36 +01:00
Matthew Parkinson
3c7d122dea Add macro for ASSUME and FAST_PATH/SLOW_PATH
Fixes GCC warning that was incorrect using an ASSUME.

Made fast path and slow path Macros so we can add additional attributes.
2019-07-01 14:35:36 +01:00
Matthew Parkinson
fb825dde09 Add an assert. 2019-07-01 14:35:35 +01:00
Matthew Parkinson
7a198cbda5 Aggressively optimise fast path for allocation
This change introduces a per small sizeclass free list.  That can be
used to access the free objects for that sizeclass with minimal
calculations being required.

It changes to a partial bump ptr.  We bump allocate a whole OS
page worth of objects at a go, so we don't switch as frequently
between bump and free list allocation.

The code for the fast paths has been restructured to minimise the
work required on the common case, and also it is all inlined for the
common case.

Allocating a zero sized object is moved off the fast path.  Ask for 1
byte if you want to be fast.
2019-07-01 14:35:35 +01:00
Matthew Parkinson
7a8eaec2cc Made a sizecass_t to wrap the sizeclass
This is useful as codegen is nicer if we use size_t, but the semantics
is uint8_t, and is stored as that in many places in the metadata.
Ultimately should introduce a wrapper to check this invariant.
2019-07-01 14:30:05 +01:00
Matthew Parkinson
cc6a9775d6 Made checks on client have own macro. 2019-06-12 15:29:25 +01:00
Matthew Parkinson
88d9534453 CR Feedback + clangformat 2019-06-12 13:54:14 +01:00
Matthew Parkinson
a8dd065fd7 A few checks for easy corruptions
Will detect corruption caused by either
* Use-after-free
* Double-free
Neither is comprehensive.  Full temporal safety is not possible.
This just aids with debugging.
2019-06-06 13:31:25 +01:00
Matthew Parkinson
48416e3241 CR Feedback 2019-05-14 21:16:11 +01:00
Matthew Parkinson
b484619f20 Added branch predictor hint. 2019-05-14 21:16:11 +01:00
Matthew Parkinson
5d711a2e65 Made checking debug only 2019-05-14 21:16:11 +01:00
David Chisnall
8bd136c224 Remove all instances of static_cast<size_t>(1).
In preparation for removing magic numbers, simplify code that is
computing masks with a single bit set.
2019-04-30 11:50:32 +01:00
David Chisnall
5c197e4ae4 [NFC] More checks, comments on end of namespace braces. 2019-04-30 09:46:01 +01:00
David Chisnall
28fac4d700 Fix the remaining clang-tidy warnings.
This introduces a new `address_t` type and two new casts: `pointer_cast`
and `address_cast` for casting between an `address_t` and a pointer.
These should make it easier to audit the codebase for casts between
pointers and integers.  In particular, the remaining `reinterpret_cast`s
and `pointer_cast`s should be the only places where we could perform
invalid pointer arithmetic.

Also adds a `pointer_offset` helper that adds an offset (in bytes) to a
pointer, preserving its original type.  This is a sufficiently common
pattern that it seemed worthwhile to centralise it.
2019-04-29 13:37:05 +01:00
David Chisnall
4bafca9be7 [NFC] Automatic fixes from clang-tidy. 2019-04-29 11:33:07 +01:00
Matthew Parkinson
f1835813bd uintptr_max instead of -1/~0 2019-04-29 11:02:47 +01:00
Matthew Parkinson
c471e1a271 CR 2019-04-29 11:02:47 +01:00
Matthew Parkinson
70e2fcf26f Fix 32bit build 2019-04-29 11:02:47 +01:00
Matthew Parkinson
37afe9d079 Clang format 2019-04-29 11:02:47 +01:00
Matthew Parkinson
2d831920ea Factored casting in external pointer calculation 2019-04-29 11:02:47 +01:00
Matthew Parkinson
a8618b0892 Use uintptr_t in signature for pagemap
We don't follow the pointers passed into the pagemap directly, but
instead use them to calculate indexs into the pagemap.  Use uintptr_t
means it is easier to perform address arithmetic, and not have casts
back to void* everywhere.
2019-04-29 11:02:47 +01:00
Matthew Parkinson
47428a096c Removing some casts and uses of void* 2019-04-29 11:02:47 +01:00
Matthew Parkinson
4faf9f3bee Use fewer header files
Removing some includes to reduce the code that is dragged in.
2019-04-29 11:02:47 +01:00
David Chisnall
9b3641df91 Address Matt's review comments. 2019-04-11 17:08:16 +01:00
David Chisnall
cd8ba18191 Delete some dead code that's difficult to use correctly. 2019-04-11 16:55:05 +01:00
David Chisnall
9d24f7e24f Fix callers of renamed function. 2019-04-11 10:42:50 +01:00
David Chisnall
a64cc5562f Remove indirection in the common case.
Rather than unconditionally storing a pointer to the pagemap and
initialising this with a global, we now provide a choice of three
compile-time options for how the pagemap should be accessed.
2019-04-11 10:33:52 +01:00
David Chisnall
ad0a22e571 Add missing doc comments. 2019-04-10 12:49:02 +01:00
David Chisnall
2442dc4f3f [NFI] clang-format 2019-04-10 12:43:04 +01:00
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
4036e54879 [NFC] clang-format. 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
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
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
8698f87018 Added some constexpr to some ifs. 2019-02-15 16:12:38 +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
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
806f7e47cc Rename TypeAlloc to Pool
Minor refactor to clarify purpose of the pool.
2019-01-18 11:12:09 +00:00
Matthew Parkinson
ee9d899aa3 Remove GRANULARITY check
This check was not doing anything.  It was from an earlier dependency
ordering issue that has now been fixed.
2019-01-17 14:38:14 +00:00
Matthew Parkinson
ab57c86e3a Addressing CR feedback 2019-01-16 17:03:15 +00:00