教师信息考核设计成绩构成参考文献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

考核设计

image-20230512143603932

4 quiz in this class 5 small projects in this class

成绩构成

image-20230512143606888

参考文献

image-20230512143608897

Msys2

Machine Cycle:

 

1. Introduction

Outline

image-20230512143611805

image-20230512143613739

image-20230512143616603

2. OS's Construction

2.1 Problems and Ideas in OS

2.1.1 Complexity is caused by the resource

2.1.2 Concurrency makes OS more complicated

2.1.3 Problem of resource competition

2.1.4 Class Structure

image-20230512143618988

2.2 Construct OS

We can distill 4 kinds of resources / concepts

2.2.1 Simple structure/monolithic structure

image-20230512143621372

2.2.2 Modular, Layered, Microkernel

image-20230512143623540

image-20230512143625269

2.2.3 Trend - Virtual machine

multiplexing computers

image-20230512143628438

image-20230512143630807

2.3 How do user use the function defined in OS

2.4 How to load and run OS

when turn on the power of computer, run ROM.

3. Proccess & Thread

3.1 Process

PCB (Process Control Block) is the one used/named data structure

  1. Process location information
  2. Process identification information
  3. Process state information
  4. Process control information

Process Transitions (1)

Process Transitions (2)

Schedulers

image-20230512143634527

IPC: Inter-Process Communication

3.2 Thread

Process switching is EXPENSIVE!

Concept of Process has two facets A Process is:

– 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切换

4. CPU Scheduling

4.1 Basic Concept

CPU-I/O Burst

4.2 Scheduling Criteria & Metrics

Parameters to evaluate the scheduling

image-20230512143639222image-20230512143647362image-20230512143652357image-20230512143659222

Scheduling Algorithms

4.3 Different Scheduling Algorithms

FCFS first Come First Serve Scheduling

先来先做

画甘特图

image-20230512143704312

Shortest Job First SJF

最短先做

image-20230512143708053

Determining length of next CPU Burst

image-20230512143711840

Shortest-Remaining-Job-First SRJF

剩的最少先做

image-20230512143717796

Priority

越小等级越高

Preemptive 和 Non- preemptive的区别:Preemptive在有新进程加入中也是一个调度时间

image-20230512143721095

Aging - 随等待时间更多,优先级提高

Round-Robin Scheduling

Preemtive, 将CPU服务轮换切片

image-20230512143726003

 

Other

4.4 Algorithm Evaluation

Deterministic modeling

Simulation

5. Synchronization

5.1 Background & basic conecpts

Race condition 多线程冲突 critical section 临界区(共享数据)

Concurrent processes -> Deadlock No controlled access -> Data Inconsistency

5.2 Problems & Solution for synchronization

5.2.1 Problems

Producer/Consumer Problem

image-20230512143730341

多Producer 和 Consumers 会覆盖

好的mutual exclusion还要考虑deadlock和starvation

Rules for robust synchronization

Software solution

Peterson's algorithm -2 processes is correct

image-20230512143734123

Hardware solution

Uniporcessor could disable interrupts Modern machines provide special atomic(non-interruptible) hardware instructions:

Test and Set

Swap

Machine Instructions for Mutual Exclusion

lock + Manager + Waiting Room

Operating System solutions

Semapore(必考)

image-20230512143739395

image-20230512143743721

image-20230512143745685

image-20230512143748379

image-20230512143751055

counting Semaphore

image-20230512143753074

image-20230512143756399

 

5.2.2 Tasks

5.2.3 Solutions

6. Deadlock

6.1 Deadlock

6.1.1 Definition, Model

6.1.2 Four necessary conditions

6.2 Methods for Handling Deadlocks

image-20230512143759460

7. Memory

MAPPING 1 - map files into main memory

MAPPING 2 - map files into persistence storage medias(HDD)

7.1 Basic conecpts

 

7.2 Basic techniques of real memory management

7.2.1 Partitioning (Static & Dynamic)

partition and swapping static固定切,dynamic动态切

placement算法

Equal-size partitions:

  1. If there is an available partition, a process can be loaded into that partition – because all partitions are of equal size, it does not matter which partition is used.
  2. If all partitions are occupied by blocked processes, choose one process to swap out to make room for the new process.

Dynamic Partitioning Placement Algorithms

