教师信息考核设计成绩构成参考文献1. IntroductionOutline2. OS's Construction2.1 Problems and Ideas in OS2.1.1 Complexity is caused by the resource2.1.2 Concurrency makes OS more complicated2.1.3 Problem of resource competition2.1.4 Class Structure2.2 Construct OS2.2.1 Simple structure/monolithic structure2.2.2 Modular, Layered, Microkernel2.2.3 Trend - Virtual machine2.3 How do user use the function defined in OS2.4 How to load and run OS3. Proccess & Thread3.1 Process3.2 Thread4. CPU Scheduling4.1 Basic Concept4.2 Scheduling Criteria & Metrics4.3 Different Scheduling AlgorithmsFCFS first Come First Serve SchedulingShortest Job First SJFShortest-Remaining-Job-First SRJFPriorityRound-Robin SchedulingOther4.4 Algorithm EvaluationDeterministic modelingSimulation5. Synchronization5.1 Background & basic conecpts5.2 Problems & Solution for synchronization5.2.1 ProblemsProducer/Consumer ProblemSoftware solutionHardware solutionMachine Instructions for Mutual ExclusionOperating System solutions5.2.2 Tasks5.2.3 Solutions6. Deadlock6.1 Deadlock6.1.1 Definition, Model6.1.2 Four necessary conditions6.2 Methods for Handling Deadlocks7. Memory7.1 Basic conecpts7.2 Basic techniques of real memory management7.2.1 Partitioning (Static & Dynamic)placement算法replacement算法7.2.2 Overlay7.2.3 Dynamic Linking7.3 Old way for OS space7.4 Paging7.4.1 Basic paging7.4.2 Paging-bsed VMSteps in handling a Page FaultEffective Access Time (EAT)Impove7.4.3 Page replacement algorithmsFIFO/FCFSOptimal Page ReplacementLRU PolicyClock PolicyDoes adding RAM always reduce misses?Thrashing7.5 Segmenting7.5.1 Basic segmenting7.5.2 Segmentation-based VMM7.6 Segment-page scheme(Hybrid)8. IO8.1 General structure to connect devices8.1.1 IO devices - Categories8.1.2 IO operationsDevice controller8.2 Taking(Magnetic) Disk for instance8.2.1 So-called "linear address sector space"8.2.2 Organize sectors into partitions, so-called "linear addressed block space"Organize sectors ino block8.2.3 Optical disk is similar9. File System9.1 Organize blocks into semantic regions9.2 Free space9.2.1 Free-Space ManagementBit Vector(Bit map:位图)Linked list9.3 Map a file into blocks9.3.1 Contiguous Allocation 连续9.3.2 Index Allocation9.4 How to organize so many files?10. IO System(Other)10.1 Scheduling algorithms for disk I/O requests算法10.1.1 FCFS 先来先服务10.1.2 SSTF 最短寻道时间优先10.1.3 elevator algorithm电梯算法SCANC-SCANLOOKC-LOOK10.2 SPOOLING10.3 RAID10.3.1 strip10.3.2 Hamming Code10.3.3 RAIDRAID 0 RAID 1RAID 2RAID 3RAID 4RAID 5RAID 610.3.4 NAS, SAN10.3.5 USB10.3.6 5G
YF809 mlinking@126.com
4 quiz in this class 5 small projects in this class
Msys2
Machine Cycle:
We can distill 4 kinds of resources / concepts
multiplexing computers
when turn on the power of computer, run ROM.
• PCB (Process Control Block) is the one used/named data structure
Process Location Information: Each process image in memory
may not occupy a contiguous range of addresses ( depends on memory management scheme used, which will be discussed in later MM part ).
Process Identification Information: A few numeric identifiers may be used
Unique process identifier (PID) –
User identifier (UID) –
the user who is responsible for the job.
Processor State Information: Contents of processor registers
Process Control Information: Scheduling and state information
Process state (i.e., running, ready, blocked...)
Priority of the process
Relationship with other processes
Process Transitions (1)
Ready → Running
Running → Ready
Process Transitions (2)
Running → Waiting
When a process requests something for which it must wait:
Waiting → Ready
Schedulers
IPC: Inter-Process Communication
Cooperating processes require an inter-process communication (IPC) mechanism that will allow them to exchange data and information.
There are two fundamental models of inter-process communication:
Shared memory
Message passing
Process switching is EXPENSIVE!
Concept of Process has two facets A Process is:
A Unit of resource ownership – process is allocated:
A Unit of execution/dispatching - process is an execution path through one or more programs (functions, code segments)
– The unit of resource ownership is referred to as a Task or (for historical reasons) also as a Process. – The unit of dispatching is referred to a Thread.
进程内部支持cpu切换
CPU-I/O Burst
Parameters to evaluate the scheduling
CPU utilization [ CPU 使用率 ] ( Efficiency )
Fairness: each process gets a “fair share” of the CPU
Throughput [ 吞吐量 ]
Turnaround time [ 周转时间 ]
Waiting time [ 等待时间 ]
Response time [ 响应时间 ]
Scheduling Algorithms
First Come First Serve Scheduling [ 先来先服务 ] ( Non-preemptive )
Shortest Job First Scheduling [ 最短任务先服务 ]
Priority Scheduling [ 优先权 ]
Round-Robin Scheduling [ 时间片轮转 ]
Multilevel Queue Scheduling [ 多层次队列 ]
Lottery Scheduling [ 抽彩 ]
先来先做
画甘特图
最短先做
Determining length of next CPU Burst
剩的最少先做
越小等级越高
Preemptive 和 Non- preemptive的区别:Preemptive在有新进程加入中也是一个调度时间
Aging - 随等待时间更多,优先级提高
Preemtive, 将CPU服务轮换切片
Short quantum: great response/interactivity but high overhead
Long quantum: poor response/interactivity, but low overhead
Advantages
Disadvantages
Poor average waiting time with similar job lengths
Performance depends on length of time-slice
Race condition 多线程冲突 critical section 临界区(共享数据)
Concurrent processes -> Deadlock No controlled access -> Data Inconsistency
多Producer 和 Consumers 会覆盖
好的mutual exclusion还要考虑deadlock和starvation
Rules for robust synchronization
Peterson's algorithm -2 processes is correct
Uniporcessor could disable interrupts Modern machines provide special atomic(non-interruptible) hardware instructions:
Test and Set
boolean TestAndSet(boolean *target) {
boolean rv = *target;
*target = TRUE;
return rv;
}
boolean lock = FALSE;
do {
while (TestAndSet(&lock)) ;
critical section
lock = FALSE;
remainder section
}
Swap
xxxxxxxxxx
void Swap(boolean *a, boolean *b) {
boolean temp = *a;
*a = *b;
*b = temp;
}
boolean lock = false;
do {
key = true; // key is a local variable
while (key == true)
Swap(lock,key);
critical section
lock = false;
remainder section
} while (TRUE);
lock + Manager + Waiting Room
Semapore(必考)
counting Semaphore
Staying Safe
Preventing Deadlocks Do not allow one of the four conditions to occur 打破4个条件的成立(主要打破Hold and Wait和 Circular Wait)
Negating Hold and Wait
Negating Circular Wait
Order resource allocation资源顺序分配法
Avoiding Deadlocks
每一次请求先判断
considers the resources currently available , the resources currently allocated , and the future (Needed) requests and releases of each process, and decides whether the current request can be satisfied or must wait to avoid a possible future deadlock.
available = total resource - max
然后选need再一步步来得到序列
Living Dangerously
Let the dead happen, then detect it and recover from it
Ignore the risks
MAPPING 1 - map files into main memory
MAPPING 2 - map files into persistence storage medias(HDD)
From program to process
Requirements of MM
partition and swapping static固定切,dynamic动态切
Equal-size partitions:
Dynamic Partitioning Placement Algorithms
Internal/External Fragmentation
compaction 压缩
discuss in virtual memory
once known as "Virtual Memory For 640K DOS"
dll
Knuth's Buddy System 二分法切割,产生内碎片
fixed partitioning but with smaller size
page数据结构
Page | Frame |
---|
OS should know the mapping relationship between pages of that process and frames of the MM
0 - > 2; physical address = offset * pagesize
p means page fault rate
The solution could be derived from the EAT equation - Improve the access speed, and decrease the page fault
keeping page table in a higher access speed media
Prefeching the possible future accessed pages
first in first out
Impossible to implement (need to know thefuture) but serves as a standard to compare with the other algorithms we shall study.
Replaces the page that has not been referenced for the longest time recently
Replaces an old page, but not the oldest page
Arranges physical pages in a circle
Each page has a used bit
Set to 1 on reference
On page fault, sweep the clock hand
享受机会可以踢掉
Yes for LRU and MIN
No for FIFO
If a process does not have “enough” pages, the page-fault rate is very high. This leads to:
Thrashing = a process is busy swapping pages in and out.
不会造成内碎片
now combines both paging and segmentation
先segmentation再paging
按访问类型分
Block devices 块设备 e.g. hard disks
Character devices 字符设备
按访问过程分
hardware that connects the device to the computer
Host (CPU+Memory) and Device Controller interaction (data transfers and control) can be in one of 3 ways:
Disk Partition 磁盘分区
Partition the disk into one or more groups of cylinders
Logical formatting or “making a file system”
Store the initial file-system data structure onto the disk…
Given a partition whose starting sector is 1024, and the size of a block is defined as 4KB, could you determine the sectors for a block 7 in this partition?
If you want to store a file of 17 KB, it’s easy to know we need ┌17/4┐= 5 blocks. – Of course we need record some information so as to retrieve the blocks used to store your file
文件是BLOCK的集合
Like the MBR for the hard disk, each partition usually uses the 1 st block for special usage, called “boot block”
to record some critical information of how those blocks in thepartition are used, such as regions for
e.g. If the block size is 4KB, and the hard disk size (or a partition) is 500 GB, how many blocks are used to store the bitmap?
Each file occupies a set of contiguous blocks on the disk
advance: Simple – only starting location (block #) and length (number of blocks) are required to find out the disk data blocks of file Random access is fast
defect: Wasteful of space (dynamic storage-allocation problem) Files cannot grow
Such as 1 block = 4KB Each entry = 4 bytes So each block could contain 4×2^10/4 = 1024 2-level index could connect 1024×1024 = 2^20 data blocks So the total size of data blocks is 2^20 ×4KB = 4GB
Directory
Disk Optimization指标
Disk latency time 转到合适的扇区的延迟
Disk seek time 磁头找到合适的轨道的延迟
Transfer 复制bits从磁面到内存
Access Time seek + latency + transfer
e.g.
Buffer
No redundant
mirror
使用hamming code
使用奇偶校验
BLOCK整个来保存,有一个进行奇偶校验
block-level distributed parity
dual redundancy