Skip to content

gh-149335: Avoid JIT trace buffer asserts with overhead above FITNESS_INITIAL - #149633

Merged
markshannon merged 3 commits into
python:mainfrom
cocolato:fix-gh-149335
May 21, 2026
Merged

gh-149335: Avoid JIT trace buffer asserts with overhead above FITNESS_INITIAL#149633
markshannon merged 3 commits into
python:mainfrom
cocolato:fix-gh-149335

Conversation

@cocolato

@cocolatococolato commented May 10, 2026

Copy link
Copy Markdown
Member

The trace buffer now reserves a small fixed overhead above FITNESS_INITIAL for entry and loop-closing uops.

@cocolato

This comment was marked as outdated.

@markshannon

Copy link
Copy Markdown
Member

I think this is the wrong approach.
We want to assert that the buffer hasn't overflowed, not handle the overflow.

We need to either reduce the fitness or increase the buffer size.
If we aren't correctly tracking the amount of buffer used, we should also fix that.

Since the fitness numbers should be tailored for giving us good traces, I'd increase the buffer size a bit.

Maybe define the fitness and then set the buffer size to that plus a small bit to account for loop closure/entry overheads.
So instead of

#defineFITNESS_INITIAL UOP_MAX_TRACE_LENGTH

use

#defineUOP_MAX_TRACE_LENGTH (FITNESS_INITIAL + OVERHEAD)

The OVERHEAD only needs to a small number, maybe 8 or 10.

@cocolatococolato changed the title gh-149335: Exit JIT trace early when the uop buffer is nearly fullgh-149335: Avoid JIT trace buffer asserts with overhead above FITNESS_INITIALMay 21, 2026
@cocolato

Copy link
Copy Markdown
MemberAuthor

thanks for review! updated.

@markshannonmarkshannon left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Looks good, thanks

@markshannon
markshannon merged commit 441af3a into python:mainMay 21, 2026
98 of 100 checks passed
@vstinner

Copy link
Copy Markdown
Member

This change should be backported to Python 3.15 which is also affected by the issue.

@cocolatococolato added the needs backport to 3.15 pre-release feature fixes, bugs and security fixes label May 22, 2026
@miss-islington-app

Copy link
Copy Markdown

Thanks @cocolato for the PR, and @markshannon for merging it 🌮🎉.. I'm working now to backport this PR to: 3.15.
🐍🍒⛏🤖

@bedevere-app

Copy link
Copy Markdown

GH-150245 is a backport of this pull request to the 3.15 branch.

@bedevere-appbedevere-appBot removed the needs backport to 3.15 pre-release feature fixes, bugs and security fixes label May 22, 2026
kumaraditya303 pushed a commit that referenced this pull request May 24, 2026
…`FITNESS_INITIAL` (GH-149633) (#150245)
gh-149335: Avoid JIT trace buffer asserts with overhead above `FITNESS_INITIAL` (GH-149633)
(cherry picked from commit 441af3a)
Co-authored-by: Hai Zhu <haiizhu@outlook.com>
@bedevere-bot

Copy link
Copy Markdown

⚠️⚠️⚠️ Buildbot failure ⚠️⚠️⚠️

Hi! The buildbot AMD64 Debian root 3.15 (tier-1) has failed when building commit 22c994c.

What do you need to do:

  1. Don't panic.
  2. Check the buildbot page in the devguide if you don't know what the buildbots are or how they work.
  3. Go to the page of the buildbot that failed (https://buildbot.python.org/#/builders/2019/builds/85) and take a look at the build logs.
  4. Check if the failure is related to this commit (22c994c) or if it is a false positive.
  5. If the failure is related to this commit, please, reflect that on the issue and make a new Pull Request with a fix.

You can take a look at the buildbot page here:

https://buildbot.python.org/#/builders/2019/builds/85

Failed tests:

  • test_embed

Failed subtests:

  • test_thread_state_ensure - test.test_embed.AuditingTests.test_thread_state_ensure

Summary of the results of the build (if available):

==

Click to see traceback logs
Traceback (most recent call last):
File "/root/buildarea/3.15.angelico-debian-amd64/build/Lib/test/support/__init__.py", line 948, in gc_collect
gc.collect()
~~~~~~~~~~^^ResourceWarning: unclosed file <_io.FileIO name=11 mode='wb' closefd=True>
Traceback (most recent call last):
File "/root/buildarea/3.15.angelico-debian-amd64/build/Lib/test/test_embed.py", line 2000, in test_thread_state_ensureself.run_embedded_interpreter("test_thread_state_ensure")
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/root/buildarea/3.15.angelico-debian-amd64/build/Lib/test/test_embed.py", line 138, in run_embedded_interpreterself.assertEqual(p.returncode, returncode,
~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^"bad returncode %d, stderr is %r"%^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
(p.returncode, err))
^^^^^^^^^^^^^^^^^^^^AssertionError: -6 != 0 : bad returncode -6, stderr is "_testembed: ./Programs/_testembed.c:2736: test_thread_state_ensure: Assertion `_Py_atomic_load_int(&data.done) == 1' failed.\n"

@cocolato
cocolato deleted the fix-gh-149335 branch May 25, 2026 02:17
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants

@cocolato@markshannon@vstinner@bedevere-bot