Internal/External Fragmentation

  1. Internal Fragmentation 内碎片,分配在内存内部没有使用的内存
  2. External Fragmentation

compaction 压缩

replacement算法

discuss in virtual memory

7.2.2 Overlay

once known as "Virtual Memory For 640K DOS"

image-20230512143817452

7.2.3 Dynamic Linking

dll

7.3 Old way for OS space

Knuth's Buddy System 二分法切割,产生内碎片

7.4 Paging

7.4.1 Basic paging

fixed partitioning but with smaller size

page数据结构

PageFrame

OS should know the mapping relationship between pages of that process and frames of the MM

image-20230512143822291

image-20230512143825335

0 - > 2; physical address = offset * pagesize

7.4.2 Paging-bsed VM

Steps in handling a Page Fault

image-20230512143827857

Effective Access Time (EAT)

image-20230512143829875

p means page fault rate

image-20230512143833180

Impove

The solution could be derived from the EAT equation - Improve the access speed, and decrease the page fault

7.4.3 Page replacement algorithms

image-20230512143836628

FIFO/FCFS

first in first out

image-20230512143840797

Optimal Page Replacement

Impossible to implement (need to know thefuture) but serves as a standard to compare with the other algorithms we shall study.

image-20230512143843819

LRU Policy

Replaces the page that has not been referenced for the longest time recently

image-20230512143846699

Clock Policy

享受机会可以踢掉

image-20230512143850031

Does adding RAM always reduce misses?

Yes for LRU and MIN

No for FIFO

Thrashing

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.

7.5 Segmenting

7.5.1 Basic segmenting

不会造成内碎片

7.5.2 Segmentation-based VMM

 

7.6 Segment-page scheme(Hybrid)

now combines both paging and segmentation

先segmentation再paging

image-20230512143853884

8. IO

8.1 General structure to connect devices

8.1.1 IO devices - Categories

按访问类型分

  1. Block devices 块设备 e.g. hard disks

  2. Character devices 字符设备

    • Character
    • Network

按访问过程分

  1. Sequential Access Device e.g. 磁带
  2. Direct Access Device

8.1.2 IO operations

Device controller

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:

8.2 Taking(Magnetic) Disk for instance

image-20230512143858059

8.2.1 So-called "linear address sector space"

Disk Partition 磁盘分区

Partition the disk into one or more groups of cylinders

Logical formatting or “making a file system”

8.2.2 Organize sectors into partitions, so-called "linear addressed block space"

Organize sectors ino block

8.2.3 Optical disk is similar

9. File System

文件是BLOCK的集合

9.1 Organize blocks into semantic regions

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

image-20230512143901721

9.2 Free space

9.2.1 Free-Space Management

Bit Vector(Bit map:位图)

image-20230512143904382

image-20221021114424796

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?

image-20230512143907536

Linked list

image-20230512143911829

9.3 Map a file into blocks

9.3.1 Contiguous Allocation 连续

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

9.3.2 Index Allocation

image-20230512143913964

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

image-20230512143916991

9.4 How to organize so many files?

Directory

10. IO System(Other)

Disk Optimization指标

Disk latency time 转到合适的扇区的延迟

Disk seek time 磁头找到合适的轨道的延迟

Transfer 复制bits从磁面到内存

Access Time seek + latency + transfer

10.1 Scheduling algorithms for disk I/O requests算法

e.g.

image-20230512143920471

10.1.1 FCFS 先来先服务

image-20230512143922522

10.1.2 SSTF 最短寻道时间优先

image-20230512143924964

10.1.3 elevator algorithm电梯算法

image-20230512143926843

SCAN

image-20230512143929184

C-SCAN

image-20230512143930822

LOOK

image-20230512143933163

C-LOOK

image-20230512143934932

10.2 SPOOLING

Buffer

image-20230512143937031

10.3 RAID

10.3.1 strip

image-20230512143939513

10.3.2 Hamming Code

image-20230512143941316

10.3.3 RAID

RAID 0

No redundant

RAID 1

mirror

RAID 2

使用hamming code

RAID 3

使用奇偶校验

RAID 4

BLOCK整个来保存,有一个进行奇偶校验

RAID 5

block-level distributed parity

RAID 6

dual redundancy

10.3.4 NAS, SAN

image-20230512143944072

image-20230512143945875

image-20230512143947677

10.3.5 USB

10.3.6 5G