Top Banner
VIRTUAL MEMORY and MEMORY MANAGEMENT REQUIREMENT Presented by: ANKIT SHARMA NITESH PANDEY MANISH KUMAR
32
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript

PowerPoint Presentation

VIRTUAL MEMORY andMEMORY MANAGEMENT REQUIREMENTPresented by:ANKIT SHARMANITESH PANDEYMANISH KUMARWhat isAn imaginary memory area supported by some operating system.(e.g Windows but not DOS)Virtual memory is an alternate set of memory addresses. Programs use these virtual addresses rather than real addresses to store instructions and data.When the program is actually executed, the virtual addresses are converted into real memory addresses.

HISTORYvirtual memory was developed in approximately 1959 1962, at the University of Manchester for the Atlas Computer, completed in 1962.

In 1961, Burroughs released the B5000, the first commercial computer with virtual memory.

WHY WE NEED IT.. An operating system needs 120mb of memory in order to hold all the running programs ,but there is currently 50mb of available physical memory stored on the RAM chip so at that situation what the processer does ?

AnswerAt that time the O.S will then set up the 120 mb of virtual memory and will use a program called the VMM to manage that 120MB. The vmm will create a file on hard disk that 70mb in size of account for the extra memory that is needed OBJECT..Multiple programs can be implemented efficiently.Enlarge the address space, the set of addresses a program can utilize.Virtual memory might contain twice as many addresses as main memory.

CPU0:1:N-1:MemoryA System with Physical Memory OnlyExamples:most Cray machines, early PCs, nearly all embedded systems, etc.Addresses generated by the CPU point directly to bytes in physical memoryPhysicalAddressesA System with Virtual MemoryExamples:workstations, servers, modern PCs, etc.Address Translation: the hardware converts virtual addresses into physical addresses via an OS-managed lookup table (page table)CPU0:1:N-1:Memory0:1:P-1:Page TableDiskVirtualAddressesPhysicalAddressesImplementation of VMVirtual memory can be implemented via:Demand paging Demand segmentation

pagingThe VMM create a file on hard disk thats holds the extra memory that is needed by the O.S which is our case in 70 MB in size this file is called a paging fileWhenever the O.S need a block of memory that is not in the real memory ,the VMM takes the block of memory from the paging file and moved it into the real memory this process is called a paging and the block of memory that are swapped is called a page The number of frame denotes the no of page that can be held in ram at any given time

The memory is partitioned into equal fixed size chunks that are relatively small. This chunk of memory is known as frames or page frames.Each process is also divided into small fixed chunks of same size. The chunks of a program is known as pages.A page of a program could be assigned to available page frame910Page table..Each process has its own page tableEach page table entry contains the frame number of the corresponding page in main memoryA bit is needed to indicate whether the page is in main memory or not

Valid-Invalid BitWith each page table entry a validinvalid bit is associated(v in-memory, i not-in-memory)Initially validinvalid bit is set to i on all entriesExample of a page table snapshot:

During address translation, if validinvalid bit in page table entry is I page faultvvvviii.Frame #valid-invalid bitpage tablePage fault

If the vailed bit is 1, then the virtual page is in RAM ,and you can get the physical page for the PTE this is called a page HITIf the vailed bit is 0, then the virtual page is not in RAM ,this means we must get the disk page corresponding to the physical page from disk and place it into a page in RAM this is called a page fault

Steps in Handling a Page Fault

Performance of Demand PagingPage Fault Rate 0 p 1.0if p = 0 no page faults if p = 1, every reference is a fault

Effective Access Time (EAT)EAT = (1 p) x memory access+ p (page fault overhead + swap page out + swap page in + restart overhead ) EAT=(1-p) x memory access + p(avg. fault service time)Demand Paging ExampleMemory access time = 200 nanoseconds

Average page-fault service time = 8 milliseconds

EAT = (1 p) x 200 + p (8 milliseconds) = (1 p) x 200 + p x 8,000,000 = 200 + p x 7,999,800

If one access out of 1,000 causes a page fault, then EAT = 8.2 microseconds. This is a slowdown by a factor of 40!!VIRTUAL ADDRESS TRANSLATIONWhat happens during a memory access?map virtual address into physical address using page tableIf the page is in memory: access physical memoryIf the page is on disk: page faultSuspend programGet operating system to load the page from disk

