Skip to content
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

Keep track of dirty regions #270

Open
deadalnix opened this issue May 31, 2023 · 1 comment · May be fixed by #361 or #362
Open

Keep track of dirty regions #270

deadalnix opened this issue May 31, 2023 · 1 comment · May be fixed by #361 or #362
Labels

Comments

@deadalnix
Copy link
Contributor

deadalnix commented May 31, 2023

The current region allocator never release memory to the system. And for "good" reasons: it doesn't track which memory has been used and which hasn't.

Newly allocated pages need to be marked as clean, while pages that are returned to the RegionAllocator must be marked as dirty.

Each region needs to keep an accounting of the number of dirty pages the contain. Regions with a higher number of dirty pages should be preferentially used.

Dirty pages can be purged, using madvise's MADV_FREE to be converted back to free pages.

A queue of run of dirty pages must be maintained so that they can be purged starting by the oldest ones. The RegionAllocator API must be extended to request the purge of a certain number of pages.

For reference, the code that registers a region:

sdc/sdlib/d/gc/region.d

Lines 134 to 156 in 6cfcf22

void registerRegion(Region* toRegister) {
Region r = *toRegister;
unusedRegions.insert(toRegister);
// First, merge adjacent ranges.
while (true) {
auto adjacent = regionsByRange.extract(&r);
if (adjacent is null) {
break;
}
r.merge(adjacent);
regionsByClass.remove(adjacent);
unusedRegions.insert(adjacent);
}
toRegister = unusedRegions.pop();
assert(toRegister !is null);
toRegister.clone(&r);
regionsByClass.insert(toRegister);
regionsByRange.insert(toRegister);
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
2 participants