Professional Documents
Culture Documents
认识操作系统
认识操作系统
I/O
shell
Win 32 API
-
UNIX
Windows
POSIX
Peterson
TSL
Futexes
Pthreads
-
- -
TLB
LRU
inode
inode
I/O
I/O
I/O
I/O
DMA
IO
I/O
I/O
I/O
DMA I/O
I/O
I/O
I/O
RAID
-
RR
RAID
DMA
/
Windows Linux FreeBSD OS X
(Graphical User Interface, GUI)
Shell
(shell GUI)
Web
CPU I/O
CPU
CPU CPU
add
(program counter)
(stack pointer)
CPU CPU
CPU
CPU N N+1 N+2
(pipeline)
(superscalar) CPU CPU
CPU CPU
PSW
CPU
CPU
I/O
PSW
(system call)
TRAP
Intel Pentinum 4 (multithreading)
(hyperthreading, Intel ) x86 CPU
SSPARC Power5 Intel Xeon Intel Core CPU
(nanosecond)
( ) CPU
CPU
CPU CPU 4
CPU
CPU
CPU
L2 4
L2 4
(
CPU )
CPU CPU CPU
(cache lines) 64
0 - 63 0 64 - 127 1
CPU CPU
(cache hit)
RAM
RAM
/home/ast/projects/minix3/src/kernel/clock.c
Web (URL) (IP
)
CPU
CPU L1 cache
CPU CPU
L1 cache L1 cache 16 KB
L2 cache L1 cache L2 cache
L1 cache L2 cache 1-2
CPU
CPU
RAM(Random Access
Memory) 1950 1960
RAM
ROM(Read Only Memory)
ROM
bootstrap ROM
I/O ROM
RAM
CMOS CMOS
( ) RAM
5400rpm 7200rpm 10800rpm
33
(track)
(cylinder)
512
1ms 5ms
10ms
50MB/s 160MB/s
RAM
CPU (Memory Management Unit, MMU)
MMU
(context switch)
I/O
CPU I/O
I/O
I/O
SATA SATA
ATA (AT Attachment) SATA
(Serial ATA)
20
SATA
(device driver)
UNIX
Windows
I/O
I/O
I/O
IN OUT
I/O
I/O
I/O
(busy waiting)
CPU CPU I/O I/O
I/O
2
CPU 3
CPU
CPU
CPU PSW CPU
(interrupt vector)
PSW
CPU
CPU
CPU
IBM PC
IBM
PC I/O CPU
x86
32
32 32
BIOS I/O
BIOS CMOS
RAM BIOS
BIOS BIOS
BIOS BIOS
CMOS
BIOS
CD-ROM USB boots
BIOS
CD-ROM Internet
GUI
I/O 1000 G
Web
CPU
Windows Linux
DVD MP3
ROM
Linux QNX VxWorks
CPU RAM ROM
CPU
Java
ROM Java Java Virtual Machine, JVM
UNIX
(Process)
(address space) ( )
(registers)
(program counter) (stack pointer)
Web
CPU CPU
read
(process table)
core image
A B C B
D E F
(interprocess
communication)
(alarm signal)
UID(User IDentification)
UID UID
GID(Group IDentification)
32 64 2^32 2^64
I/O
(directory)
(Root directory)
(path name)
CS101
/Faculty/Prof.Brown/Courses/CS101 /
Windows \ Linux /
(working directory)
/Faculty/Prof.Brown
/Courses/CS101
(file descriptor)
UNIX (special file) I/O
I/O
(block special file) (character
special file)
4 4
/dev /devv/lp
(pipe)
A B A B
UNIX
rwx rwxr-x--x
shell
UNIX
shell shell
shell
(prompt) ($) shell
1 date
shell date shell
shell
CPU
read
C
read
1 count = read(fd,buffer,nbytes);
count nbytes
count -1
errno
read
read(fd, buffer, nbytes) 11
C C++ printf( )
&
C read
TRAP
TRAP
TRAP
TRAP
TRAP
8
TRAP dispatch
TRAP
(increment stackpointer)
read read
TRAP
pid = fork()
s = execve(name,argv,environp)
exit(status)
fd = open(file, how,...)
s = close(fd)
n = read(fd,buffer,nbytes)
n = write(fd,buffer,nbytes)
position = iseek(fd,offset,whence)
s = stat(name,&buf)
s = mkdir(nname,mode)
s = rmdir(name)
s = unlink(name)
s = mount(special,name,flag)
s = umount(special)
s = chdir(dirname)
s = chmod(name,mode)
s = kill(pid, signal)
pid id fd n
position seconds
fork 0
(Process IDentified,PID) PID
fork
waitpid
waitpid -1
waitpid statloc
1 #define TRUE 1
2
3 /* */
4 while(TRUE){
5
6 /* */
7 type_prompt();
8
9 /* */
10 read_command(command,parameters)
11
12 /* fork */
13 if(fork() != 0){
14
15 /* */
16 /* */
17 waitpid(-1, &status, 0);
18 }else{
19
20 /* */
21 /* */
22 execve(command,parameters,0)
23 }
24 }
execve
shell
1 cp file1 file2
cp C
1 main(argc,argv,envp)
argc argc 3
argv i i
argv[0] cp argv[1] file1 argv[2] file2 main
name = value
execve 0 execve 0
Iseek
UNIX
stat s = stat(name,&buf)
fstat
mkdir
rmdir s = mkdir(nname,mode) s = rmdir(name)
s = link(name1,name2)
link link
1 link("/usr/jim/memo", "/usr/ast/note");
mount s = mount(special,name,flag)
USB
mount USB
a b
1 mount("/dev/sdb0","/mnt",0)
USB 0
umount
chdir chdir
1 chdir("/usr/ast/test");
xyz /usr/ast/test/xyz
UNIX - -
chmod
1 chmod("file",0644);
kill
Win 32 API
UNIX Win 32 Windows UNIX
UNIX
Windows Windows
USB UNIX
Win32 API
Win32 API
GUI
fork CreateProcess
waitpid WaitForSingleObject
exit ExitProcess
open CreateFile
close CloseHandle
read ReadFile
write WriteFile
lseek SetFilePointer
stat GetFileAttributesEx
mkdir CreateDirectory
rmdir RemoveDirectory
unlink DeleteFile
chdir SetCurrentDirectory
time GetLocalTime
ExitProcess
6 UNIX UNIX
SetFilePointer GetFileAttributesEx
Windows CreateDirectory RemoveDirectory API
SetCurrentDirectory GetLocalTime
I/O
UNIX (shared library)
Windows (Dynamic Link Library,DLL) .dll
C:\Windows\system32 1000 DLL C
E.W.Dijkstar THE
3 /
2 -
0 0
1
1
2 3 I/O
4 I/O
5
-
--- ---
MINIX 3
MINI 3
(reincarnation server)
-
-
PC web
PC Web Web
-
CPU CPU CPU
CPU
Web Web
CPU
PC
CD-ROM
CPU
CPU 1
(pseudoparallelism)
( CPU )
CPU CPU
CPU
(sequential
processes) (process)
CPU
CPU
4
4 4
CPU 2 CPU
CPU CPU
CPU CPU
CPU
CPU
init
fork
(numerous processes)
e-mail web
(daemons) UNIX ps
Windows
CPU
UNIX X Windows
web IDE
UNIX fork
fork
execve
shell sort shell fork
sort fork execve
CreateProcess Win
32 100 UNIX
Windows
UNIX Win32
fork CreateProcess
waitpid WaitForSingleObject
exit ExitProcess
open CreateFile
close CloseHandle
read ReadFile
write WriteFile
lseek SetFilePointer
stat GetFileAttributesEx
mkdir CreateDirectory
rmdir RemoveDirectory
unlink DeleteFile
chdir SetCurrentDirectory
time GetLocalTime
UNIX Windows
UNIX
UNIX
(copy-on-write)
Windows
( )
( )
( )
( )
1 cc foo.c
foo.c
0 UNIX
UNIX
kill Win32 TerminateProcess
UNIX
UNIX
kill
UNIX
init init
shell
init
Windows
Windows Windows
UNIX
Windows
shell
cat grep
tree CPU
grep
grep
1. CPU
2.
3.
CPU CPU
1
pause UNIX
2 3
2
CPU CPU
3
4
3 CPU
(process table)
text segment data segment stack segment
( )
CPU
I/O (interrupt vector)
3
1.
2.
3.
4.
5. C
6.
7. C
8.
10 - 100
CPU
I/O
web
Web
(cache)
CPU
web
web (dispatcher thread)
web
web read
web
1 while(TRUE){
2 get_next_request(&buf);
3 handoff_work(&buf);
4 }
1 while(TRUE){
2 wait_for_work(&buf);
3 look_for_page_in_cache(&buf,&page);
4 if(page_not_in_cache(&page)){
5 read_page_from_disk(&buf,&page);
6 }
7 return _page(&page);
8 }
Web Web
read read
I/O
(finite-state machine)
(thread)
CPU
(lightweight processes)
(multithreading)
CPU
thread_create
thread_exit
thread_join
thread_yield CPU
CPU
POSIX
IEEE IEEE 1003.1c
Pthreads UNIX 60
POSIX pthreads
IEEE
pthread_create
pthread_exit
pthread_join
pthread_yield CPU
pthread_attr_init
pthread_attr_destory
Pthreads
pthread_create
UNIX fork PID
pthread_exit
pthread_join
pthread_yield
pthread_attr_init
pthread_attr_destroy
pthread
1 #include <pthread.h>
2 #include <stdio.h>
3 #include <stdlib.h>
4
5 #define NUMBER_OF_THREADS 10
6
7 void *print_hello_world(vvoid *tid){
8 /* */
9 printf("Hello World. Greetings from thread %d\n",tid);
10 pthread_exit(NULL);
11 }
12
13 int main(int argc,char *argv[]){
14 /* 10 */
15 pthread_t threads[NUMBER_OF_THREADS];
16 int status,i;
17
18 for(int i = 0;i < NUMBER_OF_THREADS;i++){
19 printf("Main here. Creating thread %d\n",i);
20 status = pthread_create(&threads[i], NULL, print_hello_world, (void *)i);
21
22 if(status != 0){
23 printf("Oops. pthread_create returned error code %d\n",status);
24 exit(-1);
25 }
26 }
27 exit(NULL);
28 }
NUMBER_OF_THREADS
pthread_create, pthread_exit, pthread_join pthread_yield
(Runtime System)
(thread table)
pthread_yield
I/O
CPU
CPU
shell
A B B
A
(spooler directory)
(printer daemon)
(slot) 0 1 2 ...
out in
0
3 4 6 A B
(Murphy)
A in 7 7 next_free_slot
CPU A B B in 7
B 7 next_free_slot
7
B slot 7 in 8 B
A A next_free_slot slot 7
slot 7 in 8 slot 7 B
A B
B
(race condition)
(mutual exclusion)
A B
1.
2. CPU
3.
4.
t1 A t2
B A B t3
A B t4 B
CPU
CPU
disable CPU
CPU
0
0 0 1
1 0
0 1
0
1 0 1
1
set-before-check
C C
C C++ Java Modula3 Pascal Java
native C C++ C
Java
C C
C C++ Java
1 while(TRUE){
2 while(turn != 0){
3 /* */
4 critical_region();
5 turn = 1;
6 /* */
7 noncritical_region();
8 }
9 }
1 while(TRUE){
2 while(turn != 1){
3 critical_region();
4 turn = 0;
5 noncritical_region();
6 }
7 }
turn 0
0 turn 0 1 0
turn 1
(busywaiting) CPU
(spinlock)
0 turn 1 1 1
turn 0 0
turn 1 turn 1
0 turn
1 1 0 while 1 turn
0
3 0
Peterson
T.Dekker
Dekker
G.L.Peterson
1 #define FALSE 0
2 #define TRUE 1
3 /* */
4 #define N 2
5
6 /* */
7 int turn;
8
9 /* 0 (FALSE) */
10 int interested[N];
11
12 /* 0 1 */
13 void enter_region(int process){
14
15 /* */
16 int other;
17
18 /* */
19 other = 1 - process;
20
21 /* */
22 interested[process] = TRUE;
23 turn = process;
24
25 /* */
26 while(turn == process
27 && interested[other] == true){}
28
29 }
30
31 void leave_region(int process){
32
33 /* */
34 interested[process] == FALSE;
35 }
0 1
enter_region
leave_region
0
enter_region turn 0 1
enter_region enter_region 1
interested[0] FALSE 0 leave_region
enter_region
turn
1 turn 1 while 0
1 0
TSL
1 TSL RX,LOCK
1 2 2
1
1 enter_region:
2 | 1
3 TSL REGISTER,LOCK
4 | 0
5 CMP REGISTER,#0
6 |
7 JNE enter_region
8 |
9 RET
10
11 leave_region:
12
13 | 0
14 MOVE LOCK,#0
15 |
16 RET
Peterson 4
lock lock 1 0
0
0 lock
enter_region
lock 1 lock 0
leave_region lock 0
enter_region leave_region
TSL XCHG
1 enter_region:
2 | 1
3 MOVE REGISTER,#1
4 |
5 XCHG REGISTER,LOCK
6 | 0
7 CMP REGISTER,#0
8 | 0
9 JNE enter_region
10 |
11 RET
12
13 leave_region:
14 | 0
15 MOVE LOCK,#0
16 |
17 RET
CPU
H L
H H L H
I/O H H L
L H
(priority inversion problem)
- (producer-consumer)
(bounded-buffer)
(producer) (consumer)
m n
count N count N
count count
0 0 count
1 /* slot */
2 #define N 100
3 /* */
4 int count = 0
5
6 //
7 void producer(void){
8 int item;
9
10 /* */
11 while(TRUE){
12 /* */
13 item = produce_item()
14 /* */
15 if(count == N){
16 sleep();
17 }
18
19 /* */
20 insert_item(item);
21 /* count */
22 count = count + 1;
23 if(count == 1){
24 /* */
25 wakeup(consumer);
26 }
27 }
28 }
29
30 //
31 void consumer(void){
32
33 int item;
34
35 /* */
36 while(TRUE){
37 /* */
38 if(count == 0){
39 sleep();
40 }
41 /* */
42 item = remove_item();
43 /* count */
44 count = count - 1
45 /* */
46 if(count == N - 1){
47 wakeup(producer);
48 }
49 /* */
50 consumer_item(item);
51 }
52
53 }
C sleep wakeup
C
insert_item remove_item
- count
count 0
count 1 count 0
wakeup wakeup
count 0
2 4 6 8
E.W.Dijkstra 1965
(semaphore) 0
0
wakeup
1 /* */
2 #define N 100
3 /* int */
4 typedef int semaphore;
5 /* */
6 semaphore mutex = 1;
7 /* buffer */
8 semaphore empty = N;
9 /* buffer */
10 semaphore full = 0;
11
12 void producer(void){
13
14 int item;
15
16 /* TRUE 1 */
17 while(TRUE){
18 /* */
19 item = producer_item();
20 /* 1 */
21 down(&empty);
22 /* */
23 down(&mutex);
24 /* */
25 insert_item(item);
26 /* */
27 up(&mutex);
28 /* buffer + 1 */
29 up(&full);
30 }
31 }
32
33 void consumer(void){
34
35 int item;
36
37 /* */
38 while(TRUE){
39 /* - 1 */
40 down(&full);
41 /* */
42 down(&mutex);
43 /* */
44 item = remove_item();
45 /* */
46 up(&mutex);
47 /* + 1 */
48 up(&empty);
49 /* */
50 consume_item(item);
51 }
52
53 }
up down
CPU
TSL XCHG CPU
full empty
mutex Full
0 empty mutex 1 1
(binary
semaphores) down up
1.
2.
3.
4.
5. C
6.
7. C
8.
I/O
0 I/O down
up
5 C
up 6
mutex
(synchronization) full empty
mutex
mutex( )
(unlocked) (locked)
(integer) 0
1
mutex mutex_lock
mutex
mutex_unlock mutex
mutex_lock enter_region
TSL TSL
TSL mutex
mutex/TSL
thread_yield CPU
mutex_trylock
Futexes
(synchronization) (locking)
(Spin lock)
CPU
futex
(fast user space mutex)
futex Linux
futex
(wait queue)
futex 32 (integer)
1
(decrement and test) decrement and set Linux C
futex
Pthreads
Pthreads
mutex mutex
mutex
mutex
mutex Phread_mutex_init
Pthread_mutex_destroy mutex Pthread_mutex_lock
Pthread_mutex_trylock mutex
Pthread_mutex_unlock mutex
mutex
pthread
Pthread_cond_wait
Pthread_cond_signal
Pthread_cond_broadcast
1 #include <stdio.h>
2 #include <pthread.h>
3
4 /* */
5 #define MAX 1000000000
6 pthread_mutex_t the_mutex;
7 /* */
8 pthread_cond_t condc,condp;
9 int buffer = 0;
10
11 /* */
12 void *producer(void *ptr){
13
14 int i;
15
16 for(int i = 0;i <= MAX;i++){
17 /* mutex */
18 pthread_mutex_lock(&the_mutex);
19 while(buffer != 0){
20 pthread_cond_wait(&condp,&the_mutex);
21 }
22 /* */
23 buffer = i;
24 /* */
25 pthread_cond_signal(&condc);
26 /* */
27 pthread_mutex_unlock(&the_mutex);
28 }
29 pthread_exit(0);
30
31 }
32
33 /* */
34 void *consumer(void *ptr){
35
36 int i;
37
38 for(int i = 0;i <= MAX;i++){
39 /* mutex */
40 pthread_mutex_lock(&the_mutex);
41 while(buffer == 0){
42 pthread_cond_wait(&condc,&the_mutex);
43 }
44 /* */
45 buffer = 0;
46 /* */
47 pthread_cond_signal(&condp);
48 /* */
49 pthread_mutex_unlock(&the_mutex);
50 }
51 pthread_exit(0);
52
53 }
Pascal
C C
1 monitor example
2 integer i;
3 condition c;
4
5 procedure producer();
6 ...
7 end;
8
9 procedure consumer();
10 .
11 end;
12 end monitor;
(mutex)
(binary semaphore)
signal
signal
wait
signal
Pascal -
1 monitor ProducerConsumer
2 condition full,empty;
3 integer count;
4
5 procedure insert(item:integer);
6 begin
7 if count = N then wait(full);
8 insert_item(item);
9 count := count + 1;
10 if count = 1 then signal(empty);
11 end;
12
13 function remove:integer;
14 begin
15 if count = 0 then wait(empty);
16 remove = remove_item;
17 count := count - 1;
18 if count = N - 1 then signal(full);
19 end;
20
21 count := 0;
22 end monitor;
23
24 procedure producer;
25 begin
26 while true do
27 begin
28 item = produce_item;
29 ProducerConsumer.insert(item);
30 end
31 end;
32
33 procedure consumer;
34 begin
35 while true do
36 begin
37 item = ProducerConsumer.remove;
38 consume_item(item);
39 end
40 end;
wait wait
wait
Our_monitor
insert remove
count lo
hi lo = hi
0 N
C Pascal
CPU
TSL XCHG
CPU CPU
(messaage passing)
send receive
1 send(destination, &message);
2
3 receive(source, &message);
send receive
(acknowledgement)
(authentication)
1 /* buffer */
2 #define N 100
3
4 void producer(void){
5
6 int item;
7 /* buffer */
8 message m;
9
10 while(TRUE){
11 /* */
12 item = produce_item();
13 /* */
14 receive(consumer,&m);
15 /* */
16 build_message(&m,item);
17 /* */
18 send(consumer,&m);
19 }
20
21 }
22
23 void consumer(void){
24
25 int item,i;
26 message m;
27
28 /* N */
29 for(int i = 0;i < N;i++){
30 /* N */
31 send(producer,&m);
32 }
33 while(TRUE){
34 /* */
35 receive(producer,&m);
36 /* */
37 item = extract_item(&m);
38 /* */
39 send(producer,&m);
40 /* */
41 consume_item(item);
42 }
43
44 }
N N N
(mailbox)
send receive
-
(barrier)
A B D
B C
- -
A B
A B
X
" " X
X A
B D A C A
C B D
B D
B D - -
(Ready-Copy-Update,RCU)
CPU
/ CPU
/ (scheduler)
(scheduling algorithm)
CPU
I/O
CPU I/O
CPU I/O
CPU
I/O
a CPU b I/O a
(compute-bound) CPU (CPU-bound) b I/O
I/O (I/O-bound) CPU I/O I/O
CPU I/O CPU
I/O I/O I/O
I/O
CPU I/O
CPU I/O
I/O
CPU
(Batch)
(Interactive)
(Real time)
CPU
CPU
15
14
14
CPU I/O
CPU I/O
CPU I/O
CPU CPU
I/O CPU I/O
CPU
CPU (throughout)
50 40
(Turnaround time)
CPU
CPU 100%
(proportionality)
1
5 1
(first-come,first-
serverd) CPU
100 I/O
101 CPU 100 I/O CPU
4 b 4 8 12
20 11 4
a b c d a a+b (4a +
3b + 2c + d) / 4 a a b c
d
(round-robin)
(quantum)
CPU
CPU
a b
(process switch) (context switch)
1ms 4 ms
CPU 4 ms CPU 1 ms CPU
20%
CPU 100 ms 1%
50 CPU
50 CP U
100 ms 5
5
CPU
CPU
20 - 50
(priority scheduling)
100 90 80 70 60 UNIX nice
I/O
I/O CPU CPU I/O
I/O I/O CPU
I/O 1/f f
50 ms 1 ms 50
25 ms 2 1
4
4
4 3 2
CTSS CTSS
CPU
2 4
T0 T1
aT0+ (1- 1)T1 a
a = 1/2
T0 1/8
(aging)
n CPU 1/n n
1/n CPU
(lottery scheduling)
CPU
CPU 50
20 CPU
George Orwell
100
20 20% 20% CPU
40 f
f
1 9 2 1
90 % CPU 2 10 % CPU
CPU 50%
CPU CPU
(real-time)
CD
( ) (
)
m i Pi Ci CPU
CPU CPU
A A A A1
A A1 A
A CPU 50 ms 5 ms
CPU B
A1,A2,A3,A1,A2,A3,A1,A2,A3,A1
50 ms 5 ms 30 ms
A1,B1,A2,B2,A3,B3
Java
I/O
A B A
(RAM) IBM
7094
(memory hierarchy)
(memory manager)
20 60 20
70 20 80
1000 REGISTER1
0 8
2000
2000
a RAM(Random Access Memory) b
ROM(Read-Only Memory) c ROM
RAM a b
ROM
BIOS (Basic Input Output System) a c
IBM 360
16 KB
16KB a 24
MOV b 28 28 CMP
0
c 0 JMP 24
28 ADD
CMP
IBM 360
(static relocation)
16384 16384 JMP 28 JMP 16412
b JMP 28 MOV
REGISTER1,28 28 REGISTER (loader)
IBM 360 lock-and-key
CPU
IBM
360
(dynamic relocation)
CDC 6600( ) Intel
8088( IBM PC ) CPU
(basic register) (limit register)
c
0 16384
16384 32768 16 KB
32768 16384
CPU
c
JMP 28 JMP 16412 CMP
CDC 6600
Intel 8088 Intel 8088
ADD CMP
CMP
5 - 10MB
Photoshop 500 MB
GB
(swapping)
(virtual
memory)
A B C
d A A g A
(hole)
(memory compaction)
CPU 16GB 8ns 8
16s
data segment
data segment (
)
codesegment/textsegment
datasegment
static
bss bsssegment
static
bss
bss 0
rodata
printf
const int ival = 10 ival .rodata printf("Hello world %d\n", c);
"Hello world %d\n" .rodata
stack
( static )
heap
malloc/realloc
malloc/realloc free
Borland C++
( segment ) segment
ends
( )
(data segment) (stack segment) b
(data segment
)
(bitmap)
(free lists)
0 1
a 5 3
0 b c
4
32 1 32n n 1
1/32
k
(memory manager) k 0
0
c
(H) (P)
(segment list)
(first
fit)
(next fit)
Bays(1997)
(best fit)
2 5
18
(worst
fit)
(quick fit)
n 4 KB
8 KB 12 KB
21 KB 20 KB
(managing bloatware)
1980 4 MB VAX
64 Windows 8 2 GB
xxx xxx
GB
SATA / 1 GB
(virtual memory)
(page)
8088
text data
text data
CPU
(paging)
1 MOV REG,1000
1000 REG
16 0 - 64 K - 1
32 KB 64 KB
64 KB
(pages)
(page frames)
4KB 512 - 1G 64
KB 32 KB 16 8 RAM
1 MOV REG, 0
8192 2 24576 6
MMU 16 8
8 8 X
/ (Present/absent bit)
8 32768 12 MMU
X CPU (trap)
(page fault)
1 8 4096 MMU
1 4096 - 8191
8 1
32780 4096 + 12
MMU 2
(page table) /
0 1 3
12 15
16 4 KB 4 16
12 0-4095
/
32 (Page frame
number) /
1 0
(page fault)
(Protection)
0 1
(Modified) (Referenced)
(dirty bit)
(Referenced)
I/O I/O
CPU
1 ns 0.2 ns
32 64
4 KB 32 100 64
CPU
1 8085 8085 3
1-byte(1 ) 2-byte(2 ) 3-byte(3 )
1-byte 1 1
1-byte
2-byte: 2
MVI B, 26 H IN 56 H
3-byte: 3 16
1 140 1 RW 31
1 20 0 RX 38
1 130 1 RW 29
1 129 1 RW 62
1 19 0 RX 50
1 21 0 RX 45
1 860 1 RW 14
1 861 1 RW 75
TLB
TLB MMU
TLB TLB
MMU TLB
(address-translation cache) TLB CPU CPU CPU
TLB
MMU TLB
TLB
TLB TLB
(protection fault)
TLB
TLB TLB
TLB (trap)
TLB
TLB
TLB TLB TLB
TLB
(multi)
32 10 PT1 10 PT2 12 Offset
12 4KB 2^20
1 level 1
2 level 2 2 3 level 3
n p p
TLB TLB
1
TLB
(page replacement
algorithms)
32
64
Web Web
Web Web
Web
10 100 1000
800
600
R M
R M
1
1
R ( ) READ ONLY
M READ/WRITE
R M
0 R
R M
0 R M
1 R M
2 R M
3 R M
R
M R M
FIFO(First-In,First-Out)
1
MISS 1
2 2
MISS
1 2 3 2
2 HIT
1 2 3 5
5 5 2
2 3 5
FIFO check
R 0
R 1
(second chance) A H
a b 20 A R
20 A 0 A R 0
R A
20 R B
FIFO a R
R A R
A
R 0
R 1 R
R 0
(clokc)
LRU LRU
LRU
64 1
LRU
LRU
LRU NFU(Not Frequently
Used ) 0
R 0 1
NFU
NFU LRU
R
R
(aging)
0-5 R 1 0 1 0 1 1 0 1
1 0 2 1 0 1 0 2 4 5
R 1 0 R
a
CPU 100Mhz
100,000,000
4
0 3
LRU e
LRU
1 2
3 3 0-1 5
LRU 2 8
0
9 1000
20 ms 8
20 ms
CPU
(demand paging)
(locality of
reference)
(working set)
10 ms
(thrashing)
CPU
t
k w(k,t) k=1
k>1 w(k,t) k k
w(k,t)
k
CPU
t
R
R M
Referenced( )
R R 1
R 0
- t
t
R 0 t
R=0
R=1
WSClock( )
a) b) R=1 c) d) R=0
R M
R 1
R 0
b
R=0 c t
I/O
n
NRU( ) LRU
FIFO( )
FIFO
LRU( )
NFU( ) LRU
LRU
NRU R M
NRU
FIFO
FIFO
LRU (TLB)
LRU
NFU LRU
LRU
WSClock
WSClock LRU
(Magnetic disk)
k
k
-
(Files)
(file system)
1-8
UNIX MS-DOS
MS-DOS MS-DOS
UNIX maria Maria MARIA MS-
DOS
. prog.c
(file extension) MS-DOS
1-8 1-3 UNIX
c c
gif
hlp
html WWW
jpg JPEG
mp3 MP3
mpg MPEG
pdf pdf
ps PostScript
tex TEX
txt
zip
UNIX
file.txt
C .c
C
C C
C
UNIX Windows ( )
a
(bytes) UNIX Windows
c
key key
key
key c
pony
UNIX OS X Windows
UNIX (character special file) (block
special file) (Regular files)
/ I/O
ASCII ASCII
ASCII 13 CR \r ASCII
10 LF \n Windows
ASCII
ASCII
ASCII
UNIX
(magic number)
TOPS-20
DECsystem 20
UNIX shell make
make make
Makefiles
Make
Unix Unix
(kernel driver)
(Directories)
Linux MS-DOS UNIX
Windows / DOS
cdn big C
(sequential access)
(random access file)
read
seek seek UNIX
Windows
(attributes)
(metadata) (set)
(clear)
ID
0 / 1
0 1
0 1
0 1
ASCII / 0 ASCII 1
0 1
0 1
0 1
File Protection
(flags)
(hidden flag)
(archive flag)
(temporary flag)
1. Create
2. Delete
3. Open
4. Close
5. Read
6. Write
7. append append
8. seek seek
seek
9. get attributes
10. set attributes
set attributes
11. rename rename
(directories) (folders)
(root
directory)
1 Windows \usr\ast\mailbox
2 UNIX /usr/ast/mailbox
3 MULTICS >usr>ast>mailbox
1 cp /usr/ast/mailbox /usr/ast/mailbox.bak
1 cp mailbox mailbox.bak
. .. dot
dotdot dot dotdot
/usr/ast ..
1 cp ../lib/dictionary .
usr/lib/dictionary usr
lib dictionary
. cp
1 cp /usr/lib/dictionary .
. dictionary
1 cp /usr/lib/dictionary dictionary
1 cp /usr/lib/dictionary /usr/lib/dictionary
UNIX
1. Create . ..
2. Delete . ..
3. opendir
4. closedir
5. readdir readdir read
readdir
6. rename
7. link
(hard link)
8. unlink
UNIX
unlink
(disk
partitioning) (disk slicing)
0 (Master Boot Record, MBR)
(boot) MBR (partition table)
4096 0
CPU
CPU
(rebooting)
(Superblock) 4096
4096
0 1 0
1 16
0000111000000110
(fragment)
Windows
inode
inode(index node)
inode inode
ls -lai
inode
/
ID
ID
inode
inode
inode
1KB
50 KB 50
40 0
0 4 A 6
B A
A 3 1/2
7
D F
word
CD-ROM
CD-ROM DVD
2
2
A 4
7 2 10 12 B 6 3 11 14 A 4
A 6 B
-1
(File Application Table,FAT)
1TB 1KB
10 10 3
4 3GB 2.4GB
FAT MS-DOS
Windows
inode
inode( )
inode inode
inode
inode
inode n k inode
kn
FAT( )
n n
inode
100GB 4000GB 10000GB
inode
inode
ASCII
inode inode
inode
MS-DOS 1-8
1-3 UNIX 7 1 - 14
255
255
SPARC
(big-endian) (little-endian)
HashMap
C B
B (link)
(Directed Acyclic Graph, DAG)
C
B B C
UNIX inode
LINK B
B C B
B LINK
(symbolic linking)
B inode
C
a C C B
C +1 C
C inode B
inode B
inode
inode
C inode 1 c
c B C
C B 0
inode
inode
inode
inode
inode
CPU
Berkeley
(Log-structured File System,
LFS)
Rosenblum Ousterhout 90
I/O I/O
RAID
inode
inode
LFS (clean)
inode
inode inode
NTFS Linux ext3 OS X
UNIX
inode inode
Windows
inode
fsck
(idempotent)
inode k n
foobar
inode k
(atomic transaction)
Windows
NTFS Windows NTFS
FAT -32 FAT -16 CD-ROM
DVD Windows
C: D:
Windows
UNIX UNIX
Linux ext2 ext3 /usr Reiser
FS /home ISO 9660 CD - ROM /mnt
VFS
POSIX
open read write seek VFS
POSIX
VFS VFS
VFS VFS
VFS
VFS
VFS
VFS VFS
VFS VFS
VFS VFS
/usr
1 open("/usr/include/unistd.h",O_RDONLY)
VFS /usr
include/unistd.h
VFS vnode inode
vnode vnode
read write close
VFS vnode
read VFS
CD-ROM USB
vnode
n
1
1 KB 32
255 1 TB
255 400
(bitmap) n n 1
0 1 TB 10 130 000 1
KB 32 1
8
16 32
IO
a
I/O
I/O a-
b a-c
I/O
I/O
(enforcing disk
quotas)
1 0
Windows (recycle bin)
(incremental
dumps)
(physical dump) 0
(bad
blocks)
Windows (paging files) (hibernation files)
(logical dump)
UNIX
inode
inode (bitmap) inode
inode
inode 10 11 14 27 29 30
inode 5 6
b
inode
(skeleton)
UNIX (holes)
(inconsistent)
UNIX
fsck Windows sfc
inode
inode +1
1 1
2 (missing block)
4 2
5 5
+1
+1
inode
inode inode
0 inode
inode 1
inode 0 inode 0 inode
inode
32 10ns 100MB/S 32
5 - 10 ms
HashMap?
https://mp.weixin.qq.com/s/5-k2BJDgEp9sy
mxcSwoprw FIFO LRU
k
k+1 k+1
512 1 KB 2 2 4
2 KB 1 KB
1 KB
inode inode
inode inode
a inode b inode
inode inode
inode inode
inode
b
(SSD)
I/O
I/O
I/O
I/O I/O
I/O
I/O
I/O I/O / /
512 - 65536
USB
I/O
CPU
cs ds ss es fs gs eip flag
2 4 8
2,000,000
512 (preamble)
4096 ECC Error-Correcting
Code
I/O
CPU
(data buffer)
RAM RAM
CPU
I/O (I/O port) 8 16
I/O I/O
I/O
1 IN REG,PORT
1 OUT PORT,REG
CPU
I/O
1 IN R0,4
1 MOV R0,4
I/O 4 R0 4
R0 4
PDP-11
PDP-11?
I/O CPU
IO IO
I/O I/O x86
IBM PC 0 64K - 1 I/O 640 K 1M - 1
CPU I/O
READ
I/O I/O
I/O I/O
I/O
I/O
I/O
I/O
C C++ IN OUT I/O
C
I/O I/O
I/O
I/O
I/O
I/O
I/O
CPU
I/O
I/O
DMA
DMA
DMA
DMA DMA
DMA CPU
CPU
I/O I/O I/O
DMA DMA
DMA
DMA CPU DMA
DMA DMA
DMA
DMA DMA
CPU DMA
DMA
DMA 0 2-
4 0 DMA CPU
DMA DMA
DMA DMA
DMA
DMA CPU
CPU CPU
(cycle stealing)
DMA
(burst mode)
CPU
DMA
DMA DMA
DMA DMA MMU
MMU CPU
I/O
CPU
CPU CPU
CPU
I/O
CPU CPU
CPU
CPU
CPU
MMU
TLB
CPU
CPU ( )
PSW PSW
a
(precise interrupt)
PC
PC
PC
PC
(imprecise interrupt)
IO
I/O
1 sort
(uniform naming)
UNIX
ls
USB /usr/cxuan/backup
/usr/cxuan/backup/device
I/O I/O
I/O (buffering)
I/O I/O
I/O I/O
I/O
I/O
DMA I/O
I/O
I/O I/O CPU
CPU I/O CPU
I/O I/O CPU
CPU (polling) (busy waiting)
I/O I/O
I/O
CPU I/O
I/O
I/O
CPU
I/O CPU
I/O CPU
CPU
I/O
I/O CPU I/O
I/O
CPU I/O CPU I/O
CPU
I/O CPU
I/O CPU
CPU
I/O
CPU I/O
DMA I/O
DMA CPU I/O CPU
DMA CPU DMA DMAC
DMA CPU
DMA CPU DMA
I/O
I/O
/
ISR(Interrupt Service Routines)
up
signal
TLB MMU
MMU TLB
PSW
I/O
I/O
(Device driver)
MINIX 3 MINI 3
UNIX
UNIX
I/O
MS-DOS
I/O I/O
CPU
CPU
CPU CPU
CPU
I/O
I/O
I/O
ADSL(
)
read
n n
(double buffering)
(circular buffer)
-> -> socket
-> ->
I/O
I/O
I/O
open
open
open
I/O
I/O I/O
I/O
(overlapped seek)
RAID
RAID
RAID
RAID 0 -
RAID 1 -
RAID 2 -
RAID 3 -
RAID 4 -
RAID 5 -
RAID 6 - P + Q
(low-levvel format)
512
ECC ECC error correction code
ECC ECC ECC
ECC
ECC 16
(cylinder skew)
0
(head skew)
ECC
(high-level
format)
BIOS
(boot sector)
(system kernel)
(SSF)
6 11 , 2 , 4, 14, 8, 15, 3
5 + 9 + 2 + 10 + 6 + 7 + 12 = 51 51
4 + 1 + 1 + 4 + 3 + 3 + 1 = 17 51
(elevator
algorithm)
UP( ) DOWN( )
UP
DOWN
4 7 10 14 9 6 3 1
3 + 3 + 4 + 5 + 3 + 3 + 1 = 22
SSF
ECC
30 4
RAID
RAID
(stable storage)
(stable write)
(stable read)
(crash recovery)
1
2
1 ECC
ECC 2
ECC
CPU
CPU
CPU 1
2 1
1 2 1
1 2
RAM
(Clocks) (timers) /
CPU (clock software)
110 V 220 V
50 - 60 HZ
(one-shot mode)
-1
0 (square-
wave mode) 0
CPU
(soft timer)
TLB
I/O
CPU
(deadlock)
A R1 B R2 A B
(resource)
(preemptable resource)
(nonpreemtable resource)
request
open
(semaphore) 1
(Mutexes) :
(mutex)
A B
A A B B
(resource deadlock)
Holt 1972
R A
B S Holt
C T T D D
U U C
(A B C) (R S T)
A A
B B C
/ I/O
CPU
I/O
I/O
A S B T
C R
S B B A
C
S B A
C B S C
T
(ostrich algorithm)
P1 -
> Pn n
P1 Pn n m E1
1 E2 2 Ei i (1 <= i <= m) E
(existing resource vector)
C (current allocation matrix) R
(request matrix) Ci Pi Cij Pi
j Rij Pi j
j =
CPU
k CPU CPU
CPU
(memory image)
(resource state)
Dijkstra 1965
15 1k
A/B/C/D
13 15 A C B
D A C
15
2
(spooling
printer)
(two-phase locking)
A B A
B A B
A B
(communication
deadlock)
(timeout)
10
A B B D D
A
(livelock)
(starvvation)
CPU
CPU
I/O
UNIX (shared library)
Windows (Dynamic Link Library,DLL) .dll
C:\Windows\system32 1000 DLL C
--- ---
MINIX 3
MINI 3
-
boot loader
boot loader
boot loader
BIOS
(MBR)
RAM
Web shell
typora
CPU
http://courses.cs.vt.edu/csonline/OS/Lessons/Processes/index.html
tab
RR
RR(round-robin) RR
RR
(Mutual Exclusion)
(No Preemption)
RAID
RAID
RAID
RAID 0 -
RAID 1 -
RAID 2 -
RAID 3 -
RAID 4 -
RAID 5 -
RAID 6 - P + Q
DMA
CPU CPU
P
Doug Lea
(mutual exclusion)
1.
2. CPU
3.
4.
1. CPU
2.
3.
CPU CPU
1
pause UNIX
2 3
2
CPU CPU
3
4
3 CPU
(first-come,first-
serverd) CPU
100 I/O
101 CPU 100 I/O CPU
a 4 A B C D 8 4 4 4
A 8 B 12 C 16 D 20 14
4 b 4 8 12
20 11 4
a b c d a a+b (4a +
3b + 2c + d) / 4 a a b c
d
(priority
scheduling)
T0
T1 aT0+ (1- 1)T1
a a = 1/2
T0 1/8
(aging)
(lottery
scheduling)
CPU 50
1 9 2
1 90 % CPU 2 10 % CPU
CPU 50%
CPU CPU
NRU( ) LRU
FIFO( )
FIFO
LRU( )
NFU( ) LRU
LRU
NRU R M
NRU
FIFO
FIFO
LRU (TLB)
LRU
NFU LRU
LRU
WSClock
WSClock LRU
CPU
CPU
1. Operating System OS
2. shell
Unix CLI
··
3. GUI (Graphical User Interface)
5. (user node)
1 1 0
6. (computer architecture)
I/O
7. SATA(Serial ATA) ATA (Serial Advanced Technology Attachment)
8. (multiplexing)
9. (mainframes)
10. (batch system) :
……
13. (Time-sharing)
37. (Pipeline) :
IO
40. (multithreading)
43.
44. (cache lines)
U
53. SSD(Solid State Disks)
RAM
59. (Interrupt)
CPU
69. (Process)
74. (superuser)
root administrator supervisor
75. (directory) :
PC
PC
PC
PC
DVD USB
1 \\computer\path
UNIX Linux
1 //computer/path
107. (buffering)
CPU
108. Programmed input–output,PIO CPU ATA
109. (polling)
111. (reentrant)
116. (Daemon)
124. QR Code
QR
Windows API
128. (bitmap)
136. (Livelock)
137. (starvation)
138. (sandboxing)
141. (cloud)
142. (interpreter)
143. (paravirtualization)
private copy
157. (master-slave) /
161. (Ethernet)
163. (host)
164. (router)
TCP
166. (Connectionless service)
UDP
175. (vulnerability)
176. (exploit)
177. (virus)
178. CIA(Confidentiality,Integrity,Availability)
179. (cracker)
180. (portscan)
181. (botnets)
182. (domain)
183. (solt)
184. (logic bomb)
187. (backdoor)
188. (firewall)