3 ms·
The question is only semi-specific and the result depends on a ton of variables, like: which libc do you use; which kernel (maybe a patched linux kernel like on
by temac 7y ago
The question is only semi-specific and the result depends on a ton of variables, like: which libc do you use; which kernel (maybe a patched linux kernel like on Android, don't know if they change anything regarding memory alloc though) kernel configuration do you use (esp. in regard with overcommit), do you have any other additional tuning, etc.
> does it actually create 1 GiB worth of swap pages
Create? No; probably never.
> does it mprotect the address range and create the pages when you actually touch them like mmap does?
Both mmap and mprotect are syscalls, and syscalls do not (directly) call other syscalls. So mmap does not do that. And malloc can't because it does not run anymore after it has returned.
On top of all of that, malloc(insanely_big_value) can still fail immediately by returning NULL even if you have overcommit activated. Granted, 1GB is probably never an "insanely_big_value"? Not even sure on 32 bits systems though.
- acqq 7y agoAsking "in Linux" obviously didn't mean "on Android" and also not "in Linux after I patch the kernel configuration." The question was clear, the answer on the site was clear, by the answer here to which I responded was by somebody who I suspect simply hasn't read what was written there.