两个月学完《现代操作系统》(十三)——第七章习题

两个月学完《现代操作系统》(十三)——第七章习题

摘要:个人操作系统学习笔记

0x01题目



然后后面我会将自己的答案与标准答案放到一起,对照着看可能会更好。

0x02正文

1、数据中心中可能存在多家企业的或者是一家企业中多个不同部门的数据。不同部门,不同企业之间的数据有隔离性,而虚拟化恰巧能够满足这个要求。
There are numerous reasons, among them consolidating servers to save hardware investment cost, rack space, and electrical power, and make management of thousands of servers easier.
2、有很多种可能性吧, 可能公司有了在一台机器上运行多个操作系统的需求;同时,在一台机器上运行多个操作系统有解决服务器成本的可能。
3、开发者可能需要在多个环境中测试自己软件的兼容性。There are various reasons. A key one is to have many platforms such as Windows 7, Windows 8, Linux, FreeBSD, OS X, etc. available on a single desktop machine to test the software being developed. Also, rebooting a virtual machine after a crash induced by a software bug is much faster
4、为了好玩…
After upgrading to a new computer and operating system, the person might want to run some software that he had on the old one. Virtualization makes it possible to run the old system and new one on the same computer, thus preserving the old software
5、因为一开始的时候没这个必要。从八十年代开始才开始出现家家户户都有一台计算机的情况;从九十年代开始,面向公众的互联网及其对应服务才出现;从新千年开始,数据量开始进入爆炸增长的时代。所以,从新千年开始,虚拟化的应用价值会更高,因此虚拟化便慢慢开始普及了。
Very few programmers had access to an IBM mainframe. Starting on the 1980s, the Intel x86 series dominated computing and it was not virtualizable. While binary translation could solve that problem, that idea was not thought of until the late 1990s.
6、根据百度百科,敏感指令包括:a.企图访问或修改虚拟机模式或机器状态的指令。b.企图访问或修改敏感寄存器或存储单元,如时钟寄存器、中断寄存器等的指令。c.企图访问存储保护系统或内存、地址分配系统的指令。d.所有I/O指令。
7、move、算术计算、跳转、调用指令、移位等等。
8、全虚拟化对于客户操作系统来说是透明的,因为全虚拟化相当于将客户机所需要的硬件都给虚拟化了,全虚拟化不需要修改可会操作系统的源码;而半虚拟化对客户操作系统而言是已知的,它为客户机提供一层类似物理硬件的软件接口,其客户机执行虚拟化的调用,半虚拟化需要修改客户机的内核源码来适应之。
Full virtualization means emulating the hardware exactly so every operating system running on the virtual machine behaves exactly as it would on the bare metal. Paravirtualization consists of changing the operating system so it does not do anything that is hard to virtualize. Full virtualization in the absence of hardware support is complicated on any architecture that is complex, like the x86. It is easier on RISC machines. If virtualization hardware is present, full virtualization is not so difficult. So, which is harder probably depends on whether hardware support is available. If it is, then paravirtualizing an operating system is probably more work. If there is no hardware support, it may be easier to change the operating system to be more friendly. If there are many operating systems that have to be paravirtualized, that could be more work.
9、前者可行;后者不可行。
10、可以啊。Virtual machines have nothing to do with disk partitions. The hypervisor can take a disk partition and divide it up into subpartitions and give each virtual machine one of them. In principle, there can be hundreds. It can either statically partition the disk into n pieces or do this on demand. In hosted virtual machines, it is common to use files on the host to store disk images of the guest.
11、进程级虚拟化就是为另一个操作系统、体系结构编写的软件能够在当前操作系统中正常运行的技术。比方说Linux下的WINE兼容层。
An application or process is virtualized during runtime, by using a virtualization layer between the application and the OS. This layer executes the application’s instructions, modifying them as required prior to execution. The application is transparent to the presence of the underlying layer. Windows Emulator (WINE) is an example, where Microsoft Windows binary executables can be executed on another operating system such as Linux. This is done using onthe-fly mapping of Windows API calls to POSIX calls
12、因为第二类操作系统是以应用程序的形式存在的,对于普通的PC用户而言,这种形式更为的方便。
13、Yes. When a guest OS does I/O, for example, the virtualization hardware
catches it and gets control to the type 2 hypervisor, which then figures out
what to do. Usually this will involve making a request to the host OS to perform the I/O, but not having to worry about trapping the I/O instruction definitely simplifies matters for the hypervisor.
14、在VT技术出现之前,对硬件的虚拟化操作主要使用二进制翻译技术,来对每个基本块中的敏感指令进行替换,从而让虚拟机得以正常运行。It was invented in the early days, before virtualization hardware existed. It wasnecessary to prevent guest operating systems, which were running in user mode, from executing sensitive instructions that were not privileged. Going forward, this is less necessary since modern hardware traps when a user-mode program executes a sensitive instruction. However, in some circumstances, binary translation is faster than trapping. Nevertheless, as the hardware improves, the need for binary translation will decrease.
15、在这四个特权级中,用户程序运行于第三特权级中;宿主机OS内核或第一类虚拟机管理程序运行于第零特权级;客户操作系统运行于第一特权级中,并且在这个特权级中进行二进制改写等工作。
16、VT技术会导致很多陷入操作,这是对性能的巨大损耗。
17、翻译后更快:比方说客户机中断时,每个客户机的虚拟CPU数据结构中记录一个IF(Interrupt Flag)位,以确保虚拟机在中断打开前不会收到任何中断。客户机执行的每条CLI指令都会替换成类似VirtualCPU.IF=0的指令,数据的传输量很小,速度更快。但如果不这样干,在具有深度流水和乱序执行技术的特定CPU上会占用数十个始终周期。
18、可以吧。但可能翻译到的用不了。It could translate the entire program in advance. The reason for not doing so is that many programs have large pieces of code that are never executed. By
translating basic blocks on demand, no unused code is ever translated. A potential disadvantage of on-demand translation is that it might be slightly less efficient to keep starting and stopping the translator, but this effect is probably small. In addition, static analysis and translation of x86 code is complicated due to indirect branches (branches whose targets are computed at run time). This is made worse by the variable-size instructions on the x86. Thus you may not be sure which instructions to translate. Finally, there is the issue of selfmodifying code.
19、虚拟机管理程序是对硬件进行抽象的供虚拟机使用的一个程序,他对硬件实行的是一种全虚拟化;而微内核是一种半虚拟化技术,将所有的系统调用通过虚拟化接口来实现
A pure hypervisor just emulates the real hardware and nothing else. A pure microkernel is a small operating system that offers basic services to the programs using it. The virtual machines running on a pure hypervisor run traditional operating systems such as Windows and Linux. On top of a microkernel are generally processes that implement operating system services but in a decentralized way.
20、因为现实中的设备厂商是多样的,纵使有对应的标准,要囊括所有的设备也是困难的;同时,有些硬件本身就并不支持虚拟化的操作。
If multiple guest OSes all allocate what they think is physical page k to one of
their processes, there is a problem. Some way is needed to perform a second
mapping between pages because the guests do not really control the physical
pages, despite what they may think. This is why nested page tables are needed
21、一个虚拟机相当于一个操作系统,一个操作系统要进行正常的运行所需要的必要的内存是不可能少的,而这必要的内存也是有一定的大小的,同时运行多个虚拟机那么占用的内存当然就很大了。
相同类型的虚拟机可以共享一部分的数据。
Not only does the machine need memory for the normal (guest) operating system and all its applications, but it also needs memory for the hypervisor functions and data structures needed to execute sensitive instructions on behalf of the guest OS. Type 2 hypervisors have the added cost of the host operating system. Moreover, each virtual machine will have its own operating system, so there will be N operating system copies stored in memory. One way to reduce memory usage would be to identified “shared code” and keep only one copy of this code in memory. For example, a Web hosting company may run multiple VMs, each running an identical version of Linux and an identical copy of the Apache web server code. In this case, the code segment can be shared across VMs, even though the data regions must be private.
22、影子页表是将虚拟机使用的虚拟页映射到它分配给虚拟机的实际物理页的一种技术。对于虚拟化环境来说,存在四种地址,GVA(Guest virtual address,客户机虚拟地址)、GPA(Guest physical address,客户机物理地址)、HVA(Host virtual address,宿主机虚拟地址)、HPA(Host physical address,宿主机物理地址)。本意是在VMM中创建一个客户机页表的影子页表,能够一步完成从GVA到HPA的转换。
Each guest OS will maintain a page table that maps its virtual page numbers to physical frame numbers (on its share of the virtualized memory). In order to prevent different guest operating systems from incorrectly referring to the same physical page number, the hypervisor creates a shadow page table that maps the virtual machine’s virtual page number to the physical frame number provided by the hypervisor
23、书上的两种方法都可,一种是通过跟踪顶级页面;一种是允许向客户机向页表添加新的映射而影子页表不做任何的改动。效率其实相当吧。
Page tables can be modified only by the guest operating system, not the application programs in the guest. When the guest OS is finished modifying the tables, it must switch back to user mode by issuing a sensitive instruction like RETURN FROM TRAP. This instruction will trap and give the hypervisor control. It could then examine the page tables in the guest OS to see if they had been modified. While this could work, all the page tables would have to be checked on every system made by a guest application, that is, every time the guest OS returned to user mode. There could be thousands of these transitions per second, so it is not likely to be as efficient as using read-only pages for the page table
24、为了更好地在虚拟机之间动态的分配有限内存。不算欺骗,只是为了根据实际情况更好地调配内存
When a hypervisor runs out of pages, it has no way of figuring out which pages the guest operating systems really value. The solution is to cheat and include balloon drivers in the guests. The hypervisor then signals the balloon drivers to expand their memory usage, forcing the guest operating systems to decide which pages to evict. This is definitely cheating because the hypervisor is not supposed to talk to specific pieces of the guest operating systems. It is not supposed to know what is going on in the virtual machines at all. But this technique solves a problem in a simple way, so everyone pretends there is nothing iffy going on.
25、当所有的虚拟机都需要大量的内存时
Balloon drivers do not work if the hypervisor does not know anything about the guest operating systems running on its virtual machines. It also does not work if there is no way to include a balloon driver in them, for example, if they do not support loadable drivers and the source code is not available so they cannot be recompiled to include the balloon driver.
26、去重技术就是为了减少多个虚拟机对内存的占用所发明的。其操作是扫描虚拟机内存,计算散列,散列相同,看是否内容相同,内容相同,去重。本质上是多个虚拟机对相同部分只留一个副本,并对这个副本进行共享
Consider a case where multiple virtual machines copies of the same guest OS reside in a system. In this case, it is not necessary to maintain multiple copies of the read-only portion of the OS (such as code segments) in memory. Only one copy needs to be maintained, thereby reducing memory requirements and allowing more virtual machines on a system. This technique is called deduplication. VMware calls this ‘‘transparent page sharing.’’
27、DMA使用的是绝对的内存地址,这对虚拟机来说需要进行重新的映射。正好硬件上的I/O MMU可以做到。
Yes. Early DMA hardware used absolute memory addresses. If a guest operating system started a DMA operating to what it thought was physical address k, this would probably not go to the buffer it was supposed to go to and might overwrite something important. Early hypervisors had to rewrite code that used DMA to use addresses that would not cause trouble.
28、优点:可以不用担心运行到一般机子被关闭的问题;缺点:有延迟;数据可能被泄露
Using cloud services means you do not have to set up and maintain a computing infrastructure. You may also be able to outsource making backups. Furthermore, if your computing needs change rapidly, you can add or remove machines easily. On the downside, the cloud provider could easily steal your confidential data, and the promised expandability might be illusory if you need extra capacity just at the moment Walmart or some other big customer decides to grab 10,000 machines. Also, the bandwidth between you and the cloud might be an issue. It is likely to be far less than the local bandwidth, so if a lot of data needs to move between you and the cloud, that could be an issue. Also, if you are doing real-time work, the bandwidth between you and the cloud could vary wildly from moment to moment, causing trouble.
29、IAAS基础设施服务Infrastructure-as-a-service;PAAS平台服务Platform-as-a-service;SAAS软件服务Software-as-a-service。可以用做披萨做例子,分别为他人提供厨房、炉子、煤气,你使用这些基础设施,来烤你的披萨,比方说提供服务器;除了基础设施,他人还提供披萨饼皮,比方说VPS;他人直接做好了披萨,不用你的介入,到手的就是一个成品。你要做的就是把它卖出去,最多再包装一下,印上你自己的 Logo,比方说第三方的服务软件。
Obviously there are many, but a provider offering empty virtual x86 machines would be offering IAAS. A provider offering Windows 8 or Linux machines would be offering PAAS. A provider offering a word-processing program, such as Microsoft Word, running in the cloud would be offering software as a service.
30、因为有时候服务器出问题了,那么这个时候就需要将虚拟机转换到另一台物理机上。比方说一台服务器需要维修,那么运行在这台服务器上的虚拟机就需要将其迁移到另一台服务器上
Suppose many virtual machines were started up on a single server. Initially, all of them did about the same amount of work and required the same resources and the situation was fine. Then all of a sudden, one of them began using massive resources (CPU, memory, etc.) disturbing all the other virtual machines. This might be a good time to migrate it to a dedicated server of its own.
31、服务的暂停,这个可以通过热迁移来避免
Physical I/O devices still present problems because they do not migrate with the virtual machine, yet their registers may hold state that is critical to the proper functioning of the system. Think of read or write operations to devices(e.g., the disk) that have been issued but have not yet completed. Network I/O is particularly difficult because other machines will continue to send packets to the hypervisor, unaware that the virtual machine has moved. Even if packets can be redirected to the new hypervisor, the virtual machine will be unresponsive during the migration period, which can be long because the entire virtualmachine, including the guest operating system and all processes executing on it, must be moved to the new machine. As a result packets can experience large delays or even packet loss if the device/hypervisor buffers overflow.
32、因为一个进程的运行可能同很多该环境相关的依赖相关的,在迁移到另一台虚拟机上可能没有对于的依赖
In order to migrate a specific process, process state information has to be stored and then transferred, including open files, alarms, signal handlers, etc. Errors may creep in during the state capture task leading to potentially incorrect, incomplete or inconsistent state information. In the case of VM migration, the entire memory and disk images are moved to the new system, which is easier.
33、冷迁移需要将服务停止一段时间;热迁移不需要将服务停止。比方说内存预复制迁移,能在虚拟机提供服务的同时复制内存页。
Standard (dead) migration consists of stopping the virtual machine and saving its memory image as a file. The file is then transported to the destination, installed in a virtual machine, and restarted. Doing so causes the application to stop for a little while during transport. In many circumstances having the application stop is undesirable. With live migration, the pages of the virtual machine are moved while it is running. After they all arrive at the destination, a check is made to see if any of them have changed since being migrated. If so, they are copied again. This process is repeated until all the pages at the destination are up to date. Working this way (live migration) means applications can be moved with no downtime.
34、兼容性、性能好、隔离性
The three main requirements were: Compability (ability to run an existing guest OS without any modifications as a virtual machine); Performance (minimal overhead during VM execution; else, users would not choose to run their applications inside a VM) and Isolation (protecting the hardware resources from malicious or otherwise unauthorized access).
35、因为没有统一的标准,每个都有自己的驱动程序,而要虚拟化全部设备是不可能的。
There was no way that VMware could have drivers for the thousands of different I/O devices in existence. By having VMware Workstation be a type 2 hypervisor, it could solve the problem by indirectly using the drivers already installed in the host OS.
36、VMware ESXi has been made small so it can be put into the firmware of the servers. When the server is turned on, the BIOS can then copy itself to RAM and start creating virtual machines. This greatly simplifies the booting and startup process
37、这个其实就是SAAS,这个太多太多了。比方说问卷星、比方硕网易有数、比方说印象笔记啥的。
Several examples can be found at: virtualboximages.com. These include various distributions of preinstalled Open Source Operating Systems. For example, rather than get an ISO for a new Linux flavor go through the install process and then get the VM running, it is easier to download the preinstalled VDI. There are similar appliances that run on VMWare. Other examples can be found at: http://www.turnkeylinux.org

0x03 总结

没啥好总结的,这章大部分都是概念性的东西,可能对本科生来说讲深入了不好理解吧。


评论