René's URL Explorer Experiment


Title: gh-148286: Track JIT-allocated memory with Valgrind client requests by matthiasgoergens · Pull Request #154926 · python/cpython · GitHub

Open Graph Title: gh-148286: Track JIT-allocated memory with Valgrind client requests by matthiasgoergens · Pull Request #154926 · python/cpython

X Title: gh-148286: Track JIT-allocated memory with Valgrind client requests by matthiasgoergens · Pull Request #154926 · python/cpython

Description: Python/jit.c's jit_alloc() and jit_free() mmap and munmap the JIT's machine-code buffers directly. Valgrind's leak checker does not track raw mmap'd memory as a "block", so a forgotten jit_free() — the shape of gh-142476, a real ASan-found leak in allocate_executor — is completely invisible to it. This adds VALGRIND_MALLOCLIKE_BLOCK / VALGRIND_FREELIKE_BLOCK around those two functions, guarded by the existing --with-valgrind configure option, mirroring the pattern vendored mimalloc already uses in Include/internal/mimalloc/mimalloc/track.h. To measure the effect I injected a forgotten free into jit_free() on a machine-code JIT build (--enable-experimental-jit, LLVM 21) and ran a script that creates eight executors and drops them: build valgrind --leak-check=full without --with-valgrind definitely lost: 0 bytes in 0 blocks with --with-valgrind definitely lost: 139,264 bytes in 10 blocks and in the second case with a usable backtrace: 131,072 bytes in 8 blocks are definitely lost at jit_alloc (Python/jit.c:154) by _PyJIT_Compile by make_executor_from_uops (Python/optimizer.c:1574) by uop_optimize by _PyOptimizer_Optimize by stop_tracing_and_jit (Python/ceval.c:1090) Background noise was byte-identical between the two runs (120 bytes possibly lost, 646 bytes still reachable), so the injected leak is the only difference. The injection is not part of this patch. The include is valgrind/valgrind.h — the header configure already probes for under --with-valgrind, and the one that defines both macros used here, so no build-system change is needed. Objects/obmalloc.c includes the same header. On VALGRIND_DISCARD_TRANSLATIONS I deliberately did not add any. It seemed like the obvious thing for a JIT, but it turns out to be unnecessary here. Valgrind's munmap and mprotect syscall wrappers already discard cached translations for any range that previously held translated code, and that logic lives in architecture-independent code (coregrind/m_syswrap/syswrap-generic.c). I also checked it experimentally with a small driver that emits code, executes it enough times to guarantee a cached translation, changes it, and executes again — with a control case that genuinely does go stale so the harness is known to detect the failure. CPython's mmap → write once → mprotect → execute → munmap-whole-region pattern never executed a stale translation on either x86-64 (Valgrind 3.25.1) or aarch64 (Valgrind 3.19.0), in any --smc-check mode including none. A side effect worth recording: since that is already true, --smc-check=none is safe for CPython today with no code change. On a tight JIT-compiled integer loop that is worth about 10% over the all-non-file default (median of three runs each: 11.33 s vs 10.17 s, ranges 11.22-11.45 and 10.12-10.36, so non-overlapping). That workload is close to a best case — it is almost entirely JIT-executed — so a realistic program should expect less. Testing Builds cleanly both with and without --with-valgrind; test_capi and test_optimizer pass (1,501 tests) on the --with-valgrind build, and under valgrind memcheck. Issue: gh-148286

Open Graph Description: Python/jit.c's jit_alloc() and jit_free() mmap and munmap the JIT's machine-code buffers directly. Valgrind's leak checker does not track raw mmap'd memory as a "block", s...

X Description: Python/jit.c's jit_alloc() and jit_free() mmap and munmap the JIT's machine-code buffers directly. Valgrind's leak checker does not track raw mmap'd memory as a &...

Opengraph URL: https://github.com/python/cpython/pull/154926

X: @github

