I want to mmap a larger region of memory which I only expect to use a small portion of. The memory that is used needs read and write permissions.
Is there are difference between the following two methods for mmaping the virtual memory:
mmap(0, size, PROT_NONE, MAP_ANONYMOUS | MAP_PRIVATE | MAP_NORESERVE, (-1), 0)
and then using
mprotect(address, length, PROT_READ | PROT_WRITE)
when I need a page
versus just mmaping the entire region with PROT_READ | PROT_WRITE permissions from the start i.e
mmap(0, size, PROT_READ | PROT_WRITE, MAP_ANONYMOUS | MAP_PRIVATE | MAP_NORESERVE, (-1), 0)
edit for better context into my platform:
CPU model name : Intel(R) Core(TM) i7-8565U CPU @ 1.80GHz
Kernel Version : 5.3.0-46-generic #38~18.04.1-Ubuntu SMP