Memory management is one of the most important functions of an operating system. The working of a computer system majorly depends on two components: Memory and CPU.
As far as the memory of a system is concerned there are three important criteria which an operating system has to take care.
Practically we cannot have large memory size with less access time and less per unit cost because more search space means more time it takes to search the data. This is the reason we do not have a single type of memory in the system, we use memory hierarchy. Memory hierarchy of the system manages to fulfil the above-mentioned criteria with the help of a concept called locality of reference.
CPU can directly access main memory and registers. Because, instructions only take main memory address and registers as operands, therefore the data or any instructions must be in direct access device to be executed. CPU can access registers with one clock cycle and main memory access requires many clock cycles. Hence, cache is used to increase the access rate.
Another important task is to ensure the protection of one process data from another process. This protection is provided by the hardware. One way to do this is with the help of base register and limit register. The user process cannot access the memory address below the address specified in the limit register. The base register holds the starting physical address of the process and limit register holds the range of all addresses. For example if the base register holds 20000 and limit register is 35000, then the process can access all addresses from 20000 to 55000 (both inclusive).
The CPU hardware compares each address generated by the CPU with the value of the base register. If it is greater then or equal to the value of base register then it checks if the generated address is less than (base + limit register) value. If both the conditions are true then memory access is allowed otherwise not. (Refer PPT below)
For the CPU to execute a process, the process must be loaded into the main memory. There are two different types of address in the memory, logical address (generated by CPU) and physical address (address in the main memory). User deals with only logical addresses, therefore address translation ( or address binding) from logical to physical address must be done to locate the process in the main memory.
The address binding is done in the following ways:
Logical and Physical Address
Logical Address – An address generated by the CPU is referred to as the logical address. The set of all logical addresses comprise the Logical Address Space.
Physical Address – The address seen by the memory unit or the actual address of the physical memory (RAM) is referred to as the physical address. The set of all physical addresses comprise the Physical Address Space.
There are different ways of mapping a logical address into a physical address. One such method is as shown in Figure 3 where the value of the relocation register is added to the logical address in order to generate the physical address.
Swapping is a mechanism in which a process can be swapped temporarily out of main memory (or move) to secondary storage (disk) and make that memory available for other processes. At some later time, the system swaps back the process from the secondary storage to main memory.
Swapping is used in priority-based scheduling algorithms in order to make space for a higher priority process.
Question-Where to swap in the process?
Answer-The swapped out process can be swap back in the same physical address or different physical address. Normally a previously swapped out process will be swapped back into the same memory space, however, it depends on the type address binding method. If the address binding method is execution time-binding then a process can be swapped to a different memory space as physical address are computed during execution time.
The above discussion has been summarized in the form of a PPT with animations below.
Note: Click within the slide area for animations. Clicking on the “next” slide button will not display any animation