虚拟化与隔离
虚拟化与隔离
虚拟化与隔离
Full System Emulation
这个简单,就是 NEMU 啊:取指令、译码、执行
致命的是
性能
: 性能不及 native 的 10%
虚拟化与隔离
Full System Emulation 的黄金时代
黄金时代的起点
Disco
(1997): “brings back an idea popular in the 1970s: virtual machine monitors”
VMWare (1998): 我们能把这个技术做成产品!
Hack: Guest Ring 3 直接运行在 Host Ring 3
System call 会 trap 到 VMM
Windows Subsystem for Linux
(2016)
Xen and the art of virtualization
(2003)
Intel: VT-x (2005)
→
\to
→
VT-d (2006)
→
\to
→
EPT (2008)
(我们之前讲过 /dev/kvm)
虚拟化与隔离
为什么会有黄金时代?
Dot-com bubble 时代 (2000)
ISP (Internet Service Provider) 提供的是
物理机
虚拟机:和物理机用起来完全一样,但一台能当
n
n
n
台卖
黑心商人
:我们都是 oversubscribe 的
虚拟化与隔离
Everything is a State Machine...
虚拟机:
更容易管理状态了
!
ReVirt: Enabling intrusion analysis through virtual-machine logging and replay
(OSDI'02)
时间转移:“replay the long-term, instruction-by-instruction execution of a computer system.”
Optimizing migration of virtual computers
(OSDI'02)
空间转移:“a system that moves a computer's state over a slow (384kbps) DSL link in minutes rather than hours.”
虚拟化与隔离
Hackers 的时代
华为操作系统首席科学家;上海交通大学 IPADS 所长
Live updating operating systems using virtualization
(VEE'06)
虚拟化与隔离
浪潮过后……
操作系统:我自己就能虚拟化自己啊
应用程序只能看到系统调用 API
操作系统:“假装” 在虚拟机里执行系统调用
例子:虚拟的 pstree
pid = 1: init (systemd)
pid 可以不再是整个操作系统唯一的
给每个进程增加一个 “osid”,增加系统调用 vos(fs_root)
创建一个新的 osid
pid 从 1 开始分配
fork() 继承父进程的 osid
虚拟化与隔离
祝贺,你发明了 Linux Namespaces!
只要想 “
操作系统里有什么对象
” 就行了
需要为 osid 区别实现的对象
pid: (刚才讲了)
user: 用户和组 (这个很重要)
mnt: 文件系统和设备
ipc: 信号量、消息队列、共享内存
net: 网络设备、协议栈、端口 (localhost:5000)
time: 系统时间和时区
uts: 主机名和域名
Linux namespaces: /proc/[pid]/ns/
lsns 可以查看 (strace)
虚拟化与隔离
Namespaces (7)
clone
创建进程时可以带 CLONE_NEW_xxx (PID, IPC, ...) 选项
setns, unshare
改变某一个项目的 “osid”
ioctl
Windows Subsystem for Linux: 听我说谢谢谢你
(我选择放弃)
虚拟化与隔离
再进一步:资源调度
实现资源的控制
“圈一些进程”,设定资源使用策略
祝贺,你发明了 cgroups
cat /proc/*/cgroup
/sys/fs/cgroup
这是一个和 namespaces 正交的机制
共同使用,你就得到了容器
例子:只有 busybox 的 “系统中的系统”
祝贺,你发明了 docker!
虚拟化与隔离
云时代的虚拟机
如果只需要 Linux
容器就和虚拟机
完全一样
开销比虚拟机低很多,安全性略低
这样不就可以在一台物理上部署更多的服务了吗
黑心商人
:
的机会来啦!
Kubernetes: “容器编排”
跨主机、弹性自动编排
自动容错
:这是云厂商最爱看到的