How to estimate the amount of memory required to keep an app running, known as the 'Working Set Size (WSS)'



When selecting server memory capacity, it is easy to think that 'the more memory you have, the more comfortable it is,' but in reality, more memory than you need is a waste. Intel Fellow and computing performance expert Brendan Gregg explains how to calculate 'working set size (WSS),' the amount of memory required for an application to continue running.

Working Set Size Estimation
https://www.brendangregg.com/wss.html



To check WSS, simply check whether a swap file has been created while running the application of interest on the current system. If a swap file is always being created, it means that WSS is greater than the current memory capacity, and if no swap file is being created at all, it means that WSS is less than the current memory capacity.

You can check the status of swap file creation using the command ' vmstat ' on Linux or UNIX-based operating systems, or ' vm_stat ' on macOS.

When you run vmstat or vm_stat, the system status is output as follows. In the output, 'si' in the 'swap' column indicates the amount of memory swapped in from disk, and 'so' indicates the amount swapped out. In this example output, since no swap files have been created, you can see that 'WSS is smaller than the current memory capacity.'
[code]# vmstat
procs -----------memory---------- ---swap-- -----io---- -system-- ------cpu------
rb swpd free buff cache si so bi bo in cs us sy id wa st
0 0 0 7198308 10796 337144 0 0 2374 62 509 796 10 5 77 8 0[/code]



Clues about WSS can also be found in the performance measurement tools ' pmc-cloud-tools ' developed by Greg. For example, ' pmcarch ' included in pmc-cloud-tools can be used to check the usage rate of the CPU's LLC (L3 cache). The results of running pmcarch are displayed as shown below, with 'LLC' on the far right showing the LLC usage rate. For the workload in the table below, LLC% which is the LLC cache hit rate is nearly 100%, so the WSS of the workload can be estimated to be less than the LLC capacity.
[code]
workload_A# ./pmcarch
K_CYCLES K_INSTR IPC BR_RETIRED BR_MISPRED BMR% LLCREF LLCMISS LLC%
3062544 4218774 1.38 498585136 540218 0.11 455116420 680676 99.85
3053808 4217232 1.38 499144330 524938 0.11 454770567 667970 99.85
3132681 4259505 1.36 515882929 680336 0.13 457656727 980983 99.79
[...][/code]



Additionally, you can use ' cpucache ' included in the pmc-cloud-tools to check the usage of the L1 cache and L2 cache.
[code]
# ./cpucache
All counter columns are x 1000
CYCLES INSTR IPC L1DREF L1DMISS L1D% L2REF L2MISS L2% LLCREF LLCMISS LLC%
13652088 5959020 0.44 1552983 12993 99.16 19437 8512 56.20 10224 4306 57.88
7074768 5836783 0.83 1521268 12965 99.15 21182 10380 51.00 13081 4213 67.79
7065207 5826542 0.82 1520193 12905 99.15 19397 8612 55.60 10319 4118 60.09
[...][/code]



Greg also explains how to estimate WSS using various other methods. For Windows, you can verify WSS by referring to the following document published by Microsoft.

Reference sets for memory usage and their impact on the entire system | Microsoft Learn
https://learn.microsoft.com/ja-jp/windows-hardware/test/wpt/wpa-reference-set



in Software,   Hardware, Posted by log1o_hf