虚拟内存和物理内存 [英] Virtual Memory and Physical Memory

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

问题描述

我正在从Abraham Silberschatz和Galvin撰写的名为操作系统概念"的书中研究内存管理单元(MMU)的概念.尽管在第8章之前情况还不错,但从第9章开始,事情就开始混乱了.

我不清楚我的虚拟内存是什么?另外,物理地址和逻辑地址现在似乎令人困惑?它(虚拟内存)是否真实存在? 根据我现在的理解,系统的RAM是我所谓的物理(或主)内存.我有8GB RAM和64位OS.因此,我的RAM可以容纳2 ^ 64-1个地址.这就是我所说的物理地址空间吗?另外,逻辑地址空间到底是什么?

每个进程都必须在主内存中才能执行,否则它驻留在硬盘上.我在硬盘上的代码指令所赋予的地址就是我所说的逻辑地址吗?而当将其加载到RAM中时,由于位置不固定,因此代码可以加载到任何地方,因此此处分配的地址(RAM)称为物理地址?我认为此映射称为逻辑物理地址映射.

现在,由于我的代码或进程的大小可能大于可用RAM的大小,因此需要使用虚拟内存.据我了解,这是给程序员一个观点,即他在系统上拥有无限可用的内存,这是一种抽象.从本质上讲,这是硬盘的一部分区域,RAM中的一些进程(很少使用)被交换出去.同时将所需的页面放入主存储器.是这样吗?那么,什么决定了硬盘上该区域的大小?另外,RAM很便宜,那么为什么我们需要这种机制呢?我们不能增加RAM大小而不是包括交换的开销吗?

我在网上进行了很多搜索,但没有找到确切的定义以及这些术语之间的区别.请帮忙!

谢谢

解决方案

我不清楚我的虚拟内存是什么?另外,身体和 逻辑地址现在似乎令人困惑?是否(虚拟内存) 是否存在?

您可以阅读Wikipedia上有关虚拟内存的体面的解释.我不会在这里讨论整个事情.

是的,虚拟内存是真实存在的.它将程序使用的内存地址(称为虚拟地址)映射到计算机内存中的物理地址.流程或任务看到的主存储器显示为连续的地址空间或连续的段的集合.

虚拟内存的主要好处包括:使应用程序不必管理共享的内存空间;由于内存隔离而提高了安全性;使用分页技术,从概念上讲,能够使用比物理上可用的更多的内存.

感谢 David Schwartz 帮助我改善了内容.仍然在嵌入式设备中,虚拟内存仅用于页面映射,这是其定义的原始目的.但是,现在在现代OS中,它采取了完全不同的形式.人们正在利用虚拟内存在分页/分段中的使用,因此交换是最重要的.

如今,额外的内存区域也称为交换区域或swap-partition,通常保留给OS(Unix/Linux)使用,以便在主内存中进行交换过程. Windows具有用于实现相同目的的页面文件.

我有8GB RAM和64位OS.因此,我的RAM可以容纳2 ^ 64-1 地址.这就是我所说的物理地址空间吗?

您应该在这里谈论处理器,而不是操作系统或RAM.原则上,一个64位微处理器可以寻址16个EiB(16×2 ^ 60字节)的存储器.实际上,它还不止于此.您可以用作RAM 来使用此内存.

还有,逻辑地址空间到底是什么?

逻辑地址空间是由以下各项组成的地址空间:项目(内存单元格,存储元素,网络主机)似乎是从正在执行的应用程序的角度来看.

由于地址转换器或映射功能的操作,逻辑地址可能与物理地址不同.在计算机存储器体系结构的情况下,这样的映射功能可以是CPU和存储器总线之间的存储器管理单元(MMU),或者硬件和互联网络协议之间的地址转换层,例如数据链路层. (Internet协议)在计算机联网系统中.

在支持虚拟内存的系统中,实际上可能没有任何物理内存映射到逻辑地址,直到尝试访问.该访问触发了操作系统的特殊功能,这些功能对MMU进行了重新编程,以将地址映射到某些物理内存,也许将该内存的旧内容写入磁盘,并从磁盘上读取该内存应包含在新逻辑地址中的内容.在这种情况下,逻辑地址可以称为虚拟地址.

