There is something about AS in Linux(2)
AS = ADDRESS SPACE
Each process is assigned by the OS a physical memory region (a physical address space).
0- Init
Look at this visual : two processes A and B nicely living together in the memory
The oversimplified model I provided (part1) is based on this simple concept: The OS with a full support from the hardware could access the process physical space using a data structure called "process table" by translating the virtual address to corresponding physical address. The processor is supposed to have two registers Base register and Bound registers :
II- Two visions
Note: green spaces are memory free spaces
OS "sees" the real memory region occupied by the process A [8K,12K]. The process A "thinks" that it is living in the region [0K,4K].
With the oversimplified model using base and bound registers: If the OS decided to relocate the process A, the process A's free spaces will be relocated with it :
So, we conclude that this model is NOT flexible enough and wasteful ; During relocation, there is no need to relocate the free spaces ( green region).
The next model is called the segmentation model ( you know the infamous error segmentation fault).
III- Segmentation model
With the support of the HW, the OS decompose Process A's memory into three logical segments:
- Code segment
- Heap Segment
- Stack segment
Each segment is bounded to a pair of Base and Bound registers.So, We will have 3 pairs of base and bound registers:
Suppose that in your program A (Process A) you want to access the Virtual address 0x00F. How the OS would manage to find out the segment containing this address?
The virtual address in the segmentation model is composed of two parts:
0x||segment address||Cell Address within the segment||.
Suppose the segment address is coded on two bits. let's decompose 0x00F:
0x ||00||0000 1111||
00 = Code segment, 01= Heap Segment, 10= Stack segment
IV- Procedure
VA= Virtual Address, PA= Physical Address
Details of "algorithm" used by the processor and hardware to locate the address 0x00F:
0x ||00||0000 1111||
VA(code segment)=00 =>With the hep of Process Table=> PA(code segment)=12K
0000 1111 is the address of the cell located within the Code Segment
VA(cell) =0000 1111 => PA(cell) = PA(code segment) + offset= 12K + 0000 1111
Then the processor will test if PA(cell) is less than 13K. If the PA(cell) is not within the authorized range,the address is illegal, in this case asegmentation fault will be raised and the offended process is killed.
Happy AS