MindMap Gallery Computer operating system mind map
This is a mind map about computer operating systems, including processes and threads, memory management, file management, IO management, etc. Hope it helps everyone.
Edited at 2023-12-08 15:46:30One Hundred Years of Solitude is the masterpiece of Gabriel Garcia Marquez. Reading this book begins with making sense of the characters' relationships, which are centered on the Buendía family and tells the story of the family's prosperity and decline, internal relationships and political struggles, self-mixing and rebirth over the course of a hundred years.
One Hundred Years of Solitude is the masterpiece of Gabriel Garcia Marquez. Reading this book begins with making sense of the characters' relationships, which are centered on the Buendía family and tells the story of the family's prosperity and decline, internal relationships and political struggles, self-mixing and rebirth over the course of a hundred years.
Project management is the process of applying specialized knowledge, skills, tools, and methods to project activities so that the project can achieve or exceed the set needs and expectations within the constraints of limited resources. This diagram provides a comprehensive overview of the 8 components of the project management process and can be used as a generic template for direct application.
One Hundred Years of Solitude is the masterpiece of Gabriel Garcia Marquez. Reading this book begins with making sense of the characters' relationships, which are centered on the Buendía family and tells the story of the family's prosperity and decline, internal relationships and political struggles, self-mixing and rebirth over the course of a hundred years.
One Hundred Years of Solitude is the masterpiece of Gabriel Garcia Marquez. Reading this book begins with making sense of the characters' relationships, which are centered on the Buendía family and tells the story of the family's prosperity and decline, internal relationships and political struggles, self-mixing and rebirth over the course of a hundred years.
Project management is the process of applying specialized knowledge, skills, tools, and methods to project activities so that the project can achieve or exceed the set needs and expectations within the constraints of limited resources. This diagram provides a comprehensive overview of the 8 components of the project management process and can be used as a generic template for direct application.
operating system
Chapter 1 Overview
basic concept
A collection of programs that controls and manages the hardware and software resources of the entire computer system, rationally organizes and schedules computer work and resource allocation, and provides users with convenient interfaces and environments.
feature
concurrent
Multiple events occur within the same time interval
Different from parallel Parallelism is parallelism at the same time
shared
mutually exclusive sharing
Only one process is allowed to access resources within a specified time
Only after the process has accessed and released the resource can another process access the resource.
critical resources
Only one process is allowed access for a period of time
Such as: physical devices, stacks, variables, tables, etc.
Visit simultaneously
Allow "simultaneous" access by multiple processes over a period of time
At the same time, macroscopically, On a micro level, they may access resources alternately (time-sharing)
Resource sharing is conditioned on program concurrency. If program concurrency is not allowed, there will be no resource sharing.
Two basic characteristics
virtual
Entities become logical counterparts
Concurrent execution via multiprogramming
Use multiprogramming technology to divide a physical CPU into multiple logical CPUs
virtual technology
time division multiplexing technology
time sharing
space division multiplexing technology
virtual storage
asynchronous
Process execution is not done in one step, but in a stop-and-go manner because resources are limited.
The operating system serves as the interface between the user and the computer hardware system
How users use computers
1) Command interface
via command interpreter
The shell command parser is also a command interface
Online command interface
Suitable for time-sharing and real-time systems
Emphasis on user interactivity
Offline command interface
No manual operation required
for batch processing systems
Together with the pre-prepared jobs, they are handed over to the system. When the jobs are scheduled, the system's command interpreter controls the execution.
2) Program interface
Consists of system calls
Use system calls to request the operating system to provide services for it
The operating system does not provide system calls for the system cache, and the cache is transparent to the user.
development path
1) Manual operation stage
There is no operating system at this time and all work is done manually
2) Batch processing stage
Single lane batch processing system
1) Sequentiality
2) Automaticity
3) Unidirectionality
Only one program is executed in the memory
Multi-channel batch processing system
through multiprogramming techniques
Multiple programs enter the memory at the same time and are executed alternately within the CPU.
Shared hardware/software
When a program is suspended due to IO, the CPU immediately runs another program.
via interrupt
advantage
1) Multiple channels
2) Macro-parallelism
3) Micro serial
4) High utilization rate and large throughput
Disadvantages: Long response time, no human interaction provided, no control over the computer
3) Time-sharing operating system
Multiple users share a host simultaneously through the terminal
Through time slice rotation
Realize human-computer interaction
1) Simultaneity
2) Interactivity
3) Independence
Multiple users operate independently without interfering with each other
4) Timeliness
Get response in a short time
4) Real-time operating system
Complete urgent tasks (preemptive high-priority tasks) within a certain time limit, No need for time slice queuing
5) Network operating system and distributed computer system
network operating system
Each computer is organically integrated
distributed computer system
Every computer has equal status
6) Personal computer operating system
win,Linux,Mac OS
Operating environment
Processor operating mode
1) Privileged instructions
Directives that users are not allowed to use
IO instruction, set interrupt instruction, send status word, save register, set clock
Can only be executed in kernel mode
2) Non-privileged instructions
Directives that allow users to use
No direct access to system hardware and software resources
Only allow access to user address space
system call
Trap instructions, also known as access management instructions, are used to initiate system calls and request the system to provide services.
It is used in user mode. So it is not a privileged instruction
The program runs in user mode
Kernel programs run in kernel mode
The instruction to switch to user mode is a privileged instruction
The application requests services from the operating system through access management instructions, generates an interrupt event, and converts the operating system into kernel mode.
The execution process of generalized instructions (system call commands) must be in the kernel state. And its call may be in user mode or kernel mode.
Switching from user mode to kernel mode must pass an interrupt
As long as an interrupt occurs, it will inevitably switch to the kernel state.
subroutine call
Save only breakpoints
Next instruction address
User mode→core mode
example
Request system services
Interrupt occurs
User program error
User program wants to execute privileged instructions
The conversion from user mode to core mode is completed by hardware
It must be achieved through interrupts
As long as an interrupt occurs, it must be processed and must be converted to the kernel state.
When the user state enters the core state, not only the state is switched, but the stack is also converted to the system stack.
clock management
Implement process switching through clock interrupt management
clock interrupt
Process time-related information to decide whether to execute the scheduler
System time, time slice, delay, CPU usage time, timer, etc.
Interrupts and Exceptions
interrupt (external interrupt)
The operating system cannot operate without interrupts
Only a small part of the function belongs to the kernel, protecting and restoring interrupt scene information, Transfer control to the relevant handler
saved data
Hardware save
PC
Status word PSW
operating system save
general register x
abnormal (internal interrupt)
Illegal operation code, address out of bounds, overflow, page fault, self-trap, etc.
System call, access command
Exceptions cannot be masked and should be handled immediately once they occur.
primitive
is a procedure
1) At the bottom of the operating system
2) The program runs atomically
3) The program has short running time and frequent calls
4) Components of the kernel
management style
Device management
Process management
memory management
operating system structure
layered approach
It is difficult to define each layer
Modular
Inter-module interfaces are difficult to meet actual needs
macro kernel
The main functional modules all run in the kernel state as a closely related whole.
win, Linux, iOS, android
microkernel
The main functions are retained in the kernel, and functions that are not necessary to be executed in the kernel mode are transferred to the user mode.
File service runs in user mode
The main disadvantage is performance issues
Hongmeng OS
OS boot
Activate CPU
Execute JMP instruction to jump to BIOS
Register the entry address of the BIOS interrupt program
Hardware self-test
Load the hard drive with the OS
Load the Master Boot Record MBR
MBR contains hardware partition table
MBR checks the partition table to find the active partition and transfers the partition's startup program into memory for execution.
Scan hard drive partition
Load boot record PBR (Partition Boot Record)
Find and activate the program in the root directory of the partition used to boot the operating system
Load boot manager
Located on the hard disk and used to boot the operating system
Load OS
virtual machine
Chapter 2 Processes and Threads
Processes and Threads
concept
Process control block PCB
Enable each program (including data) participating in concurrent execution to run independently
PCB is the only sign of the existence of the process
Process Entity (Image)
It consists of three parts: program segment, relevant data segment and PCB
A process is the running process of a process entity
It is an independent unit for resource allocation and scheduling in the system.
feature
is caused by the concurrent execution of multiple programs
Dynamic
Concurrency
independence
Asynchronicity
Process status and transitions
Running state→Blocking state
Protect the scene
Process composition
PCB
Program section
Program code segments that can be scheduled by the process to be executed by the CPU
data segment
process control
Programs used for process control are called primitives
Each parent and child process has its own PCB
The parent process and the child process share some resources, but do not share the virtual address space
process terminated
event
End normally
abnormal end
outside intervention
process
Retrieve PCB, read status
Terminate operation
Give resources to other processes
or returned to the operating system
Kill all child processes
Remove PCB
process communication
Information exchange between processes
low level communication
PV operation
cannot be interrupted
advanced communications
shared storage
Threads within a process naturally share process space Process space is shared between processes through special system calls.
messaging
Data exchange is in formatted messages
direct communication
indirect communication method
The intermediate entity is the mailbox
pipe communication
Data is first in, first out in the pipeline
Pipe file exists in memory
If the data is read empty, the reading process blocks
Pipes can only be accessed by the creating process
Ordinary pipes only allow one-way communication
Threads and multithreading
Is a basic CPU execution unit
Is the smallest unit of program execution flow
Thread control block TCB consists of
Thread ID
program counter
register set
Stack composition
Thread-specific storage area
In the same process, multiple threads can execute concurrently
After introducing threads
The process serves as the allocation unit of system resources outside the CPU.
Threads as allocation units of the processor
Process is the basic unit that owns resources in the system. Threads do not own system resources.
Thread implementation
Classification
user-level thread
All work is done by the application in user space
Thread switching does not require kernel space and has low overhead
Choose different scheduling algorithms as needed
If a user-level thread is blocked, the entire process is also blocked.
Kernel level threads
Completed with operating system support
Thread switching in the same process requires switching from user mode to kernel mode, which is expensive
Multiple threads of the same process can be scheduled to execute in parallel on the CPU at the same time
multi-threaded model
many to one
Multiple users mapped to one core
One to one
many to many
Processor Scheduling
Scheduling concepts
Select a process from the ready queue according to a certain algorithm and assign the processor to it
Jobs and processes
Jobs are submitted by users and are based on user tasks. The process is generated by the operating system and is the basic unit for resource allocation and independent operation.
Scheduling hierarchy
Advanced scheduling
job scheduling
Job scheduling is scheduling between memory and auxiliary storage
Each job is loaded only once and loaded once
Intermediate Scheduling
memory scheduling
Program call out and call in
Improve memory utilization and system throughput
Processes that are not running temporarily are scheduled to external memory and suspended.
low level scheduling
process scheduling
Process scheduling frequency is high
The most basic and indispensable
Performance
CPU utilization
CPU effective working time / (effective waiting)
Turnaround time
Turnaround time = job completion time – job submission time
Average turnaround time = ∑turnaround time / n
Weighted turnaround time = job turnaround time / job actual running time
Average weighted turnaround time = ∑weighted turnaround time / n
waiting time
Response time
Scheduling implementation
scheduler
queuer
Dispatcher
context switcher
Execute a large number of load/store instructions and save register contents
Scheduling timing, switching and processes
Situations where scheduling and switching cannot be performed
1) During the process of handling interrupts
2) The process is in the critical section of the system kernel
After entering the critical section, lock it, Processes should not be switched before unlocking
3) During the atomic process
During atomic processes, even interrupts are masked
Situations that can be scheduled and switched
nondeprivation scheduling
A scheduling condition occurs and the current process cannot continue.
deprivation scheduling
Interrupt processing ends
The trap ends
Scheduling method
Non-preemptive
Let the current process continue even if an emergency process is ready
Preemptive
Emergency events have higher priority
Hanging out process
When there are no other processes running on the system, enable idle idle
Scheduling of two threads
user level
Thread switching within the same process, using a small number of machine instructions
kernel level
The kernel selects a specific thread to run and assigns it a time slice
Scheduling Algorithm
First come, first served
inalienable algorithm
The algorithm is simple and low in efficiency
Conducive to busy CPU operations Not conducive to busy IO operations
Short jobs first
Jobs with the shortest running time take precedence
Not good for long jobs
Failure to fully consider the urgency of the job
Average waiting time, lowest average turnaround time
priority scheduling
Execute according to job priority
Can be used for both process scheduling and job scheduling
priority
static priority
Once decided it cannot be changed
dynamic priority
The priority can be adjusted according to the situation
in principle
1) System process > User process
2) Interactive process > non-interactive process
3) IO process > Computing process
Because the IO device is slower than the CPU
High response ratio priority
Response ratio = (waiting time required service time) / required service time
time slice rotation
for time sharing systems
If the time slice is large enough that all jobs can be executed within one time slice, The time slice rotation algorithm degenerates into first come, first served
multi-level queue
Processes of different types or properties are assigned to different ready queues
Multi-level feedback queue
Multiple ready queues, each with different priorities
The process time slice size of each queue is different
Each queue is first come, first served
Queues are scheduled by priority
Compare
Process switching
context switch
Context refers to: the contents of the CPU registers and program counter at a certain moment
The CPU switches to another process and needs to save the state of the current process and restore the state of the other process.
Update PCB
Mode switching
Switching between user mode and kernel mode
Synchronization and mutual exclusion
concept
critical resources
Only one process is allowed to use it at a time
Such as printer, variable, data
Entry area
Check whether the critical section can be entered
critical section
The code in the process that accesses critical resources
Exit area
Clear the flag that the critical section is being accessed
remaining area
the rest of the code
Process synchronization
direct restrictive relationship
The relationship between processes is direct collaboration, and the concurrency of processes is asynchronous.
mutually exclusive
indirect constraints
When one process accesses a critical resource, another process must wait
criteria
Free to let in
If you are busy, wait
limited wait
Guaranteed to enter the critical section within a limited time
give way and wait
When the process cannot enter the critical section, the processor is immediately released to prevent the process from being busy waiting.
mutually exclusive methods
Software implementation method
single mark method
Double mark method check first
Double mark method post-inspection
peterson algorithm
To prevent two processes from entering the critical section and waiting indefinitely, the variable turn is set
Hardware implementation method
Interrupt masking method
Hardware command method
testandset
swap
Advantages of hardware implementation methods
Works with any number of processes
shortcoming
Hungry may occur
mutex lock
acquire
get lock
release
release lock
signal
PV operation is actually composed of two uninterruptible processes
The p operation is the wait operation, which means waiting until the resource is available. If the resource is unavailable, it enters the blocking state. The process during p operation is in running state
V operation is a single operation, which means that the process releases a resource so that the number of resources available for allocation in the system is 1
integer semaphore
record semaphore
Using semaphores to achieve process synchronization
Using semaphores to implement process mutual exclusion
The initial value of the mutex is generally 1, which means that only one process is allowed to enter the critical section at a time. When it is 0, it means that a process has entered the critical section and there is no process waiting outside the critical section. When the mutex is less than 0, it means that there is a process in the critical section. The absolute value of the mutex indicates the number of processes waiting outside the critical section.
Using semaphore to implement precursor
management
Process synchronization tool
Guaranteed process mutual exclusion
Able to achieve synchronization and mutual exclusion between processes
Only one process uses a shared resource at a time
A data structure that represents a shared resource, and a resource management program that consists of a set of procedures that operate on that shared data structure in real time
Signal is different from V operation. If there is no process blocked due to condition, signal has no effect.
Sync issues
producer consumer problem
reader-writer problem
read first
Write first
philosophers dining problem
Possible problems: when everyone grabs chopsticks (greedy algorithm), deadlock may occur.
smoker problem
deadlock
definition
Deadlock caused by multiple processes competing for a resource
These processes cannot continue without external forces
cause
1) Competition for system resources
Inalienable resources in the system, the quantity is not sufficient to satisfy multiple processes
2) The process advancement sequence is illegal
Improper order of requesting and releasing resources
Necessary conditions for deadlock to occur
1) Mutually exclusive conditions
A certain resource is only occupied by one process during a certain period of time
2) No deprivation of conditions
cannot be preempted by other processes
3) Request and hold conditions
The process has occupied a resource and requested another resource at the same time, and the resource occupied is not released.
4) Waiting in a loop
The resources occupied by each process are simultaneously requested by the next process
Deadlock handling strategy
1) Deadlock prevention
Destroy one or more of the four necessary conditions
1. Destruction of mutual exclusion conditions
Allow system resource sharing
2. Destroy the conditions of non-deprivation
Release processes that are occupying resources and cannot continue to execute
3. Destroy the request and keep the condition
Apply for all required resources at once and do not put it into operation before its resources are met.
4. Break the loop and wait
Adopt sequential resource allocation method
2) Deadlock avoidance
Prevent the system from entering an unsafe state
1. System security status
Before the system allocates resources, it should first calculate the security of the allocation.
safe state
There must be no deadlock
non-safe state
May enter a deadlock
2. Banker’s Algorithm
Prevent the system from entering an unsafe state
3) Deadlock detection and release
Detect the occurrence of deadlock and take some measures to relieve the deadlock
If the system does not take any measures when allocating resources to the process, deadlock detection and release methods should be provided.
Resource Allocation Map
The circles in the box represent resources
Process-to-resource directed edge call requests
deadlock release
1) Resource deprivation
The process that hangs the deadlock will seize its resources and allocate them to other deadlocked processes.
2) Undo the process
Forcibly cancel some or even all deadlocked processes and deprive them of resources
3) Process rollback
Let a deadlocked process roll back enough to avoid the deadlock
Compare
The difference between deadlock and starvation
hunger
Execution of a process is postponed indefinitely
There can be only one process that enters starvation
It can be ready or blocked.
deadlock
The process has reached an impasse and cannot move forward.
The number of processes entering a deadlock must be equal to or greater than two
The process in which deadlock occurs must be in a blocked state
Chapter 3 Memory Management
concept
Memory management is to better support the concurrent execution of multi-programs
Program linking and loading
Link
static link
The library function is linked into a load module and the relative address is modified.
Load-time dynamic linking
When loading into memory, link while loading
Runtime dynamic linking
Object modules that are not used during execution will not be loaded into memory or linked into modules.
load
Absolutely mount (static)
in the programming phase
Suitable for single program, logical address and memory address are exactly the same
It can be given by the programmer or by compilation or assembly.
relocatable load
static relocation
The process of modifying the instructions and data addresses in the target program during loading is called relocation.
Do not change after loading
When loading, modify the logical address to the final physical address
Dynamic runtime loading
dynamic relocation
After the loader loads the module into memory, it does not immediately convert the relative address of the loaded module into an absolute address, but postpones the conversion process until execution.
May be swapped out after loading
The addresses after loading into memory are all relative addresses.
memory protection
Add the logical address to the relocation value to get the physical address
Boundary address register determines whether it is out of bounds
Loading the relocation register and boundary address register must use privileged instructions, which is completed by the operating system kernel and is not allowed to be modified by the user.
memory sharing
Only read-only areas can be shared
Reentrant code (pure code) allows access by multiple processes but does not allow modification by any process
Reentrant technology reduces code transfers in and out, reducing the number of swaps to improve system performance.
Cover and swap
cover
The program segments to be accessed are put into the coverage area, and other segments are put into the external memory. The system needs to transfer them into the coverage area before calling and replace the original segments.
exchange
Transfer the waiting program from memory to auxiliary storage, which is intermediate scheduling
continuous allocation management
single contiguous allocation
The system area is used by the operating system and is placed in the low address part.
In the user area memory, there is only one user program
Use overlay technology
Partition management
The simplest storage management solution that satisfies multi-programming with the lowest cost
Fixed partition allocation
The user memory is divided into several fixed-size areas, and each partition only loads one job.
question
1) The program is too large to fit into any partition, so use overwriting technology
2) If the program is too small and placed in the partition, internal fragmentation will occur
Dynamic partition allocation
Over time, many small blocks of memory are created in the memory, called external fragmentation
Solved by compact technology, the operating system moves and organizes processes
allocation strategy
first fit algorithm
Link in order of increasing address
Neighbor Adaptation Algorithm
When allocating memory, search starts from the position where the last search ended.
best fit algorithm
Free partitions form a chain of free partitions in order of increasing capacity.
Generates the most external debris
worst fit algorithm
Form a chain of free partitions in descending order of capacity
Reclaim memory
Merging free areas through splicing technology
1) The recovery area is adjacent to the previous free partition of the insertion point
Merge two partitions and modify the size of the previous partition table entry to the sum of the two
2) The recovery area is adjacent to the free partition after the insertion point
The size of the modified partition table entry is the sum of the two
3) The recovery area is adjacent to the two partitions before and after the insertion point
Modify the size of the previous partition table entry to the sum of the three
Cancel the next partition table entry
4) The recycling area has no adjacent free partitions
Create a new table entry for the recycling area, fill in the starting address, size, and insert the free partition chain
The physical address space provided by the system to the user is the total space size minus the length of the page table or segment table.
Pagination management
Paging management produces internal fragmentation but does not produce external fragmentation
A block in a process is called a page, and a block in memory is called a page frame.
The address structure determines the addressing space size of virtual memory
The system creates a page table for each process, and the page table is stored in memory.
The starting address of the page table is placed in the page table base address register
Once the page size is determined, all pages are the same size (power of 2)
Address Translation Authority
Segmentation management
generate external fragmentation
Continuous within a segment, but not required to be continuous between segments
Segmentation is when users program, the program is divided into several logical segments according to logic.
related to logical structure
Dynamic linking that facilitates programs
Segment page management
generate internal fragmentation
The system creates a segment table for the process, and each segment has a page table.
Segmented approach to managing and allocating user address space Paging method to manage and allocate physical address space
One access actually requires three accesses to main memory.
virtual memory management
feature
multiple times
The job is divided into multiple times and loaded into memory.
interchangeability
Recall unused programs and data out of memory
virtuality
Logically expand memory capacity
Actual capacity of virtual memory ≤ memory capacity external storage capacity
The maximum capacity of virtual memory ≤ the maximum capacity that the computer’s address bits can accommodate
Implementation
1) Request paging management
Requires hardware support
Memory, external memory, interrupt mechanism, address conversion, etc.
Page table mechanism
Page number, physical block number, status bit, access field, modification bit, external memory address
Page fault interrupt mechanism
When the accessed page is not in the memory, a page fault interrupt is generated and the system is requested to transfer it into the memory.
The page fault rate is affected by the page size, the number of physical blocks allocated, the replacement algorithm, and programming.
Address Translation Authority
Page frame allocation
resident set
A collection of page frames allocated to a process
The fewer page frames allocated to a process, the more processes will reside in main memory, improving CPU utilization.
A process has too few pages in main memory and the page fault rate is relatively high.
Memory allocation strategy
1) Fixed allocation of local replacement
Allocate a certain number of physical blocks to the process. After a page fault occurs, select a page from the memory page allocated to the process and call it out.
2) Variable allocation global replacement
Allocate a certain number of physical blocks, which can be increased or decreased appropriately Global replacement: select a block from free physical blocks and assign it to the process, and transfer the missing page
3) Variable replacement local replacement
When a page is missing, only this process is allowed to select one page from the memory pages and call it out.
Physical block loading algorithm
fixed allocation strategy
1) Average distribution algorithm
2) Distribute proportionally
Allocate proportionally according to process size
3) Priority allocation
Allocation based on urgency
Time to load the page
Load before running
Called during runtime
replacement algorithm
1) Best replacement algorithm
Eliminate pages that will never be used or pages that have not been used for the longest period of time
2) First in first out algorithm
Belady abnormality will occur
The number of allocated physical blocks increases, and the number of page faults increases instead of decreasing.
3) Not used recently and for the longest time
Requires hardware support for registers and stacks
Because it needs to calculate pages that have not been visited recently, it is expensive.
4) Clock algorithm
5) Improved clock algorithm
Added modification bit
Prioritize pages that have not been used or modified
Judgment based on access bit A and modification bit M
Jitter and working set
Jitter
The page that was just swapped out needs to be swapped in again immediately (pages are frequently loaded in and out)
High page fault rate
reason
There are too many processes running simultaneously in the system and too few physical blocks allocated to each process.
working set
A collection of pages that a process will access within a certain period of time
Prevent jitter
2) Request segment management
3) Request segment page management
Chapter 4 Document Management
file properties
name
type
creator
owner
Location
size
Protect
time
File is an abstract data type, data structure
File Control Block FCB
file directory entry
Data structure that stores various information required by the control file
Access by name
Contains: basic information, access control information, usage information
index node inode
File directory on disk
disk index node
Each file has a unique disk index node
Primary identifier, type, permissions, physical address, length, link count, access time
memory index node
Index nodes stored in memory
When the file is opened, the disk index node is copied to the memory index node.
Node number, status, access count, logical device number, link pointer
File operations
open and close
Open
Call open to search the directory according to the file name, copy the attributes of the specified file (including physical location) from the external storage to the entry of the open file table in the memory, and return the entry number to the user
Store FCB in the memory file directory table
closure
Call close, the system will open the file table to delete this entry
During the read call, if the file is not in memory, the process goes to sleep.
File protection
Password protection
The password is stored inside the system and is not secure enough.
Encryption protection
Prevent files from being stolen
Access control
Control how users access files
The logical structure of the file
Unstructured files (streaming files)
Sequentially organized into records (ordered collections)
There are structured files (recorded files)
sequence file
string structure
Sorted by deposit time
sequential structure
Sort by keyword
index file
fixed length record file
variable length record file
sequential search
index sequence file
N records are divided into √N groups. There are √N entries in the index table, and a total of √N/2 √N/2 searches are required.
direct file/hash file
Given the key value of the record or the key value transformed by the hash function, the physical address of the record is determined.
The physical structure of the file
Allocation
continuous allocation
Supports sequential access/random access
Fast access speed
Repeatedly deleting files creates external fragmentation
Inconvenient to add, delete or modify
The file physical address field in the file's directory entry includes the address of the first block and the length of the file allocation area.
Link assignment
Discrete allocation method
External debris eliminated
Inconvenient to check
implicit link
Only suitable for sequential access
The directory contains a pointer to the first block of the file and a pointer to the last block
generate internal fragmentation
explicit link
A link table that explicitly stores link pointers in memory is called a file allocation table (FAT). Each entry stores the next disk block number
There is only one FAT in the entire disk, and it is also a data structure.
FAT entries correspond to physical disk blocks one-to-one. The special number -1 can be used to represent the last block, and other numbers can be used to indicate that the disk block is free. FAT not only records the link relationship of each block, but also marks the free disk. piece
index allocation
Support random access
Access is not as fast as continuous allocation
no external debris
Mixed index allocation
Table of contents
Directory Structure
Single directory structure
Access by name
Search speed is slow, duplicate names are not allowed, and sharing is inconvenient
Secondary directory structure
Solved the duplicate name problem
Unable to classify files, lack of flexibility
tree directory structure
Access to files by a process is equivalent to the current directory.
Intermediate nodes need to be accessed step by step by path name, which increases the number of disk accesses.
Acyclic graph directory structure
For shared files, only one real file exists and any changes will be visible to other users.
Directory implementation
linear list
Takes a linear list of filenames and pointers
Using a chain structure can reduce the time of deleting files
Time-consuming search
Hash table
Find quickly
Need to avoid conflicts
File Sharing
static sharing
Hard link (based on index node)
The physical address of the file and the file attribute information are no longer placed in the directory entry, but in the index node.
The index node also has a count, which indicates that it is shared by several users.
Soft links (using symbolic links)
Create a link file and find the file based on the path name in the file
Only the file owner has a pointer to its index node Other users only have the pathname of this file
Every time you access a file, you have to read the disk multiple times, which is expensive.
When sharing network files, you only need to provide the network address of the machine where the file is located and the file path name.
dynamic sharing
Several users operate on a file at the same time
File system
The structure of the file system in external memory
physical format
Divide sectors, check bad sectors, replace bad sectors
Logical formatting
Disk partition, complete file system initialization of each partition
produce
Master Boot Record MBR
Determine the active partition and read the boot block
boot block
MBR executes the program in the boot block and starts the operating system
super block
Contains all key information of the file system. When the file system is started for the first time, the super block is read into the memory.
Free space management
Such as: bitmap
i node area
Index nodes are stored continuously and have the same size.
Root directory
The structure of the file system in memory
user area
file descriptor/file handle
kernel area
directory cache
System open file table
only one
User opens file table
Contains system open file table index
virtual file system
Provide a unified and standard system call interface to upper-level users Shield implementation differences of underlying specific file systems
It is required that the lower-level files must implement certain functions
Each opened file will create a vnode in the main memory, represented by a unified data structure
vnode only exists in main memory The inode will be loaded into main memory and stored in external memory.
File system mounting (installation)
Register the newly mounted file system in the virtual file system, The memory mount table contains information for each file system
The newly mounted file system must provide a function address list to the virtual file system.
Mount the file system to the mount point (parent directory)
File space management
Storage space division
Divide the physical disk into file volumes (logical disk, logical volume)
A file volume can be composed of multiple physical disks
Storage space initialization
File volume initialization
directory area
Stores file directory information FCB, information used for disk storage space management
file area
Store file data
space management
free list method
Belongs to continuous allocation method
Allocate contiguous storage space for files
First adaptation, best adaptation, and worst adaptation can be used
Recycling is the same as dynamic allocation
free list method
Free disk chain
Link free disk blocks like a linked list
The free disk block stores a pointer to the next free disk block.
distribute
Find the disk blocks that meet the conditions through the adaptation algorithm
Recycle
Hang the recycled disk blocks to the end of the chain
Allocation and recycling are simple but inefficient
free extent chain
Several consecutive free disk blocks constitute a free disk area
The extent length is recorded in the first free disk block in the extent and is a pointer to the next extent.
distribute
Usually first adaptation
Recycle
Merge reclaim area with adjacent free extents
Allocation and recycling are troublesome, but efficient
Bitmap method
Use binary bits to indicate whether a disk block is used
Disk number b = n×i j
n represents the word length
i represents font size (line number)
i = b/n
remove
j represents the bit number (column number)
j = b%n
Take remainder
Applicable to both continuous and discrete allocations
Group linking method
The group chain block (super block) is used to store the block number of the free disk block and the number of the next group of free disk blocks.
The block number of the free disk block is the first disk block number of the group block (extent)
The number of a group is limited, for example: only 100 free disk blocks are allowed to form a group
If there is no free disk block for the next group, the block number is set to -1
distribute
Allocate from the last disk block and change the number of free disk blocks in the super block
If a certain block stores the next group of information, the information must be copied to the super block and then allocated.
Recycle
If the super block is not full
Then insert the recycled block directly after the super block
If the super block is full
Linked list-like head insertion method
disk
structure
disk
track
sector
It's a disk block
Each sector has the same capacity, and the innermost sector has the highest density.
Disk
Each disk surface corresponds to a magnetic head
cylinder
Tracks with the same relative position on all disks form a cylinder
The disk address is represented by (cylinder number-disk number-sector number)
Disk scheduling algorithm
The time required for a read and write
seek time
Start the head arm
Time taken
moving head
It takes m to span one track and needs to span n tracks.
=sm×n
Transmission time
Read/write time
The rotation speed is r, the number of bytes read and written is b, and the number of bytes on each track is N
= b/(r N)
delay
The disk speed is r
= 1/(2r)
Disk scheduling algorithm
Will directly affect the seek time
First come, first served
Shortest search time first
May cause hunger
Scan algorithm
The magnetic head can only move in the opposite direction when it moves to the innermost or outermost track.
Even if the outermost or innermost layer does not process the request, you still have to move here before starting to move in the opposite direction.
Will not cause hunger
look algorithm
Scanning algorithm improvements
If there are no other requests in the direction of head movement, you can change the direction directly.
Cycle scan (elevator dispatch)
Solve the problem of uneven response of scanning algorithm to various positions
Do not respond to any requests when returning and move directly to the starting end
Only change direction after moving to the very edge (same as scanning algorithm)
c-look algorithm
Loop scan improvements
There is no need to move to the edge to change the direction. The moving direction can change the direction without other requests.
Ways to reduce latency
alternate numbering
Keep logically adjacent sectors physically separated
Misplaced naming
Let the sectors in the same sector be staggered (for example, sector 0 and sector 1 are separated by sectors with other numbers)
Address structure design
Cylinder number-disk number-sector number
Reduced head movement time
Disk management
Disk initialization
physical format
Divide each disk track into sectors
Partition
Partition the disk, each partition consists of several cylinders
Logical formatting
Create file system
boot block
A series of initialization work is required when the computer is turned on, and the initialization work is completed by executing the bootloader program.
The complete bootloader is stored on the startup block (boot block) of the disk, which is located at a fixed location on the disk
Bad block processing
Bad blocks are hardware failures
For simple disk
Bad blocks are opaque to the operating system (will be marked)
For complex disks
sector spare
For complex disks, the disk controller will maintain a bad block linked list, initialize it during physical formatting, and use spare sectors to replace bad blocks.
Solid state drive SSD
principle
Based on flash memory Belongs to electrically erasable ROM (EEPROM)
composition
flash translation layer
Translation logical block number
Find the corresponding page
storage media
Multiple flash memory chips
Each chip contains multiple blocks
Each block contains multiple pages
Read and write performance
in pages
in blocks
Support random access
Fast reading speed Slow writing speed
Comparison with mechanical hard drive
SSD reads and writes faster than mechanical hard drives and has random access
SSD is quiet and noiseless
A certain block of SSD will be damaged after being erased multiple times. Mechanical hard disk sectors will not be damaged due to heavy writing
Wear leveling
average erase operations across blocks
Dynamic wear leveling
When writing data, give priority to flash memory blocks with fewer accumulated erases.
static wear leveling
The old block is responsible for read operations. The new block is responsible for write operations.
Static is better than dynamic
Chapter 5 IO Management
Equipment classification
block device
Data exchange is in blocks
High transmission rate
character device
Data exchange is in characters
Transfer rate is low and not addressable
low speed device
Mouse and keyboard
medium speed equipment
printer
high speed equipment
disk drive, CD drive
io interface
device controller
Located between the CPU and the device
Interface between device controller and cpu
Contains data lines, address lines, control lines
Interface between device controller and device
There are one or more device interfaces in the controller
io logic
Realize control of equipment
Device controller functions
Accepts commands to identify the CPU
data exchange
Identify and report device status
address recognition
data buffer
error control
io port
Registers in the device controller that can be directly accessed by the CPU
In other words, multiple io ports form an io interface
data register
status register
control register
CPU and io port communication method
Independent addressing
Assign a port number to each port and only the operating system can access the port using special io instructions
Unified addressing
Each port is assigned a unique memory address
io control method
direct program control
The CPU checks the peripheral status in a loop until it determines that the word is in the io controller's data register
Interrupt driven mode
Allow io devices to actively interrupt the operation of the CPU and request services, thereby freeing up the CPU
Interrupt the CPU every time data needs to be transferred
DMA mode
Establish a direct data exchange path between io devices and memory
Interrupts the CPU at the end of the requested batch of data transfer
When the CPU issues an instruction, it can only read or write consecutive data blocks.
Channel control mode
A processor specifically responsible for input and output
is a kind of hardware
The CPU issues an io command, indicating the location of the channel program and the io device for execution.
The channel executes the channel program in memory
Channels share memory with the CPU
io software hierarchy
User io software
Implement spooling technology
virtual device technology
Improve utilization of exclusive equipment
Convert an exclusive device to a shared device
Ease the contradiction between high speed of CPU and low speed of io device
via software
Requires multi-programming technical support
The system opens up two areas in the fixed area of the disk, input and output wells.
Open up two buffers in memory: input buffer and output buffer
Shared printer
Exclusive device
A device that allows serial use by individual processes
Use static allocation
Shared device
A device that allows multiple processes to use it together
Simultaneous use in a macro sense Microscopically, it still alternates
Use dynamic allocation
Shared printing principles
The system puts the print requests required by each user into the input well of the disk, and uses the speed difference between the disk, memory, and CPU to achieve microscopic alternation and macroscopic simultaneous
Device-independent software (device-independent software)
independence
The device the user is programming with has nothing to do with the actual device
Function
Manage logical device table
Only set up one system logical device table LUT
Set up logical device table LUT for each user
error control
Equipment allocation and recycling
Factors considered in allocation
Device intrinsic properties
Device Allocation Algorithm
Device allocation security
Safe distribution method
After the process issues an IO request, it enters the blocking state and is not released until the IO operation is completed.
CPU and io devices become serial work
Unsafe allocation method
After the process issues an io request, it continues to run and can still issue io requests. It will only enter blocking when the io request cannot be satisfied.
deadlock possible
allocation strategy
static allocation
Allocate all the resources needed from the start
dynamic allocation
Continue allocation as needed during process execution
Device allocation data structure
Channel, controller, device relationship
Device Control Table DCT
Represents a certain device, and the table entry content is each attribute of the device.
Controller control table COCT
Channel control table CHCT
Each channel corresponds to a CHCT
System Device Table SDT
Including all devices
Assignment step improvements
User supplied logical device name
Through the mapping of logical device names and physical device names (logical device table LUT)
LUT entries include logical device names, physical device names, and device driver entry addresses.
Buffer management
Purpose
Solve the problem of data accumulation caused by the input and output speed being slower than the CPU processing speed
single buffer
Calculate the processing time of each piece of data
Assume an initial state and calculate the time it takes to reach this state next time
The time of input to the buffer is T, the time of transferring the buffer to the work area is M, and the time of processing the data is C
Initial state: work area full, buffer empty
Time taken to process each block of data: MAX (C, T) M
The formula is for reference, specific problems are analyzed in detail, and a Gantt chart is used.
double buffering
The work area is empty, one buffer is empty and one buffer is full.
Time taken to process each block of data: MAX (C M, T)
buffer pool
Enable concurrent processes to efficiently input and output
Implement io scheduling
Use some algorithm to determine a good order to process io requests
Device protection
Devices are viewed as special files, each file is assigned FCB, and permissions are set
device driver
Specific control over hardware devices
Calculate the cylinder number, head number, sector number, etc. of the disk where the data is located
Different devices require different drivers
io API
character device interface
get/put call, read and write a character to the character device
block device interface
read/write system call: read and write characters seek: Modify
Network device interface
network socket interface socket system call: Create a network socket and specify the network protocol bind: Bind the socket to the local port connect: connect the socket to the remote address read/write: read and write data from the socket
Blocking/non-blocking io
blockingio
The program issues an io system call, and the process becomes blocked and waits.
non-blocking io
The program issues an io system call, and the system call can return quickly, and the process does not need to block and wait.