Is demand paging enabled in linux kernels of Android?

Greg Freemyer greg.freemyer at gmail.com
Wed Mar 19 14:53:51 EDT 2014


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 at 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 at gmail.com> wrote:
>>
>> Hi Sandeep,
>>
>>
>> On Wed, Mar 19, 2014 at 4:48 AM, manty kuma <mantykuma at 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 at kernelnewbies.org
> http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
>



More information about the Kernelnewbies mailing list