Skip to content

Commit

Permalink
sort pages
Browse files Browse the repository at this point in the history
  • Loading branch information
d-netto committed Oct 23, 2023
1 parent c540340 commit a8530e1
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion src/gc.c
Original file line number Diff line number Diff line change
Expand Up @@ -1666,6 +1666,11 @@ void gc_free_pages(void)
}
}

static int gc_pg_cmp(jl_gc_pagemeta_t *pg, jl_gc_pagemeta_t *pg2)
{
return (pg->nfree - pg2->nfree);
}

// setup the data-structures for a sweep over all memory pools
static void gc_sweep_pool(void)
{
Expand Down Expand Up @@ -1743,18 +1748,28 @@ static void gc_sweep_pool(void)
if (ptls2 == NULL) {
continue;
}
// create a temporary array of pages to sort them
arraylist_t a;
arraylist_new(&a, 0);
jl_gc_pagemeta_t *pg = jl_atomic_load_relaxed(&ptls2->page_metadata_allocd.bottom);
while (pg != NULL) {
jl_gc_pagemeta_t *pg2 = pg->next;
arraylist_push(&a, pg);
pg = pg2;
}
// sort by number of free objects in ascending order
qsort(a.items, a.len, sizeof(jl_gc_pagemeta_t*), (int (*)(const void *, const void *))gc_pg_cmp);
for (int i = 0; i < a.len; i++) {
jl_gc_pagemeta_t *pg = (jl_gc_pagemeta_t*)a.items[i];
if (pg->fl_begin_offset != UINT16_MAX) {
char *cur_pg = pg->data;
jl_taggedvalue_t *fl_beg = (jl_taggedvalue_t*)(cur_pg + pg->fl_begin_offset);
jl_taggedvalue_t *fl_end = (jl_taggedvalue_t*)(cur_pg + pg->fl_end_offset);
*pfl[t_i * JL_GC_N_POOLS + pg->pool_n] = fl_beg;
pfl[t_i * JL_GC_N_POOLS + pg->pool_n] = &fl_end->next;
}
pg = pg2;
}
arraylist_free(&a);
}

// null out terminal pointers of free lists
Expand Down

0 comments on commit a8530e1

Please sign in to comment.