Page translationAddress bits = page number + page offsetTranslate virtual page number(VPN) into physical page number(PPN) using page table Lets assume that we have 1MB of RAM is also called physical and 10MB of disk memory and size of page is 4k then.. What is page number ?Thus 1M/4k =256 pages thus our ram has 256 physical pages which holding 4KLets assume we have 10MB of disk thus we have 2560MB of pages

SEGMENTATION:Divide virtual space of the process intosegments. Similar to paging except we can have segments match with needed sizes.virtual addresses comprised ofsegment numberandsegment offsethighnbits of virtual address give segment numberremaining lower bits give the segment offsetnumber of bits in segment number limit number of possible segmentsvirtual addresses bound to physical addresses at access timeAddress translation:Address translation makes use ofsegment tables. A segment table contains an entry for each segment for a process. Entries contain:pointer to start of segment in physical memory (base)size of segment (bounds)indication of whether or not segment is currently in memoryprotection information

HARDWARES ROLE:The hardware performs the following address translation for every memory reference:extract segment number from virtual addressif segment number is greater than max number of segments, trap with ``illegal segment''.consult segment table entry.if segment not present in memory, trap ``missing segmentif segment offset is greater than segment size, trap ``offset out of rangeif process does not have access permissions, trap ``protection violation''

Segment Faults:

When a process references data in a missing segment, the hardware generates asegment faultthat traps to the kernel. The fault handler:tries to find a chunk of free memory into which it can place the missing segmentif no free chunk is available, it must first swap out an existing segment to make roomloads the new segment into memoryrestarts the process that caused the fault

Segmentation with Paging: Intel Pentium

Intel Pentium supports segmentation. A segmentselectoris 16 bits (13 bits to identify a specific segment).These bits map to a segment descriptor, which contains the base address and size of the segment. Combined with offset the result is a 32-bit linear address.If paging is disabled this address is a physical address (pure segmentation).

Contd.If paging is enabled then address is a virtual address. Three level scheme:page directory entry--10 bitspage table entry--10 bitsoffset--12 bits (4K page)Note: can also disable segmentation by mapping entire address space to same segment and have pure paging.

MMU (Memory Management Unit)The hardware base that makes a virtual memory system possible.Allows software to reference physical memory by virtual addresses, quite often more than one.It accomplishes this through the use of page and page tables.Use a section of memory to translate virtual addresses into physical addresses via a series of table lookups.

HOW DOES IT WORKSTo facilitate copying virtual memory into real memory, the operating system divides virtual memory into pages, each of which contains a fixed number of addresses.Each page is stored on a disk until it is needed.When the page is needed, the operating system copies it from disk to main memory, translating the virtual addresses into real addresses.

MEMORY MANAGEMENT REQUIREMENT:Memory management should satisfy the following requirements:1.Relocation2.Sharing3.Protection4.Logical organization5.Physical organization.

Relocation:Relocation is a basic requirement of memory management. For simplification purposes let us assume that the process image occupies a contiguous region of main memory. The operating system need to know the location of:Process control informationExecution stackEntry point to begin the execution of a program.Processor must deal with memory references within the program.Branch instructions contain an address to reference the instruction to be executed next.Data reference instructions contain the address of the byte or word of data referenced.

SHARING:Any protection mechanism must have the flexibility to allow several processes to access the same portion of main memory.

E.g., if numbers of processes are executing the same program then it is advantageous to allow each process to access the same copy of the program rather than its own separate copy.

PROTECTION:Once we have two programs in memory at the same time there is a danger that one program can write to the address space of another program. Every process should be protected against unwanted interference by other processes. Satisfaction of the relocation requirement increases the difficulty of satisfying the protection requirement.CPU tend to support absolute addressing which means that code runs differently when loaded in different places.It is not possible to check the absolute address at compile time. Most of the programming languages allow the dynamic calculation of address at run time.

4.Logical organization:

Main memory is organized as a linear or one-dimensional address space that consists of sequence of bytes or words. Secondary memory at its physical level is similarly organized. Most of the programs are organized into modules.

PHYSICAL Organization:

Computer memory is organized into two levels:Main memory- Main memory is a volatile memory and it provides fast access at relatively high cost.Secondary memory- Secondary memory is a non-volatile memory and it is slower and cheaper than main memory.