virtual memory various memory management techniques have been discussed. all these strategies have...

14
Virtual Memory • Various memory management techniques have been discussed. All these strategies have the same goal: to keep many processes in memory simultaneously to allow multiprogramming. However, they are required the entire process to be in memory before the process can execute. But virtual memory is a technique that allows the execution of processes that may not be completely in memory. Virtual memory : A technique that allows a process to execute in main memory space which is smaller then the process size. Only a part of a process needs to be loaded in the main memory for it to execute. Sharing of address space among several processes. Overlays and dynamic loading can help to implement VM. Virtual memory can be implemented via: Demand paging (done by lazy swapper) Demand segmentation

Upload: edwin-gilmore

Post on 21-Jan-2016

212 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Virtual Memory Various memory management techniques have been discussed. All these strategies have the same goal: to keep many processes in memory simultaneously

Virtual Memory• Various memory management techniques have been discussed. All

these strategies have the same goal: to keep many processes in memory simultaneously to allow multiprogramming. However, they are required the entire process to be in memory before the process can execute. But virtual memory is a technique that allows the execution of processes that may not be completely in memory.

• Virtual memory : A technique that allows a process to execute in main memory space which is smaller then the process size.

• Only a part of a process needs to be loaded in the main memory for it to execute.

• Sharing of address space among several processes.• Overlays and dynamic loading can help to implement VM.• Virtual memory can be implemented via:

– Demand paging (done by lazy swapper)– Demand segmentation

Page 2: Virtual Memory Various memory management techniques have been discussed. All these strategies have the same goal: to keep many processes in memory simultaneously
Page 3: Virtual Memory Various memory management techniques have been discussed. All these strategies have the same goal: to keep many processes in memory simultaneously

Demand paging• Bring a page into memory only when it is needed– Potentially less I/O needed– Potentially less memory needed– Faster response– Higher degree of multiprogramming

• Page is needed==a reference is made to it– Invalid reference==abort– Not-in-memory

• Page fault• Bring page to memory

– No free frame===swapping to SS(out and in) so required page replacement algorithms if memory is not free.

Page 4: Virtual Memory Various memory management techniques have been discussed. All these strategies have the same goal: to keep many processes in memory simultaneously

Valid-invalid bit scheme

• With this scheme, we need some form of hardware support to distinguish between those pages that are in memory and those pages that are on the disk.

• when this bit is set to "valid," this value indicates that the associated page is both legal and in memory.

• If the bit is set to "invalid,“ this value indicates that the page either is not valid (that is, not in the logical address space of the process), or is valid but is currently on the disk. The page-table entry for a page that is not currently in memory is simply marked invalid, or contains the address of the page on disk.

Page 5: Virtual Memory Various memory management techniques have been discussed. All these strategies have the same goal: to keep many processes in memory simultaneously
Page 6: Virtual Memory Various memory management techniques have been discussed. All these strategies have the same goal: to keep many processes in memory simultaneously

Not in address space G,H

Page 7: Virtual Memory Various memory management techniques have been discussed. All these strategies have the same goal: to keep many processes in memory simultaneously

Page faultWhen the process

tries to access location that are not in memory, the hardware traps to the operating system. This is called page fault. The operating system reads the desired page into memory and restart the process.

Page fault is the issue of Demand paging.

Page 8: Virtual Memory Various memory management techniques have been discussed. All these strategies have the same goal: to keep many processes in memory simultaneously

Page faultThe procedure for handling a page fault is straightforward:• We check an internal table (usually kept with the process control block)

for this process to determine whether the reference was valid or invalid memory access.

• If the reference was invalid we terminate the process. If it was valid, but we have not yet brought in that page, we now page it in.

• We find a free frame (by taking one from the free-frame list, for example)• We schedule a disk operation to read the desired page into the newly

allocated• frame.• When the disk read is complete, we modify the internal table kept with

the process and the page table to indicate that the page is now in memory.

• We restart the instruction that was interrupted by the illegal address trap. The process can now access the page as though it had always been in memory.

Page 9: Virtual Memory Various memory management techniques have been discussed. All these strategies have the same goal: to keep many processes in memory simultaneously

Page fault

Page 10: Virtual Memory Various memory management techniques have been discussed. All these strategies have the same goal: to keep many processes in memory simultaneously

Page fault issues

• Problem with restarting instruction that cause page faults– Auto

increment/decrement location

– Block move

Page 11: Virtual Memory Various memory management techniques have been discussed. All these strategies have the same goal: to keep many processes in memory simultaneously

Effective access time• Performance of demand paging• Let p be the probability of a page fault (0 ≤ p ≤ 1). We would expect p to

be close to zero, that is, there will be only a few page faults. The effective access time is then:

Effective access time = (1-p) * ma + p * page fault time

• If we take an average page fault service time of 25 milliseconds and a memory access time of 100 nanoseconds, then the effective access time in nanoseconds is

Effective access time = (1-p) * (100) + p (25 milliseconds)= (1-p) * 100 + p * 25,000,000= 100 + 24,999,900 * p

• We see then that the effective access time is directly proportional to the page fault rate. If one access out of 1,000 causes a page fault (1/1000), the effective access time is 25 microseconds. The computer would be slowed down by a factor of 250 because of demand paging (means 250 times of memory access time= 250*100*10 ns=25 microsec)

Page 12: Virtual Memory Various memory management techniques have been discussed. All these strategies have the same goal: to keep many processes in memory simultaneously

• If we want less than 10 percent degradation in effective memory access time , we need:110 > 100 + 25,000,000 * p10 > 25,000,000 * pp < 0.0000004 =1

• This means we can allow only one page fault every 2500,000.

Page 13: Virtual Memory Various memory management techniques have been discussed. All these strategies have the same goal: to keep many processes in memory simultaneously

To compute the effective access time, we must know how much time is needed to service a page fault. A page fault causes the following sequence to occur:

• Trap to the operating system• Save the user registers and process states• Determine that the interrupt was a page fault• Check that the page reference was legal and determine the location of the page on disk• Issue a read from the disk to a free frame:

– Wait in a queue for this device until the read request is serviced– Wait for the device seek and/or latency time– Begin the transfer of the page to a free frame

• While waiting, allocate the CPU to some other user (CU scheduling; optimal)• Interrupt from the disk (I/O completed)• Save the registers and process state for the other user (if step 6 is executed)• Determine that the interrupt was from the disk• Correct the page table and other tables to show that the desired page is now in memory• Wait for the CPU to be allocated to this process again• Restore the user registers, process state and new page table

Page 14: Virtual Memory Various memory management techniques have been discussed. All these strategies have the same goal: to keep many processes in memory simultaneously

Examples• Effective memory access is 100 ns• Page fault overhead is 100 microseconds = 105 ns• Page swap time is10 milliseconds = 107 ns• 50% of the time the page to be replaced is “dirty”• Restart overhead is 20 microseconds = 2 x 104 ns

Effective access time = 100 * (1-p) + (105 + 2 * 104 + 0.5 * 107 + 0.5 * 2 * 107) * p = 100 * (1-p) + 15,120,000 * p

What is a Good Page Fault Rate?• For the previous example suppose p is 1% (means p=1/100), then EAT is

= 100 * (1-p) + 15,120,000 * p= 151299 ns

• Thus a slowdown of 151299 / 100 = 1513 occurs.• For the luxury of virtual memory to cost only 20% overhead, we need

120 > 100 * (1-p) + 15,120,000 * p120 > 100 -100 p + 15,120,000 pp < 0.00000132

⇒ Less than one page fault for every 755995 memory accesses!