The memory consists of a large array of words or bytes, each with its own address. The CPU fetches instructions from memory. The instruction is then decoded and may cause operands to be fetched from memory. After the instruction has been executed on the operands, results may be stored back in memory. Let’s understand more about memory management in operating system.
Logical and Physical Address
Logical Address: An address generated by the CPU is called logical address. The set of all logical addresses generated by a program is logical address space. The logical address is also referred as virtual address.
Physical Address: The actual available memory in memory unit is called physical address. The set of all physical addresses corresponding to these logical addresses is a physical address space.
The run-time mapping from virtual to physical addresses is done by a hardware device called the memory-management unit (MMU). The compile-time and load-time address-binding methods generate identical logical and physical addresses.
With dynamic loading, a routine/process is not loaded until it is called. All routines are kept on disk in a re-locatable load format. Only the routine/process in use is loaded into the memory. The advantage of dynamic loading is that an unused routine is never loaded.
With dynamic linking, frequently used routines/processes are not linked into the program. Instead, just a stub is linked. When the routine is called, the stub checks to see if the real routine is loaded (it may have been loaded by another program). If not loaded, load it. If already loaded, share it. The advantage of dynamic linking is that it saves space.
A process must be in memory to be executed. A process, however, can be swapped temporarily out of memory to a backing store and then brought back into memory for continued execution. This process is called swapping.
Contiguous Memory Allocation
The main memory must accommodate both the operating system and the various user processes. Contiguous Memory Allocation is the memory allocation technique in which each process is allocated a single contiguous section of memory.
Fragmentation is phenomenon that occurs when there are many small free memory blocks available in memory but they are not big enough to be allocated to a process. It is of two types:
- External Fragmentation: In this type of fragmentation, the total memory space exists to satisfy a request but it is not contiguous. It can be solved through technique named compaction.
- Internal Fragmentation: In this type of fragmentation, the allocated memory may be slightly larger than requested memory
Paging is a memory-management scheme that permits the physical address space of a process to be noncontiguous. In this technique, Logical address space of a process can be noncontiguous. The process is allocated physical memory whenever it is available. Paging is used for faster access of data.
In this technique, the physical memory is divided into fixed-sized blocks called frames. The logical memory into blocks of same size called pages.
The user’s view of memory is not the same as the actual physical memory. Segmentation is a memory-management scheme that supports user view of memory. A program is a collection of segments. A segment is a logical unit such as:
- Main program
- Local variables
- Global variables
- Common block
- Symbol table