Skip to content

Commit

Permalink
Use pages_purge to zero blocks in the extent map.
Browse files Browse the repository at this point in the history
  • Loading branch information
deadalnix committed Jan 12, 2024
1 parent 14b6543 commit 2e804ec
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
5 changes: 4 additions & 1 deletion sdlib/d/gc/memmap.d
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,10 @@ void pages_unmap(void* addr, size_t size) {
}

void pages_purge(void* addr, size_t size) {
auto ret = madvise(addr, size, Madv.Free);
import core.stdc.stdio;
printf("pages_purge(%p, %ld)\n", addr, size);

auto ret = madvise(addr, size, Madv.DontNeed);
assert(ret == 0, "madvise failed!");
}

Expand Down
12 changes: 11 additions & 1 deletion sdlib/d/gc/rtree.d
Original file line number Diff line number Diff line change
Expand Up @@ -166,13 +166,23 @@ public:

auto leaves = getLeaves(cache, ptr);
if (leaves is null) {
import d.gc.util;
ptr = nextPtr;
continue;
}

auto key1 = subKey(ptr, 1);

// If we need to clear the whole page, do so via purging.
// XXX: We might want to do it for smaller runs, but this is
// more complicated as the alternative path requires atomic ops.
if (key1 == 0 && stop >= nextPtr) {
import d.gc.memmap;
pages_purge(cast(void*) leaves.ptr, typeof(*leaves).sizeof);

ptr = nextPtr;
continue;
}

auto subStop = stop < nextPtr ? stop : nextPtr;
while (ptr < subStop) {
(*leaves)[key1++].store(T(0));
Expand Down

0 comments on commit 2e804ec

Please sign in to comment.