Skip to content

Conversation

@corona10
Copy link
Member

@corona10 corona10 commented Aug 27, 2025

@python-cla-bot
Copy link

python-cla-bot bot commented Aug 27, 2025

All commit authors signed the Contributor License Agreement.

CLA signed

@corona10 corona10 changed the title gh-137800: Fix JIT trace buffer overrun by pre-reserving exit stub space gh-13780: Fix JIT trace buffer overrun by pre-reserving exit stub space Aug 27, 2025
@corona10 corona10 changed the title gh-13780: Fix JIT trace buffer overrun by pre-reserving exit stub space gh-137838: Fix JIT trace buffer overrun by pre-reserving exit stub space Aug 27, 2025
// Leave space for possible trailing _EXIT_TRACE
int max_length = buffer_size-2;
// Leave space for possible trailing _EXIT_TRACE and estimated exit stubs
// Reserve 20% of buffer space for exit stubs (empirically sufficient)
Copy link
Member

Choose a reason for hiding this comment

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

Can we have a tighter and more logical bound than this?

Copy link
Member Author

Choose a reason for hiding this comment

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

Maybe 15%? or 10%?

Copy link
Member Author

Choose a reason for hiding this comment

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

10% is too small. Let me test from 15%.

Copy link
Member

Choose a reason for hiding this comment

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

No I mean something based on math. Like a loose bound would be:

Every instruction needs a _DEOPT or _EXIT_TRACE

_DEOPT might have _ERROR_POP_N before it

Therefore from n instructions we must reserve 2n instructions.

This bound is overly loose, but it would be good to work it out

Copy link
Member Author

Choose a reason for hiding this comment

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

Hmm, let me think about this differently. I’ll share the next commit with an improvement that tracks each instruction based on a mathematical assumption

@corona10
Copy link
Member Author

Hi @Fidget-Spinner,

I adjusted the calculation of max_length to take a more conservative approach.

On my local setup, both of the following tests passed:

  • PYTHON_UOPS_OPTIMIZE=0 ./python.exe -m test -j8
  • ./python.exe -m test -j8

I’m not entirely sure if this approach is ideal from the JIT maintainers’ perspective, so I’d appreciate it if you could take a look before we ask them for a review.

@corona10
Copy link
Member Author

Hmm, not sure if this 20% magic number is the correct way.. Let me take a look other approach that calculate max_length properly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants