Closed Bug 656941 Opened 10 years ago Closed 9 years ago
lazily commit stack memory on !Windows
638 bytes, text/plain
Currently we only lazily commit stack memory on Windows (using VirtualAlloc's MEM_RESERVE/MEM_COMMIT options). It seems possible to also lazily commit memory on Posix by passing PROT_NONE to mmap() (to reserve the address space) and using mprotect() to commit. To support fun.apply of large arrays (comparable to the other JS engines), the max JS stack size is 4MB (per JS-running thread), so this could mean non-trivial memory savings. This bug should also verify that mmap(PROT_NONE) does actually reduce reported virtual memory usage on Linux (desktop/Android) and OSX.
Well, bad news. I found this advice on stack overflow and it appears to not be valid for OS X or Android. I wrote the attached test (please feel free to double check me on this) and found that VmSize (from /proc/pid/status) increased after mmap(PROT_NONE) (without mprotect(PROT_READ | PROT_WRITE)). IIUC, that means that our "explicit allocation" will not benefit from this bug: once we mmap it, it counts against us. As already expected, RSS does *not* include the 100MB allocation, even after mprotect(PROT_READ | PROT_WRITE). (To verify, it does increase after the final loop which touches each location.) Thus, the large stack allocations *are* hurting our VM size, but *not* hurting RSS which is what, FWIW, we really care about on mobile.
WONTFIX'ing. Please feel free to reopen with any good ideas (hopefully with measurements to confirm).
Status: ASSIGNED → RESOLVED
Closed: 9 years ago
Resolution: --- → WONTFIX
For anyone who wants to test this, I highly recommend finding your own command line, as the one that I found may be doing horrible, incorrect things. That being said, this is the command line that I used to build the test: /home/mrosenberg/android/android-ndk-r6/toolchains/arm-linux-androideabi-4.4.3/prebuilt/linux-x86/bin/arm-linux-androideabi-gcc ./test.c -o test.exe -I/home/mrosenberg/android/android-ndk-r6/platforms/android-5/arch-arm//usr/include -L/home/mrosenberg/android/android-ndk-r6/platforms/android-9/arch-arm/usr/lib --sysroot=/home/mrosenberg/android/android-ndk-r6/platforms/android-9/arch-arm -rpath-link=/home/mrosenberg/android/android-ndk-r6/platforms/android-9/arch-arm/usr/lib -mandroid
You need to log in before you can comment on or make changes to this bug.