2. WHAT IS VIRTUAL MEMORY???
Entire process in memory before it can be executed.
Virtual memory is a technique that allows execution
of the processes that are not completely in memory.
Program can be larger than physical memory.
Virtual memory – separation of user logical memory
from physical memory.
Memory storage limitation can be freed.
Virtual memory is not easy to implement.
3. BACKGROUND
Only part of the program needs to be in memory for
execution.
The need of instruction in physical memory to be
executed seems to be necessary & reasonable, but its
unfortunate.
The entire program is not needed.
Executing the program partially in memory has
benefits:
Program would no longer be constrained by the
amount of physical memory that is available.
If programs could take less physical memory, more
programs could be run at the same time.
5. Thus, running a program that is not entirely
in memory would benefit both the system and the
user.
Virtual memory can be implemented via:
• Demand paging
• Demand segmentation
8. In addition to separating logical memory from physical memory,
virtual memory also allows files and memory to be shared by
two or more processes through page sharing. This leads to the
following benefits:
System libraries can be shared by several processes through
mapping of the shared object into a virtual address space.
Virtual memory enables processes to share memory.
Virtual memory can allow pages to be shared during process
creation with the forkO system call, thus speeding up process
creation.
9. DEMAND PAGING
Consider how an executable program might be
loaded from disk to memory.
One option, load the entire program in physical
memory.
Ex: User selection program
Second approach, load the pages only as they
needed ( DEMAND PAGING).
A demand paging system is similar to the paging
system with swapping.
10. • Bring a page into memory only when it is needed
– Less I/O needed
– Less memory needed
– Faster response
– More users
• Page is needed reference to it
– invalid reference abort
– not-in-memory bring to memory
12. Valid-Invalid Bit
• With each page table entry a valid–invalid bit is associated
(1 in-memory, 0 not-in-memory)
• Initially valid–invalid bit is set to 0 on all entries
• Example of a page table snapshot:
Frame #
valid-invalid bit
1
1
1
1
0
0
0
page table
• During address translation, if valid–invalid bit in page table entry is
0 page fault
14. Page Fault
• What happens if the process tries to access a page and
that page was not brought into memory??????
• OS looks at another table to decide:
– Invalid reference abort.
– Just not in memory.
• Get empty frame.
• Swap page into frame.
• Reset tables, validation bit = 1.
• Restart instruction: Least Recently Used
– block move
– auto increment/decrement location
16. The hardware to support Demand paging:
Page Table
Secondary Memory
17. What happens if there is no free frame?
• Page replacement – find some page in
memory, but not really in use, swap it out
– algorithm
– performance – want an algorithm which
will result in minimum number of page
faults
• Same page may be brought into memory
several times
18. Performance of Demand Paging
• Page Fault Rate 0 p 1.0
– if 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)
19. Demand Paging Example
If we take an average page-fault service time of
8 milliseconds and a memory-access time of 200
nanoseconds, then the effective access time in
nanoseconds is
20. Copy-on-Write
• Copy-on-Write (COW) allows both parent and
child processes to initially share the same pages
in memory
If either process modifies a shared page, only
then is the page copied
• COW allows more efficient process creation as
only modified pages are copied
• Free pages are allocated from a pool of zeroedout pages