windows 什么是工作集?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/896226/
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
What is Working Set?
提问by Porco
I'm confused with the concept of Working Set ,while reading the Memory Management code of the Windows Research Kernel.
在阅读 Windows Research Kernel 的内存管理代码时,我对 Working Set 的概念感到困惑。
回答by Tom Leys
The "working set" is short hand for "parts of memory that the current algorithm is using" and is determined by which parts of memory the CPU just happens to access. It is totally automatic to you. If you are processing an array and storing the results in a table, the array and the table are your working set.
“工作集”是“当前算法正在使用的内存部分”的简写,由 CPU 恰好访问的内存部分决定。这对你来说是完全自动的。如果您正在处理一个数组并将结果存储在一个表中,则该数组和该表就是您的工作集。
This is discussed because the CPU will automatically store accessed memory in cache, close to the processor. The working set is a nice way to describe the memory you want stored. If it is small enough, it can all fit in the cache and your algorithm will run very fast. On the OS level, the kernel has to tell the CPU where to find the physical memory your application is using (resolving virtual addresses) every time you access a new page (typically 4k in size) so also you want to avoid that hit as much as possible.
之所以讨论这一点,是因为 CPU 会自动将访问的内存存储在靠近处理器的缓存中。工作集是描述您想要存储的内存的好方法。如果它足够小,它就可以全部放入缓存中,并且您的算法将运行得非常快。在操作系统级别,每次访问新页面(通常为 4k 大小)时,内核都必须告诉 CPU 在哪里可以找到应用程序正在使用的物理内存(解析虚拟地址),因此您也希望尽可能避免这种情况尽可能。
See What Every Programmer Should Know About Memory - PDFfor graphs of algorithm performance vs size of working set (around page 23) and lots of other interesting info.
请参阅What Every Programmer should Know About Memory - PDF中的算法性能与工作集大小的关系图(第 23 页左右)以及许多其他有趣的信息。
Basically - write your code to access the smallest amount of memory possible (i.e classes are small, not too many of them), and try to ensure tight loops run on a very very small subset of that memory.
基本上 - 编写代码以访问尽可能少的内存(即类很小,而不是太多),并尝试确保在该内存的非常小的子集上运行紧密循环。
回答by Dave
Roughly, the working set is the areas of memory in active use. http://en.wikipedia.org/wiki/Working_set
粗略地说,工作集是活跃使用的内存区域。http://en.wikipedia.org/wiki/Working_set
回答by cjs
The "working set" is an informal term meaning the memory that's being accessed "frequently" (for some definition of frequently) by an application or set of applications. Applications may also allocate memory that they access infrequently (no more than once every few dozen seconds, perhaps not even once an hour); this would be outside of the working set.
“工作集”是一个非正式术语,表示一个应用程序或一组应用程序“频繁”(对于频繁的某些定义)访问的内存。应用程序也可能会分配它们不经常访问的内存(不超过每几十秒一次,甚至可能不超过一小时一次);这将在工作集之外。
An example might be if you have two Firefox Windows, a minimized one that you haven't looked at for several hours, and an open one that you're browsing in right now. The memory used to store the data associated with the open window is going to be in the working set; the memory used to store the data associated with the window that's not open and that you haven't looked at for several hours is not in the working set.
一个例子可能是,如果您有两个 Firefox Windows,一个是您几个小时没有查看的最小化版本,另一个是您正在浏览的打开的窗口。用于存储与打开的窗口相关联的数据的内存将在工作集中;用于存储与未打开且您已经数小时未查看的窗口相关联的数据的内存不在工作集中。
This is mainly used in discussions about whether you have enough RAM in your system. If your working set is smaller than your RAM, you can work comfortably, because the data your program or programs frequently access is always in memory. If your working set is larger than your RAM, the operating system will be constantly swapping pages out to disk to make room to swap in pages that an application wants to access; these swapped out pages, being in the working set, will almost immediately be needed again, meaning that you've got to take other pages and write them out to disk, and it just goes on and on like this. This is referred to as "thrashing."
这主要用于讨论您的系统中是否有足够的 RAM。如果你的工作集比你的 RAM 小,你可以舒服地工作,因为你的一个或多个程序经常访问的数据总是在内存中。如果您的工作集比您的 RAM 大,操作系统将不断地将页面换出到磁盘,以腾出空间来换入应用程序想要访问的页面;这些被换出的页面,在工作集中,几乎会立即再次被需要,这意味着你必须获取其他页面并将它们写到磁盘上,就像这样继续下去。这被称为“颠簸”。
If you're not reading or writing many files, your disk light is on all the time, and your system feels very slow, that's a pretty good sign that you're thrashing.
如果您没有读取或写入很多文件,您的磁盘灯一直亮着,并且您的系统感觉很慢,这是一个很好的迹象,表明您正在颠簸。
回答by Sean
The working set is the set of pages that are physically in memory at any one time. Although the working set if quoted and displayed in kilobytes the smallest working set you can have is 4k (8K on Itanium) as thats the size of a page in Windows.
工作集是在任何时候物理上位于内存中的一组页面。尽管工作集如果以千字节为单位引用和显示,但您可以拥有的最小工作集是 4k(在 Itanium 上为 8K),因为这是 Windows 中页面的大小。
To see the working set of a process look at the "Mem Usage" column in the task manager's "Processes" tab.
要查看进程的工作集,请查看任务管理器“进程”选项卡中的“内存使用”列。
If you're running a .NET app you can watch the working set be reduced looking at the process in the task manager process tab and then minimizing the application. Its working set is dramatically reduced as Windows swaps it out to the page file (since the process is assumed to not be "working" as much).
如果您正在运行 .NET 应用程序,您可以通过查看任务管理器进程选项卡中的进程来观察工作集的减少,然后最小化应用程序。随着 Windows 将其换出到页面文件,它的工作集显着减少(因为假定该进程没有“工作”那么多)。
回答by Webastronaut
The term "Working Set" is related to the Working Set Page Replacement Algorithm (the algorithm is very well explained in this article of Andrew Tanenbaum).
术语“工作集”与工作集页面替换算法有关(该算法在Andrew Tanenbaum 的这篇文章中有很好的解释)。
So the working set is a number of pages a process demands to be loaded from memory during execution. The working set consists of the most recently loaded page and the k
pages that have been loaded before. When it comes to make a frame free for a new demanded page, only pages that are not in the working set may be swapped.
因此,工作集是进程在执行期间需要从内存加载的许多页面。工作集由最近加载的页面和k
之前加载的页面组成。当涉及为新的请求页面腾出框架时,只有不在工作集中的页面可以交换。
回答by daniil_
Working set is a subset of virtual pages resident in physical memory.
工作集是驻留在物理内存中的虚拟页面的子集。
回答by Zan Lynx
All the memory your program is using that is notin the "working set" is marked for swap to disk. When the operating system needs more memory for other work it will try to keep the working set of each program in memory, but everything else is up for grabs.
您的程序使用的所有不在“工作集”中的内存都被标记为交换到磁盘。当操作系统需要更多内存用于其他工作时,它会尝试将每个程序的工作集保留在内存中,但其他一切都可以抢夺。