add minimal commit size for increased efficiency (decommit fine grained, commit coarse grained)

This commit is contained in:
daan 2022-02-05 10:57:15 -08:00
parent 9ca363d0e4
commit e11100a137
2 changed files with 12 additions and 4 deletions

View file

@ -320,10 +320,15 @@ typedef enum mi_segment_kind_e {
// the corresponding MI_COMMIT_SIZE area is committed. // the corresponding MI_COMMIT_SIZE area is committed.
// The MI_COMMIT_SIZE must be a multiple of the slice // The MI_COMMIT_SIZE must be a multiple of the slice
// size. If it is equal we have the most fine grained // size. If it is equal we have the most fine grained
// decommit but setting it higher can be more efficient. // decommit (but setting it higher can be more efficient).
// The MI_MINIMAL_COMMIT_SIZE is the minimal amount that will
// be committed in one go which can be set higher than
// MI_COMMIT_SIZE for efficiency (while the decommit mask
// is still tracked in fine-grained MI_COMMIT_SIZE chunks)
// ------------------------------------------------------ // ------------------------------------------------------
#define MI_COMMIT_SIZE (8*MI_SEGMENT_SLICE_SIZE) #define MI_MINIMAL_COMMIT_SIZE (16*MI_SEGMENT_SLICE_SIZE) // 1MiB
#define MI_COMMIT_SIZE (MI_SEGMENT_SLICE_SIZE)
#define MI_COMMIT_MASK_BITS (MI_SEGMENT_SIZE / MI_COMMIT_SIZE) #define MI_COMMIT_MASK_BITS (MI_SEGMENT_SIZE / MI_COMMIT_SIZE)
#define MI_COMMIT_MASK_FIELD_BITS MI_SIZE_BITS #define MI_COMMIT_MASK_FIELD_BITS MI_SIZE_BITS
#define MI_COMMIT_MASK_FIELD_COUNT (MI_COMMIT_MASK_BITS / MI_COMMIT_MASK_FIELD_BITS) #define MI_COMMIT_MASK_FIELD_COUNT (MI_COMMIT_MASK_BITS / MI_COMMIT_MASK_FIELD_BITS)

View file

@ -470,17 +470,20 @@ static void mi_segment_commit_mask(mi_segment_t* segment, bool conservative, uin
if (p >= (uint8_t*)segment + segsize) return; if (p >= (uint8_t*)segment + segsize) return;
size_t diff = (p - (uint8_t*)segment); size_t diff = (p - (uint8_t*)segment);
mi_assert_internal(diff + size <= segsize);
size_t start; size_t start;
size_t end; size_t end;
if (conservative) { if (conservative) {
// decommit conservative
start = _mi_align_up(diff, MI_COMMIT_SIZE); start = _mi_align_up(diff, MI_COMMIT_SIZE);
end = _mi_align_down(diff + size, MI_COMMIT_SIZE); end = _mi_align_down(diff + size, MI_COMMIT_SIZE);
} }
else { else {
// commit liberal
start = _mi_align_down(diff, MI_COMMIT_SIZE); start = _mi_align_down(diff, MI_COMMIT_SIZE);
end = _mi_align_up(diff + size, MI_COMMIT_SIZE); end = _mi_align_up(diff + size, MI_MINIMAL_COMMIT_SIZE);
} }
mi_assert_internal(end <= segsize);
if (end > segsize) { if (end > segsize) {
end = segsize; end = segsize;
} }