450 likes | 483 Views
Computer Science Overview Chapter Three-Operation System (3). JainShing Wu. Virtual Memory. Lack of memory For multi-tasking Paging. Virtual Memory. Provides application a full continuous memory but actual fragments
E N D
Computer Science OverviewChapter Three-Operation System (3) JainShing Wu
Virtual Memory • Lack of memory • For multi-tasking • Paging
Virtual Memory • Provides application a full continuous memory but actual fragments • Using secondary memory (disk) to provide more memory space for more processes
Page Table • Transfer virtual address into physical address • Every process has one page table • Consists of • Resident bit • Records the page in main memory or not • Page fault • Page at the storage address in Disk • The frame number that page is loaded in
Page Table • Problem • Large amount of tables • Thrashing • High paging activity (load, process, remove) • CPU overhead (for handling page interrupt) • Necessary page hardware
Page Fault • Occur when the required page not in the memory • Handling page fault SOP • Service the page-fault interrupt • Read in the required page from secondary memory (disk) • If not found => terminate the process • If found=> select a page to replace • Replace page algorithm • Resume the process
Page Replacement Algorithm • FIFO • Optimality • Least Recently Used (LRU)
First In First Out • New page replaces the first page that is loaded to memory in a circular buffer • Advantage • Simplest • Disadvantage • Performance is not always good • Belady's Anomaly
First In First Out Ref string page 17 page faults
Belady's Anomaly • Increase the page table size, but cause higher page faults
Belady's Anomaly Ref string page 17 page faults Ref string page 14 page faults
Belady's Anomaly Ref string page 15 page faults
Optimality • Selects for replacement that page for which the time period to the next reference is the longest • Has the lowest page fault rate of all algorithm • Difficult to implement because of requiring the OS to have future knowledge of the reference string
Optimality Ref string page 7page faults
Least Recently Used • Replaces the page in memory that has not been referenced for the longest time • May require substantial hardware assistance • Two implementation are feasible to determine the order for the frames defined by the time of last use
Least Recently Used Ref string page 12page faults
Dead Lock • When two processes hold the resource that are the required resource of each other • Circular wait • No preemptive
Dead Lock • EX: A room with a door that requires two keys, key1 and key2 to open • The one that first leaves the room wins $10000, and the second one wins $5000 • No kill !
Dead Lock • There are two persons A and B. Both A and B want to leave this rooms • A holds key1, and B holds key2 • A waits B to release the key2 and B waits A to release the key1
Dead Lock Handling • Abort all deadlock process • Back up each dead lock process to some previously defined checkpoint and restart all processes (Rollback) • Successively abort dead lock processes until deadlock no longer exits • Successively preempt resources until deadlock no longer exits
Storage Management • Disk structure • Disk scheduling • Disk management • Swap space mangement
Disk Structure • Information on the disk is referenced by a multiple address • Drive number, • Surface (cylinder) • Track • Sector • Sector is the smallest unit of information that can be read from or write to the disk
Disk Structure • I/O transfer between memory and disk are performed in units of one or more sectors called blocks to improve I/O efficiency
Disk Scheduling • Before sending system call to OS to perform disk I/O, the information • Input or output • Disk address (C/T/S) • The memory address that Load to /read from • How many bytes to transfer
Disk Scheduling • Disk scheduling algorithm • FCFS • SSTF • SCAN • C-SCAN • Look scheduling
First Come First Served • Process track items from the queue in sequential order • Advantage • Easy to program • Intrinsically fair • Disadvantage • Performance low
First Come First Served • The header is parked at track 0 • Disk I/O sequence: 30,50,20,70,40 • The total movement: • (30-0)+(50-30)+(50-20)+(70-20)+(70-40)=130 30 50 20 70 40 Track 100 Track 0
Shortest Seek Time First • Selects the request with minimum seek time from the current head position • High use, small queues • Like SJK scheduling, it may cause starvation of some requests
Shortest Seek Time First • The header is parked at track 0 • Disk I/O sequence: 30,50,20,70,40 • The total movement: • (20-0)+(30-20)+(40-30)+(50-40)+(70-50)=70 20 30 40 50 70 Track 100 Track 0
Scan Scheduling • The read-write head starts at one end of the disk • Move toward the other end • Servicing requests as it reaches each tack until it hit the other end of the disk • Better service distribution • Also called elevator scheduling
Scan Scheduling 30 • The header is parked at track 30 • Disk I/O sequence: 30,50,20,70,40 • The total movement: • (30-0)+(20-0)+(30-20)+(40-30)+(50-40)+(70-50)=100 20 30 40 50 70 Track 100 Track 0
C-Scan Scheduling • A variant of Scan scheduling • Designed to provide more uniform waiting time • Moves the head from one end to the other disk end and servicing the requests as it goes • Lower service variability
C-Scan Scheduling 30 • The header is parked at track 30 • Disk I/O sequence: 30,50,20,70,40 • The total movement: • (30-0)+(100-70)+(70-50)+(50-40)+(40-30)+(30-20)=110 70 50 40 30 20 Track 100 Track 0
Look Scheduling • More Commonly, the head is only moved as far as the last request in each direction • As soon as there are no request in the current direction, the movement is reversed • Service guarantee & load sensitive
Look Scheduling 20 30 • The header is parked at track 30 • Disk I/O sequence: 30,50,20,70,40 • The total movement: • (30-20)+(30-20)+(40-30)+(50-40)+(70-50)=60 30 40 50 70 Track 100 Track 0
Security • Data protection • Virus • Internet attack
Data Protection • File Lock • Lock the files/directories and only the owner can open • File attributes • Read/Write/Execute (Unix like system) • Read only/File sharing (Windows system) • Data transfer protection • 加密 • Public key and private key • RSA
Virus • First designed for copy wright protection • Behavior • Destroy the systems • Hacking the system • Obtain the personal private information • Obtain the control of the system • Virus Buster
Internet Attack • Attack type • Deny of Service (DOS attack) • Intersection • Hacking • Net fishing • Firewall
Password Policy • As long as possible • As hard to rememberas possible • Add more numbers in the password as possible • One password for one week • EX: • s5h6i7n8g • el vm/6284vm,6
Homework • Q1: If there are 10 jobs (job1, job 2, …, job 10) with working time {5, 1, 15, 2, 3 , 7, 11, 7, 9, 6}, Please specify the job finished order and the finial finish time using the following scheduling (a) SJF (b) Round-robin (c) FCFS
Homework • If there is a page reference string • Please use the FIFO, Optimality, and LRU page replacement algorithms to replace the page and specify the page faults of three algorithms Ref string page
Homework • Q3: Disk scheduling • The disk is from track 0 to track 100 • The header is parked at track 20 • The Disk I/O sequence: 10, 50, 15, 25, 75, 60, 70, 5, 30, 40 • Please use the following scheduling to show the process and the total movements • (a) FCFS (b) SSTF (d) Scan (d) Look