-
-
Notifications
You must be signed in to change notification settings - Fork 30k
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
Function locals and evaluation stack should be stored in a contiguous, per-thread stack #88198
Comments
Currently, the local variables (inc. cell and free vars) for functions and the evaluation stack are kept in per-activation chunks in the frame object. This is not a good design for modern hardware. Allocating a per-thread stack would improve memory locality considerably, and pave the way to allocating heap objects for function activations lazily, only when needed for debugging and introspection. Generators would still need heap allocated locals and stack, but that would be no worse than currently. |
Using Pablo's (or Victor's) reproducer from bpo-44184, I'm getting a crash, apparently because _PyThreadState_PushLocals() is called after PyThreadState_Clear(). In Python/pystate.c interpreter_clear(), we're first calling PyThreadState_Clear() (line 295), and a few lines later (line 326) we're running _PyGC_CollectNoFail(). Clearing tstate _after_ the last GC collect resolves the issue (see attached patch), but it might introduce other problems; I'm not at all familiar with this part of the codebase. FYI, git HEAD is at b11a951 on main. ================================================================= 0x629000000220 is located 32 bytes inside of 16384-byte region [0x629000000200,0x629000004200) previously allocated by thread T0 here: SUMMARY: AddressSanitizer: heap-use-after-free pystate.c:2030 in _PyThreadState_PushLocals |
cc. Pablo, Victor |
Mark, can you check the failure? Otherwise is going to start failing on the buildbots when we add the test case for the issue Erlend mentions. |
What's the test case, exactly? ref.py for the other issue doesn't crash if I change "func.py" to "ref.py" |
Is the test added here: import ast
import builtins
import sys
import os
tree = ast.parse("pass")
x = [tree]
x.append(x)
# Put the cycle somewhere to survive until the *last* GC collection
def callback(*args):
pass
callback.a = x
os.register_at_fork(after_in_child=callback) If this doesn't work maybe Erlend may help you reproducing this. |
bpo-44184 has been fixed, it was unrelated. Mark fixed a bug in commit af5d497. It seems like all issues are solved, I close the issue. Mark: please set the version field to 3.11 for work in 3.11. Commits: commit b11a951
commit 498383c
commit af5d497
|
Removing the PyFrameObject.f_code member (commit b11a951) broke by gevent project: |
I created bpo-46836: "[C API] Move PyFrameObject to the internal C API". |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: