What is virtual memory, how is it implemented, and why do operating systems use it?
来源:互联网 发布:提高口才知乎 编辑:程序博客网 时间:2024/06/05 14:15
Real, or physical, memory exists on RAM chips inside the computer. Virtual memory, as its name suggests, doesn’t physically exist on a memory chip. It is an optimization technique and is implemented by the operating system in order to give an application program the impression that it has more memory than actually exists. Virtual memory is implemented by various operating systems such as Windows, Mac OS X, and Linux.
So how does virtual memory work? Let’s say that an operating system needs 120 MB of memory in order to hold all the running programs, but there’s currently only 50 MB of available physical memory stored on the RAM chips. The operating system will then set up 120 MB of virtual memory, and will use a program called the virtual memory manager (VMM) to manage that 120 MB. The VMM will create a file on the hard disk that is 70 MB (120 – 50) in size to account for the extra memory that’s needed. The O.S. will now proceed to address memory as if there were actually 120 MB of real memory stored on the RAM, even though there’s really only 50 MB. So, to the O.S., it now appears as if the full 120 MB actually exists. It is the responsibility of the VMM to deal with the fact that there is only 50 MB of real memory.
The paging file and the RAM
Now, how does the VMM function? As mentioned before, the VMM creates a file on the hard disk that holds the extra memory that is needed by the O.S., which in our case is 70 MB in size. This file is called a paging file (also known as a swap file), and plays an important role in virtual memory. The paging file combined with the RAM accounts for all of the memory. Whenever the O.S. needs a ‘block’ of memory that’s not in the real (RAM) memory, the VMM takes a block from the real memory that hasn’t been used recently, writes it to the paging file, and then reads the block of memory that the O.S. needs from the paging file. The VMM then takes the block of memory from the paging file, and moves it into the real memory – in place of the old block. This process is called swapping (also known as paging), and the blocks of memory that are swapped are called pages. The group of pages that currently exist in RAM, and that are dedicated to a specific process, is known as the working set for that process.
As mentioned earlier, virtual memory allows us to make an application program think that it has more memory than actually exists. There are two reasons why one would want this: the first is to allow the use of programs that are too big to physically fit in memory. The other reason is to allow for multitasking – multiple programs running at once. Before virtual memory existed, a word processor, e-mail program, and browser couldn’t be run at the same time unless there was enough memory to hold all three programs at once. This would mean that one would have to close one program in order to run the other, but now with virtual memory, multitasking is possible even when there is not enough memory to hold all executing programs at once.
Virtual Memory Can Slow Down Performance
However, virtual memory can slow down performance. If the size of virtual memory is quite large in comparison to the real memory, then more swapping to and from the hard disk will occur as a result. Accessing the hard disk is far slower than using system memory. Using too many programs at once in a system with an insufficient amount of RAM results in constant disk swapping – also called thrashing, which can really slow down a system’s performance.
- What is virtual memory, how is it implemented, and why do operating systems use it?
- What Is UAT, And Why Do It?
- What is a cronjob and how do I use it?
- What is a NullPointerException, and how do I fix it?
- Hadoop: What it is, how it works, and what it can do
- What is JNI Graphics and how to use it?
- What is reflection and how to use it in CSharp ?
- What is svchost.exe And Why Is It Running? :: the How-To Geek
- What is initrd and why is it necessary
- What Is UTF-8 And Why Is It Important?
- What is svchost.exe And Why Is It Running?
- What is a magic number? And why is it bad?
- 【html】What is href=“#” and why is it used?
- What is Docker and why is it so darn popular?
- (Page 1 of 3 )A walking tour of JavaBeans What JavaBeans is, how it works, and why you want to use it
- (Page 2 of 3 )A walking tour of JavaBeans 2 :What JavaBeans is, how it works, and why you want to use it
- (Page 3 of 3 )A walking tour of JavaBeans What JavaBeans is, how it works, and why you want to use it
- Requirement Traceability Matrix (RTM) – What Is RTM And Why Do We Need It?
- 黑马程序员——正则表达式的总结及案例
- 使用TestFlight进行内部测试
- [leetcode] 199. Binary Tree Right Side View 解题报告
- IntelliJ IDEA
- Struts2-拦截器的使用
- What is virtual memory, how is it implemented, and why do operating systems use it?
- [leetcode] 222. Count Complete Tree Nodes 解题报告
- udig中配置style对于中文标注设置问题
- BZOJ 3211: 花神游历各国 |树状数组|并查集
- clojure on the beginning
- ES6学习——类语法:继承内置的类(如Array,Error等)
- python isinstance(), stack,判断list, dict, tuple为空
- 对Keil MDK 启动代码的理解
- linux(Ubuntu)中安装mavne私服Nexus