Skip to content

Commit

Permalink
Zero slabs that are freed that contain pointers, so when they are all…
Browse files Browse the repository at this point in the history
…ocated next time, they are already zero. (#395)

This isn't as performant as I would like it to be. I can't think of a
good way to run both finalization and zeroing in the same pass.

I also think there is an opportunity to memset batches of slabs, which
might happen if you for instance free an entire graph of nodes at once.
I might be able to get something like that working.
  • Loading branch information
schveiguy authored Oct 17, 2024
1 parent 2a3f6ff commit 84ffdbc
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion sdlib/d/gc/tcache.d
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ import sdc.intrinsics;

enum DefaultEventWait = 65536;

enum ShouldZeroFreeSlabs = true;

alias RNode = Node!ThreadCache;
alias ThreadRing = Ring!ThreadCache;

Expand Down Expand Up @@ -412,7 +414,13 @@ private:
// We trigger the de-allocation event first as it might
// recycle the bin we are interested in, which increase
// our chances that free works.
triggerDeallocationEvent(binInfos[sc].slotSize);
auto slotSize = binInfos[sc].slotSize;
triggerDeallocationEvent(slotSize);

// If the allocation contains pointers, zero it before freeing it
if (ShouldZeroFreeSlabs && pd.containsPointers) {
memset(ptr, 0, slotSize);
}

auto index = getBinIndex(sc, pd.containsPointers);
auto bin = &bins[index];
Expand Down

0 comments on commit 84ffdbc

Please sign in to comment.