Search

A technology, a device or an article

Who owns the shared megabytes: calculating PSS in Linux

PSS distributes shared-page costs. A worked example shows a share growing without allocation and physical usage growing while RSS stays unchanged.

A terracotta disk with radial seams surrounded by separate blue bowls
ITNWS AI-generated conceptual illustration. The common disk evokes shared memory cost; its segments do not encode the worked example’s shares.ITNWS · image_gen · Original ITNWS AI-generated conceptual editorial illustration

In a hypothetical system, process A uses 120 MiB of its own resident pages, process B uses 80 MiB. Another 60 MiB of physical pages are simultaneously mapped to both processes. The example has no other mappings of these pages. All considered pages are ordinary and resident, and no page is mapped twice within one process. Then the RSS of process A is 180 MiB, the RSS of process B is 140 MiB. Addition gives 320 MiB, although the physical data in question takes up 260 MiB. The contradiction only appears when trying to read the sum of the two representations as the size of a single physical set.

PSS, proportional set size, distributes the total volume between participants. Under given conditions, everyone will get half of the total 60 MiB. Therefore, PSS A will be 150 MiB, PSS B will be 110 MiB, and the total will be the same 260 MiB. This is a calculation based on hypothetical values, and not a measurement of the ITNWS server. It is useful because it immediately separates the cost of sharing from the way it is assigned to processes. Linux proc documentation, reviewed October 31, 2026, describes proportional accounting and the significant limitations of its interpretation.

One physical set, different amounts

Process Own pages Shared pages in RSS Shared-page contribution to PSS RSS PSS
A 120 MiB 60 MiB 30 MiB 180 MiB 150 MiB
B 80 MiB 60 MiB 30 MiB 140 MiB 110 MiB
Total 200 MiB 120 MiB 60 MiB 320 MiB 260 MiB

For each ordinary shared physical fragment, the idea is simple: its contribution is distributed among the corresponding mappings. In our example, the number of mappings coincides with the number of processes, so it is convenient to talk about half per participant. In a real system, the repeated mapping of the same page within the same process and the peculiarities of large pages make the common "divide by the number of PIDs" an insufficient description of the implementation. The documentation directly specifies accounting options. The table deliberately excludes these circumstances in order to verify the arithmetic of the main case, and not to pass it off as a universal snapshot of any kernel.

RSS answers its own useful question: how much resident memory is associated with a given process’s mappings. The shared page is indeed accessible to both A and B. Writing it on both lines does not mean making a mistake. It is a mistake to forget later that the lines intersect. PSS chooses a different aggregation method, distributing the cost instead of repeating the entire total volume. There is no competition between indicators for the title of the only correct memory measure. There are questions about the resident set of a process and the allocated share of a physical resource, which require different numbers.

“Own pages” in the table means pages not shared with another mapping in this model. This is not an exact renaming of the MAP_PRIVATE flag. In such a mapping, the file page can be physically shared with other processes before being written. Conversely, a particular page of an object that allows shared mapping may currently have a single contributor. The smaps manual helps distinguish the properties of a virtual region from the observed physical sharing. The mapping mode communicates the access rules, but does not exhaust the current physical cost of the pages.

Therefore, identical data by itself also does not guarantee a common physical page. If two processes separately allocated memory and wrote the same bytes, normal accounting is not required to automatically count it as one object. Physical unification requires appropriate mechanisms and conditions. PSS describes existing sharing, not the potential savings after content comparison. Otherwise, the indicator would have to be calculated as a search for ideal deduplication of the entire system. This meaning does not follow either from the name or from the algorithm for the proportional distribution of resident pages.

Neighbor left, share increased

Now B terminates. Suppose its own 80 MiB are freed, and all 60 MiB of the common set remain resident and mapped to A. A’s own set does not change: the same 120 MiB. RSS A is still 180 MiB. But there is no one to share common pages with, so PSS A becomes 180 MiB instead of 150 MiB. The growth is 30 MiB without allocating A new physical pages. The application might not have written anything or even done any useful work at the time of the change.

At the same time, the physical volume of the data under consideration drops from 260 to 180 MiB. The result is a strange combination at first glance: the system uses less memory, and the PSS of the remaining process increases. This is an expected consequence of the distribution of total cost. The indicator varies depending on the composition of participants, and not just on the actions of the observed program. To declare any such growth a leak is to attribute a mechanism to the process that the measurement did not establish. To find a leak, you need a connection with live allocations and the lifetime of objects, and not one direction of a proportional curve.

To examine the reverse change, restore A and B to their initial state. A third process C joins the existing 60 MiB without creating a physical copy of them. With one mapping per participant, A and B’s share of the total set is reduced to 20 MiB. If the private sets are unchanged, their PSS drops by 10 MiB each, although nothing from this shared set has disappeared from physical memory. The new neighbor received part of the distributed value. A single monitoring line is therefore able to show an improvement that, at the level of the entire machine, is not the freeing of the corresponding pages.

When aggregating a group, you have to select a boundary. If A and B are included in the report, but C is outside of it, the sum of their PSS no longer contains the full cost of the pages shared with C. It honestly contains the shares of the selected participants. The RSS sum, on the contrary, can repeat the general set within the group. No mechanical summation automatically assigns the correct volume to a service. It is necessary to determine whether the resource that disappears when the service stops is considered, the current allocated share, or all resident mappings of its processes. These are different counterfactual and accounting issues.

