Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Android: mmap issue #165

Open
truboxl opened this issue Feb 10, 2024 · 9 comments
Open

Android: mmap issue #165

truboxl opened this issue Feb 10, 2024 · 9 comments

Comments

@truboxl
Copy link

truboxl commented Feb 10, 2024

On Android, we sporadically hit mmap and ENOMEM issues despite adding patches to try mitigate issues. I am not sure this is fixable on upstream side.
termux/termux-packages#18573
termux/termux-packages#19180

Here are the patches and build script to build and package blink.
https://github.com/termux/termux-packages/tree/master/packages/blink

Some of the enhancement is to a set up like proot + blink on Android which is equivalent to blink VFS. I am however unable to make blink VFS work on Android satisfactory.

@Saikatsaha1996
Copy link

On Android, we sporadically hit mmap and ENOMEM issues despite adding patches to try mitigate issues. I am not sure this is fixable on upstream side. termux/termux-packages#18573 termux/termux-packages#19180

Here are the patches and build script to build and package blink. https://github.com/termux/termux-packages/tree/master/packages/blink

Some of the enhancement is to a set up like proot + blink on Android which is equivalent to blink VFS. I am however unable to make blink VFS work on Android satisfactory.

Any solution available? I am facing exactly same issue.. problem with -U not recognised which is inside Termux patch

@jart
Copy link
Owner

jart commented Apr 21, 2024

Does passing the -m flag fix it?

@Saikatsaha1996
Copy link

Saikatsaha1996 commented Apr 21, 2024

Does passing the -m flag fix it?

Trying to run like this..

