Windows - 提交大小与虚拟大小

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/22174310/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-09 11:26:18  来源:igfitidea点击:

Windows - Commit Size vs Virtual Size

windowsmemoryvirtual-memory

提问by Faris Zacina

i would like to know the exact difference between Commit Size(visible in the Task Manager) and Virtual Size(visible in SysInternals' Process Explorer).

我想知道提交大小(在任务管理器中可见)和虚拟大小(在 SysInternals 的进程资源管理器中可见)之间的确切区别。

The Virtual Sizeparameter in Process Explorerlooks like a more accurate indicator of Total Virtual Memory usage by a process. However the Commit Sizeis always smaller than the Virtual Sizeand I guess it does not include all virtual memory in use by the process. I would like somebody to explain what is exactly included in these parameters.

Process Explorer 中Virtual Size参数看起来更像是一个进程使用的总虚拟内存的更准确的指标。然而,提交大小总是小于虚拟大小,我猜它不包括进程使用的所有虚拟内存。我希望有人解释这些参数中究竟包含什么。

回答by Damon

Memory can be reserved, committed, first accessed, and be part of the working set. When memory is reserved, a portion of address space is set aside, nothing else happens.

内存可以被保留、提交、首次访问并成为工作集的一部分。保留内存时,会出一部分地址空间,不会发生其他任何事情。

When memory is committed, the operating system guarantees that the corresponding pages couldin principle exist either in physical RAM or on the page file. In other words, it counts toward its hard limit of total available pages on the system, and it formallycreates pages. That is, it creates pages and pretends that they exist (when in reality they don't exist yet).

当内存被提交,操作系统保证了相应的页面可能在原则上存在无论是在物理RAM或页面文件。换句话说,它计入系统上可用页面总数的硬限制,并正式创建页面。也就是说,它创建页面并假装它们存在(实际上它们还不存在)。

When memory is accessedfor the first time, the pages that formallyexist are created so they trulyexist. Either a zero page is supplied to the process, or data is read into a page from a mapping. The page is moved into the working setof the process (but will not necessarily remain in there forever).

第一次访问内存时,会创建正式存在的页面,使其真正存在。要么向进程提供零页,要么将数据从映射读入页。页面被移动到进程的工作集中(但不一定永远留在那里)。

Every running process has a number of pages which are factually and logicallyin RAM, that is these pages exist, and they exist "officially", too. This is the process' working set.
Further, every running process has pages that are factuallyin RAM, but do not officially exist in RAM any more. They may be on what's called the "standby list" or part of the buffer cache, or something different. When these are accessed, the OS may simply move them into the working set again.
Lastly, every process has pages that are not in RAM at all (either on swap or they don't exist yet).

每个正在运行的进程都有许多页,这些页实际上和逻辑上都在 RAM 中,也就是说这些页存在,它们也“正式”存在。这是进程的工作集。
此外,每个正在运行的进程都有实际上在 RAM 中的页面,但不再正式存在于 RAM 中。它们可能位于所谓的“备用列表”或缓冲区缓存的一部分,或其他内容。当这些被访问时,操作系统可以简单地再次将它们移动到工作集中。
最后,每个进程都有根本不在 RAM 中的页面(在交换中或它们尚不存在)。

Virtual sizecomprises the size of all pages that the process has reserved.

虚拟大小包括进程保留的所有页面的大小。

Commit sizeonly comprises pages that have been committed.

提交大小仅包括已提交的页面。

That is, in layman terms, "virtual size" is pretty much your own problem, and only limited by the size of your address space, whereas "commit size" is everybody's problem since it consumes a global limited resource (RAM plus swap). It therefore affects other processes.

也就是说,通俗地说,“虚拟大小”几乎是您自己的问题,仅受地址空间大小的限制,而“提交大小”则是每个人的问题,因为它消耗全局有限资源(RAM 加交换)。因此它会影响其他进程

回答by Hans Passant

Commit size is the amount of space reserved in the paging file for the process. Used when its pages need to be swapped out to make room in RAM for other processes.

提交大小是页面文件中为进程保留的空间量。当其页面需要换出以在 RAM 中为其他进程腾出空间时使用。

And yes, the virtual memory size will be larger since it includes the pages that are not backed by the paging file. At least the code and resource sections in the EXE and non-relocated DLLs. When necessary, those pages can simply be discarded and reloaded from the file. All the operating system DLLs fit this category. Additionally any memory-mapped files used by the process. SysInternals' VMMap utility can give insight.

是的,虚拟内存大小会更大,因为它包括页面文件不支持的页面。至少是 EXE 和非重定位 DLL 中的代码和资源部分。必要时,可以简单地丢弃这些页面并从文件中重新加载。所有操作系统 DLL 都属于这一类别。此外,进程使用的任何内存映射文件。SysInternals 的 VMMap 实用程序可以提供洞察力。

回答by egur

Virtual size is the size of the process's virtual address space.

虚拟大小是进程的虚拟地址空间的大小。

When allocating memory, you can request an address range without actually committing memory behind it. Those address do not point to physical memory until a second allocation call is used to commit them.

分配内存时,您可以请求一个地址范围,而无需在其后实际提交内存。在使用第二个分配调用提交它们之前,这些地址不会指向物理内存。

Read more on VirtualAlloc. Linux has the mmap function that does the same thing.

阅读更多关于VirtualAlloc。Linux 有 mmap 函数可以做同样的事情。