Skip to content

Commit

Permalink
Merge pull request #65 from microsoft/queue_of_slabs
Browse files Browse the repository at this point in the history
Use a queue of slabs for free lists
  • Loading branch information
davidchisnall authored Jul 8, 2019
2 parents 97bfa68 + d1db6d0 commit c35a394
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 2 deletions.
25 changes: 25 additions & 0 deletions src/ds/dllist.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ namespace snmalloc
std::is_same<decltype(T::next), T*>::value, "T->next must be a T*");

T* head = Terminator();
T* tail = Terminator();

public:
bool is_empty()
Expand Down Expand Up @@ -96,13 +97,35 @@ namespace snmalloc

if (head != Terminator())
head->prev = item;
else
tail = item;

head = item;
#ifndef NDEBUG
debug_check();
#endif
}

void insert_back(T* item)
{
#ifndef NDEBUG
debug_check_not_contains(item);
#endif

item->prev = tail;
item->next = Terminator();

if (tail != Terminator())
tail->next = item;
else
head = item;

tail = item;
#ifndef NDEBUG
debug_check();
#endif
}

void remove(T* item)
{
#ifndef NDEBUG
Expand All @@ -111,6 +134,8 @@ namespace snmalloc

if (item->next != Terminator())
item->next->prev = item->prev;
else
tail = item->prev;

if (item->prev != Terminator())
item->prev->next = item->next;
Expand Down
2 changes: 1 addition & 1 deletion src/mem/alloc.h
Original file line number Diff line number Diff line change
Expand Up @@ -1114,7 +1114,7 @@ namespace snmalloc
if ((allow_reserve == NoReserve) && (slab == nullptr))
return nullptr;

sl.insert(slab->get_link());
sl.insert_back(slab->get_link());
}
auto& ffl = small_fast_free_lists[sizeclass];
return slab->alloc<zero_mem>(
Expand Down
2 changes: 1 addition & 1 deletion src/mem/slab.h
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ namespace snmalloc
meta.link = index;

// Push on the list of slabs for this sizeclass.
sl->insert(meta.get_link(this));
sl->insert_back(meta.get_link(this));
meta.debug_slab_invariant(is_short(), this);
return Superslab::NoSlabReturn;
}
Expand Down

0 comments on commit c35a394

Please sign in to comment.