Skip to content

Commit

Permalink
parallelize sweeping of object pools (JuliaLang#51282)
Browse files Browse the repository at this point in the history
  • Loading branch information
d-netto authored and kpamnany committed Oct 19, 2023
1 parent ee406dc commit 96e5d13
Show file tree
Hide file tree
Showing 6 changed files with 178 additions and 82 deletions.
4 changes: 2 additions & 2 deletions src/gc-debug.c
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ static void gc_clear_mark_outer(int bits)
{
for (int i = 0; i < gc_n_threads; i++) {
jl_ptls_t ptls2 = gc_all_tls_states[i];
jl_gc_pagemeta_t *pg = ptls2->page_metadata_allocd;
jl_gc_pagemeta_t *pg = jl_atomic_load_relaxed(&ptls2->page_metadata_allocd.bottom);
while (pg != NULL) {
gc_clear_mark_page(pg, bits);
pg = pg->next;
Expand Down Expand Up @@ -1157,7 +1157,7 @@ static void gc_count_pool_pagetable(void)
{
for (int i = 0; i < gc_n_threads; i++) {
jl_ptls_t ptls2 = gc_all_tls_states[i];
jl_gc_pagemeta_t *pg = ptls2->page_metadata_allocd;
jl_gc_pagemeta_t *pg = jl_atomic_load_relaxed(&ptls2->page_metadata_allocd.bottom);
while (pg != NULL) {
if (gc_alloc_map_is_set(pg->data)) {
gc_count_pool_page(pg);
Expand Down
10 changes: 5 additions & 5 deletions src/gc-pages.c
Original file line number Diff line number Diff line change
Expand Up @@ -129,22 +129,22 @@ NOINLINE jl_gc_pagemeta_t *jl_gc_alloc_page(void) JL_NOTSAFEPOINT
jl_gc_pagemeta_t *meta = NULL;

// try to get page from `pool_clean`
meta = pop_lf_page_metadata_back(&global_page_pool_clean);
meta = pop_lf_back(&global_page_pool_clean);
if (meta != NULL) {
gc_alloc_map_set(meta->data, GC_PAGE_ALLOCATED);
goto exit;
}

// try to get page from `pool_freed`
meta = pop_lf_page_metadata_back(&global_page_pool_freed);
meta = pop_lf_back(&global_page_pool_freed);
if (meta != NULL) {
gc_alloc_map_set(meta->data, GC_PAGE_ALLOCATED);
goto exit;
}

uv_mutex_lock(&gc_perm_lock);
// another thread may have allocated a large block while we're waiting...
meta = pop_lf_page_metadata_back(&global_page_pool_clean);
// another thread may have allocated a large block while we were waiting...
meta = pop_lf_back(&global_page_pool_clean);
if (meta != NULL) {
uv_mutex_unlock(&gc_perm_lock);
gc_alloc_map_set(meta->data, GC_PAGE_ALLOCATED);
Expand All @@ -161,7 +161,7 @@ NOINLINE jl_gc_pagemeta_t *jl_gc_alloc_page(void) JL_NOTSAFEPOINT
gc_alloc_map_set(pg->data, GC_PAGE_ALLOCATED);
}
else {
push_lf_page_metadata_back(&global_page_pool_clean, pg);
push_lf_back(&global_page_pool_clean, pg);
}
}
uv_mutex_unlock(&gc_perm_lock);
Expand Down
Loading

0 comments on commit 96e5d13

Please sign in to comment.