页面抖动,程序驻留集 RSS 和工作集 WSS;use htop to check process resident set size;

页面抖动(颠簸)

在页面置换过程中的一种最糟糕的情形是,刚刚换出的页面马上又要换入主存,刚刚换入的页面马上就要换出主存,这种频繁的页面调度行为称为抖动,或颠簸。如果一个进程在换页上用的时间多于执行时间,那么这个进程就在颠簸。

频繁的发生缺页中断(抖动),其主要原因是某个进程频繁访问的页面数目高于可用的物理页帧数目。虚拟内存技术可以在内存中保留更多的进程以提髙系统效率。在稳定状态,几乎主存的所有空间都被进程块占据,处理机和操作系统可以直接访问到尽可能多的进程。但如果管理不当,处理机的大部分时间都将用于交换块,即请求调入页面的操作,而不是执行进程的指令,这就会大大降低系统效率。

工作集

工作集是指在某段时间间隔内,进程要访问的页面集合。经常被使用的页面需要在工作集中,而长期不被使用的页面要从工作集中被丢弃。为了防止系统出现抖动现象,需要选择合适的工作集大小。

工作集模型的原理是:让操作系统跟踪每个进程的工作集,并为进程分配大于其工作集的物理块。如果还有空闲物理块,则可以再调一个进程到内存以增加多道程序数。如果所有工作集之和增加以至于超过了可用物理块的总数,那么操作系统会暂停一个进程,将其页面调出并且将其物理块分配给其他进程,防止出现抖动现象。

正确选择工作集的大小,对存储器的利用率和系统吞吐量的提嵩,都将产生重要影响。

程序工作集,就是驻留集,有误。

# 关于程序驻留集与工作集:2021年12月30日09:48:04

有网友评论,工作集与驻留集混淆的问题,我认真查了一下文档:

Working Set:https://docs.microsoft.com/en-us/windows/win32/memory/working-set working set on windows

The working set of a process is the set of pages in the virtual address space of the process that are currently resident in physical memory. 
The working set contains only pageable memory allocations; nonpageable memory allocations such as Address Windowing Extensions (AWE) or large page allocations are not included in the working set.

Working Set Size Estimation:https://www.brendangregg.com/wss.html https://www.brendangregg.com/blog/2018-01-17/measure-working-set-size.html

The Working Set Size (WSS) is how much memory an application needs to keep working. 
Your application may have 100 Gbytes of main memory allocated and page mapped, but it is only touching 50 Mbytes each second to do its job. 
That's the working set size: the "hot" memory that is frequently used. It is useful to know for capacity planning and scalability analysis.

You may never have seen WSS measured by any tool (when I created this page, I hadn't either). OSes usually show you these metrics:
  Virtual memory: Not real memory. It's an artifact of a virtual memory system. For on-demand memory systems like Linux, malloc() immediately returns virtual memory, which is only promoted to real memory later when used (promoted via a page fault).
  Resident memory or Resident set size (RSS): Main memory. Real memory pages that are currently mapped.
  Proportional set size (PSS): RSS with shared memory divided among users.
These are easily tracked by the kernel as it manages virtual and main memory allocation. But when your application is in user-mode doing load and store instructions across its WSS, the kernel isn't (usually) involved. So there's no obvious way a kernel can provide a WSS metric.

Resident Set size:https://en.wikipedia.org/wiki/Resident_set_size https://lwn.net/Articles/97346/

In computing, resident set size (RSS) is the portion of memory occupied by a process that is held in main memory (RAM). 
The rest of the occupied memory exists in the swap space or file system, either because some parts of the occupied memory were paged out, or because some parts of the executable were never loaded.

通过对比,简而言之,驻留集 (RSS) 就是程序当前使用的物理内存,工作集 (WSS) 就是当前程序保持工作的内存,可以认为工作集是驻留集的子集,驻留集中的一部分内存,在内存紧张的时候可以换出到外存上面以释放内存空间。

当前没有直接测量工作集的方法,具体估计方法可以参考Brendan Gregg的博客 Working Set Size Estimation,驻留集比较容易测量,使用htop即可查看。

# htop中查看程序驻留集的大小;2021年8月29日12:22:49 

在htop之中,即可方便查看程序的驻留集,即程序占用的物理内存;

       M_SIZE (VIRT)
            The size of the virtual memory of the process.
       M_RESIDENT (RES)
            The resident set size (text + data + stack) of the process (i.e. the size of the process's used physical memory).
       M_SHARE (SHR)
            The size of the process's shared pages.
       M_TRS (CODE)
            The text resident set size of the process (i.e. the size of the process's executable instructions).
       M_DRS (DATA)
            The data resident set size (data + stack) of the process (i.e. the size of anything except the process's executable instructions).
       M_LRS (LIB)
            The library size of the process.
       M_DT (DIRTY)
            The size of the dirty pages of the process.

保持更新;cnblogs.com/xuyaowen;

 
posted @ 2019-01-19 20:49  "Michael_Xu"  阅读(3784)  评论(2编辑  收藏  举报