-
-
Notifications
You must be signed in to change notification settings - Fork 3.8k
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
Slowdown of Termux when accessing shared internal storage #1967
Comments
I tested Termux's speed at copying files (using cp command) while on verbose. Its copy speed is ludicrously slow -- but once again speeds up for a second when I rotate my phone. Why might Termux speed up while adjusting to rotation, and how do I keep its speed decent? |
Well, all these can be easily solved by using a servo motor and mounting your phone on it and keep rotating it while running termux commands. |
But can be looked into. Does it still happen if you acquire a wakelock, even though it's to prevent sleep. |
Ooh! Big discovery! Termux ONLY slows down when dealing with files from outside it's own directory -- that is, files that can only be accessed after the termux-setup-storage command. |
Well, external shared storage is emulated with sdcardfs, so performance would definitely be slower. But weird that rotation has an effect on it. |
Hmm. After looking it up, it seems that many programs access storage more slowly since Android 11. Probably something to do with beefed up security for every interaction with storage. So this is likely more of an Android problem than a Termux problem. Still, I'll still happily accept advice, haha! Edit: I guess a good temporary solution is to move files to Termux's on directory with the "mv" command, to minimize programs' interactions with shared storage. This has worked very well for me, since mapillary_tools interacts with tens of thousands of small files multiple times while processing images. |
Scoped storage is currently not being applied to termux, however, android would still be doing extra processing internally to handle scoped storage itself, so performance impact could/would likely be there. Moving would depend on what you are actually doing. If you are repeatedly accessing the same file at different times or are in place editing, then the one move operation would be worth it for faster operations later. However, if there is only a one time read operation for processing a file, then moving it first would make that two operations so would be twice as slow. And you are right, slow external storage issues are not a termux issue, and can't likely be solved by it. Your rotation issue is weird currently, that can be looked into. |
Does touching the screen (scrolling a terminal or notification list) have similar effect as rotating screen? This seems like either misconfigured bus or cpu frequency scaling. This also can be done intentionally by manufacturer, so device reaching its full performance only in certain cases for battery power saving when user doesn't interact with the device. Never observed such behavior except on custom kernels with "powersaving" configs. |
Actually, you may be right, it might be a boost in CPU speed instead of storage speed, duh!. The interactive CPU governor for the kernel has settings like the input_boost for boosting CPU freq for a few milliseconds when touchscreen is touched. Not sure what android 11 (or his device) is using as the default governor these days but other governors have similar settings and this could be related. Rotating requires redrawing of activities, so a boost at that time would make sense, that's likely what's happening. |
Stock Samsung kernel uses |
Yeah, can't really guess without checking. There are also ARM big.LITTLE CPU cluster specific governors. On my LG G5, the big cores (0 and 1) are set to |
@arocoun My Galaxy device was also updated on Android 11 yesterday. Your |
My problem has nothing to do with an SD card, but rather the phone's internal storage (ie when you first open Termux, the directory you go to with I have no idea how to form an easily-reproduced situation where Termux interacts with internal storage thousands of times, then interacts with files in it's own directory thousands of times to compare the speed. (Probably something using the I use Termux / Linux command line for one thing, mapillary_tools. My experience beyond that is limited. Perhaps someone with more experience could come up with something. |
I do not wont to manage an account for mapillary. That's why the request a simple bash script like: Here all camera recordings of your device are copied in Termux |
Oh, thanks for clarifying what you meant by /sdcard! Like I said, I don't have much experience in Termux. Also, thanks of thinking so much about this! What you saw in the video was not files being copied. Rather, it was one small part of image processing, where the images are analyzed. Thousands of tiny descriptive files are created, and they are written to or read from hundreds of thousands of times. When these files are somewhere in shared storage, this process takes over 30 minutes. When these files are in Termux's directory, the process takes less than 2 minutes. Regarding your copying experiment: I'm thinking that if the slowdown for each file interaction is, say, 10 milliseconds, you wouldn't notice a slowdown copying 1000 image files. When I did the copying mentioned in my second post, I was copying almost 10,000 tiny files created by the aforementioned process -- so the per-interaction delay played a bigger role. When I copy 1000 image files now, I see almost no slowdown. |
Even though that shared storage (/sdcard, /storage/emulated/0) and Termux home directory are stored on same partition, there still some differences. As shared storage is mounted through overlay, certain performance penalty is expected, especially in random-access mode. |
Probably true there'll be some slow down in any case! But before Android 11, the slowdown wasn't noticeable. I now find myself wondering if mapillary_tools is uncommon in the number of file interactions it does, and if this problem is not likely to affect other folks. |
Probably because Android 11 implemented changes to the overlay filesystem (sdcardfs or how it is called) to meet the requirements of the further scoped storage enhancements. |
@xeffyr I can reproduce that! When I use in the example above
@arocoun is this the *first time, that you use mapillary on a _rotatable device? |
Hi, another interested but unskilled user here, @arocoun have you tried using <sdcard>/Android/data/<package name> ? For some time it's been the only directory on the sdcard usable by an app without specific permissions so might not be slowed by the system. (on Android 2.3.5 it's <sdcard>/.android/data/<package> I don't know when it changed) On my device it's /storage/emulated/0/Android/data/com.termux but Termux doesn't have permission to create the directory, you have to do it with a file manager (I was very surprised the setup routine hadn't created it). It's created with Owner: <package> & Group: sdcard_rw & permissions: rwxrwx--x so other apps can access it. |
The You can create the directory from termux by running |
Termux, like Android, is a steep learning curve. What does this command do, exactly? What would happen if I ran it now that I've created the directory manually? Would it do anything extra? |
@annihat It will create that directory again. Here is a Java function which does that: https://github.com/termux/termux-app/blob/master/app/src/main/java/com/termux/app/TermuxInstaller.java#L192 |
@xeffyr , @agnostic-apollo , thanks for that, it produces a useful-looking group of directories (including the root of the sdcard) & asks for permission to use them. It doesn't do anything with the one already-writable directory though. |
Welcome. The termux |
@agnostic-apollo , I like termux-setup-storage, I really do, but it's an additional feature & correctly so. My opinion is that the installer from the appstore should create <sdcard>/Android/data/com.termux & provide a link to it in $HOME because no permissions are needed & it can still be used if the user chooses not to grant them (special-use installations like the one in this thread wouldn't seem to need general permission when a specific permission is already available) |
This comment was marked as spam.
This comment was marked as spam.
The authorization can be granted with the Android Setup as well as |
Accessing And everybody doesn't need symlinks in their Automatically creating the |
Back to this Issue - with my 29+ check process I've got:
So I find (duplex) with |
Closing since likely an Android 11 OS issue. Users should use termux private app data directory |
This requires enough memory. My normale Termux usage would then fail to 2 of my 3 devices. With Target 28, however, it is never a real problem to save everything except |
Then go complain to android OS devs, although unlikely to be solved since its part of design now or use root to access
It's possible to detect the condition from within termux about storage permission being granted but still permission denied errors, but I don't know how to reproduce that situation to test it. Also don't know if that happens when targeting sdk 29+. If someone does, let me know. |
root would be nice to the check, but is not a solution for the IP Obj on Android (Checks with 29+ Artifakt). In AVD I use one virtual sdcard ( The updated-flavor Branch by @fornwall generates two |
Problem description
An image processing and uploading program I use, mapillary_tools, has started running much slower on Termux -- at less than 1/10 normal speed.
I suspect it has something to with the update to Android 11, and how Android allocates resources to Termux. Termux actually SPEEDS UP DRAMATICALLY for a second while my phone is adjusting to being rotated!
Video of this odd behavior: https://youtu.be/O5wTd0V7610
I've tried resetting my phone, reinstalling Termux, reinstalling mapillary_tools, and making sure battery optimization is off for Termux. After taking WAY too long searching, I haven't found that anyone else has had this problem.
Steps to reproduce
Not sure what lead to this.
Expected behavior
Termux and any programs on it run at normal speeds.
Additional information
The text was updated successfully, but these errors were encountered: