1. ucore lab3介绍
虚拟内存介绍
在当前的硬件体系结构中,程序必须加载到物理主存中才能在计算机上运行。在支持多程序运行的系统上,我们希望包括操作系统内核在内的各种程序能够并发执行,而物理主存的总量通常是非常有限的,这就限制了并发程序的发展。由于成本问题,一台主存容量足够大的个人计算机对于普通人来说是负担不起的。因此,计算机科学家找到了另一种方法,想用局部性原理来解决我们应该能够同时运行大量程序和使计算机的成本足够低的矛盾。
[En]
In the current hardware architecture, programs must be loaded into physical main memory in order to run in a computer. On the system that supports multi-program running, we want all kinds of programs, including the operating system kernel, to be executed concurrently, while the total amount of physical main memory is usually very limited, which limits the development of concurrent programs. Due to the problem of cost, a personal computer with a large enough capacity of main memory is unaffordable for ordinary people. Therefore, computer scientists have found another way, thinking of using the locality principle to solve the contradiction that we should be able to run a large number of programs concurrently and make the computer low enough cost.
局部性原理告诉我们,大多数程序通常都在执行循环逻辑,访问数据时访问最频繁的也是数组等连续结构。一个程序在某一时刻所执行的代码和所访问的数据通常都聚集在一个很小的范围内。
虚拟内存机制的核心思想是将物理主存扩展到磁盘外存这一容量更大,单位存储成本更低的存储介质上,令主存在某种程度上作为了磁盘的缓存。因为即使程序所需要的内存很大,某一时刻所访问的内存都聚集在一个很小的页面集合中(工作集),操作系统可以将那些暂时不会被访问到的内存页置换到磁盘上,等到需要访问时再从磁盘中读出置换回主存。
操作系统提供的这一抽象层允许应用程序申请比实际可用物理主内存多得多的内存,但内存数据可能不会全部存储在物理主内存中,而是存储在磁盘上。这也是虚拟内存这个名称的由来。由于局部性的存在,通过高效的替换算法进行调度,与充分利用主存相比,访问速度不会受到太大影响。
[En]
This layer of abstraction provided by the operating system allows applications to apply for far more memory than the actual available physical main memory, but the memory data may not all be stored in physical main memory, but on disk. This is also the origin of the name virtual memory. Due to the existence of locality, through the efficient replacement algorithm for scheduling, the access speed is not greatly affected compared with the full use of main memory.
而ucore在lab3中,将实现虚拟内存机制,结合lab2完成的物理内存管理功能,完整的构建起ucore的内存管理子系统。
lab3相比lab2的改进
lab3在lab2的基础上,主要新增了以下功能:
1. kern_init总控函数中新增了vmm_init、ide_init、swap_init函数入口,分别完成了虚拟内存管理器、ide硬盘交互以及虚拟内存磁盘置换器的初始化。