Is demand paging enabled in linux kernels of Android?
Hi, Suppose I have an executable of size 60MB and I want to execute it on android(ARM), will 60MB be allocated to load the code onto the RAM? I remember studying about demand paging in Linux kernel. Is it relevant here? If yes, is it implemented in Linux kernels used in Android? Also, is there a config with which i can enable or disable the configs. I posted the same on SO. Answer it either place. Thank you. http://stackoverflow.com/questions/22499031/is-demand-paging-implemented-in-... BR, Sandeep Kumar
Hi Sandeep, On Wed, Mar 19, 2014 at 4:48 AM, manty kuma <mantykuma@gmail.com> wrote:
Hi,
Suppose I have an executable of size 60MB and I want to execute it on android(ARM), will 60MB be allocated to load the code onto the RAM?
I remember studying about demand paging in Linux kernel. Is it relevant here? If yes, is it implemented in Linux kernels used in Android?
All executables are brought into memory through demand paging. So the kernel will only load those parts of the executable that are actually executed. Swap isn't typically enabled by default though (I don't recall the exact config options). -- Dave Hylands Shuswap, BC, Canada http://www.davehylands.com
Thanks david. So my next question was that is it enabled in linux kernel that android uses. How do i confirm it? On Thursday, March 20, 2014, Dave Hylands <dhylands@gmail.com> wrote:
Hi Sandeep,
On Wed, Mar 19, 2014 at 4:48 AM, manty kuma <mantykuma@gmail.com<javascript:_e(%7B%7D,'cvml','mantykuma@gmail.com');>> wrote:
Hi,
Suppose I have an executable of size 60MB and I want to execute it on android(ARM), will 60MB be allocated to load the code onto the RAM?
I remember studying about demand paging in Linux kernel. Is it relevant here? If yes, is it implemented in Linux kernels used in Android?
All executables are brought into memory through demand paging. So the kernel will only load those parts of the executable that are actually executed.
Swap isn't typically enabled by default though (I don't recall the exact config options).
-- Dave Hylands Shuswap, BC, Canada http://www.davehylands.com
Hi Dave, Very sorry to mispell your name. Apolodies. Sandeep On Thursday, March 20, 2014, manty kuma <mantykuma@gmail.com> wrote:
Thanks david. So my next question was that is it enabled in linux kernel that android uses. How do i confirm it?
On Thursday, March 20, 2014, Dave Hylands <dhylands@gmail.com<javascript:_e(%7B%7D,'cvml','dhylands@gmail.com');>> wrote:
Hi Sandeep,
On Wed, Mar 19, 2014 at 4:48 AM, manty kuma <mantykuma@gmail.com> wrote:
Hi,
Suppose I have an executable of size 60MB and I want to execute it on android(ARM), will 60MB be allocated to load the code onto the RAM?
I remember studying about demand paging in Linux kernel. Is it relevant here? If yes, is it implemented in Linux kernels used in Android?
All executables are brought into memory through demand paging. So the kernel will only load those parts of the executable that are actually executed.
Swap isn't typically enabled by default though (I don't recall the exact config options).
-- Dave Hylands Shuswap, BC, Canada http://www.davehylands.com
Hi Sandeep, On Wed, Mar 19, 2014 at 9:06 AM, manty kuma <mantykuma@gmail.com> wrote:
Thanks david. So my next question was that is it enabled in linux kernel
that android uses. How do i confirm it? Perhaps put a sleep(30) right at the start of main() Run your program. Look at /proc/PID/status Then when the sleep is finished and your program continues executing, look at /proc/PID/status again To do the test properly you'd probably need to generate some code which has lots of no-ops (maybe a megabytes worth), and look at /proc/PID/status before and after executing that function. I think that as more code gets paged in you'll see VmRSS increase. IIRC VmRSS also includes your heap and stack. -- Dave Hylands Shuswap, BC, Canada http://www.davehylands.com
Manty, I don't think there is a way in the linux kernel to disable "demand paging" at program initial execution, so there would be no pre-defined ABI for testing if it is enabled. Swap is a different matter, but it only applies to data pages or other "dirty" pages. The executable pages that get demand paged in would typically never get dirty, so they would never need to be swapped out. I'm not a MM expert, but I assume that if there is enough memory pressure, the "clean" executable memory pages just get discarded to free up ram. If for some reason, your running an app that modifies the executable pages, then those would not be discarded until program termination. == From userspace== An app can force the space to be reserved at application startup: mlockall(MCL_CURRENT); mlockall(MCL_FUTURE); Should do it. The first call locks all the previously demand_paged pages in place. I think the second call reserves pages for the entire executable and any known data pages. Note from the man page "If MCL_FUTURE has been specified, then a later system call (e.g., mmap(2), sbrk(2), malloc(3)), may fail if it would cause the number of locked bytes to exceed the permitted maximum (see below). In the same circumstances, stack growth may likewise fail: the kernel will deny stack expansion and deliver a SIGSEGV signal to the process." I've never used mlockall(MCL_FUTURE) so I can't say how easy or hard it is to get right. I also don't think it actually demand_pages in all the potential pages. I think it just reserves space for them if they are needed. Greg -- Greg Freemyer On Wed, Mar 19, 2014 at 12:06 PM, manty kuma <mantykuma@gmail.com> wrote:
Thanks david. So my next question was that is it enabled in linux kernel that android uses. How do i confirm it?
On Thursday, March 20, 2014, Dave Hylands <dhylands@gmail.com> wrote:
Hi Sandeep,
On Wed, Mar 19, 2014 at 4:48 AM, manty kuma <mantykuma@gmail.com> wrote:
Hi,
Suppose I have an executable of size 60MB and I want to execute it on android(ARM), will 60MB be allocated to load the code onto the RAM?
I remember studying about demand paging in Linux kernel. Is it relevant here? If yes, is it implemented in Linux kernels used in Android?
All executables are brought into memory through demand paging. So the kernel will only load those parts of the executable that are actually executed.
Swap isn't typically enabled by default though (I don't recall the exact config options).
-- Dave Hylands Shuswap, BC, Canada http://www.davehylands.com
_______________________________________________ Kernelnewbies mailing list Kernelnewbies@kernelnewbies.org http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
participants (3)
-
Dave Hylands -
Greg Freemyer -
manty kuma