direct link

Domain: github.com

react-profiling0
react-import-mapreact,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322
route-pattern/:user_id/:repository/pull/:id/files(.:format)
route-controllerpull_requests
route-actionfiles
fetch-noncev2:fa5b75d3-d285-9350-95d0-2762ea1d806c
current-catalog-service-hashae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b
request-id9FE8:1F65:867A1:AF938:6B024F3E
html-safe-nonce1ad2d19ddab912c80f1323450c4b62001d6444268041c13c0ce8b47d7b6285fb
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5RkU4OjFGNjU6ODY3QTE6QUY5Mzg6NkIwMjRGM0UiLCJ2aXNpdG9yX2lkIjoiMTAxMTI0MDQzMDkxMTc3MDQzMCIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9
visitor-hmac2d0502d416f2d40beaf6369c48d04437772ddda955966c80183d387f7c43e9e3
hovercard-subject-tagpull_request:4169733508
github-keyboard-shortcutsrepository,pull-request-list,pull-request-conversation,pull-request-files-changed,copilot
google-site-verificationApib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I
octolytics-urlhttps://collector.github.com/github/collect
analytics-location///pull_requests/show/files
fb:app_id1401488693436528
apple-itunes-appapp-id=1477376905, app-argument=https://github.com/python/cpython/pull/154926/files
twitter:imagehttps://avatars.githubusercontent.com/u/57026?s=400&v=4
twitter:cardsummary_large_image
og:imagehttps://avatars.githubusercontent.com/u/57026?s=400&v=4
og:image:altPython/jit.c's jit_alloc() and jit_free() mmap and munmap the JIT's machine-code buffers directly. Valgrind's leak checker does not track raw mmap'd memory as a "block", s...
og:site_nameGitHub
og:typeobject
hostnamegithub.com
expected-hostnamegithub.com
None87e774ee7c6b3bee0490394e4d3e57ec9dbc956f74b87ea685dc8996c1676456
turbo-cache-controlno-preview
diff-viewunified
go-importgithub.com/python/cpython git https://github.com/python/cpython.git
octolytics-dimension-user_id1525981
octolytics-dimension-user_loginpython
octolytics-dimension-repository_id81598961
octolytics-dimension-repository_nwopython/cpython
octolytics-dimension-repository_publictrue
octolytics-dimension-repository_is_forkfalse
octolytics-dimension-repository_network_root_id81598961
octolytics-dimension-repository_network_root_nwopython/cpython
turbo-body-classeslogged-out env-production page-responsive full-width
disable-turbotrue
browser-stats-urlhttps://api.github.com/_private/browser/stats
browser-errors-urlhttps://api.github.com/_private/browser/errors
release423dbb54c5e7bfecc838eb387c1435eb3d0e760d
ui-targetcanary-1
theme-color#1e2327
color-schemelight dark

Links:

