can same physical address be allocated to different virtual address in different processes?

Viewed 42

In Linux with 4KB page size, we have two processes A & B. If process A allocated 1KB and process B allocated 1KB, is there any chance that kernel will map physical address X of size 4k, where first 1k byte of X to process A and 2nd 1k byte of X to process B ? or kernel will use different address Y to either of these processes ?

Is this a valid scenario ?

1 Answers

is there any chance that kernel will map physical address X of size 4k, where first 1k byte of X to process A and 2nd 1k byte of X to process B ?

No. The page size is the smallest allocation size, so the kernel cannot allocate less than 4kB of memory. If a process requests less than that amount of memory, the kernel rounds it up to the nearest PAGE_SIZE in the case of both mmap(2) and brk(2).

or kernel will use different address Y to either of these processes ?

Each process will receive one separate physical page. They could have the same virtual address, but that doesn't matter since they're independent processes with their own page tables.

Related