date: 2019-02-17
tags: OS 6.828
这里会记录阅读6.828课程lecture note的我的个人笔记。可能会中英混杂,不是很适合外人阅读,也请见谅。
这一讲基本上都是介绍工具,就不在此记录了,C的部分可以看K&R,gdb的部分可以直接搜课件。pointer.c
的例子应该在lab1中已经进行了解释。
app -> printf() -> write() -> SYSTEM CALL -> sys_write() -> ...
回顾作业(这部分就直接放在hw xv6 shell的那篇里面讲了,就不在这里赘述)。
fork/exec看起来很浪费,因为需要先复制parent的内存到child,之后再用exec替代。为什么不合二为一呢?
因为分开非常方便。同时实际上因为使用了一些技巧(在lab4中有实现,就是利用page fault进行lazy allocation),fork
的开销很小。
file descriptor设计
FDs are a level of indirection。
FD统一了console, pipe和files的接口
整体的设计哲学:用简洁的接口相互组合实现复杂功能。
为什么kernel需要pip而不用一个临时文件进行redirect:
pipe有如下四点优势:
- pipes automatically clean themselves up; with the file redirection, a shell would have to be
careful to remove /tmp/xyz when done.
pipes can pass arbitrarily long streams of data, while file redirection requires enough free space on disk to store all the data. (这也是为什么pipe需要多个指令同时执行)
pipes allow for parallel execution of pipeline stages, while the file approach requires the first program to finish before the second starts.
if you are implementing inter-process communication, pipes’ blocking reads and writes are more efficient than the non-blocking semantics of files.
为什么kernel的system call只用int char作为buffer,而不用一个pointer指向kernel file object?
我不确定这个是为什么,感觉就是为了isolation吧,如果给一个pointer,那用户就很容易把kernel代码搞崩。
核心的unix system call已经很古老了,have they held up well?
yes, very successful!
不过UNIX的一些地方不是完美的:
一些UNIX abstractions不够高效:
所以一直都有备用方案:
这部分最好先阅读一下xv6 book的第一章。
OS的主要目的之一是进行isolation。
monolithic kernel
microkernel design
exokernel
apps可以semi-directly使用
apps can use hardware semi-directly, but O/S isolates e.g. app can read/write own page table, but O/S audits e.g. app can read/write disk blocks, but O/S tracks block owners good: more flexibility for demanding applications jos will be a mix of microkernel and exokernel
(这里不是很明白,可能写完JOS作业就懂了...)
之后会有不适用硬件支撑kernel/user mode的isolation,叫Singularity O/S,之后的课中会讲到。