Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve slow path performance for allocation #143

Merged
merged 39 commits into from
Mar 31, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
1e454cc
Remote dealloc refactor.
mjp41 Mar 9, 2020
91b7e08
Clang format
mjp41 Mar 9, 2020
ffb7b82
Clang format again.
mjp41 Mar 16, 2020
78f40d4
Improve remote dealloc
mjp41 Mar 9, 2020
a22e438
CR feedback.
mjp41 Mar 10, 2020
0274b71
Clang format.
mjp41 Mar 10, 2020
d080654
Inline remote_dealloc
mjp41 Mar 10, 2020
bac6336
Improve fast path in Slab::alloc
mjp41 Mar 10, 2020
a52aca6
Refactor initialisation to help fast path.
mjp41 Mar 10, 2020
bd8c443
Fixup
mjp41 Mar 10, 2020
267a726
Minor tidy to statically sized dealloc.
mjp41 Mar 10, 2020
52c0ff0
Refactor semi-slow path for alloc
mjp41 Mar 10, 2020
e563bfb
Test initial operation of a thread
mjp41 Mar 12, 2020
a1d139c
Correctly handle reusing get_noncachable
mjp41 Mar 12, 2020
f9e0f64
Fix large alloc stats
mjp41 Mar 12, 2020
37d7e15
Fix TLS init on large alloc path
mjp41 Mar 12, 2020
075874e
Fixup slab refactor
mjp41 Mar 12, 2020
68b49df
Minor refactor.
mjp41 Mar 12, 2020
f8b77a8
Minor refactor
mjp41 Mar 12, 2020
d656232
Add Bump ptrs to allocator
mjp41 Mar 12, 2020
54dcb20
Bug fix
mjp41 Mar 13, 2020
bd19484
Change to a cycle non-empty list
mjp41 Mar 13, 2020
ed69bbb
Comments.
mjp41 Mar 16, 2020
06032f2
Update differences
mjp41 Mar 16, 2020
941e28a
Rename first allocation
mjp41 Mar 16, 2020
8a8a2f6
Fixup for thread alloc.
mjp41 Mar 16, 2020
2215815
Clangformat + CR feedback
mjp41 Mar 16, 2020
a857b92
More CR
mjp41 Mar 16, 2020
841314e
Revert "More CR"
mjp41 Mar 16, 2020
baff3ef
CR attempt two.
mjp41 Mar 16, 2020
6bf7115
Fix assert
mjp41 Mar 16, 2020
193e27a
Bug fix found by CI.
mjp41 Mar 16, 2020
6d60feb
Clang tidy.
mjp41 Mar 16, 2020
04e74c4
Merge branch 'master' into alloc_slow_optimise
mjp41 Mar 19, 2020
0c40c84
Use a ptrdiff to help with zero init.
mjp41 Mar 25, 2020
65bb8c1
Make GlobalPlaceholder zero init
mjp41 Mar 25, 2020
50486c0
Comment.
mjp41 Mar 25, 2020
4fd24db
Merge remote-tracking branch 'origin/master' into alloc_slow_optimise
mjp41 Mar 25, 2020
4b19611
Clang format.
mjp41 Mar 25, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/ds/bits.h
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@ namespace snmalloc
*
* `std::min` is in `<algorithm>`, so pulls in a lot of unneccessary code
* We write our own to reduce the code that potentially needs reviewing.
**/
*/
template<typename T>
constexpr inline T min(T t1, T t2)
{
Expand All @@ -340,7 +340,7 @@ namespace snmalloc
*
* `std::max` is in `<algorithm>`, so pulls in a lot of unneccessary code
* We write our own to reduce the code that potentially needs reviewing.
**/
*/
template<typename T>
constexpr inline T max(T t1, T t2)
{
Expand Down
8 changes: 4 additions & 4 deletions src/ds/cdllist.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ namespace snmalloc
* Special class for cyclic doubly linked non-empty linked list
*
* This code assumes there is always one element in the list. The client
* must ensure there is a sentinal element.
*/ust ensure there is a sentinal element.
mjp41 marked this conversation as resolved.
Show resolved Hide resolved
**/
mjp41 marked this conversation as resolved.
Show resolved Hide resolved
class CDLLNode
{
Expand All @@ -20,7 +20,7 @@ namespace snmalloc

public:
/**
* Single element cyclic list. This is the empty case.
*/ingle element cyclic list. This is the empty case.
**/
CDLLNode()
{
Expand All @@ -34,7 +34,7 @@ namespace snmalloc
}

/**
* Removes this element from the cyclic list is it part of.
*/emoves this element from the cyclic list is it part of.
**/
SNMALLOC_FAST_PATH void remove()
{
Expand Down Expand Up @@ -85,7 +85,7 @@ namespace snmalloc
/**
* Checks the lists invariants
* x->next->prev = x
* for all x in the list.
*/or all x in the list.
**/
void debug_check()
{
Expand Down
2 changes: 1 addition & 1 deletion src/ds/helpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ namespace snmalloc
*
* Wraps on read. This allows code to trust the value is in range, even when
* there is a memory corruption.
**/
*/
template<size_t length, typename T>
class Mod
{
Expand Down
18 changes: 9 additions & 9 deletions src/mem/alloc.h
Original file line number Diff line number Diff line change
Expand Up @@ -714,7 +714,7 @@ namespace snmalloc
*
* If result pointer is null, then this code raises a Pal::error on the
* particular check that fails, if any do fail.
**/
*/
void debug_is_empty(bool* result)
{
auto test = [&result](auto& queue) {
Expand Down Expand Up @@ -890,7 +890,7 @@ namespace snmalloc
/**
* Check if this allocator has messages to deallocate blocks from another
* thread
**/
*/
SNMALLOC_FAST_PATH bool has_messages()
{
return !(message_queue().is_empty());
Expand Down Expand Up @@ -1042,7 +1042,7 @@ namespace snmalloc
/**
* Slow path for handling message queue, before dealing with small
* allocation request.
**/
*/
template<ZeroMem zero_mem, AllowReserve allow_reserve>
SNMALLOC_SLOW_PATH void* small_alloc_mq_slow(sizeclass_t sizeclass)
{
Expand All @@ -1053,7 +1053,7 @@ namespace snmalloc

/**
* Attempt to find a new free list to allocate from
**/
*/
template<ZeroMem zero_mem, AllowReserve allow_reserve>
SNMALLOC_SLOW_PATH void* small_alloc_next_free_list(sizeclass_t sizeclass)
{
Expand All @@ -1079,7 +1079,7 @@ namespace snmalloc
* Called when there are no available free list to service this request
* Could be due to using the dummy allocator, or needing to bump allocate a
* new free list.
**/
*/
template<ZeroMem zero_mem, AllowReserve allow_reserve>
SNMALLOC_SLOW_PATH void* small_alloc_rare(sizeclass_t sizeclass)
{
Expand All @@ -1094,7 +1094,7 @@ namespace snmalloc
/**
* Called on first allocation to set up the thread local allocator,
* then directs the allocation request to the newly created allocator.
**/
*/
template<ZeroMem zero_mem, AllowReserve allow_reserve>
SNMALLOC_SLOW_PATH void* small_alloc_first_alloc(sizeclass_t sizeclass)
{
Expand All @@ -1106,7 +1106,7 @@ namespace snmalloc
/**
* Called to create a new free list, and service the request from that new
* list.
**/
*/
template<ZeroMem zero_mem, AllowReserve allow_reserve>
SNMALLOC_FAST_PATH void* small_alloc_new_free_list(sizeclass_t sizeclass)
{
Expand All @@ -1122,7 +1122,7 @@ namespace snmalloc
/**
* Creates a new free list from the thread local bump allocator and service
* the request from that new list.
**/
*/
template<ZeroMem zero_mem, AllowReserve allow_reserve>
SNMALLOC_FAST_PATH void* small_alloc_build_free_list(sizeclass_t sizeclass)
{
Expand All @@ -1146,7 +1146,7 @@ namespace snmalloc
* Allocates a new slab to allocate from, set it to be the bump allocator
* for this size class, and then builds a new free list from the thread
* local bump allocator and service the request from that new list.
**/
*/
template<ZeroMem zero_mem, AllowReserve allow_reserve>
SNMALLOC_SLOW_PATH void* small_alloc_new_slab(sizeclass_t sizeclass)
{
Expand Down
12 changes: 6 additions & 6 deletions src/mem/largealloc.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,23 +60,23 @@ namespace snmalloc
{
/**
* Flag to protect the bump allocator
**/
*/
std::atomic_flag lock = ATOMIC_FLAG_INIT;

/**
* Pointer to block being bump allocated
**/
*/
void* bump = nullptr;

/**
* Space remaining in this block being bump allocated
**/
*/
size_t remaining = 0;

/**
* Simple flag for checking if another instance of lazy-decommit is
* running
**/
*/
std::atomic_flag lazy_decommit_guard = {};

public:
Expand All @@ -87,7 +87,7 @@ namespace snmalloc

/**
* Make a new memory provide for this PAL.
**/
*/
static MemoryProviderStateMixin<PAL>* make() noexcept
{
// Temporary stack-based storage to start the allocator in.
Expand Down Expand Up @@ -197,7 +197,7 @@ namespace snmalloc

/***
* Method for callback object to perform lazy decommit.
**/
*/
static void process(PalNotificationObject* p)
{
// Unsafe downcast here. Don't want vtable and RTTI.
Expand Down
4 changes: 2 additions & 2 deletions src/mem/metaslab.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ namespace snmalloc
* - was full before the subtraction
* this returns true, otherwise returns false.
**/
bool return_object()
b*/ return_object()
{
return (--needed) == 0;
}
Expand Down Expand Up @@ -158,7 +158,7 @@ namespace snmalloc
* We don't expect a cycle, so worst case is only followed by a crash, so
* slow doesn't mater.
**/
size_t debug_slab_acyclic_free_list(Slab* slab)
s*/_t debug_slab_acyclic_free_list(Slab* slab)
{
#ifndef NDEBUG
size_t length = 0;
Expand Down
2 changes: 1 addition & 1 deletion src/mem/pagemap.h
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ namespace snmalloc
/**
* Simple pagemap that for each GRANULARITY_BITS of the address range
* stores a T.
**/
*/
template<size_t GRANULARITY_BITS, typename T>
class alignas(OS_PAGE_SIZE) FlatPagemap
{
Expand Down
2 changes: 1 addition & 1 deletion src/mem/pool.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ namespace snmalloc
* concurrency safe.
*
* This is used to bootstrap the allocation of allocators.
**/
*/
template<class T, class MemoryProvider = GlobalVirtual>
class Pool
{
Expand Down
4 changes: 2 additions & 2 deletions src/mem/slab.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ namespace snmalloc
* Takes a free list out of a slabs meta data.
* Returns the link as the allocation, and places the free list into the
* `fast_free_list` for further allocations.
**/
*/
template<ZeroMem zero_mem, typename MemoryProvider>
SNMALLOC_FAST_PATH void* alloc(
SlabList& sl,
Expand Down Expand Up @@ -90,7 +90,7 @@ namespace snmalloc
* list, and stores it in the fast_free_list. It will only create a page
* worth of allocations, or one if the allocation size is larger than a
* page.
**/
*/
static SNMALLOC_FAST_PATH void
alloc_new_list(void*& bumpptr, FreeListHead& fast_free_list, size_t rsize)
{
Expand Down
8 changes: 4 additions & 4 deletions src/mem/threadalloc.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ namespace snmalloc
* replacement. This function returns true, if the allocator passed in
* requires initialisation. As the TLS state is managed externally,
* this will always return false.
**/
*/
SNMALLOC_FAST_PATH bool needs_initialisation(void* existing)
{
UNUSED(existing);
Expand All @@ -54,7 +54,7 @@ namespace snmalloc
* Function passed as a tempalte parameter to `Allocator` to allow lazy
* replacement. There is nothing to initialise in this case, so we expect
* this to never be called.
**/
*/
SNMALLOC_FAST_PATH void* init_thread_allocator()
{
return nullptr;
Expand Down Expand Up @@ -94,7 +94,7 @@ namespace snmalloc

/**
* Default clean up does nothing except print statistics if enabled.
**/
*/
static void register_cleanup()
{
# ifdef USE_SNMALLOC_STATS
Expand Down Expand Up @@ -254,7 +254,7 @@ namespace snmalloc
* replacement. This function returns true, if the allocated passed in,
* is the placeholder allocator. If it returns true, then
* `init_thread_allocator` should be called.
**/
*/
SNMALLOC_FAST_PATH bool needs_initialisation(void* existing)
{
return existing == &GlobalPlaceHolder;
Expand Down
10 changes: 5 additions & 5 deletions src/pal/pal_consts.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ namespace snmalloc
* This struct is used to represent callbacks for notification from the
* platform. It contains a next pointer as client is responsible for
* allocation as we cannot assume an allocator at this point.
**/
*/
struct PalNotificationObject
{
std::atomic<PalNotificationObject*> pal_next;
Expand All @@ -72,12 +72,12 @@ namespace snmalloc

/***
* Wrapper for managing notifications for PAL events
**/
*/
class PalNotifier
{
/**
* List of callbacks to notify
**/
*/
std::atomic<PalNotificationObject*> callbacks = nullptr;

public:
Expand All @@ -86,7 +86,7 @@ namespace snmalloc
*
* The object should never be deallocated by the client after calling
* this.
**/
*/
void register_notification(PalNotificationObject* callback)
{
callback->pal_next = nullptr;
Expand All @@ -105,7 +105,7 @@ namespace snmalloc

/**
* Calls the pal_notify of all the registered objects.
**/
*/
void notify_all()
{
PalNotificationObject* curr = callbacks;
Expand Down
4 changes: 2 additions & 2 deletions src/pal/pal_windows.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ namespace snmalloc

/**
* List of callbacks for low-memory notification
**/
*/
static inline PalNotifier low_memory_callbacks;

/**
Expand Down Expand Up @@ -98,7 +98,7 @@ namespace snmalloc
* Register callback object for low-memory notifications.
* Client is responsible for allocation, and ensuring the object is live
* for the duration of the program.
**/
*/
static void
register_for_low_memory_callback(PalNotificationObject* callback)
{
Expand Down
2 changes: 1 addition & 1 deletion src/test/perf/low_memory/low-memory.cc
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ void reduce_pressure(Queue& allocations)
* Wrapper to handle Pals that don't have the method.
* Template parameter required to handle `if constexpr` always evaluating both
* sides.
**/
*/
template<typename PAL>
void register_for_pal_notifications()
{
Expand Down