虚拟内存和物理内存有什么区别? [英] What are the differences between virtual memory and physical memory?

查看:20
本文介绍了虚拟内存和物理内存有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我经常对操作系统中的虚拟化概念感到困惑.将 RAM 视为物理内存,为什么我们需要虚拟内存来执行进程?

I am often confused with the concept of virtualization in operating systems. Considering RAM as the physical memory, why do we need the virtual memory for executing a process?

当来自外部硬盘的进程(程序)被带到主内存(物理内存)执行时,这个虚拟内存在哪里.

Where does this virtual memory stand when the process (program) from the external hard drive is brought to the main memory (physical memory) for the execution.

谁来管理虚拟内存,虚拟内存的大小是多少?

Who takes care of the virtual memory and what is the size of the virtual memory?

假设 RAM 的大小为 4GB(即 2^32-1 个地址空间),虚拟内存的大小是多少?

Suppose if the size of the RAM is 4GB (i.e. 2^32-1 address spaces) what is the size of the virtual memory?

推荐答案

除其他外,虚拟内存是一种抽象,让程序员产生一种错觉,即在他们的系统上拥有无限内存可用.

Virtual memory is, among other things, an abstraction to give the programmer the illusion of having infinite memory available on their system.

虚拟内存映射对应于实际物理地址.操作系统创建并处理这些映射——利用页表以及其他数据结构来维护这些映射.虚拟内存映射总是在页表或一些类似的数据结构中找到(在其他虚拟内存实现的情况下,我们可能不应该称它为页表").页表也位于物理内存中 - 通常位于用户程序无法覆盖的内核保留空间中.

Virtual memory mappings are made to correspond to actual physical addresses. The operating system creates and deals with these mappings - utilizing the page table, among other data structures to maintain the mappings. Virtual memory mappings are always found in the page table or some similar data structure (in case of other implementations of virtual memory, we maybe shouldn't call it the "page table"). The page table is in physical memory as well - often in kernel-reserved spaces that user programs cannot write over.

虚拟内存通常比物理内存大 - 如果虚拟内存和物理内存大小相同,就没有太多理由进行虚拟内存映射.

Virtual memory is typically larger than physical memory - there wouldn't be much reason for virtual memory mappings if virtual memory and physical memory were the same size.

通常只有程序需要的部分驻留在内存中 - 这是一个称为分页"的主题.虚拟内存和分页密切相关,但不是同一主题.虚拟内存还有其他实现方式,例如分段.

Only the needed part of a program is resident in memory, typically - this is a topic called "paging". Virtual memory and paging are tightly related, but not the same topic. There are other implementations of virtual memory, such as segmentation.

我可能在这里假设错了,但我敢打赌,您发现难以理解的事情与虚拟内存的特定实现有关,很可能是分页.没有一种方法进行分页 - 有多种实现方式,您的教科书描述的一种可能与 Linux/Windows 等真实操作系统中出现的不同 - 可能存在细微差别.

I could be assuming wrong here, but I'd bet the things you are finding hard to wrap your head around have to do with specific implementations of virtual memory, most likely paging. There is no one way to do paging - there are many implementations and the one your textbook describes is likely not the same as the one that appears in real OSes like Linux/Windows - there are probably subtle differences.

我可以说一千段关于分页的废话……但我认为最好留给专门针对该主题的不同问题.

I could blab a thousand paragraphs about paging... but I think that is better left to a different question targeting specifically that topic.

这篇关于虚拟内存和物理内存有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