Closed Bug 1324574 Opened 7 years ago Closed 3 years ago

Firefox for Android can reliably allocate only around 512MB of typed array memory on a 4GB phone

Categories

(Firefox for Android Graveyard :: General, defect)

ARM
Android
defect
Not set
normal

Tracking

(Not tracked)

RESOLVED INCOMPLETE

People

(Reporter: jujjyl, Unassigned)

Details

STR:

1. Reboot your phone
2. After booting, make sure not to start any other applications/activities, and launch Firefox.
3. With fresh Firefox with no other tabs open, visit http://clb.demon.fi/bugs/largest_allocatable_typed_array.html

The page tries to allocate as large typed array as possible, and reports the results.

On my Samsung Galaxy S7 Edge, which has 4GB of RAM, most of the time the page only succeeds in allocating a typed array of 512MB in size. Repeating the test sequence multiple times, I got 1105 MB once, and 768MB a couple of times, but 512MB seems to be the most common size.

These sizes are quite small compared to the phone having 4GB of physical RAM total. Running the same page on 32-bit Firefox on desktop is able to attain 2032MB (the maximum amount that a typed array can currently be for asm.js/wasm heap size)

Looking at available memory in adb shell via "cat /proc/meminfo" after rebooting the phone but before step 2 gives

MemAvailable:    2139904 kB

which suggests that there should be plenty of memory that is not in use. (Even though Android doesn't swap/page to disk, Android does have virtual memory addressing, so all physical memory should theoretically be contiguously addressable in a fresh process?)

Is there something that could be done to improve Firefox for Android to reliably get more than 512MB of memory at boot on these kinds of very high end (4GB+) phones?
This inquiry relates to the thread from bug 1323639 with the difference of aiming for what our "best effort" scenario could be, after a fresh phone boot in a fresh Firefox instance with only one tab open, in the absence of any real process isolation that bug 1323639 is asking for.
You're probably hitting a bunch of systemic limits. (Unlike the Dalvik heap, which is limited to as little as 16MB, Android doesn't really impose specific limits on native allocations.)

Remember there are two heaps on Android: Dalvik/ART's heap and 'native'. The Dalvik heap is probably a big contiguous slab of memory, and it might well be getting in your way. I wouldn't be surprised to see some of the device's memory also reserved for graphics.

Calling

https://developer.android.com/reference/android/app/ActivityManager.html#getProcessMemoryInfo(int[])

will give you info on the native and dalvik heaps.

More: 

http://stackoverflow.com/questions/2298208/how-do-i-discover-memory-usage-of-my-application-in-android
You might want to try flipping the largeHeap manifest flag. I'm not optimistic, but it's worth trying.

https://developer.android.com/guide/topics/manifest/application-element.html#largeHeap
This is likely part of some limitations of 32-bit processes on Android (or just Linux). We ran into some similar issues with address space that you're having in bug 1323639 over in bug 1164027. The gist is that the lower 1GB is reserved for brk()-style allocations (like a caveman), and the upper 1GB is reserved by the kernel. That leaves you just 2GB of address space, and the Android zygote process has a bunch of stuff mapped, leaving you with something like 1.5GB. With all of the resources, libraries, etc, that gets eaten up fast.

I think the best solution for this kind of thing is to just build a 64-bit Gecko for Android.
We have completed our launch of our new Firefox on Android. The development of the new versions use GitHub for issue tracking. If the bug report still reproduces in a current version of [Firefox on Android nightly](https://play.google.com/store/apps/details?id=org.mozilla.fenix) an issue can be reported at the [Fenix GitHub project](https://github.com/mozilla-mobile/fenix/). If you want to discuss your report please use [Mozilla's chat](https://wiki.mozilla.org/Matrix#Connect_to_Matrix) server https://chat.mozilla.org and join the [#fenix](https://chat.mozilla.org/#/room/#fenix:mozilla.org) channel.
Status: NEW → RESOLVED
Closed: 3 years ago
Resolution: --- → INCOMPLETE
Product: Firefox for Android → Firefox for Android Graveyard
You need to log in before you can comment on or make changes to this bug.