每个进程都必须在主存储器中才能执行,否则 驻留在硬盘上.地址是否提供给我的说明 硬盘上的代码是我所谓的逻辑地址?什么时候 它被加载到RAM中,因为位置不固定,因此代码 可以加载到任何地方,这里分配的地址(i RAM)称为 物理地址?我认为此映射称为 逻辑-物理地址映射.

如今,几乎所有系统都支持虚拟内存(有一些例外).因此,是的,当您的进程从RAM中换出以使其他进程可以执行时,它们将分别保存在硬盘的保留部分,即虚拟内存.而且,有一种虚拟内存寻址方案,您称之为逻辑地址.

页表用于将应用程序看到的虚拟地址转换为硬件用来处理指令的物理地址;这种处理这种特定转换的硬件通常称为内存管理单元.页表中的每个条目都包含一个标志,该标志指示相应的页是否在实存储器中.如果它在真实内存中,则页面表条目将包含存储页面的真实内存地址.

现在,因为我的代码或进程的大小可能大于 可用RAM,这里是虚拟内存的使用.据我了解, 这是给程序员一个观点,认为他有一个 系统上的无限可用内存量.基本上是 硬盘的某些区域(很少使用)是来自RAM的进程 换了出去.同时将所需的页面放入主页面 记忆.是这样吗?那么什么决定了这个区域的大小 磁盘?

与上述完全相同.并且,不同类型的OS会建议这种大小的保留硬盘空间(虚拟内存).但是,通常将其定义为在Unix/Linux OS的不同分区(交换分区)上.与* nix的交换分区相比,Windows具有页面文件;尽管两者之间存在许多技术差异.这是特定于OS的,但概念几乎相同.在* nix系统中,我已经看到建议将交换分区的大小保持为系统中RAM大小的两倍.我对此无能为力,也许有人可以提出更多细节.

此外,RAM很便宜,那么为什么我们需要这种机制? 我们不能增加RAM大小,而不是包括 交换?

不,与RAM的成本相比,硬盘的价格仍然非常经济.而且,RAM昂贵,并且并非所有PC都可以升级以增加RAM.幸运的是,当内存不足时,增加虚拟内存是最佳选择.此外,Microsoft建议您将虚拟内存设置为计算机上RAM的不少于1.5倍且不超过RAM的3倍. (最后一行的来源).

I am studying the concept of Memory Management Unit(MMU) from the book titled "Operating System Concepts" - by Abraham Silberschatz and Galvin. Though things were fine till chapter 8. As soon I started with chapter 9, things started messing up.

I am not clear about what my virtual memory is? Also, physical and logical addresses seems to be confusing now? Does it(virtual memory) exists in real or not? As per my understanding of now, the RAM of my system is what I call Physical(or main) Memory. I have 8GB RAM and 64- bit OS. Thus, my RAM can accommodate 2^64-1 addresses. Is this what I call physical address space? Also, what exactly is logical address space?

Every process has to be in main memory for execution otherwise it resides on hard disk. Are the addresses given to instructions of my code residing on hard disk is what I call logical address? And when it's loaded in RAM, because location is not fixed and hence the code can be loaded anywhere, the addresses assigned here(RAM) called Physical Addresses? This mapping I suppose is referred to as Logical-Physical address mapping.

Now, because size of my code or process can be large than the size of RAM available, here comes the use of virtual memory. As I understood, it's an abstraction to give the programmer a view that he has an infinite amount of memory available on the system. It's basically an area of hard disk where some processes(which are seldom used) from RAM are swapped out. Simultaneously desired pages are brought in the main memory. Is it so? Then what determines the size of this area on hard disk? Also, RAM is cheap, then why do we need to have such a mechanism? Can't we increase our RAM size instead of including this overhead of swapping?

I have searched much on web but didn't find the exact definition and difference between these terms. Please help!

Thanks

解决方案

I am not clear about what my virtual memory is? Also, physical and logical addresses seems to be confusing now? Does it(virtual memory) exists in real or not?

You can read a decent explanantion on Wikipedia about Virtual Memory. I am not going to discuss the whole thing here.

