Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

task: reuse stack immediately when Task dies and switches to new Task #57496

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

vtjnash
Copy link
Member

@vtjnash vtjnash commented Feb 21, 2025

Previously we forced it to ping-pong between two stacks, always wasting a little bit of memory (8MB * nthreads) and losing out a bit on possibly warmer caches.

Previously we forced it to ping-pong between two stacks, always wasting
a little bit of memory (8MB * nthreads) and losing out a bit on possibly
warmer caches.
@vtjnash vtjnash requested a review from JeffBezanson February 21, 2025 19:44
src/task.c Outdated
if (t->ctx.stkbuf == NULL) {
if (!t->ctx.started && !t->ctx.copy_stack && t->ctx.stkbuf == NULL) {
// need to allocate the stack
void *stkbuf = killed && !lastt->ctx.copy_stack && lastt != ptls->root_task && lastt->ctx.bufsz >= t->ctx.bufsz && t->ctx.bufsz <= lastt->ctx.bufsz * 1.5 ? lastt->ctx.stkbuf : NULL;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe split this condition in a couple lines, this is a bit hard to read

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the size comparison part might not be what's intended? It seems to say t <= lastt && t <= lastt*1.5 but possibly should be t <= lastt && lastt <= t*1.5? (I believe to make sure the reused stack isn't excessively large?)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants