Memory - Address, Contiguous allocation, MMU
Memory #
Memory management is about how to run multiple processes together in a memory space that has physical addresses. So, what is a physical address? In short, it's a location in memory space.
We've often heard phrases like "it's eating up memory" or "how much memory does it have?", and the familiar term RAM is also related to memory. Abstractly, one might think that when a program is executed, the data required for its execution is loaded into memory and then run.
Program execution means that the process's context is loaded into memory and executed by the CPU.
Address Binding #
Since the CPU cannot determine the actual memory address using only logical addresses to execute a process's tasks, a mapping operation between logical addresses and the physical addresses mentioned above is required, and this operation is called address binding.
Logical Address? The address system virtually generated by the CPU is called a logical address. This logical address is mapped to a physical address for use, and the device that maps logical addresses to physical addresses here is the MMU. Logical addresses are an essential concept due to benefits such as abstraction, memory protection, and virtual memory.
Returning to the topic, there are three address binding methods as follows:
- Compile-time binding
- Load-time binding
- Execution-time (runtime) binding
The difference between these three address binding methods depends on when the physical address is determined.

Compile Time Binding #
Compile-time binding is, as the name suggests, an address binding method where the physical memory address is determined at compile time.
The compilation process is the process of creating object code with a compiler or assembler.
To put the term "compile time" simply, you can think of the address used internally by the program—that is, the logical address—as being the same as the physical address.
This method is not widely used. The reason is that the computers we use today do not run only one process.
If we use physical addresses without knowing the current computer's state, we can't simply overwrite memory occupied by another running process.
It's essentially a method of "loading this process into memory!", which is impractical.
Load Time Binding #
Load-time binding determines physical addresses when a process begins execution.
It uses the logical addresses briefly explained above, where the memory addresses used within the process (relative addresses, i.e., logical addresses) starting from address 0 are mapped to physical addresses according to where the entire process is loaded.
So, what problems does load-time binding have?
Every time a process is executed, physical addresses are mapped. If a new mapping is performed every time it changes, it causes a problem where memory loading takes a long time. This is because there are many segments storing code instructions when a program runs, and each one needs to be calculated every time it's executed.
Runtime binding emerged to compensate for the shortcomings of the two binding methods above.
Runtime Binding #
As the name suggests, it's a binding method where physical addresses can change even after a program has started running.
In runtime binding, every time the CPU references an address, it checks the binding using an address mapping table to determine where in physical memory that data is located. Also, as explained in load-time binding above, when there are many segments and calculations need to be performed every time each one is executed, hardware, not software, performs the task, and this hardware is the MMU.
Contiguous allocation #
Before diving into MMU, let's briefly look at memory organization and partitioning methods.
Main memory must be able to run not only the operating system but also multiple processes.
Memory is generally divided into two parts: one for the operating system loaded in memory, and one for user processes.
Therefore, to use a computer effectively, main memory must be partitioned and allocated in the most efficient way.
Among these methods, we will explore contiguous memory allocation, which is not used much nowadays.
The operating system can be located at either end of memory, but it is usually located in low memory. The reason for this is the interrupt vector.
Interrupt vectors are mostly located in low memory, so the operating system is usually placed in low memory. Therefore, we will proceed with the explanation assuming the operating system is located in low memory.
Since it is usually efficient for multiple processes to be loaded into memory simultaneously, we continuously ponder how to efficiently allocate memory to processes waiting in the input queue. In a contiguous memory allocation system like the one described above, a process occupies a contiguous block of memory.
To summarize, contiguous memory allocation means that if logical addresses are contiguous, then physical addresses are also allocated contiguously.
However, it is not frequently used nowadays due to fragmentation issues. This is also why paging was introduced.
MMU #
As mentioned above, a process's logical address is mapped to a physical address space by certain hardware at execution time. At this point, hardware called a relocation register and a limit register are used for mapping logical addresses to physical addresses. An MMU register, integrated within the CPU core, adds the values of these two registers to specify the physical address space from the logical address.

In the MMU method, address binding is performed using the base register value + logical address value.
What if that value exceeds the address range of the process? There's a possibility that the process might access an area it shouldn't. To prevent such problems, a Limit Register with memory protection is used.
The limit register stores the maximum logical address value. Every time the CPU requests a logical address, it checks if the value is smaller than the limit register's value. If it's larger, it triggers a memory protection fault.
So, we said that each process has its own unique address space, and logical address values are allocated independently for each process. For example, both Process A and Process B could have logical address 100. In that case, the actual physical address mapped to logical address 100 for Process A would be different from the actual physical address mapped to logical address 100 for Process B.
Therefore, in the MMU technique, every time a context switch occurs, the value of the relocation register must be reset to the value corresponding to the new process.