Repository navigation
Run redroid on kernels without dma_heap, PSI or CONFIG_COMPAT (OrbStack, Alpine, ...) - #940
Open
gauravsuman007 wants to merge 2 commits into
Open
gauravsuman007 wants to merge 2 commits into
gauravsuman007 wants to merge 2 commits into
Conversation
On kernels like OrbStack's, redroid 12/13 exit right away (init aborts without /proc/sys/vm/mmap_rnd_compat_bits), 14 never finishes booting (lmkd exits without PSI, boot sticks on FallbackHome) and every version lacks Codec2 encoders without DMA-BUF heaps. Add userspace workarounds that need only docker run flags: - entry.sh runs before /init and fakes the in-kernel lowmemorykiller sysfs files when PSI is missing - patch-init.py makes 12/13 init read mmap_rnd_compat_bits from /dev - dmaheap-shim is an LD_PRELOAD library that serves DMA_HEAP_IOCTL_ALLOC from memfds, as real dma-bufs via udmabuf when available, preloaded into media.swcodec and adbd Tested with 12/13/14 64only images on OrbStack and Debian 13: boot and scrcpy H.264 + Opus work. Binder is still required.
Alpine sets kernel.unprivileged_bpf_disabled = 1, which the kernel won't change until reboot. Android 14's bpfloader writes 0 there, fails, and init reboots because the service is reboot_on_failure, so the container exits right after start. Replace patch-init.py with patch-binaries.py, which also points a copy of bpfloader at /dev/.nk-vm/. entry.sh provides the file and run.sh mounts the patched binary only when the host value is locked to 1, so the host keeps unprivileged BPF disabled. 12/13 bpfloader doesn't touch the sysctl and is left alone. Tested on Alpine 3.23 linux-lts 6.18 (12 and 14 boot, scrcpy H.264 + Opus) and re-checked on Debian 13 (13 and 14). redroid 13 crash-loops in system_server on that Alpine kernel even with the stock image; noted in the README.
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.
Problem
On some Docker hosts redroid fails even though binder is available. OrbStack on macOS is the most common one:
Unable to set adequate mmap entropy value!because the kernel has noCONFIG_COMPAT, so/proc/sys/vm/mmap_rnd_compat_bitsdoesn't exist.FallbackHome. There's no PSI (/proc/pressure), so lmkd exits ("Kernel does not support memory pressure events or in-kernel low memory killer"), init restarts it forever, andsys.boot_completedis never set.kernel.unprivileged_bpf_disabled = 1, so bpfloader's write of0fails, and the service isreboot_on_failure.Changes
A new
nokernel/directory works around these from userspace, using onlydocker runflags and no image rebuild:entry.shruns before/init(static busybox). When PSI is missing it fakes/sys/module/lowmemorykiller/parameters/{minfree,adj}, so lmkd runs in legacy in-kernel mode. Each fix applies only if the kernel needs it.patch-binaries.pymakes copies of init (12/13) and bpfloader (14) use files under/devinstead ofmmap_rnd_compat_bits/unprivileged_bpf_disabledin/proc. A fake under/procdoesn't survive, because init mounts a fresh procfs.run.shmounts each patched binary only when the host needs it, so on Alpine the host keeps unprivileged BPF disabled.dmaheap-shim/is a small freestandingLD_PRELOADlibrary. It answersDMA_HEAP_IOCTL_ALLOCwhen the kernel can't, using a memfd turned into a real dma-buf via/dev/udmabufwhen possible, and a plain memfd otherwise. It's preloaded intomedia.swcodecandadbd(so scrcpy's server gets it). It builds with stock clang, no NDK.prepare.sh/run.shwrap it all up. The README gets a troubleshooting pointer.Binder is still required.
nokernel/README.mddocuments which hosts have it (Docker Desktop's LinuxKit kernel and Debian's cloud kernels don't).Testing
redroid/redroid:{12,13,14}.0.0_64only-latest, arm64:nokernel/run.shlinux-image-arm64,binder_linux)linux-lts6.18, binderfs built in)Possible follow-ups in the images
init.redroid.rc.mmap_rnd_compat_bitsto 12/13.unprivileged_bpf_disabledwrite fails.HAL_PIXEL_FORMAT_BLOBingralloc.redroid. Withdebug.stagefright.c2-poolmask=0xB0000, Codec2 would then need no dma-buf at all.These would make most of
nokernel/unnecessary.