Skip to content

Improve codegen for sized free. #115

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

Merged
merged 2 commits into from
Jan 22, 2020
Merged
Changes from all commits
Commits
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
35 changes: 19 additions & 16 deletions src/mem/alloc.h
Original file line number Diff line number Diff line change
Expand Up @@ -237,41 +237,44 @@ namespace snmalloc
* Free memory of a dynamically known size. Must be called with an
* external pointer.
*/
void dealloc(void* p, size_t size)
SNMALLOC_FAST_PATH void dealloc(void* p, size_t size)
{
#ifdef USE_MALLOC
UNUSED(size);
return free(p);
#else
handle_message_queue();

sizeclass_t sizeclass = size_to_sizeclass(size);

if (sizeclass < NUM_SMALL_CLASSES)
if (likely((size - 1) <= (sizeclass_to_size(NUM_SMALL_CLASSES - 1) - 1)))
{
Superslab* super = Superslab::get(p);
RemoteAllocator* target = super->get_allocator();

if (target == public_state())
sizeclass_t sizeclass = size_to_sizeclass(size);
if (likely(target == public_state()))
small_dealloc(super, p, sizeclass);
else
remote_dealloc(target, p, sizeclass);
return;
}
else if (sizeclass < NUM_SIZECLASSES)
dealloc_sized_slow(p, size);
#endif
}

SNMALLOC_SLOW_PATH void dealloc_sized_slow(void* p, size_t size)
{
if (size == 0)
dealloc(p, 1);

if (likely(size <= sizeclass_to_size(NUM_SIZECLASSES - 1)))
{
Mediumslab* slab = Mediumslab::get(p);
RemoteAllocator* target = slab->get_allocator();

if (target == public_state())
sizeclass_t sizeclass = size_to_sizeclass(size);
if (likely(target == public_state()))
medium_dealloc(slab, p, sizeclass);
else
remote_dealloc(target, p, sizeclass);
return;
}
else
{
large_dealloc(p, size);
}
#endif
large_dealloc(p, size);
}

/*
Expand Down