Skip to content

Commit

Permalink
early free of non-copy-stacks back to pool
Browse files Browse the repository at this point in the history
  • Loading branch information
vtjnash committed Jun 25, 2018
1 parent 534cd24 commit e57a9fc
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
14 changes: 14 additions & 0 deletions src/gc-stacks.c
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,20 @@ JL_DLLEXPORT void jl_free_stack(void *stkbuf, size_t bufsz)
}


void jl_release_task_stack(jl_ptls_t ptls, jl_task_t *task)
{
void *stkbuf = task->stkbuf;
size_t bufsz = task->bufsz;
if (bufsz <= pool_sizes[JL_N_STACK_POOLS - 1]) {
unsigned pool_id = select_pool(bufsz);
if (pool_sizes[pool_id] == bufsz) {
task->stkbuf = NULL;
arraylist_push(&ptls->heap.free_stacks[pool_id], stkbuf);
}
}
}


JL_DLLEXPORT void *jl_malloc_stack(size_t *bufsz, jl_task_t *owner)
{
jl_ptls_t ptls = jl_get_ptls_states();
Expand Down
10 changes: 6 additions & 4 deletions src/task.c
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,8 @@ JL_DLLEXPORT void julia_init(JL_IMAGE_SEARCH rel)
_julia_init(rel);
}

void jl_release_task_stack(jl_ptls_t ptls, jl_task_t *task);

static void ctx_switch(jl_ptls_t ptls, jl_task_t **pt)
{
jl_task_t *t = *pt;
Expand Down Expand Up @@ -243,10 +245,10 @@ static void ctx_switch(jl_ptls_t ptls, jl_task_t **pt)
if (killed) {
*pt = lastt; // can't fail after here: clear the gc-root for the target task now
lastt->gcstack = NULL;
// if (!lastt->copy_stack) { // TODO: early free of stkbuf
// jl_free_stack(lastt->stkbuf, lastt->bufsz);
// lastt->stkbuf = NULL;
// }
if (!lastt->copy_stack && lastt->stkbuf) {
// early free of stkbuf back to the pool
jl_release_task_stack(ptls, lastt);
}
}
else {
#ifdef COPY_STACKS
Expand Down

0 comments on commit e57a9fc

Please sign in to comment.