Repository navigation
Conversation
…ery granule below it
iOS extends __PAGEZERO by the ASLR slide, so the address map starts at the
app image (address-map=[0x104e60000,0xfc0000000)) and every fixed mapping
below is refused. Mach reports that range as a free hole, so
ios_skip_occupied had nothing to jump over and a bottom-up scan whose window
starts at 0x10000 tried it one 64 KB granule at a time: 66,845 refused
mach_vm_map calls and as many mach_vm_region queries to place one 4 KB view,
all under virtual_mutex ("[va-scan] SLOW window=0x10000..0x400000000
size=0x1000 ... tries=66845 ... firstfail=0x10000 errno=12").
Madeira Dock takes a process snapshot once a second while a game runs
(sh_hold_poll), and Wine's toolhelp maps and unmaps such a view for every
Process32First/Next: 14 of these scans a second kept Dock's main thread at
~85% of a core while holding the lock every other thread needs for a read,
an ioctl or an allocation. In Terraria (iPad14,8, 2026-11-13) the game's
main thread ran only in the gaps: a few frames, then a stall, about once a
second, with frame times of hundreds of ms beside 1.3 ms of GPU time.
env.MADEIRA_DOCK_KEEP_ALIVE = 0 (no snapshots) made it smooth, which
confirmed the cause.
try_map_free_area now asks the kernel for the map's floor once
(TASK_VM_INFO.min_address) and, bottom-up, resumes at the floor; top-down,
the scan ends there. The granules not tried are still counted as tries and
reported as the first refusal, so the [va-scan] line and the pressure latch
decide exactly as before; the line gains below-floor=N. A fixed-address
attempt is left alone. env.MADEIRA_VA_SCAN_FLOOR = 0 restores the crawl.
tests/host/check-va-scan-floor.py runs the scan on the host against a fake
address map: same address, tries and first refusal with the switch on, off
and with no floor reported; the measured case drops from 66,793 mapping
attempts to 4.
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Signed-off-by: Vuqar05 <vuqarakhmedov05@gmail.com>
Vuqar05
force-pushed
the
fix/va-scan-unmappable-floor
branch
from
November 13, 2026 19:50
cc78825 to
3adceb5
Compare
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.
Summary
Dock's periodic process snapshots exposed an allocator bottleneck: the kernel reports the forbidden range below the app image as an empty hole, so the existing occupied-region skip could not jump over it. Each small mapping could trigger over 66,000 refused mapping attempts while holding
virtual_mutex, periodically blocking Terraria despite low GPU time.Preserve fixed-address attempts, allocation results, diagnostic attempt counts and pressure-latch behavior. If the kernel cannot supply a usable boundary, retain the old scan. Add
env.MADEIRA_VA_SCAN_FLOOR=0as an opt-out and expose it in the settings catalog.Only the main Madeira repository changes; no Wine or Dock submodule changes or pin updates are included. The separate OpenGL startup workaround used for device testing is not part of this PR.
Evidence
After: The same harness uses 4 mapping attempts with identical allocation results. The rebuilt app was installed on an iPad Air (M2), and the user confirmed Terraria works with the fix.
python3 tests/host/check-va-scan-floor.py— PASS. Covers bottom-up and top-down searches, different alignments and windows, explicit fixed-address attempts, opt-out and unavailable kernel boundary.git diff --check origin/main...HEAD— PASS.Merge Danger
Door: two-way
Revert the commit or set
env.MADEIRA_VA_SCAN_FLOOR=0to restore the previous search. No persistent data or format changes.Blast Radius: allocator
Applies to iOS free-area searches, not only Terraria. The optimization trusts the cached kernel-reported lower address boundary; other games and OS versions have not been exhaustively tested. Dock polling remains enabled and unchanged.