Translucent sheets with rectangular windows over one dark ink stain
ITNWS AI-generated conceptual illustration. Several windows expose one underlying mark: a shared-page metaphor, not RAM construction. — ITNWS · image_gen · Original ITNWS AI-generated conceptual editorial illustration

The copy changes the physical task

Let’s return A and B to their original state. Let A write 12 MiB from the common set under copy-on-write conditions, obtaining separate private pages, and B continues to use the original ones. The remaining 48 MiB remain shared. A now has 132 MiB of its own and 48 MiB of shared pages; B has 92 MiB of its own and the same 48 MiB of shared ones. Volume 92 includes the previous 80 and 12 MiB, which after the separation of A remained to the only B. This is a description of the state after the copy has been performed, without a statement about the instantaneous atomicity of the observation.

Under these conditions, RSS A is still 180 MiB, RSS B is 140 MiB. But PSS A becomes 156 MiB, PSS B becomes 116 MiB. Their total is 272 MiB: the physical set has increased by 12 MiB due to new copies. The two unchanged RSSs masked the actual increase in total expenditure. Proportional accounting helps to express it if all participants are taken into account at the same time. This is not a promise to detect any leak: the specific pages, operation and composition of the system are known here, and in a live application these circumstances have yet to be established.

The example explains why the same total virtual size does not mean the same physical cost after a write. The virtual areas may have remained the same, but the overall physical basis has changed. But from this you cannot automatically deduce how much RAM will be freed when A completes. Some pages will remain mapped by B, some may be stored in the file cache, and there are other users of the resource outside the selected set. PSS distributes the current state according to a specific rule. It does not perform the thought experiment of killing a process along with all the consequences for the kernel.

The values Shared_Clean, Shared_Dirty, Private_Clean and Private_Dirty add a characteristic of page cleanliness. They help explain the origins of the accounting, but are not a ready-made description of the release delay. The word dirty is associated with change relative to the corresponding basis and consideration of the kernel, and not with the human quality of the data. To decide on reclaim, additional conditions are required. Turning one smaps field into a promise of "this can be returned to the system immediately" is out of bounds. A useful analysis is keeping field names close to their definitions, especially when several columns appear similar.

Where the ledger ends

The smaps file gives details by area of the process, and smaps_rollup allows you to read aggregated fields at a lower cost than doing a complete parsing of all areas yourself. The detail is not free: the kernel has to examine the mappings. Therefore, collection frequency becomes part of the monitoring system. For routine service evaluation, seconds and milliseconds have different values, and redundant polling does not make the state immutable. The report must save the moment of reading and the selected interface. You cannot combine rows from different minutes and call them a single physical snapshot.

While reading, processes can map and unmap pages, terminate, or spawn neighbors. The proc documentation warns about maps and smaps read races. Even careful reading of one process does not turn a sequential traversal of hundreds of PIDs into an atomic snapshot of the entire machine. Therefore, a small discrepancy between the calculated amount and another system metric may reflect the observation time. This is not a reason to reject all accounting; this is the basis for specifying its resolution and comparing comparable windows. The more dynamic the service, the more important this caveat is for interpreting short bursts.

There are also differences in interfaces. Proc PID status manual warns that some quick estimates of resident memory are inaccurate. Therefore, a familiar process column in one program does not have to literally coincide with a detailed smaps crawl in another second. Before constructing an explanation for the discrepancy, it is useful to establish where each number comes from. RSS or memory names in the interface do not replace the source indication. The comparison must consider definition, update method, and timing, not just identical MiB units.

Large pages add implementation features. In some configurations, the kernel uses an approximation of the number of mappings for parts of a large allocation, so PSS may not be accurate. In addition, hugetlb accounting has historically been placed in its own fields and should not be silently lost during summation. This is not a reason to turn the article into a catalog of all memory modes. It is enough to maintain an essential boundary: the exact calculation of our table refers to explicitly selected ordinary pages, and the observation of a real service requires reading the documentation of its kernel and the composition of the mappings.

Retaining a virtual address does not put an evicted page back into resident RAM. There are separate fields for swap, including SwapPss with its own accounting area. It is permissible to add them to PSS only after explaining the new indicator: the amount no longer means only the current share of resident pages. Likewise, the amount of physical memory on a machine includes kernel resources and other objects that the user PSS list does not fully list. The balance from our small model should not be spread over the entire installed DIMM capacity without accounting for the missing cost categories.

For the container limit, another agreement is needed. Cgroup v2 documentation describes its own memory.current accounting and expense allocation rules. They are not defined as a simple sum of the PSS values of the container’s processes. Accounted memory includes pages and expenses with a different calculation method. Therefore, replacing the limit indicator with a proportional amount can give an incorrect margin to the limit. Process accounting and constraint accounting have different tasks; the similar word memory does not make them interchangeable or assign one metric power over another.

The original table retained a useful rigor: 60 MiB was counted physically once and distributed among those who used it. As soon as the neighbor left, the shares changed without new work by A. As soon as a copy appeared, the physical set grew without changing the RSS of both participants. For RAM this is a good way to separate the presence of a resource from its attribution. The choice between RSS, PSS and system accounting begins with the issue of responsibility. It is the question that determines the useful amount, and not the number of columns that were beautifully added.

Sources & documentation

  1. Linux proc filesystem documentation ↗
  2. Linux proc PID smaps manual ↗
  3. Linux proc PID status manual ↗
  4. Linux memory cgroup v2 documentation ↗