Skip to content

Keep track of dirty regions #270

Description

@deadalnix

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);
}

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions