Repository navigation
gh-149584: _remote_debugging: Map remote pages with mach_vm_remap on macOS instead of copying them - #161011
Open
maurycy wants to merge 2 commits into
Open
gh-149584: _remote_debugging: Map remote pages with mach_vm_remap on macOS instead of copying them#161011maurycy wants to merge 2 commits into
_remote_debugging: Map remote pages with mach_vm_remap on macOS instead of copying them#161011maurycy wants to merge 2 commits into
Conversation
maurycy
commented
Oct 31, 2026
| } | ||
|
|
||
| static int | ||
| alias_maybe_probe_entry(proc_handle_t *handle, alias_page_entry_t *entry) |
Contributor
Author
There was a problem hiding this comment.
mach_vm_region_recurse is expensive, hence adaptive probing here, as the exact churn depends on the target
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The PR adds
vm_remapsupport toprofiling.sampling(Tachyon) on macOS, instead of always usingmach_vm_read_overwrite().In plain English :-) instead of copying remote proces memory, just map the same page and read from it directly. Direct
memcpy()is much cheaper than a syscall. The trick works especially for typically stably mapped objects, hence explicit syscall read in #160888 for data stack.The performance gain is relatively good:
mainb84e0b7 + #160888)On top of this, there's little loss in accuracy:
Oracle, this PR (12 cases, 3 runs, 0.5 s each)
v.
Oracle, baseline (12 cases, 3 runs, 0.5 s each)
(this is where #153804 shines in my opinion.)
To make things even better, the CPU usage is also relatively better:
(everything on PGO+LTO builds.)
Some considerations:
vm_remapis a Mach 3, so it's at least 1992? The XNU kernel is extremely helpful, but there's also https://github.com/apple-oss-distributions/xnu/blob/f6217f891ac0bb64f3d375211650a4c1ff8ca1ea/osfmk/man/vm_remap.html etc. I used Fable 5.1, and previous Claude models, a lot when asking questions about the kernel. I recommend doing the same._Py_RemoteDebug_ReadRemoteMemoryand_Py_RemoteDebug_PagedReadRemoteMemoryare increasingly leaky abstractions; the optimal way of reading depends on what (simply: datastacks have different volatility / are less stable than interpreters etc.), the operating system; this is visible more since gh-149584: Fix excessive overhead in the Tachyon profiler regarding the cache behavior #149649 We can reorganize this as a follow up_remote_debugging: reading whole pages over and over #149584