WSS & RSS Memory

Introduction
WSS (Working Set Size) and RSS (Resident Set Size) are distinct metrics used to measure memory usage, particularly relevant in contexts like container monitoring and performance analysis.
Resident Set Size (RSS):
- RSS represents the amount of memory a process or container is currently occupying in main memory (RAM).
- It includes both private memory (memory exclusively used by the process) and shared memory (memory shared with other processes, like shared libraries), but only the portion that is currently resident in RAM.
- RSS does not include memory that has been swapped out to disk or memory used for file caches that are not actively in use.
Working Set Size (WSS):
- WSS refers to the amount of memory actively being used by a process or container at a given time.
- It is considered a more accurate representation of the memory truly required for the application's current operations.
- WSS typically includes the RSS and the "active" portion of the file cache (page cache) that the operating system considers to be in active use by the process.
- It aims to capture the memory that, if not present in RAM, would likely lead to significant performance degradation due to page faults and disk I/O (thrashing).
Key Differences and Implications:
Inclusion of Cache:
WSS generally includes active file cache, while RSS primarily focuses on resident memory not including inactive cache.
Active Usage Focus:
WSS emphasizes the actively used memory, which is crucial for understanding an application's immediate memory demands and for capacity planning.
OOM Prevention:
When setting resource limits for containers (e.g., in Kubernetes), monitoring both RSS and WSS can help prevent Out-Of-Memory (OOM) situations, as exceeding either can lead to issues. If WSS exceeds the limit, even with low RSS, the active cache could be a factor in OOM.
Conclusion
In essence, RSS provides a measure of the physical memory allocated to a process, while WSS attempts to quantify the actively required memory footprint, offering insights into potential performance bottlenecks and resource needs.




