为什么操作系统为运行进程创建虚拟内存 [英] why OS create the virtual memory for running process

查看:54
本文介绍了为什么操作系统为运行进程创建虚拟内存的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当程序启动时,操作系统会创建一个虚拟内存,它分为stackheapdata>, text 在其上运行一个进程.我知道每个段用于规范目的,例如 text 保存程序的二进制代码,data 保存 staticglobal 变量.我的问题是为什么操作系统需要创建 virtual memory 并将其划分为段?如果操作系统只使用物理内存并且进程直接在物理内存上运行,那如何?我认为答案可能与同时运行多个进程、在进程之间共享内存有关,但我不确定.如果你能给我一个关于创建虚拟内存并将其划分为段的好处的例子,我会很高兴.

when a program started the OS will create a virtual memory, which divided into stack, heap, data, text to run a process on it.I know that each segment is used for specification purpose such as text saves the binary code of program, data saves static and global variable. My question is why the OS need to create the virtual memory and divide it into the segments ? How about if OS just use the physical memory and the process run directly on the physical memory. I think maybe the answer is related with running many process at the same time, sharing memory between process but i am not sure. It is kind if you give me an example about the benefit of creating virtual memory and dividing it into the segments.

推荐答案

在通过内存映射单元进行内存保护的环境中,所有内存都是虚拟的(通过 MMU 映射).可以简单地将每个虚拟地址线性映射到物理地址,同时仍然使用 MMU 的保护功能,但这样做没有意义.不喜欢直接映射内存的原因有很多,例如能够在同一程序或不同程序的实例之间共享程序指令和共享库代码,能够fork等.

In an environment with memory protection via a memory mapping unit, all memory is virtual (mapped via the MMU). It's possible to simply map each virtual address linearly to physical addresses, while still using the protection capabilities of the MMU, but doing that makes no sense. There are many reasons to prefer that memory not be directly mappped, such as being able to share program instructions and shared library code between instances of the same program or different programs, being able to fork, etc.

这篇关于为什么操作系统为运行进程创建虚拟内存的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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