#!/data/data/com.termux/files/usr/bin/bash
cd $(dirname $0)
## unset LD_PRELOAD in case termux-exec is installed
unset LD_PRELOAD
command="proot"
command+=" -q blink -m"
## uncomment following line if you are having FATAL: kernel too old message.
#command+=" -k 4.14.81"
#command+=" --link2symlink"
command+=" -0"
#command+=" -q blink -m"
command+=" -r debian-fs"
if [ -n "$(ls -A debian-fs/binds)" ]; then
    for f in debian-fs/binds/* ;do
      . $f
    done
fi
command+=" -b /dev"
command+=" -b /proc"
command+=" -b /dev/null:/proc/stat"
command+=" -b /sys"
command+=" -b /data/data/com.termux/files/usr/tmp:/tmp"
command+=" -b debian-fs/tmp:/dev/shm"
command+=" -b /data/data/com.termux"
command+=" -b /:/host-rootfs"
command+=" -b /sdcard"
command+=" -b /storage"
command+=" -b /mnt"
command+=" -w /root"
command+=" /usr/bin/env -i"
command+=" HOME=/root"
command+=" PATH=/usr/local/sbin:/usr/local/bin:/bin:/usr/bin:/sbin:/usr/sbin:/usr/games:/usr/local/games"
command+=" TERM=$TERM"
command+=" LANG=C.UTF-8"
command+=" /bin/bash --login"
com="$@"
if [ -z "$1" ];then
    pulseaudio --start --load="module-native-protocol-tcp auth-ip-acl=127.0.0.1 auth-anonymous=1" --exit-idle-time=-1;
    exec $command
else
    $command -c "$com"
fi

~ $ bash debian.sh
proot warning: can't sanitize binding "-0": No such file or directory
WARNING: linker: Warning: failed to find generated linker configuration from "/linkerconfig/ld.config.txt"
__bionic_open_tzdata: couldn't find any tzdata when looking for Asia/Kolkata!
I have no name!@localhost:~$ apt update
Get:1 http://security.debian.org/debian-security bookworm-security InRelease [48.0 kB]
Get:2 http://deb.debian.org/debian bookworm InRelease [151 kB]
Get:3 http://deb.debian.org/debian bookworm-updates InRelease [55.4 kB]
Get:4 http://security.debian.org/debian-security bookworm-security/main amd64 Packages [155 kB]
Get:5 http://security.debian.org/debian-security bookworm-security/main Translation-en [94.2 kB]
Get:6 http://security.debian.org/debian-security bookworm-security/contrib amd64 Packages [644 B]
Get:7 http://security.debian.org/debian-security bookworm-security/contrib Translation-en [372 B]
Get:8 http://deb.debian.org/debian bookworm/main amd64 Packages [8786 kB]
Get:9 http://deb.debian.org/debian bookworm/main Translation-en [6109 kB]
Get:10 http://deb.debian.org/debian bookworm/contrib amd64 Packages [54.1 kB]
Get:11 http://deb.debian.org/debian bookworm/contrib Translation-en [48.7 kB]
Get:12 http://deb.debian.org/debian bookworm-updates/main amd64 Packages [12.7 kB]
Get:13 http://deb.debian.org/debian bookworm-updates/main Translation-en [13.8 kB]
Get:14 http://deb.debian.org/debian bookworm-updates/contrib amd64 Packages [768 B]
Get:15 http://deb.debian.org/debian bookworm-updates/contrib Translation-en [408 B]
Fetched 15.5 MB in 47s (328 kB/s)
E: Dynamic MMap ran out of room. Please increase the size of APT::Cache-Start. Current value: 25165824. (man 5 apt.conf)
Reading package lists... Error!
E: Dynamic MMap ran out of room. Please increase the size of APT::Cache-Start. Current value: 25165824. (man 5 apt.conf)
E: Error occurred while processing python3-duo-client (NewFileVer2)
E: Problem with MergeList /var/lib/apt/lists/deb.debian.org_debian_dists_bookworm_main_binary-amd64_Packages
E: The package lists or status file could not be parsed or opened.
I have no name!@localhost:~$

@Saikatsaha1996
Copy link

Saikatsaha1996 commented Apr 21, 2024

Does passing the -m flag fix it?

Some how it's running.. but it's slow.. & received a big issues with libc when I was tried to install apt update && apt upgrade -yy && apt install neofetch

https://pastebin.com/AsfwVpP1

@jart
Copy link
Owner

jart commented Apr 21, 2024

OK if blink -m fixed it then chances are the software that you're running is using MAP_FIXED. You can confirm that by using blink's system call tracing feature blink -s. If it is using MAP_FIXED then that's bad. Because without -m memory safety Blink lets the guest allocate pretty much whatever memory it wants, so if it chooses an address that overlaps with Blink's memory, Android's memory, or Bionic's memory, then you're going to get an mmap() crisis.

@jart
Copy link
Owner

jart commented Apr 21, 2024

You might want to consider virtualizing a simpler operating system than Ubuntu. I'm not sure if Blink is ready to be Docker. For example, Alpine Linux is significantly tinier, and it uses Musl instead of Glibc, and Musl tends to be a much more behaved and proper citizen than Glibc.

@Saikatsaha1996
Copy link

Saikatsaha1996 commented Apr 21, 2024

You might want to consider virtualizing a simpler operating system than Ubuntu. I'm not sure if Blink is ready to be Docker. For example, Alpine Linux is significantly tinier, and it uses Musl instead of Glibc, and Musl tends to be a much more behaved and proper citizen than Glibc.

Okay tomorrow will try with alpine but I not used -m because I actually confused how i should use -m ..

I just run with Termux proot .. not proot-distro

#!/data/data/com.termux/files/usr/bin/bash
cd $(dirname $0)
## unset LD_PRELOAD in case termux-exec is installed
unset LD_PRELOAD
command="proot"
## uncomment following line if you are having FATAL: kernel too old message.
#command+=" -k 4.14.81"
command+=" --link2symlink"
command+=" --root-id"
command+=" -q blink"
command+=" -r ubuntu-fs"
if [ -n "$(ls -A ubuntu-fs/binds)" ]; then
    for f in ubuntu-fs/binds/* ;do
      . $f
    done
fi
command+=" -b /dev"
command+=" -b /proc"
command+=" -b /dev/null:/proc/stat"
command+=" -b /sys"
command+=" -b /data/data/com.termux/files/usr/tmp:/tmp"
command+=" -b ubuntu-fs/tmp:/dev/shm"
command+=" -b /data/data/com.termux"
command+=" -b /:/host-rootfs"
command+=" -b /sdcard"
command+=" -b /apex"
command+=" -b /linkerconfig/ld.config.txt"
command+=" -b /storage"
command+=" -b /mnt"
command+=" -w /root"
command+=" /usr/bin/env -i"
command+=" HOME=/root"
command+=" PATH=/usr/local/sbin:/usr/local/bin:/bin:/usr/bin:/sbin:/usr/sbin:/usr/games:/usr/local/games"
command+=" TERM=$TERM"
command+=" LANG=C.UTF-8"
command+=" /bin/bash --login"
com="$@"
if [ -z "$1" ];then
    pulseaudio --start --load="module-native-protocol-tcp auth-ip-acl=127.0.0.1 auth-anonymous=1" --exit-idle-time=-1;
    exec $command
else
    $command -c "$com"
fi

@jart
Copy link
Owner

jart commented Apr 21, 2024

Here's an example of how to get an alpine system running with blink.

git clone https://github.com/jart/blink
cd blink
./configure --enable-vfs
make -j32
sudo make install
wget https://dl-cdn.alpinelinux.org/alpine/v3.17/releases/x86_64/alpine-minirootfs-3.17.2-x86_64.tar.gz
mkdir alpine-minirootfs-3.17.2-x86_64
cd alpine-minirootfs-3.17.2-x86_64
tar xf ../alpine-minirootfs-3.17.2-x86_64.tar.gz
PATH='/bin:/usr/bin:/usr/local/bin' PS1='$? > ' blink -C . sh

Sadly their "minirootfs" doesn't include their apk package manager. But I can't imagine it'd be that hard to copy over from a real alpine install. Ask the Alpine community for further help on this, and let me know if you encounter any bugs with Blink. Because if you use Alpine, it'll be much easier for me to support you.

@Saikatsaha1996
Copy link

Saikatsaha1996 commented Apr 21, 2024

Here's an example of how to get an alpine system running with blink.

git clone https://github.com/jart/blink
cd blink
./configure --enable-vfs
make -j32
sudo make install
wget https://dl-cdn.alpinelinux.org/alpine/v3.17/releases/x86_64/alpine-minirootfs-3.17.2-x86_64.tar.gz
mkdir alpine-minirootfs-3.17.2-x86_64
cd alpine-minirootfs-3.17.2-x86_64
tar xf ../alpine-minirootfs-3.17.2-x86_64.tar.gz
PATH='/bin:/usr/bin:/usr/local/bin' PS1='$? > ' blink -C . sh

Sadly their "minirootfs" doesn't include their apk package manager. But I can't imagine it'd be that hard to copy over from a real alpine install. Ask the Alpine community for further help on this, and let me know if you encounter any bugs with Blink. Because if you use Alpine, it'll be much easier for me to support you.

No problem but exactly I use same for build & use..

with alpine sh or bash not found

~/alpine-minirootfs-3.17.2-x86_64 $ PATH='/data/data/com.termux/files/usr/bin:/bin:/usr/bin:/usr/local/bin' PS1='$? > ' blink -C . sh
blink: command not found: sh

With Ubuntu error

~/ubuntu-fs $ PATH='/data/data/com.termux/files/usr/bin:/bin:/usr/bin:/usr/local/bin' PS1='$? > ' blink -C . bash
/lib64/ld-linux-x86-64.so.2: failed to load interpreter (errno 2)

Finally login but as normal use.. how can I login with root user with blink?

.../alpine/alpine-x86_64 $ PATH='/usr/local/sbin:/usr/local/bin:/bin:/usr/bin:/sbin:/usr/sbin:/usr/games:/usr/local/games' PS1='$? > ' /data/data/com.termux/files/usr/bin/blink -m -L . -C . /bin/busybox bin/sh --login
localhost:/$

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants