Skip to content

Commit

Permalink
address follow-up comments from 50137
Browse files Browse the repository at this point in the history
  • Loading branch information
d-netto committed Jun 29, 2023
1 parent 3d7aa6e commit 53fe3e3
Showing 1 changed file with 15 additions and 18 deletions.
33 changes: 15 additions & 18 deletions src/gc.c
Original file line number Diff line number Diff line change
Expand Up @@ -1238,7 +1238,10 @@ static NOINLINE jl_taggedvalue_t *gc_add_page(jl_gc_pool_t *p) JL_NOTSAFEPOINT
// Do not pass in `ptls` as argument. This slows down the fast path
// in pool_alloc significantly
jl_ptls_t ptls = jl_current_task->ptls;
jl_gc_pagemeta_t *pg = jl_gc_alloc_page();
jl_gc_pagemeta_t *pg = pop_page_metadata_back(&ptls->page_metadata_lazily_freed);
if (pg == NULL) {
pg = jl_gc_alloc_page();
}
pg->osize = p->osize;
pg->thread_n = ptls->tid;
set_page_metadata(pg);
Expand Down Expand Up @@ -1295,20 +1298,8 @@ STATIC_INLINE jl_value_t *jl_gc_pool_alloc_inner(jl_ptls_t ptls, int pool_offset
assert(pg->osize == p->osize);
pg->nfree = 0;
pg->has_young = 1;
pg = pop_page_metadata_back(&ptls->page_metadata_lazily_freed);
if (pg != NULL) {
v = gc_reset_page(ptls, p, pg);
pg->osize = p->osize;
push_page_metadata_back(&ptls->page_metadata_allocd, pg);
}
else {
v = NULL;
}
}
// Not an else!!
if (v == NULL) {
v = gc_add_page(p);
}
v = gc_add_page(p);
next = (jl_taggedvalue_t*)((char*)v + osize);
}
p->newpages = next;
Expand Down Expand Up @@ -1353,15 +1344,19 @@ static jl_taggedvalue_t **gc_sweep_page(jl_gc_pool_t *p, jl_gc_pagemeta_t **allo
char *data = pg->data;
jl_taggedvalue_t *v = (jl_taggedvalue_t*)(data + GC_PAGE_OFFSET);
char *lim = data + GC_PAGE_SZ - osize;
char *lim_newpages = data + GC_PAGE_SZ;
if (gc_page_data((char*)p->newpages - 1) == data) {
lim_newpages = (char*)p->newpages;
}
size_t old_nfree = pg->nfree;
size_t nfree;

int reuse_page = 1;
int re_use_page = 1;
int freed_lazily = 0;
int freedall = 1;
int pg_skpd = 1;
if (!pg->has_marked) {
reuse_page = 0;
re_use_page = 0;
#ifdef _P64 // TODO: re-enable on `_P32`?
// lazy version: (empty) if the whole page was already unused, free it (return it to the pool)
// eager version: (freedall) free page as soon as possible
Expand Down Expand Up @@ -1402,7 +1397,9 @@ static jl_taggedvalue_t **gc_sweep_page(jl_gc_pool_t *p, jl_gc_pagemeta_t **allo
jl_taggedvalue_t **pfl_begin = NULL;
while ((char*)v <= lim) {
int bits = v->bits.gc;
if (!gc_marked(bits)) {
// if an object is past `lim_newpages` then we can guarantee it's garbage
if (!gc_marked(bits) || (char*)v >= lim_newpages) {
v->bits.gc = GC_CLEAN;
*pfl = v;
pfl = &v->next;
pfl_begin = (pfl_begin != NULL) ? pfl_begin : pfl;
Expand Down Expand Up @@ -1439,7 +1436,7 @@ static jl_taggedvalue_t **gc_sweep_page(jl_gc_pool_t *p, jl_gc_pagemeta_t **allo
nfree = pg->nfree;

done:
if (reuse_page) {
if (re_use_page) {
push_page_metadata_back(allocd, pg);
}
else if (freed_lazily) {
Expand Down

0 comments on commit 53fe3e3

Please sign in to comment.