Files
DroidDeck/docs/development/proot-performance.md
MaxsTechReview 49a5f4aa94 ESync, FSync, NTSync + OpenNow + FEX for Desktop Apps (#197)
* Make the Compatible Proton ARM64 the default and label compatible builds

The CompatToolMapping "0" default always points at DroidDeck's Proton
ARM64 tool, and per-game picks of adopted GE/CachyOS builds are kept,
including when the shortcuts writer remaps.

The tool is named after the Proton build it runs, Proton Experimental
ARM64 (Compatible), or Proton 11.0 ARM64 (Compatible) once that newer build
is installed. Adopted builds carry the same Compatible mark, read from a
string resource the app stages into the runtime, and the Proton page
explains which builds have the prefix fixes.

The registrar is renamed steam-compatibility and the tool
droiddeck-proton-arm64. Existing installs migrate on the next session: the
old tool directory is removed, every mapping that named it moves to the new
tool, and the retired bannerlator-steam-compat script is removed from the
runtime. CI and local packaging include the renamed script.

* Drop the duplicate R import left by merging main

* Add userspace ntsync for Proton on Android

Android kernels have no /dev/ntsync and its app policy refuses futex_waitv,
so every Proton 11 build here fell back to wineserver for every wait.
libblsession now serves /dev/ntsync itself: wineserver opens a memfd region,
each sync object is a timerfd that carries its slot, and the kernel ntsync
ioctls are answered in shared memory with futexes, following the kernel
driver's wake order. Valve's Proton Experimental ARM64, GE-Proton and
proton-cachyos use it unchanged.

Locks record their owner so a killed process cannot wedge the others,
signals are held off inside each critical section, dead processes and
exiting threads are swept, and object lifetimes follow close, dup2, dup3,
close_range and received descriptors.

Fast sync is on by default under Performance > Session fixes, and
PROTON_NO_NTSYNC=1 turns it off per game.

* Add droiddeck-esync as the default sync for Proton on Android

Without a kernel ntsync driver, Proton 11 builds here fell back to
wineserver for every wait. droiddeck-esync brings eventfd and shared-memory
sync to the exact Proton build a game runs on: a pack holds that build's
ntdll.so and wineserver with the patch series in tools/droiddeck-esync
applied, and the guest runs Proton from a shadow tree that links the stock
tool and swaps in those two files. A wineserver from a pack still prefers
/dev/ntsync when a kernel driver or droiddeck-ntsync is there.

Packs are built in Valve's SDK image from each release's own wine source
(Proton Experimental ARM64 tags, GE-Proton and proton-cachyos releases); the
control build must reproduce the release binaries byte for byte, and a
signed index lists the packs. The APK bundles the packs pinned in
release.env, the app fetches newer ones, and Steam's compatibility tool
picks the pack for each Proton build, so new Proton releases get packs
without an app update.

The ntdll side reads, writes and polls its eventfds with raw system calls,
so the guest's LD_PRELOAD wrappers stay out of the sync path. The server
abandons a mutex once a thread killed by TerminateThread has really exited
and when its process dies, and a mutex's owner and recursion count change
in one atomic step, so a killed owner cannot touch the next owner's count.

droiddeck-esync is on by default and PROTON_NO_ESYNC=1 turns it off per
game; droiddeck-ntsync, the userspace ntsync, is now an opt-in toggle.

* Watch Valve's Proton releases and build droiddeck-esync packs for them

A scheduled workflow reads the Proton ARM64 builds Steam ships (anonymous
steamcmd app info) and the upstream source tags, compares them with the
previous watch state and starts the pack build for any build that has no
pack yet. The pack build applies the patch series with --fuzz=0 and runs a
smoke test of each new pack against the esstress suite before it is
published.

* Add droiddeck-fsync, keep Steam and the app on one Proton, fix DirectAudio

droiddeck-fsync: libblsession answers futex_waitv(2), which the app
sandbox refuses, in userspace, so Proton's own fsync runs on the stock
Proton files with no pack. Waiters register the words they wait on in a
table beside the fsync shared memory and sleep on a futex of their own;
FUTEX_WAKE on the fsync memory wakes the registered waiters. Slots carry
one owner word that the sweeper and the owner claim with a CAS, and the
mapping table is rebuilt under a lock held across the real munmap, so a
reused address or a recycled slot cannot lose a waiter. It stands in for
a Proton build without a pack (droiddeck-ntsync where fsync is off), takes
over for games with esync off, and the "droiddeck-fsync first" toggle
(BL_FSYNC_FIRST, also per game) puts it ahead of the packs. The games
Proton keeps off fsync and esync never get it. A launch into a prefix
whose wineserver is still running keeps that server's sync choice.

One Proton for Steam and the app: the Components page's Proton is the
default Steam uses, applied live through the client while Steam runs
(droiddeck-steam-compat) and at the next start otherwise; a choice made in
Steam's menu comes back to the app. Requests are ordered by a sequence that
never goes backwards, and the page no longer jumps back to the default
after a swap or restore.

DirectAudio: the wrapper wrote the driver key with its backslashes
stripped, so no game ever used DirectAudio. Wine 11 also loads a builtin
only from the prefix, so the driver is now linked into system32 and
syswow64 before "directaudio,pulse" is selected; mmdevapi falls back to
winepulse whenever DirectAudio cannot start.

* Pick esync, ntsync or fsync from the Steam settings' Games group

A three-way tab row above the FEX preset sets the sync Proton games use. It
writes the existing switches together (droiddeck-ntsync, droiddeck-fsync
first, droiddeck-esync), so the Performance toggles and the tabs always agree,
starts on esync and keeps the choice until it is changed again.

* Make droiddeck-fsync the default sync for Proton games

A fresh install, or one that never picked a sync, starts on fsync; a choice made
in the Steam settings' Games group still sticks. Games Proton keeps off fsync
still fall back to droiddeck-esync.

* Add wineserver to the Wine sync tabs and order them ntsync, fsync, esync, wineserver

wineserver turns every in-process sync off so games wait through wineserver;
picking any other tab turns sync back on. The tabs shrink to fit a narrow pane.

* Shorten the Wine sync description

* Answer openat2 and execveat for FEX in the session preload

FEX opens every file of its x86 rootfs with openat2(RESOLVE_IN_ROOT) and
only falls back to the host path on EXDEV. Under proot on Android openat2
answers ENOSYS, so each lookup of an x86 library silently went to the host
and missed. The exported syscall() now turns openat2 into openat once the
real call reports ENOSYS: RESOLVE_IN_ROOT paths are taken relative to the
root fd (FEX has already resolved the links inside the rootfs), and an
absolute path under RESOLVE_BENEATH fails with EXDEV as the kernel would.

execveat with an absolute path, or relative to AT_FDCWD, and without
AT_EMPTY_PATH or AT_SYMLINK_NOFOLLOW, is plain execve; it is sent as such
because proot refuses execveat with a directory fd, which FEX uses when it
re-executes itself for a child x86 program.

* Run x86 Linux games and programs through FEX

Steam: Linux-only titles that have no ARM64 build (from the client's
appinfo cache: type game, demo, application or beta) are mapped to a new
compatibility tool, droiddeck-fex ("Linux x86 (FEX)", linux to linux,
no required runtime). Valve's own "fex" tool needs pressure-vessel, which
cannot run under proot, so a mapping to it or to a Steam Linux Runtime is
replaced; any other pick the user made stays. Titles that also ship for
Windows stay on Proton. When such a title is installed and FEX or the
sniper runtime is missing, the client is asked to install them.

droiddeck-fex runs the program under the FEX that Steam installs (app
3127680), with Steam Linux Runtime 3.0 (sniper, app 1628350) as the x86
rootfs:
- the sniper platform is linked in place from its usr-mtree (relative
  links only, files/usr -> .), once per runtime version;
- the x86_64 and i386 builds of libblsession and libfakeinput go into the
  runtime's lib/<triplet>/droiddeck and its etc/ld.so.preload, mirroring
  the session's own list, so x86 programs get the pads and the session
  fixes (FEX passes their system calls straight to the kernel, so the
  ARM64 preloads cannot reach them);
- Config.json sets RootFS and the GL and Vulkan thunks, so x86 games draw
  with the device's Turnip and Mesa;
- the FEX preset and the game's own environment from the Steam settings
  apply, and ARM64 entries are dropped from LD_PRELOAD/LD_LIBRARY_PATH.
It also links ~/.steam/sdk64 and sdk32 to the client's x86 steamclient
when the client has one and nothing is there yet.

Desktop: x86_64 and i386 AppImages can be imported now; they unpack
through FEX (or unsquashfs) and record their architecture. Scripts,
AppImages and programs started in a run session use FEX automatically
when they are x86, and each added app has a "Use FEX" Auto/On/Off choice
in its edit dialog. The launchers' "still running" checks also look at
FEX processes, whose exe is FEX rather than the program. A GitHub release
without an ARM64 AppImage falls back to its x86_64 one. Decky's x86
loader starts through droiddeck-fex instead of the fex-mesa rootfs path,
which no runtime ships.

The x86 preloads are built against glibc 2.31 (Debian 11) so they load
in sniper: tools/linuxfs/build-x86-preloads.sh, run in CI and by
build_local.sh. fakeinput's stat hooks fall back to __xstat on a glibc
without a stat export, and mmap64 takes off64_t for the i386 build.

* Keep a FEX unixlib from outliving its DLL

A FEX package or original bundle without the aarch64-unix helpers left
the previous version's libarm64ecfex.so / libwow64fex.so in the Proton,
so the new DLLs loaded a unixlib built for another FEX. A swap now removes
the helpers the package does not carry; FEX then runs DLL-only, which it
already falls back to when Wine cannot load the unixlib.

* Fix the Wine sync choices an audit found

- wineserver tab: it passed Proton's environment through, so a build with
  esync built in (GE, cachyos) still ran esync and a kernel ntsync would
  still be used. It now sets PROTON_NO_ESYNC, PROTON_NO_FSYNC and
  PROTON_NO_NTSYNC (unless the game's own environment sets them).
- ntsync tab: a Proton whose wineserver has no /dev/ntsync client got
  wineserver-only sync although fsync would work. The hash cache records
  whether the wineserver has one; without it the launch goes to
  droiddeck-fsync, and no stand-in or pack turns droiddeck-ntsync on.
- A build with esync built in returned before the per-game fallbacks, so
  a game that turns esync off ran with no in-process sync. It now gets
  droiddeck-fsync, or droiddeck-ntsync where fsync is off too.
- When a pack's proton cannot start and the stock one is used, or the
  selection fails, the prefix's record now says stock, so a second
  launch into the same running prefix no longer picks the pack's ntdll.
- droiddeck-fsync: its mutex is held across fork and re-made in the
  child, a closed or replaced shm fd is forgotten (close, dup2, dup3,
  close_range, closefrom), and a waiter woken while it was leaving on a
  timeout or signal reports the wake instead of losing it.
- BL_SYNC_MIN_NOFILE applies per game to every verb, debug logs carry
  prefixes.json, the device report names the chosen sync instead of the
  three raw switches, and PATCHES.md and the proot notes describe the
  selector, the fsync default and droiddeck-fsync's futex_waitv.

* Name the runtime's scripts and files droiddeck, migrating old installs

The guest scripts are droiddeck-* now (droiddeck-session and the other 19),
as are the files the app and scripts generate (etc/droiddeck, the network
state files, the components dir, the Steam install stamp, the redist marker,
the extra-Proton wrapper and backups) and the compositor's own names
(libdroiddeckwayland, droiddeck_* sources, DROIDDECK_* switches, the
wl_output and seat names).

Installed runtimes carry on: LegacyNames moves etc/bannerlator and
share/bannerlator over and leaves relative links at the old paths before
every proot command, turns any old script into a link to its new name,
moves the generated files and points menu entries at the new scripts.
The session scripts and steam-compatibility move their markers on first
use, the components dir's desired.tsv is rewritten with it, and the
runtime counts as installed under either session script.

Kept: the banner_ahb_v1/banner_desktop_v1 wire names and BANNER_AUDIO_DIRECT
(read by prebuilt Turnip and Wine builds), Banners-Turnip and other
third-party names, BL_* switches, libblsession, and credits to Bannerlator.

* Unpack x86 AppImages without FEX, then ask Steam for FEX

Importing an x86 AppImage failed when FEX was not installed yet ("needs FEX
to unpack and no unsquashfs is installed"). AppImages now unpack with
uruntime (VHSgunzo, MIT, v0.8.1 aarch64, pinned by sha256 and shipped
unmodified with its licence), which reads SquashFS and DwarFS images of any
architecture natively. FEX's own --appimage-extract and unsquashfs stay as
fallbacks, and an ARM64 image whose own runtime cannot unpack it goes the
same way.

An x86 import with FEX missing records that FEX is wanted, so the next
Steam session requests FEX and the Steam Linux Runtime, and the program's
page says FEX is not set up yet and how to get it.

* Run Vulkan Qt Quick AppImages on Wayland

OpenNOW (Qt 6.8, Qt Quick on Vulkan) closed within two seconds in a run
mode. The session sends toolkits to gamescope's Xwayland, and Qt's xcb
backend only presents with Vulkan when Mesa's X11 WSI does, which needs
DRI3; Xwayland on KGSL has none, so Qt found no queue that can present and
aborted ("Failed to create RHI").

An AppImage that bundles Qt Quick, the Vulkan loader and Qt's Wayland
plugin now runs on gamescope's Wayland socket (the desktop's, outside
gamescope), where Turnip presents as it does for games, with Qt's xcb
backend as the fallback. SDL_VIDEODRIVER and XDG_SESSION_TYPE follow, so
helpers that pick their window system from them (OpenNOW's streamer) agree
with Qt. Everything else stays on X11; a qt file in the app's directory
(wayland or xcb) overrides the choice.

* Keep gamescope's WSI layer away from Qt apps on its Wayland socket

OpenNOW still closed at once: its FFmpeg (the Raspberry Pi fork, libavutil
61) creates its Vulkan queues internally synchronized whenever the driver
offers VK_KHR_internally_synchronized_queues, which DD-Turnip does. The
gamescope WSI layer registers every queue of a new device through
vkGetDeviceQueue, which only returns queues created without flags, so it
got VK_NULL_HANDLE and vkroots aborted on assert(obj) before Qt opened a
window.

Programs that draw on gamescope's Wayland socket do not need the layer,
which only carries X11 windows past Xwayland, so it is turned off for
them. OpenNOW bundles no Vulkan loader (it reaches Vulkan through Qt and
dlopen), so a binary that uses QVulkanInstance counts as a Vulkan app too,
and a Qt Quick app left on X11 says why in the session log.

* Keep the end of the session log, and say when FEX is missing

The session sends its output through head -c into session.log. head
writes through stdio, so it held up to 4 KB that proot's --kill-on-exit
threw away when the guest ended: every log stopped mid-line at a 4096-byte
boundary, losing exactly the lines that say why a program quit (an x86
AppImage's "x86 Linux programs need FEX" among them). dd writes each read
as it comes and keeps the same cap.

A run mode always ends with status 0 (gamescope does not pass its child's
on), so a program that could not start just closed. When the log says FEX
is missing, the ended screen now says so and how to get it.

The app reads FEX's readiness from status.json, which only a launch or an
import wrote, so it still said "not set up" after Steam installed FEX.
droiddeck-fex status rewrites it, and a Steam session ends with it while
FEX is wanted. FEX is also looked for at the tool's root and under files/,
and a tool folder without it lists what it holds.

* Let FEX and its runtime install runnable on an SD card library

A Steam library on shared storage loses the executable bits, so native
tools are staged in private directories bound over it; only Proton and
SteamLinuxRuntime folders were. FEX (3127680) installed there could never
run, droiddeck-fex saw no FEX and kept asking Steam for it. FEX and the
sniper runtime (1628350) now get private directories from their first
download, whatever their install folder is called.

* Keep fsync off in the pack smoke test

A runner whose kernel allows futex_waitv started stock Proton with fsync,
so the server-side baseline never said what the test waits for and every
pack was waved through as untestable; the esync run would have measured
fsync too.

* Judge a pack against stock's own esstress failures

Stock Proton fails esstress's dup wait all under server-side sync as well
(a Wine bug, seen on the phone too), and any stock failure made the test
call the runner unusable. A pack now fails only when it crashes, hangs or
fails a check stock passes.

* Ask Steam for FEX and its runtime one at a time

Both steam://install requests were started together, and the running client
took only the first: FEX installed, the sniper runtime FEX needs never did.
Each request now waits for the client to take it before the next.

* Bundle the first published droiddeck-esync packs in the apk

* Log how an x86 program under FEX ends

FEX keeps its own errors quiet unless asked, so a program it could not run
left nothing in the session log. Its log now goes to stderr, and the AppImage
launcher records the program's exit status or the signal that ended it.

* Show the log a failed AppImage program wrote

Programs like Eden stop themselves on a failed check and say why only in
their own log under the home folder. When the program ends badly, the end of
any log it wrote during the run is copied into the session log.

* Report where an x86 program under FEX hit an illegal instruction

A tiny x86_64 preload, built without libc, catches SIGILL and writes the
address, the instruction bytes and the mapping they belong to before the
program dies as it would have. droiddeck-fex preloads it into x86_64 programs.

* Load the fault reporter from the x86 runtime

Programs under FEX look libraries up in the x86 runtime, so the reporter is
copied there with the other preloads and named by its path inside it.

* Hand FEX its x86 runtime and thunks through the environment

Valve's FEX runs portable and reads its config beside itself, so the
Config.json droiddeck-fex writes was not seen: programs ran without the
runtime. The runtime, thunk libraries and thunk list now also go in FEX's
own environment variables, and each launch says what it was given.

* Use the sync pack built for the installed Proton release

Some Proton releases ship byte-identical ntdll.so and wineserver (Valve
11.0-2b/2c, CachyOS 0702/0703), so a pack built for a newer release
matched an older install exactly and the older install never fetched its
own pack. A pack from a newer release no longer counts as an exact match;
among matches the one built for the installed version wins, then rev.

The app ranks the pack a tool already uses the same way and only fetches
a pack that ranks higher, reads the release epoch from tools.tsv and
refetches when tools.tsv changes. A prefix whose server is still running
re-checks its recorded pack on waitforexitandrun and starts fresh when a
better one now applies.

* Keep published sync packs and revocations consistent

The publish step never replaces a pack that has an entry beside it; a
pack left without its entry by an interrupted run is replaced so the
build stops repeating. Discovery counts revocations the signed index does
not show yet, including superseded packs only the flavor releases list,
so the index is signed again. The release watch always builds every
flavor.

* Fetch the droiddeck-esync packs from DroidDeck-Components

The packs, the signed index and the apk bundle now live in the releases
of Droid-Deck/DroidDeck-Components, together with the pipeline that
builds them, so this repository keeps only the app and the guest code
that consumes them. The app's index and asset URLs point there,
release.env names the repository its bundle comes from, and the apk
builds drop bundled packs that the published index revokes.

* Stop the apk build when the published sync index cannot be read

* Ask Steam for one FEX dependency at a time

The client shows a confirmation dialog for each steam://install, and a
second request replaces the first dialog, so FEX was never installed
when the runtime was requested right after it. The next dependency is
now requested once the previous one has an app manifest.

* Use generic names in the AppImage test fixtures

* Give x86-64 apps under FEX the Vulkan thunk

Apps that bring their own glibc and Vulkan loader skipped FEX's thunk
overlay and loaded their bundled desktop Mesa drivers, which crash on the
phone's GPU during Vulkan setup. droiddeck-fex now adds an x86-64 audit
module when a program's bundled glibc and libstdc++ meet the thunk's
version needs. The module sends libvulkan.so.1 lookups to a nodelete stub
that needs FEX's thunk path. That keeps the thunk mapped when an app
unloads Vulkan and loads it again, since FEX keeps its first trampoline
links and the old addresses get reused.

The fault reporter now restores the default action before re-raising,
because FEX ignores SA_RESETHAND and the handler looped.
2026-10-04 12:43:57 -04:00

21 KiB
Raw Permalink Blame History

proot, glibc and where the time goes

Research notes for feat/performance-fixes-2 (2026-09-30). The question was whether Steam and the games should keep running under proot, run directly on glibc, or a mix of the two, and what the fastest correct setup is. Everything below was measured on a Snapdragon 8 Elite Gen 5 (SM8850, kernel 6.12.38-android16, Android 16) over adb, unless it says otherwise.

Short answer

  • Don't drop proot. On Android it does two jobs. It translates paths. It also answers every syscall that Android's app seccomp policy blocks (rseq, set_robust_list, faccessat2, fchmodat2, openat2, the set*id family, futex_waitv, ...).
    • Stock Arch glibc without a tracer is killed by SIGSYS on its first pthread_create. That stays true even with an in-process SIGSYS handler, because glibc makes those calls with every signal blocked.
    • Going "pure glibc" means building Termux-style glibc (relocated prefix, blocked syscalls rewritten), an exec shim for every ELF Steam self-updates, a /proc/self/exe emulator for Chromium, path redirects for /tmp, /dev/shm, /mnt/* and the fake /proc and /sys files, and Wine's hard-coded /tmp/.wine-<uid>.
    • That is a project of its own, and its failure mode is a crash instead of a slow call.
  • During gameplay, proot already costs almost nothing, thanks to patches 0004–0013. GPU submits (ioctl), futex, read/write, mmap, ppoll/epoll, sendmsg/recvmsg and clock_gettime (via the vDSO) all run at native speed under the filter.
  • What proot still costs is every path syscall, execve, brk, thread and process creation, and every Android-blocked syscall: 15–60 µs each, against ~0.5 µs natively. All of it goes through one tracer thread, which tops out around 75–95k traps/s. Steam start-up, game loading and asset streaming, Proton's Python, and any burst on several threads at once all hit this.
  • Most of that cost is not proot's code but the two cross-core wake-ups per trap. Any out-of-process mechanism pays them: ptrace, and seccomp user-notification too (measured the same). The only real fix is to not leave the process.
  • Recommendation: proot plus an in-process fast path. A preloaded library answers the common path calls inside the process. It sends them through a trampoline page that proot's filter lets through, and it falls back to proot for anything it can't prove proot would answer the same way.
    • The prototype is in this branch: tools/proot/fastpath/ and patches/0014.
    • Speed: stat 25 µs → 0.6 µs, open 25 µs → 0.9 µs, missing-file lookups 23 µs → 1.6 µs. Eight threads doing stat went from 89k/s to 3.6M/s.
    • Correctness: an equivalence suite of awkward paths produced byte-identical results.
    • It only uses syscalls the app policy allows.

How a session runs today

SessionService ─HostProcess─▶ libproot.so (ONE tracer process, nice -6 after 2 s)
  └─ /usr/bin/env -i … droiddeck-session steam
       └─ gamescope ─▶ droiddeck-session (BL_INSIDE) ─▶ steamrtarm64/steam (+ steamwebhelper/CEF tree)
            └─ reaper ─▶ droiddeck-game-env ─▶ droiddeck-proton ─▶ Valve ARM64 Proton (python)
                 └─ wine (arm64ec, FEX loaded in-process as a DLL) ─▶ wineserver, game.exe, …
  • Every process in the tree, from the session script to the game, is a tracee of the same proot.
  • The options are --kill-on-exit, --kernel-release=… (kompat, for the hostname), -i uid:uid (fake_id0, for Xwayland's setgid/setuid), and about 25 binds: /dev, /proc, /sys, fake /proc and /sys files, the GPU node, /dev/shm, storage and the game libraries.
  • /etc/ld.so.preload loads libblsession.so (the tools/linuxfs/preload/*.c shims) into every guest process.
  • The Flatpak sandboxes (BwrapSpawner) already run in separate proot instances, started from the Android side.

What proot does per traced syscall

The tracee runs into proot's seccomp filter, which returns SECCOMP_RET_TRACE. Then:

  1. The kernel stops the tracee and wakes the tracer: a cross-core IPI, and possibly an exit from a deep idle state.
  2. The tracer reads the registers (PTRACE_GETREGSET) and reads the path (process_vm_readv).
  3. It canonicalises the path against the rootfs and bindings: an lstat per component, or one O_PATH open plus a /proc/self/fd readlink with patch 0002.
  4. It writes the host path into a scratch area in the tracee (process_vm_writev) and updates the registers.
  5. It resumes the tracee, which is another cross-core wake-up.

Calls flagged FILTER_SYSEXIT stop a second time on the way out, for example to translate the result of readlink or getcwd. Android-blocked syscalls arrive as a SIGSYS signal stop instead, and proot emulates them (src/tracee/seccomp.c). Fork, clone, exec and thread exit each add PTRACE_EVENT_* stops.

Measurements

The tools are in tools/proot/bench/; run-device.sh explains the device layout.

Caveat: adb shell is not under the app seccomp filter. Mechanism costs are the same, but syscalls that Android blocks only for apps (see below) can't be reproduced there.

Caveat: the phone in Doze (screen off) runs everything about 7× slower. All numbers below were taken with the screen awake.

Per call, as a session runs proot today

sysbench in the patched (patched) and unpatched (vanilla) columns, using the session's own proot options and a similar set of binds.

call direct glibc termux proot (vanilla) this repo's proot (0001–0013) + fast path (0014)
getppid / futex / ioctl / pread (untraced) 0.1–0.4 µs futex 16.6, fstat 32.8, ioctl 30.5 µs 0.2–0.4 µs 0.2–0.4 µs
stat, deep absolute path 0.8 µs 41.7 25.3 0.6
open + close 1.7 µs 40.4 25.3 0.9
access 27.2 26.2 1.0
fstatat relative to a dirfd 45.5 26.8 1.9
stat of a missing file 38.9 22.9 1.6
readlink /proc/self/exe 42.8 38–43 (proot)
getcwd / uname / brk 31–35 30–33 (proot)
memfd_create 20.4 18.6 (proot)
pthread create+join 58 48 48
fork + exec + wait ~1.1 ms 1.16 ms 0.70–0.78 ms +0.2–0.4 ms (see open items)

The patches already in the repo pay off: kompat (0011) and fake_id0 (0012) took futex, fstat and sendmsg off the trap list, and 0013 did the same for ioctl.

What one trap costs, by mechanism (mechbench; the handler does nothing)

mechanism cost
native syscall 0.1 µs
seccomp filter of 0 / 50 / 150 / 300 compares, allowed syscall no difference (kernel ≥5.11 caches constant decisions per syscall number)
ptrace + seccomp, tracer and tracee on the same core 6.2 µs (6.7 µs with register get/set)
ptrace + seccomp, unpinned (as the app runs it) 15.5 µs
ptrace + seccomp, different cores (same cluster / across clusters) 34–36 / 42–61 µs
ptrace with a spinning tracer, different cores 20 µs (the tracee's side still has to wake)
seccomp user-notification (the "modern proot" design) 5.7 µs same core, 34–58 µs across, 43 µs unpinned; SYNC_WAKE_UP doesn't help
in-process SIGSYS (SECCOMP_RET_TRAP) 0.83 µs
openat2 RESOLVE_IN_ROOT (kernel-side chroot lookup) 1.0 µs, but blocked in apps

Takeaways:

  • The tracer's own work is about 8 µs of the ~14 µs same-core trap. Everything above that is scheduling.
  • Moving to seccomp user-notification would be a rewrite for no gain.
  • The filter's length doesn't matter. What matters is not breaking the kernel's cache:
    • Any check on an argument or the instruction pointer must come after the syscall-number dispatch. The first version of 0014 checked the address first. That made every syscall in the session run the whole filter, and cost +0.5 ms per exec.
    • Patches 0004 and 0013 already follow this rule.

One tracer for everything (parstat: N threads doing stat)

1 thread 4 threads 8 threads
one proot 37k/s, 27 µs 74–95k/s, 42–54 µs 68–89k/s, 90–118 µs each
two proots, 2 threads each 187k/s total, 21 µs
proot + fast path 1.64M/s, 0.6 µs 2.76M/s 3.60M/s, 2.2 µs

A burst of path calls on several threads therefore queues behind the single tracer. CEF loading assets, Proton's Python, a game streaming files on worker threads and the shader-cache threads all produce such bursts.

CPU placement

The workload ran with taskset; no fast path. Times are per traced call, and the last column is one fork + exec.

affinity stat exec
default 25.8 µs 750 µs
one core 14.0 µs 370 µs
the two prime cores 14.6 µs
the six-core cluster 25.9 µs

The scheduler's wake-affine placement helps when it can put the tracer and the tracee together, and spreading them apart hurts. Never pin the tracer away from its tracees. Today raiseTracer only renices it, which is correct.

Whole programs

Times are in ms, each with proot's ~40 ms start-up already subtracted.

direct glibc vanilla proot this repo's proot + fast path
python3: 10 stdlib imports 75–89 ~130 ~110 ~90 (878 of 879 path calls answered in-process)
tar of 2.7k files 10–40 ~180 ~80 ~20
200 × fork+exec of true 230 ~600 ~500 ~500
find over 2.7k files 16–23 noisy noisy unchanged: glibc's fts calls internal entry points

Android's app seccomp policy decides more than proot does

The app filter is generated from bionic's SYSCALLS.TXT, minus the blocklists, plus the allowlists. It is the same for every app whatever its targetSdk, and anything not listed gets SECCOMP_RET_TRAP, a SIGSYS. Filters stack, and the strictest one wins: a blocked call never reaches proot's RET_TRACE. It arrives as a SIGSYS stop, and proot answers it (usually ENOSYS).

Checked against bionic android16-release:

syscall app policy who calls it
rseq, set_robust_list blocked glibc, at the start of every thread, while all signals are blocked
faccessat2 blocked glibc's faccessat(), which tries it on every call before falling back, so 2 round trips (access() calls the plain faccessat syscall directly)
fchmodat2, openat2 blocked newer glibc, Flatpak/libglnx, FEX's rootfs lookups (libblsession.so turns openat2 into openat)
setuid, setgid and the rest of the family blocked Xwayland (hence -i)
futex_waitv, io_uring_*, landlock_* blocked Proton's fsync (droiddeck-fsync answers futex_waitv in libblsession.so), some engines
clone3 blocked before Android 15 glibc pthread_create
close_range blocked on Android 12
statx, process_vm_readv/writev, memfd_create, pidfd_*, seccomp allowed

On top of the ptrace round trips, every one of these costs a signal round trip through proot.

Every traced syscall: what it needs and whether it can bypass proot

This is the filter of termux proot at source.env plus patches 0001–0013. "Fast path" means the call can be answered in-process with the 0014 design.

syscalls why proot traps them can it bypass proot?
openat/open/creat, newfstatat/stat/lstat, statx, faccessat/access, readlinkat (exit), mkdirat, unlinkat, renameat(2), symlinkat, linkat, fchmodat, fchownat, utimensat, truncate, *xattr, inotify_add_watch, name_to_handle_at path translation (guest → host), plus exit fixups for readlink and rename Yes, through libc wrappers. The prototype covers open, stat, statx, access, readlink, opendir and fopen; the write family is next. Raw svc and glibc's internal callers (ld.so, fts, realpath, nss) still go to proot.
chdir/fchdir, getcwd (exit) proot emulates the cwd; until 0014 the kernel's cwd never moved With 0014 the kernel's cwd follows the guest's. getcwd stays in proot (cheap, rare).
execve/execveat runs the loader, maps PT_INTERP inside the rootfs, shebangs, tracks /proc/self/exe No. This is the core of what proot is for. Costs 0.4–0.8 ms per exec; the session scripts already avoid exec-heavy loops (nap).
brk (entry and exit) heap emulation: programs are mapped by proot's loader, so the kernel's brk area is the loader's No (PR_SET_MM needs CAP_SYS_RESOURCE). Fewer calls: GLIBC_TUNABLES=glibc.malloc.top_pad=… grows the heap in larger steps.
bind, connect, accept(4), getsockname, getpeername sun_path of Unix sockets Same-path binds (runtime dir, files dir) need no translation, but the filter can't see the address. Possible fast-path candidate.
wait4/waitpid, ptrace ptrace emulation inside the guest (breakpad, gdb) Could become opt-in; then wait4 is free (one stop per wait today).
prctl(PR_SET_DUMPABLE), setrlimit/prlimit64(RLIMIT_STACK) loader and stack fixups Already narrowed to these arguments (0004).
ioctl(TCSETSF, termios2, FICLONE) Android pty policy, FICLONE EACCES Already narrowed to these requests; GPU ioctls are free (0013).
uname, sethostname, setdomainname the DroidDeck hostname (kompat) Rare. Keep.
set*id, *setxattr fake_id0 identity mode (0012) Rare. Keep.
memfd_create Qt JIT and php workarounds (string argument) Every Wayland wl_shm buffer and Chromium shared memory pays one stop. Could be dropped if the DroidDeck runtime doesn't need those workarounds.
statfs (exit) fakes tmpfs for /dev/shm Rare.
open_tree, move_mount, fspick, mount_setattr, openat2 answered ENOSYS (0008, 0010) Fine.
Android-blocked calls (previous table) SIGSYS emulation Avoidable at the source: GLIBC_TUNABLES=glibc.pthread.rseq=0 removes one stop per thread. The rest need a patched glibc.
clone/fork/vfork/exec/exit events tracking tracees Needed while proot traces.

Options weighed

  1. Pure glibc, no proot. Rejected as the main path, for the reasons in the short answer.

    • Closest prior art: huntergdavis/steamclienttermux, which runs steamrtarm64 on a patched Termux glibc 2.44 with an exec shim and a /tmp and /dev/shm redirect preload.
    • They report Steam's first window 7× faster and about 5% more FPS, with proot having used 60–65% of a core.
    • They still run Proton and the games under proot.
    • DroidDeck also has four package names (tools/release/variants.txt), so a relocated prefix would need four builds or Winlator-style padded path rewriting.
  2. Hybrid by process (Steam in proot, game on glibc, or the reverse). The game side is the harder half. Wine re-execs itself and wineserver, which hits PT_INTERP. Its server directory is hard-coded under /tmp, and Proton's esync and fsync use shm_open (/dev/shm) and futex_waitv, which is blocked (droiddeck-fsync emulates it in the session preload, which a glibc-side game would have to load too). A game's steady state is already mostly untraced, so the gain is in loading. Not worth it before the fast path.

  3. Seccomp user-notification instead of ptrace. It measures the same as ptrace, and it can't rewrite arguments, so every call would have to be emulated. No.

  4. In-process SIGSYS for everything (0.8 µs). The kernel resets a blocked SIGSYS to the default action and kills the process (force_sig_seccomp, HANDLER_CURRENT). glibc and Wine block all signals around exactly these calls. Unsafe without also trapping rt_sigprocmask. No.

  5. proot plus an in-process fast path (this branch). Recommended. Details below.

  6. A proot-aware glibc, the follow-up to 5. Rebuild the rootfs's own glibc (same version, same Arch package) with two changes:

    • its internal path entry points (__open_nocancel, __fstatat64, ld.so's opens) go through the fast path, which covers ld.so, fts, realpath and nss;
    • it never makes the Android-blocked calls, as Termux's fakesyscall.json does.

    This removes the remaining library-loading traps and all the SIGSYS round trips. The rootfs is versioned (linuxfs-rN), so glibc rebuilds stay under control.

  7. On the tracer side, with no in-process changes:

    • A second proot for the game tree. Measured 2.5× trap throughput, and Steam/CEF bursts no longer stall the game. BwrapSpawner already shows the pattern: a stand-in process in the session relays stdio, the exit status and signals to a proot started from the app.
    • Leave the tracer unpinned (above).
    • Set GLIBC_TUNABLES=glibc.pthread.rseq=0:glibc.malloc.top_pad=16777216 in the session environment.

The fast path (prototype)

The code is tools/proot/fastpath/fastpath.c, preloaded into every guest process. On the proot side it needs patches/0014, enabled with PROOT_FASTPATH=1.

  • Trampoline. The library maps a 4 KiB executable page at the fixed address 0xffff00000. It holds mov x8,x0 … svc #0; ret. With PROOT_FASTPATH, proot's filter checks the caller's address just before each RET_TRACE and allows syscalls coming from that page.
  • Mapping a path. The library takes the literal guest path and finds the longest binding whose guest path is a prefix of it; otherwise the path is under the rootfs.
    • It opens the parent host directory O_PATH and requires /proc/self/fd to name exactly that path. That proves no component on the way was a symlink, so proot would have walked the same directories.
    • The last component is never followed: a symlink there goes to proot.
  • Missing files. For a missing file, the deepest existing ancestor is verified the same way, and the next component must not exist even as a symlink. Then ENOENT is exact.
  • What always goes to proot:
    • .., a trailing /, /proc, /dev/fd and /dev/std*;
    • O_TMPFILE, AT_EACCESS, and any flag not handled;
    • any doubt at all. "Go to proot" means calling the real libc function, so proot decides.
  • Relative paths. Patch 0014 keeps the kernel's cwd at the guest cwd's host directory. Relative and dirfd lookups are mapped through /proc/self/{cwd,fd/N}.
  • Verified-parent cache. Verified parents are cached for 2 s (PROOT_FP_TTL_MS). That is the same trade-off preload/pathcache.c already makes for the Steam client. A parent directory turned into a symlink inside that window would be missed; PROOT_FP_TTL_MS=0 verifies every call, at 2.0 µs instead of 0.6 µs.
  • Allowed syscalls only. It uses only openat, newfstatat, statx, faccessat, readlinkat and close, all allowed for apps. A first version used openat2 RESOLVE_IN_ROOT, which the app policy blocks.
  • Equivalence check. bench/equiv.py runs stat, lstat, readlink, read, listdir and access over awkward paths, from several working directories and through a dirfd. Its output is byte-identical with and without the fast path, at TTL 0 and at TTL 2000. The paths include:
    • absolute and relative symlinks into binds, .. symlinks, dangling links and loops;
    • files inside binds, nested binds (/dev/shm inside /dev) and /proc;
    • missing paths behind symlinks.

Open items before shipping it

  • Validate inside the app, not just from adb. Three things to check:
    • The app domain allows an anonymous PROT_EXEC page (execmem). If not, map a page of the library file itself at the fixed address instead, as proot's loader does for every program.
    • Nothing claims 0xffff00000 first.
    • The stub's syscalls pass Android's filter. They should: all are allowed.
  • Integrate into libblsession.so rather than a second preload. opens.c and pathcache.c already define open and access, so their "real" call should become the fast path. That also removes the second library's load cost, about 0.2–0.4 ms per exec that is still unexplained (see the exec row above).
  • Wire the launcher. The app already knows the binds (LinuxRuntime.binds):
    • set PROOT_FASTPATH=1 in proot's environment;
    • pass PROOT_FP_ROOT and PROOT_FP_BINDS to the guest;
    • add a Performance toggle next to "Run proot without seccomp", with the fast path off whenever seccomp is off.
  • Cover the write family (mkdir, unlink, rename, symlink, chmod, utimens) and Unix-socket connect/bind for same-path binds. Then measure a real Steam start in the app, a game load, and PROOT_FP_STATS hit rates for steam, steamwebhelper, wine and wineserver.
  • FEX, inside Proton as a DLL, translates x86 path syscalls through glibc's syscall(), not the wrappers, so they still trap. A syscall() hook could route openat and newfstatat there too.