Yes, virtual memory exists in real. It maps memory addresses used by a program, called virtual addresses, into physical addresses in computer memory. Main storage as seen by a process or task appears as a contiguous address space or collection of contiguous segments.

The primary benefits of virtual memory include freeing applications from having to manage a shared memory space, increased security due to memory isolation, and being able to conceptually use more memory than might be physically available, using the technique of paging.

Thanks to David Schwartz for helping me improve the content. Still in embedded devices, virtual-memory is used just for the page-mapping, it's native purpose for which it was defined. But, now in modern OS', it has taken a totally different form. People are exploiting the usage of virtual-memory in paging/segmentation,thus swapping being the most-important.

The extra memory area is also known as swap-area or swap-partition nowadays which is generally reserved for usage by OS(Unix/Linux) for swapping process in and out of the main-memory. Windows has pagefiles for achieving the same.

I have 8GB RAM and 64- bit OS. Thus, my RAM can accommodate 2^64-1 addresses. Is this what I call physical address space?

You should talk about processor here, and not OS or the RAM directly. In principle, a 64-bit microprocessor can address 16 EiBs (16 × 2^60 bytes) of memory. In practice, it is less than that. This memory is what you can possibly use as RAM.

Also, what exactly is logical address space?

Logical address space is the address space consisting of addresses at which items (memory cell, storage element, network host) appear to reside from the perspective of an executing application program.

A logical address may be different from the physical address due to the operation of an address translator or mapping function. Such mapping functions may be, in the case of a computer memory architecture, a memory management unit (MMU) between the CPU and the memory bus, or an address translation layer, e.g., the Data Link Layer, between the hardware and the internetworking protocols (Internet Protocol) in a computer networking system.

In a system supporting virtual memory, there may actually not be any physical memory mapped to a logical address until an access is attempted. The access triggers special functions of the operating system which reprogram the MMU to map the address to some physical memory, perhaps writing the old contents of that memory to disk and reading back from disk what the memory should contain at the new logical address. In this case, the logical address may be referred to as a virtual address.

Every process has to be in main memory for execution otherwise it resides on hard disk. Are the addresses given to instructions of my code residing on hard disk is what I call logical address? And when it's loaded in RAM, because location is not fixed and hence the code can be loaded anywhere, the addresses assigned here(i RAM) called Physical Addresses? This mapping I suppose is referred to as Logical-Physical address mapping.

Nowadays, almost all systems support virtual memory(there are a few exceptions). So, yes, when your processes are swapped out from RAM so that other processes could execute, they are separately kept in that reserved portion of hard-disk called virtual memory. And, there is an addressing scheme for virtual-memory which is what you call as a logical address.

Page tables are used to translate the virtual addresses seen by the application into physical addresses used by the hardware to process instructions; such hardware that handles this specific translation is often known as the memory management unit. Each entry in the page table holds a flag indicating whether the corresponding page is in real memory or not. If it is in real memory, the page table entry will contain the real memory address at which the page is stored.

Now, because size of my code or process can be large than the size of RAM available, here comes the use of virtual memory. As I understood, it's an abstraction to give the programmer a view that he has an infinite amount of memory available on the system. It's basically an area of hard disk some processes(which are seldom used) from RAM are swapped out. Simultaneously desired pages are brought in the main memory. Is it so? Then what determines the size of this area on hard disk?

Exactly the same as described above. And, this size of reserved hard-disk space(virtual-memory) is recommended by different types of OS differently. But, generally it is defined to be on a different partition on Unix/Linux OS(swap partition). Windows has pagefile compared to *nix's swap partition; although there are many technical differences between the two.. This is OS-specific but the concept is almost the same. In *nix systems I have seen that it is recommended to keep the size of swap partition to be double of the size of the RAM in the system. I can't argue more about this,maybe someone can suggest more detail.

Also, RAM is cheap, then why do we need to have such a mechanism? Can't we increase our RAM size instead of including this overhead of swapping?

No, as compared to the cost of the RAM, the price of hard-disk is still much economical. Also, RAM is expensive and not all PCs can be upgraded to increase RAM. Luckily increasing virtual memory is the best option when you are low on memory. Also, Microsoft recommends that you set virtual memory to be no less than 1.5 times and no more than 3 times the amount of RAM on your computer. (Source of the last line).

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

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