Skip to contenthttps://github.com/python/cpython/pull/154926/files#start-of-content
https://github.com/
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fpython%2Fcpython%2Fpull%2F154926%2Ffiles
GitHubRepository hosting, code review, and collaborationhttps://github.com/platform
CopilotAI coding agent for tasks, projects, and automated workhttps://github.com/features/copilot
ActionsCI/CD and automationhttps://github.com/features/actions
Code QualityQuality analysis, fixes, and enforcementhttps://github.com/features/code-quality
CodespacesCloud development environmentshttps://github.com/features/codespaces
Code SecurityVulnerability detection and remediationhttps://github.com/security/advanced-security/code-security
Secret ProtectionSecret scanning and leak preventionhttps://github.com/security/advanced-security/secret-protection
All Featureshttps://github.com/features
Documentationhttps://docs.github.com/en
Traininghttps://learn.github.com/skills
Certificationshttps://learn.github.com/credentials
Build with Copilothttps://github.com/features/ai
Customize Copilothttps://docs.github.com/en/copilot/how-tos/copilot-on-github/customize-copilot/customize-copilot-overview
Integrationshttps://github.com/marketplace
Trending reposhttps://github.com/trending
GitHub Sponsorshttps://github.com/open-source/sponsors
Developer articleshttps://github.com/resources/articles
ChangelogYour source for the latest features, improvements, and fixes across GitHub products, all in one place.https://github.blog/changelog/
Enterpriseshttps://github.com/enterprise
Teamhttps://github.com/team
Startupshttps://github.com/enterprise/startups
Nonprofitshttps://github.com/solutions/industry/nonprofits
Healthcarehttps://github.com/solutions/industry/healthcare
Financial serviceshttps://github.com/solutions/industry/financial-services
Manufacturinghttps://github.com/solutions/industry/manufacturing
Governmenthttps://github.com/solutions/industry/government
See all industrieshttps://github.com/solutions/industry
Why GitHubhttps://github.com/why-github
Customer Storieshttps://github.com/customer-stories
Business insightshttps://github.com/solutions/executive-insights
Trust Centerhttps://github.com/trust-center
GitHub Advanced SecurityEnterprise-grade code securityhttps://github.com/security/advanced-security
Copilot for businessEnterprise-grade AI featureshttps://github.com/features/copilot/copilot-business
Premium SupportEnterprise-grade 24/7 supporthttps://github.com/enterprise/premium-support
Documentationhttps://docs.github.com/en
Resource centerhttps://github.com/resources
Bloghttps://github.blog/
Events & webinarshttps://github.com/resources/events
Community Forumhttps://github.com/orgs/community/discussions
Customer Storieshttps://github.com/customer-stories
Integrationshttps://github.com/marketplace
Customer supporthttps://help.github.com/
Traininghttps://learn.github.com/skills
GitHub Statushttps://www.githubstatus.com/
Abouthttps://github.com/about
Partnershttps://github.com/partners
Changeloghttps://github.blog/changelog/
GitHub UniverseThe event for developers, by developers — talks, workshops, and what’s next for GitHub.https://githubuniverse.com/
Pricinghttps://github.com/pricing
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fpython%2Fcpython%2Fpull%2F154926%2Ffiles
Sign uphttps://github.com/signup?ref_cta=Sign+up&ref_loc=header+logged+out&ref_page=%2F%3Cuser-name%3E%2F%3Crepo-name%3E%2Fpull_requests%2Fshow%2Ffiles&source=header-repo&source_repo=python%2Fcpython
Reloadhttps://github.com/python/cpython/pull/154926/files
Reloadhttps://github.com/python/cpython/pull/154926/files
Reloadhttps://github.com/python/cpython/pull/154926/files
pythonhttps://github.com/python
cpythonhttps://github.com/python/cpython
Codehttps://github.com/python/cpython
Issues5k+ (5k+)https://github.com/python/cpython/issues
Pull requests2.4k (2.4k)https://github.com/python/cpython/pulls
Actionshttps://github.com/python/cpython/actions
Projectshttps://github.com/python/cpython/projects
Security and qualityhttps://github.com/python/cpython/security
Insightshttps://github.com/python/cpython/insights
Sign up for GitHub https://github.com/signup?return_to=%2Fpython%2Fcpython%2Fissues%2Fnew%2Fchoose
terms of servicehttps://docs.github.com/terms
privacy statementhttps://docs.github.com/privacy
Sign inhttps://github.com/login?return_to=%2Fpython%2Fcpython%2Fissues%2Fnew%2Fchoose
matthiasgoergenshttps://github.com/matthiasgoergens
python:mainhttps://github.com/python/cpython/tree/main
matthiasgoergens:vgclient-jit-integrationhttps://github.com/matthiasgoergens/cpython/tree/vgclient-jit-integration
Conversation 2 https://github.com/python/cpython/pull/154926
Commits 1 https://github.com/python/cpython/pull/154926/commits
Checks 68 https://github.com/python/cpython/pull/154926/checks
Files changed https://github.com/python/cpython/pull/154926/files
Please reload this pagehttps://github.com/python/cpython/pull/154926/files
gh-148286: Track JIT-allocated memory with Valgrind client requests https://github.com/python/cpython/pull/154926/files#top
Show all changes 1 commit https://github.com/python/cpython/pull/154926/files
f3dec60 gh-148286: Track JIT-allocated memory with Valgrind client requests matthiasgoergens Jul 30, 2026 https://github.com/python/cpython/pull/154926/commits/f3dec60a7777cb8089e4bb78c1813cf3dca38dab
Clear filters https://github.com/python/cpython/pull/154926/files
Please reload this pagehttps://github.com/python/cpython/pull/154926/files
Please reload this pagehttps://github.com/python/cpython/pull/154926/files
2026-07-30-18-30-00.gh-issue-148286.Qv8Rk3.rst https://github.com/python/cpython/pull/154926/files#diff-d534b10a26962782dc4b6c2a2a5dff1b19aa2f9c15929c6f8c76149efa84d71c
jit.c https://github.com/python/cpython/pull/154926/files#diff-d62eca10c65b7e30ce4e711d63b1e6c921c8b90bd4fb08c672d0806025e6d5e0
Misc/NEWS.d/next/Core_and_Builtins/2026-07-30-18-30-00.gh-issue-148286.Qv8Rk3.rsthttps://github.com/python/cpython/pull/154926/files#diff-d534b10a26962782dc4b6c2a2a5dff1b19aa2f9c15929c6f8c76149efa84d71c
View file https://github.com/python/cpython/blob/f3dec60a7777cb8089e4bb78c1813cf3dca38dab/Misc/NEWS.d/next/Core_and_Builtins/2026-07-30-18-30-00.gh-issue-148286.Qv8Rk3.rst
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/python/cpython/pull/154926/{{ revealButtonHref }}
https://github.com/python/cpython/blob/main/.github/CODEOWNERS#L291
Python/jit.chttps://github.com/python/cpython/pull/154926/files#diff-d62eca10c65b7e30ce4e711d63b1e6c921c8b90bd4fb08c672d0806025e6d5e0
View file https://github.com/python/cpython/blob/f3dec60a7777cb8089e4bb78c1813cf3dca38dab/Python/jit.c
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/python/cpython/pull/154926/{{ revealButtonHref }}
https://github.com/python/cpython/pull/154926/files#diff-d62eca10c65b7e30ce4e711d63b1e6c921c8b90bd4fb08c672d0806025e6d5e0
https://github.com/python/cpython/pull/154926/files#diff-d62eca10c65b7e30ce4e711d63b1e6c921c8b90bd4fb08c672d0806025e6d5e0
https://github.com/python/cpython/pull/154926/files#diff-d62eca10c65b7e30ce4e711d63b1e6c921c8b90bd4fb08c672d0806025e6d5e0
https://github.com/python/cpython/pull/154926/files#diff-d62eca10c65b7e30ce4e711d63b1e6c921c8b90bd4fb08c672d0806025e6d5e0
https://github.com/python/cpython/pull/154926/files#diff-d62eca10c65b7e30ce4e711d63b1e6c921c8b90bd4fb08c672d0806025e6d5e0
Please reload this pagehttps://github.com/python/cpython/pull/154926/files
https://github.com
Termshttps://docs.github.com/site-policy/github-terms/github-terms-of-service
Privacyhttps://docs.github.com/site-policy/privacy-policies/github-privacy-statement
Securityhttps://github.com/security
Statushttps://www.githubstatus.com/
Communityhttps://github.community/
Docshttps://docs.github.com/
Contacthttps://support.github.com?tags=dotcom-footer

Viewport: width=device-width


URLs of crawlers that visited me.