alicemare / ideas

用Issue来记录一些简单的笔记?
0 stars 0 forks source link

Operating Systems: Three Easy Pieces #12

Open alicemare opened 5 years ago

alicemare commented 5 years ago

Operating Systems: Three Easy Pieces 虚拟化 Memory部分 P: For understanding virtual memory, start with this: every address generated by a user program is a virtual address. S: .... (awkward pause) ... Anyway, why does the OS want to provide this illusion again? P: Mostly ease of use: the OS will give each program the view that it has a large contiguous address space to put its code and data into; thus, as a programmer, you never have to worry about things like “where should I store this variable?” because the virtual address space of the program is large and has lots of room for that sort of thing. Life, for a programmer, becomes much more tricky if you have to worry about fitting all of your code data into a small, crowded memory. Student: Why else? Professor: Well, isolation and protection are big deals, too. We don’t want one errant program to be able to read, or worse, overwrite, some other program’s memory, do we?

alicemare commented 5 years ago

It is those darned users with their expectations of “ease of use”, “high performance”, “reliability”, etc., that really have led to all these headaches. Next time you meet one of those computer users, thank them for all the problems they have caused.

早些时候人们对计算机的期望无疑是很低的...然后...才有了这些让我们后来的计算机学习生头疼的问题 计算机在内存管理方面的大致发展历程:

单任务系统时代(era)

此时的OS占据了0-64K的空间,进程用去余下的所有空间,此时是OS设计者最为幸福的时期

多任务时代(memory-sharing)

由于计算机造价昂贵,为了提高利用效率(比如,可以让一个程序在等待IO时把CPU交给另一个进程使用),也就有了多任务系统,以批处理为主,执行一个任务的时候,把它从disk装载到内存中,然后开始执行

分时系统(time-sharing)

由于批处理系统的交互性太差,程序员希望有更好的交互性,所以开始了分时系统,此时已经有了多个任务同时在内存中,CPU只切换reg-file的大致情景,于是,人们开始要求程序之间彼此要能安全,不能越界访问需求才是第一生产力

地址空间

为了满足这些pesky(讨厌的)用户,且保证易用的“假象”,我们开始使用地址空间,当然,这也是被我们“欺骗”的进程在系统中看到内存的景象

alicemare commented 5 years ago

How can the OS build this abstraction of a private, potentially large address space for multiple running processes (all sharing memory) on top of a single, physical memory? When the OS does this, we say the OS is virtualizing memory, because the running program thinks it is loaded into memory at a particular address (say 0) and has a potentially very large address space (say 32-bits or 64-bits); the reality is quite different

Summary We have seen the introduction of a major OS subsystem: virtual memory. The VM system is responsible or providing the illusion of a large, sparse, private address space to programs, which hold all of their instructions and data therein. The OS, with some serious hardware help, will take each of these virtual memory references, and turn them into physical addresses, which can be presented to the physical memory in order to fetch the desired information. The OS will do this for many processes at once, making sure to protect programs from one another, as well as protect the OS. The entire approach requires a great deal of mechanism (lots of low-level machinery) as well as some critical policies to work; we’ll start from the bottom up, describing the critical mechanisms first. And thus we proceed!

alicemare commented 5 years ago

TIP: INTERPOSITION IS POWERFUL Interposition is a generic and powerful technique that is often used to great effect in computer systems. In virtualizing memory, the hardware will interpose on each memory access, and translate each virtual address issued by the process to a physical address where the desired information is actually stored. However, the general technique of interposition is much more broadly applicable; indeed, almost any well-defined interface can be interposed upon, to add new functionality or improve some other aspect of the system. One of the usual benefits of such an approach is transparency; the interposition often is done without changing the client of the interface, thus requiring no changes to said client.

介入是一种操作系统常用的技术,可以用于任何接口定义好的操作中,这样介入的好处是对用户透明 在这里,为了实现VM,操作系统一方面要考虑控制性,也要注意效率,如同在进程调度时LDE的方法,操作系统采取的是一种,只在必要时候动手的策略大概就是越界的时候让进程终止运行吧

alicemare commented 5 years ago

地址翻译是一个动态重定向的过程(dynamic relocation) base+bound寄存器,举例,进程认为自己拥有0-16kb的地址空间,而实际上硬件在执行程序的时候通过把-虚拟地址+基地址得到物理地址,这个过程是在运行时发生的,甚至我们可以移动进程的地址空间而不受影响,所以称为动态重定向 在这个过程中,base寄存器用于确定偏移量,bound用于确定执行指令的地址在程序的地址空间内(注意不是物理地址,所以这里bound总是16kb) base-bound组合也被称为MMU(Memory management unit)