Module IV Memory Organization
Virtual Memory In a virtual memory system, the OS manages the long programs. User programs can be larger than the physical main memory (2GB). OS stores the entire program on a hard disk whose capacity is much larger than the physical memory size.
Virtual Memory At a given time, only some portions of the program are brought into the main memory from the hard disk. As and when needed, a portion which is not in main memory is taken from the hard disk, and at the same time, a portion of the program which is present is released out of the main memory and stored on the hard disk. This process is known as swapping. In a virtual memory system, when a program is executed, swapping is performed as per the requirement on a continuous basis.
Virtual Memory
Virtual Memory The CPU fetches instruction and data from the main memory. Whenever the required instruction or data is not present in main memory, the hardware raises an interrupt known as virtual memory interrupt or page fault. In response, the operating system loads a section of the program (containing the required instruction or data) from the hard disk drive to the main memory. The page fault occur within an instruction cycle. After the page fault interrupt is serviced, the CPU will continue processing the partially executed instruction.
Virtual Memory
Advantages of Virtual Memory Program size is not limited by physical memory size. User do not have to do memory allocation. Main memory allocation is done automatically according to the demands of the program. Program can be loaded in any area of physical memory It allows processes to share files easily.
Virtual Memory It is implemented using two techniques: Segmentation Paging
Segmentation This memory management technique supports user’s view of memory.
User’s view of a program
Segmentation Users prefer to view memory as a collection of variable-sized segments : Code : to store program Data : variables defined by the code are stored Stack : Used by sub-routines and interrupt service routines to hold temporary data and addresses.
Segmentation All applications need to be loaded into main memory before they can be executed. In order to do so, a temporary 'segment' is created by the memory manager
A typical segment
Segmentation There can be many segments in memory at the same time. Each one is a separate process or application and each may be a different size
Segmentation Segmentation allows the OS to do is to place each one of those segments in different parts of physical memory.
Segmentation
Segmentation In segmentation, a memory reference includes a value that identifies a segment (segment number) and an offset within that segment. A segment is associated with a flag indicating whether it is present in main memory or not information indicating where the segment is located in memory(the address of the first location in the segment)(base address) has a set of permissions Length
Segmentation If the segment is not present in main memory, an exception is raised and the OS will read the segment into memory from secondary storage.
Segmentation If a reference to a location within a segment is made, Physical address = base address +offset A memory management unit (MMU) is responsible for translating a segment and offset (logical address) into a memory address, checking to make sure the translation can be done and that the reference to that segment and offset is permitted.
Segmentation The mapping is done with help of segment table. Logical address consists of two parts: a segment number s, and offset d s is used as an index to the segment table. Each entry of segment table has base and limits. base contains starting physical address where resides in memory limit specifies length of the segments d must be between 0 and the segment limit. If not, it traps to addressing error If offset is valid, it is added to base to produce physical address
Segmentation: Hardware
Example