Skip to content

Commit

Permalink
[GC] Move thread bin maintenance out of the bin lock when batch alloc…
Browse files Browse the repository at this point in the history
…ating.
  • Loading branch information
deadalnix committed Dec 3, 2024
1 parent 7083718 commit 2381be3
Showing 1 changed file with 45 additions and 38 deletions.
83 changes: 45 additions & 38 deletions sdlib/d/gc/bin.d
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,51 @@ struct Bin {
"Invalid arena or sizeClass!");
assert(slotSize == binInfos[sizeClass].slotSize, "Invalid slot size!");

mutex.lock();
scope(exit) mutex.unlock();
void** insert;

return (cast(Bin*) &this)
.batchAllocateImpl(filler, emap, sizeClass, top, bottom, slotSize);
{
mutex.lock();
scope(exit) mutex.unlock();

insert = (cast(Bin*) &this)
.batchAllocateImpl(filler, emap, sizeClass, top, bottom,
slotSize);
}

/**
* Note: If we are worried about security, we might want to shuffle
* our allocations around. This makes the uses of techniques
* like Heap Feng Shui difficult.
* We do not think it is worth the complication and performance
* hit in the general case, but something we might want to add
* in the future for security sensitive applications.
*
* http://www.phreedom.org/research/heap-feng-shui/heap-feng-shui.html
*/

// We filled the whole stack, done.
if (likely(insert is top)) {
return bottom;
}

/**
* We could simplify this code by inserting from top to bottom,
* in order to avoid moving all the elements when the stack has not
* been filled.
*
* However, because we allocate from the best slab to the worse one,
* this would result in a stack that allocate from the worse slab
* before the best ones.
*
* So we allocate from the bottom to the top, and move the whole stack
* if we did not quite reach the top.
*/
while (insert > bottom) {
*(--top) = *(--insert);
}

assert(bottom <= top);
return top;
}

uint batchFree(const(void*)[] worklist, PageDescriptor* pds,
Expand Down Expand Up @@ -88,40 +128,7 @@ private:
slabs.remove(e);
}

/**
* Note: If we are worried about security, we might want to shuffle
* our allocations around. This makes the uses of techniques
* like Heap feng Shui difficult.
* We do not think it is worth the complication and performance
* hit in the general case, but something we might want to add
* in the future for security sensitive applications.
*
* http://www.phreedom.org/research/heap-feng-shui/heap-feng-shui.html
*/

// We filled the whole stack, done.
if (likely(insert is top)) {
return bottom;
}

/**
* We could simplify this code by inserting from top to bottom,
* in order to avoid moving all the elements when the stack has not
* been filled.
*
* However, because we allocate from the best slab to the worse one,
* this would result in a stack that allocate from the worse slab
* before the best ones.
*
* So we allocate from the bottom to the top, and move the whole stack
* if we did not quite reach the top.
*/
while (insert > bottom) {
*(--top) = *(--insert);
}

assert(bottom <= top);
return top;
return insert;
}

uint batchFreeImpl(const(void*)[] worklist, PageDescriptor* pds,
Expand Down

0 comments on commit 2381be3

Please sign in to comment.