Memory Schemes - VRIG-Ritsec/Resources GitHub Wiki
Physical Memory
The most basic and unconstrained scheme is that of physical memory. In physical memory, the address corresponds to the byte that you trying to access.
This is to say that suppose you have 1 KiB (1024 bytes) of memory/RAM. Then if you access address 0
then you get the 0th byte of RAM. Likewise, if you access address 0x200
then you get 512th byte of RAM.
The main issue with this scheme arises when you start to have multiple processes. Suppose you have 1 KiB of memory and process A occupies the address range 0x0..0xff
and process B occupies the address range 0x100..0x1ff
. In this scheme, process A can simply access process B's memory and vice versa without any problem at all. The main reason for this is that physical memory has no permission schemes or any way to partition memory between two processes. The only hope is that process A nor B are not malicious/buggy and won't access each other's memory.
Segmentation
The first solution to this scheme is segmentation. Segmentation involves defining a base and a limit for each process that defines what they can access. If a process accesses outside its segment, it is delivered a general-protection (#GP) fault that kills it.
In the previous scheme, if process A exists between the range 0x0..0xff
then its base
would be 0x0
and its limit would be 0xff
. Likewise, if process B exists between the range 0x100..0x1ff
then its base would be 0x100
and its limit would be 0xff
. The valid access range for a segment would be base..base+limit
as an inclusive range.
The main issue with segmentation arises with fragmentation.
Consider we have our 1024 (0x400) bytes of memory with process A occupying 0x0..0xff
, process B occupying 0x100..0x17f
, process C occupying 0x200..0x2ff
and process D occupying 0x300..0x37f
. Suppose we want to introduce some process E that needs 0x100
contiguous bytes. In this scheme of segmentation, this is not possible. Even though we have 0x100
bytes of memory total remaining on our system (0x180..0x1ff
and 0x380..0x3ff
), we cannot accommodate 0x100
bytes of contiguous memory and thus we cannot run process E on the system. This problem is common in segmentation and is known as fragmentation.
Virtual Memory/Paging
The modern scheme used is virtual memory/paging. This system was devised to solve the fragmentation problem