Thread View: linux.debian.bugs.dist
1 messages
1 total messages
Started by Anton Plotkin
Mon, 16 Nov 2026 09:10
Bug#1154136: python3.13: please backport the gh-142183 data stack chunk cache (3.13.13) to trixie
Author: Anton Plotkin
Date: Mon, 16 Nov 2026 09:10
Date: Mon, 16 Nov 2026 09:10
128 lines
8907 bytes
8907 bytes
This is a multi-part message in MIME format.
--------------9ZluBU8AH00j8m0BQaJH4FRt
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Package: python3.13
Version: 3.13.5-2+deb13u5
Severity: important
Tags: patch upstream fixed-upstream trixie
Dear Maintainer,
CPython keeps the frame data stack in 16 KiB chunks. Up to 3.13.12 it
frees a chunk as soon as the last frame in it returns. When a hot call
sits exactly at a chunk boundary, every call maps a new chunk, faults it
in and unmaps it again.
Upstream issue ("Calls across stack chunks perform badly"):
https://github.com/python/cpython/issues/142183
Upstream fixed it by caching one chunk per thread state:
main: https://github.com/python/cpython/pull/145789
3.13: https://github.com/python/cpython/pull/146123
commit 684e7af8cd61bca4914d0ec01b814ff530d5a123, released in
3.13.13
NEWS: "gh-142183: Avoid a pathological case where repeated calls at a
specific stack depth could be significantly slower."
The 3.13 commit changes Python/pystate.c (+26 -4) and
Include/cpython/pystate.h (+2), plus NEWS and Doc/data/python3.13.abi.
Upstream put the new PyThreadState member at the end of the struct, so
the existing layout does not change.
Sid has 3.13.18-1 with the fix; trixie's 3.13.5-2+deb13u5 does not.
I set severity important because ordinary requests of a long-running
application spend a large share of their CPU in the kernel on this, and
the affected loop runs more than 20 times slower; please adjust if you
see it
differently.
How it shows up: a Django application served by uWSGI 2.0.31 has deep
call stacks, so some request handlers loop right at a chunk boundary.
Same x86_64 KVM guest, same code and database, trixie
chroot, both interpreters running pyuwsgi 2.0.31. CPU of one heavy
request, median of three requests without tracing; the mmap counts come
from a separate pass under strace:
trixie python3.13 3.13.5-2+deb13u5: 3880 ms CPU (user 2620, system
1260),
about 349k mmap + 349k munmap of
16 KiB
3.13.18 built from python.org source
in the same chroot: 2360 ms CPU (user 2320, system 40),
78 mmap
The two interpreters also differ in other upstream fixes and in build
options, so not all of the difference is this bug; the reproducer below
isolates it.
The attached chunk-sweep.py (stdlib only) reproduces it: it runs 10000
calls at every extra stack depth from 0 to 159 and prints the depths
with about one
minor page fault per call. The same loop, run by our benchmark with the
trixie /usr/bin/python3.13 in a trixie chroot on two x86_64 KVM guests,
gave:
3.13.5-2+deb13u5, AMD EPYC guest: 3 of 160 depths thrash; worst depth
35.3 ms per 10000 calls against a median of 1.45 ms, 10000 minor
faults, 35.9 ms system time
3.13.5-2+deb13u5, Intel guest: 3 of 160 depths thrash; worst depth
18.6 ms against a median of 0.67 ms, 10000 minor faults
3.13.18, same chroots and guests: 0 of 160; worst depth 1.3 ms (median
1.09 ms) and 0.6 ms (median 0.57 ms), no minor faults
Would you consider the upstream 3.13 commit for a trixie point release?
The same problem exists in bookworm's python3.11, but upstream does not
fix it in 3.11 (security fixes only), so I am not asking for that.
Thanks
Kind regards,
Anton Plotkin
--------------9ZluBU8AH00j8m0BQaJH4FRt
Content-Type: text/plain; charset=UTF-8; name="chunk-sweep.py"
Content-Disposition: attachment; filename="chunk-sweep.py"
Content-Transfer-Encoding: base64
IiIiUmVwcm9kdWNlciBmb3IgQ1B5dGhvbiBnaC0xNDIxODMgKGRhdGEgc3RhY2sgY2h1bmsg
YWxsb2MvZnJlZSB0aHJhc2hpbmcpLCBzdGRsaWIgb25seS4KCkF0IGV2ZXJ5IGV4dHJhIHN0
YWNrIGRlcHRoIGZyb20gMCB0byAxNTkgaXQgcnVucyAxMDAwMCBjYWxscyBvZiBhIGZ1bmN0
aW9uIHdob3NlIGZyYW1lIGlzIGxhcmdlcgp0aGFuIHRoZSBwYWRkaW5nIGZyYW1lcywgYW5k
IHByaW50cyB0aGUgZGVwdGhzIHdoZXJlIHRoZSBsb29wIGlzIG11Y2ggc2xvd2VyIGFuZCB0
YWtlcyBhYm91dCBvbmUKbWlub3IgcGFnZSBmY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VfU0VMRikKICAgIHJvd3MuYXBwZW5kKChlbGFwc2VkLCAo
YWZ0ZXIucnVfc3RpbWUgLSBiZWZvcmUucnVfc3RpbWUpICogMTAwMCwgYWZ0ZXIucnVfbWlu
Zmx0IC0gYmVmb3JlLnJ1X21pbmZsdCwgZGVwdGgpKQoKbm9ybWFsID0gc3RhdGlzdGljcy5t
ZWRpYW4ocm93WzBdIGZvciByb3cgaW4gcm93cykKc2xvdyA9IFtyb3cgZm9yIHJvdyBpbiBy
b3dzIGlmIHJvd1syXSA+PSBDQUxMUyAvLyAyXQpwcmludCgnUHl0aG9uICVzIG9uICVzICVz
JyAlIChzeXMudmVyc2lvbi5yZXBsYWNlKCdcbicsICcgJyksIHBsYXRmb3JtLnN5c3RlbSgp
LCBwbGF0Zm9ybS5tYWNoaW5lKCkpKQpwcmludCgnbWVkaWFuICUuMmYgbXMgcGVyICVkIGNh
bGxzOyBkZXB0aHMgd2l0aCBhYm91dCBvbmUgbWlub3IgZmF1bHQgcGVyIGNhbGw6ICVkIG9m
ICVkJyAlIChub3JtYWwsIENBTExTLCBsZW4oc2xvdyksIERFUFRIUykpCmZvciBlbGFwc2Vk
LCBzdGltZSwgbWluZmx0LCBkZXB0aCBpbiBzbG93OgogICAgcHJpbnQoJyAgKyUzZCBmcmFt
ZXM6ICU3LjFmIG1zICglLjBmeCBtZWRpYW4pLCBzeXN0ZW0gJTUuMWYgbXMsIG1pbm9yIGZh
dWx0cyAlZCcgJSAoZGVwdGgsIGVsYXBzZWQsIGVsYXBzZWQgLyBub3JtYWwsIHN0aW1lLCBt
aW5mbHQpKQo=
--------------9ZluBU8AH00j8m0BQaJH4FRt--
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads