Download Operating System Today Introduction Swapping Swapping

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Document related concepts
no text concepts found
Transcript
Today
• Solutions for lack of memory
Operating System
– Swapping
– Virtual Memory
Lecture 7:
– Paging
Virtual Memory
1
2
Introduction
Swapping
• We’ve discussed
• When there are too many processes
and not enough memory
– address space structures
• segmented, paged, segmented and paged
– keep some processes on disk
– logical vs. physical address spaces
– disk storage is large and cheap
• Problems
• Important issue
– too many processes
– swapping in and out
– LAS >> PAS
3
4
Process State Diagram with
Swapped State
Swapping
• When to swap out
waiting
for an
event
– process has been resident for long time
and room is needed
Running
preempt
dispatch
Blocked
– if a process is blocked
• When to swap in
– when process is ready and there is room
swap out
event has
happened
swap out
Swapped
5
Ready
swap in
6
1
Swapping
Contention for Main Memory
• What if one process is too large?
• If it does not fit in main memory
• Swapping is slow
– because disks are slow
– it can’t run
• If it fits, but no one else can fit
– to swap 1MB process:
– large process out
• poor single-user performance
– large process in, others out
• poor system performance
• 1MB x 10msec/KB = 10sec!
7
Principle of Locality
8
Principle of Locality
• To run a process, not all of it needs
to be in memory
• Memory references tend to exhibit
locality
• Solution
– keep only region of locality in memory
– rest of process is swapped out
– do this for all processes
– space: next reference will be close to
this one
– time: the same address will be
referenced soon
9
Virtual Memory
10
Virtual Memory
• Illusion of a large fast memory
• Incorporate the following concepts
– much larger than main memory
– almost as fast as main memory
– memory model becomes independent of
specific machine
– each process’ memory is independent of
others
– pages and/or segments
– logical addressing
– protection and sharing
– swapping between main memory and disk
• but exploiting locality
11
12
2
Virtual Addressing
Virtual Addressing
• Addresses for a virtual memory are
called virtual addresses
• The HW mechanism for virtual
address translation is the memory
management unit
– virtual address space
• Compiler generates virtual addresses
• Given memory reference, hardware
converts VA to PA
– this is called virtual address translation
13
Swapping of Segments
Segment Faults
• If address space is segmented
• If present bit is off, segment fault
– swap segments
• Trap into OS
• If segments are not in memory
– contents of a register tell OS that a
segment fault occurred
– segment fault
• Memory management
– finding holes
• Find segment on disk
• Problems
– external fragmentation
– compaction
14
– kept in separate OS data structure
15
Segment Faults
16
Swapping of Pages
• If address space is paged
• Read it into memory
– swap pages (paging)
– need to find a big-enough hole
• Record base address in segment table
entry
• Set present bit
• If a page is not in memory
– page fault
• Memory management
– simpler
• Retry instruction
• Problem
17
– internal fragmentation
18
3
Page Faults
Page Faults
• Read it into a free frame
• If present bit is off, page fault
– may need to make room
• Trap into OS
• Record frame number in page table
entry
– contents of a register tell OS that a
page fault occurred
• Set present bit
• Find page on disk
• Retry instruction
– kept in separate OS data structure
19
20
Swapping and Paging
Segmentation on top of Paging
• When using segmentation on top of
paging
• Long-term swapping
– swapping of processes
– need to deal with page faults only!
• Short-term swapping
– swapping of pages
21
22
Summary
• Swapping
– moving processes between memory and disk
•
•
•
•
•
Principle of locality
Virtual Memory
Swapping of segments and pages
Paging
Long-term vs. short term swapping
23
4