Skip to content

Commit

Permalink
msgpass benchmark and its refactoring dependencies (#659)
Browse files Browse the repository at this point in the history
* NFC: split freelist_queue from remoteallocator

This lets us use freelists as message queues in contexts other than
the remoteallocator.  No functional change indended.

* freelist_queue: add and use destroy_and_iterate

* freelist: make backptr obfuscation key "tweakable"

* freelist: tweakable keys in forward direction, too

* test/perf/msgpass: ubench a producer-consumer app

Approximate a message-passing application as a set of producers, a set of
consumers, and a set of proxies that do both.  We'll use this for some initial
insight for #634 but it seems worth
having in general.
  • Loading branch information
nwf-msr authored Jun 13, 2024
1 parent 2a7eabe commit 835ab51
Show file tree
Hide file tree
Showing 7 changed files with 691 additions and 206 deletions.
31 changes: 15 additions & 16 deletions src/snmalloc/mem/corealloc.h
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,7 @@ namespace snmalloc
freelist::Object::make<capptr::bounds::AllocWild>(
capptr_to_user_address_control(curr_ptr.as_void())),
key,
NO_KEY_TWEAK,
entropy);
curr_ptr = curr_ptr->next;
} while (curr_ptr != start_ptr);
Expand All @@ -258,6 +259,7 @@ namespace snmalloc
Aal::capptr_bound<void, capptr::bounds::AllocFull>(
p.as_void(), rsize))),
key,
NO_KEY_TWEAK,
entropy);
p = pointer_offset(p, rsize);
} while (p < slab_end);
Expand All @@ -271,7 +273,7 @@ namespace snmalloc
{
auto& key = entropy.get_free_list_key();
freelist::Iter<> fl;
auto more = meta->free_queue.close(fl, key);
auto more = meta->free_queue.close(fl, key, NO_KEY_TWEAK);
UNUSED(more);
auto local_state = backend_state_ptr();
auto domesticate = [local_state](freelist::QueuePtr p)
Expand Down Expand Up @@ -303,7 +305,7 @@ namespace snmalloc

if (more > 0)
{
auto no_more = meta->free_queue.close(fl, key);
auto no_more = meta->free_queue.close(fl, key, NO_KEY_TWEAK);
SNMALLOC_ASSERT(no_more == 0);
UNUSED(no_more);

Expand Down Expand Up @@ -348,7 +350,8 @@ namespace snmalloc
{
if (check_slabs)
{
meta->free_queue.validate(entropy.get_free_list_key(), domesticate);
meta->free_queue.validate(
entropy.get_free_list_key(), NO_KEY_TWEAK, domesticate);
}
return;
}
Expand Down Expand Up @@ -709,7 +712,7 @@ namespace snmalloc
auto& key = entropy.get_free_list_key();

// Update the head and the next pointer in the free list.
meta->free_queue.add(cp, key, entropy);
meta->free_queue.add(cp, key, NO_KEY_TWEAK, entropy);

return SNMALLOC_LIKELY(!meta->return_object());
}
Expand Down Expand Up @@ -849,19 +852,14 @@ namespace snmalloc

if (destroy_queue)
{
auto p_wild = message_queue().destroy();
auto p_tame = domesticate(p_wild);

while (p_tame != nullptr)
{
auto cb = [this](capptr::Alloc<void> p) {
bool need_post = true; // Always going to post, so ignore.
auto n_tame =
p_tame->atomic_read_next(RemoteAllocator::key_global, domesticate);
const PagemapEntry& entry =
Config::Backend::get_metaentry(snmalloc::address_cast(p_tame));
handle_dealloc_remote(entry, p_tame.as_void(), need_post);
p_tame = n_tame;
}
Config::Backend::get_metaentry(snmalloc::address_cast(p));
handle_dealloc_remote(entry, p.as_void(), need_post);
};

message_queue().destroy_and_iterate(domesticate, cb);
}
else
{
Expand All @@ -886,7 +884,8 @@ namespace snmalloc
BackendSlabMetadata* meta) SNMALLOC_FAST_PATH_LAMBDA {
if (!meta->is_large())
{
meta->free_queue.validate(entropy.get_free_list_key(), domesticate);
meta->free_queue.validate(
entropy.get_free_list_key(), NO_KEY_TWEAK, domesticate);
}
});

Expand Down
Loading

0 comments on commit 835ab51

Please sign in to comment.