Question

I have doubt with respect to the address space. I have thought that the RAM if 4 GB is split up into 2 halves for kernel space(1GB) and user space(3GB).

1] Does RAM also maintains stack,heap,code and data section as hard disk.

2] Won't the process running is not given a boundary where the stack, data, code and heap have to grow in RAM.

3] My thought was that the stack,heap,code and data segment all be in the consecutive address space given to the process at the time of process creation.

4] How does the CPU takes the correct address of the process to execute, as the processes are not contiguous in physical memory.

enter image description here

Was it helpful?

Solution

No, only the virtual memory address space is split in two. Physical memory, the RAM in the machine, contains an entirely random collection of blocks that map to virtual memory addresses. From both operating system pages and user program pages. Much like the image shows although it is a bit misleading about showing the OS pages at the bottom.

That mapping constantly changes, a page fault is the essential mechanism to get a virtual memory page mapped to RAM. Which is triggered when a program accesses a virtual memory page that isn't present in RAM yet. As needed, RAM pages may be unmapped to make room, their content is either discarded or written to the pagefile. Code is usually discardable, it can be read back from the executable file, data usually isn't.

Some pages in RAM are special, they contain code and data that's used by drivers. They are page-locked. Required when the driver handles device interrupts and the code/data used by the interrupt handler must be present in RAM to allow the interrupt to be handled, can't afford a page fault at such a critical time. The probable reason the image was drawn like that.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top