]> granicus.if.org Git - procps-ng/commitdiff
ps: Add PSS and USS fields
authorCraig Small <csmall@dropbear.xyz>
Wed, 16 Jun 2021 11:13:52 +0000 (21:13 +1000)
committerCraig Small <csmall@dropbear.xyz>
Wed, 16 Jun 2021 11:13:52 +0000 (21:13 +1000)
The library added smaps_rollup fields in the referenced commit.
This commit exploits the new fields to give pss and uss options.

These options were first proposed back in 2015 by Petr Malat
and, with the library update, they are finally made it into ps.

Why use proportional or unique segment size? It is argued that
these give a better idea of the "real" memory usage of a process.

References:
 commit 12543b6c7690c379abc28e278cd804c05490a8b1
 issue #112
 https://www.freelists.org/post/procps/PSS-and-USS-support-for-ps
 https://lwn.net/Articles/230975/

Signed-off-by: Craig Small <csmall@dropbear.xyz>
NEWS
ps/common.h
ps/global.c
ps/output.c
ps/ps.1

diff --git a/NEWS b/NEWS
index 79b80441612be620da48804a51eeb03110f6508a..80e3523ad027d55b50cd3e771528dfe1a349b21b 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -7,6 +7,7 @@ procps-ng-NEXT
   * pkill: Check for lt- variants of program name          issue #192
   * ps: Add OOM and OOMADJ fields                          issue #198
   * ps: Add IO Accounting fields                           issue #184
+  * ps: Add PSS and USS fields                             issue #112
   * slabtop: Don't combine d and o options                 issue #160
   * top: exploit some library smaps_rollup provisions      issue #112
 
index 092299ef5c7e835234b109075d76d1226d097c78..99735cd79145fd89ff26cc0f179a7173b29e45a9 100644 (file)
@@ -144,6 +144,9 @@ makEXT(SIGCATCH)
 makEXT(SIGIGNORE)
 makEXT(SIGNALS)
 makEXT(SIGPENDING)
+makEXT(SMAP_PRV_CLEAN)
+makEXT(SMAP_PRV_DIRTY)
+makEXT(SMAP_PSS)
 makEXT(STATE)
 makEXT(SUPGIDS)
 makEXT(SUPGROUPS)
index 8ce95b03fda6892fa5c94061883a55a2f511d74c..d812991b06828db2ba8d489763bc24bd9a68947d 100644 (file)
@@ -131,6 +131,9 @@ makREL(SIGCATCH)
 makREL(SIGIGNORE)
 makREL(SIGNALS)
 makREL(SIGPENDING)
+makREL(SMAP_PRV_CLEAN)
+makREL(SMAP_PRV_DIRTY)
+makREL(SMAP_PSS)
 makREL(STATE)
 makREL(SUPGIDS)
 makREL(SUPGROUPS)
index 867c9a690eeaf99186fee7ebe989f7b086a86020..350de1ae25f768db3301ce48a3e7cc12bbc9ae93 100644 (file)
@@ -1009,6 +1009,11 @@ setREL1(PROCESSOR)
   return snprintf(outbuf, COLWID, "%d", rSv(PROCESSOR, u_int, pp));
 }
 
+static int pr_pss(char *restrict const outbuf, const proc_t *restrict const pp){
+setREL1(SMAP_PSS)
+  return snprintf(outbuf, COLWID, "%lu", rSv(SMAP_PSS, ul_int, pp));
+}
+
 static int pr_numa(char *restrict const outbuf, const proc_t *restrict const pp){
 setREL1(PROCESSOR_NODE)
   return snprintf(outbuf, COLWID, "%d", rSv(PROCESSOR_NODE, s_int, pp));
@@ -1117,6 +1122,12 @@ setREL1(SIGCATCH)
   return help_pr_sig(outbuf, rSv(SIGCATCH, str, pp));
 }
 
+static int pr_uss(char *restrict const outbuf, const proc_t *restrict const pp){
+setREL2(SMAP_PRV_CLEAN, SMAP_PRV_DIRTY)
+  return snprintf(outbuf, COLWID, "%lu",
+         rSv(SMAP_PRV_CLEAN, ul_int, pp) + rSv(SMAP_PRV_DIRTY, ul_int, pp));
+}
+
 ////////////////////////////////////////////////////////////////////////////////
 
 /*
@@ -1707,6 +1718,7 @@ static const format_struct format_array[] = { /*
 {"projid",    "PROJID",  pr_nop,           PIDS_noop,                5,    SUN,  PO|RIGHT},
 {"pset",      "PSET",    pr_nop,           PIDS_noop,                4,    DEC,  TO|RIGHT},
 {"psr",       "PSR",     pr_psr,           PIDS_PROCESSOR,           3,    DEC,  TO|RIGHT},
+{"pss",       "PSS",     pr_pss,           PIDS_SMAP_PSS,            5,    XXX,  PO|RIGHT},
 {"psxpri",    "PPR",     pr_nop,           PIDS_noop,                3,    DEC,  TO|RIGHT},
 {"rbytes",    "RBYTES",  pr_rbytes,        PIDS_IO_READ_BYTES,       5,    LNX,  TO|RIGHT},
 {"rchars",    "RCHARS",  pr_rchars,        PIDS_IO_READ_CHARS,       5,    LNX,  TO|RIGHT},
@@ -1802,6 +1814,7 @@ static const format_struct format_array[] = { /*
 {"userns",    "USERNS",  pr_userns,        PIDS_NS_USER,            10,    LNX,  ET|RIGHT},
 {"usertime",  "USER",    pr_nop,           PIDS_noop,                4,    DEC,  ET|RIGHT},
 {"usrpri",    "UPR",     pr_nop,           PIDS_noop,                3,    DEC,  TO|RIGHT}, /*upr*/
+{"uss",       "USS",     pr_uss,           PIDS_SMAP_PRV_CLEAN,      5,    XXX,  PO|RIGHT},
 {"util",      "C",       pr_c,             PIDS_extra,               2,    SGI,  ET|RIGHT}, // not sure about "C"
 {"utime",     "UTIME",   pr_nop,           PIDS_TICS_USER,           6,    LNx,  ET|RIGHT},
 {"utsns",     "UTSNS",   pr_utsns,         PIDS_NS_UTS,             10,    LNX,  ET|RIGHT},
diff --git a/ps/ps.1 b/ps/ps.1
index 5c0d9d4e5141f0a5ce10713d136df8bd52671049..aa6755c2242e386a4a15307e0b8760dbcc371139 100644 (file)
--- a/ps/ps.1
+++ b/ps/ps.1
@@ -4,7 +4,7 @@
 .\" Quick hack conversion by Albert Cahalan, 1998.
 .\" Licensed under version 2 of the Gnu General Public License.
 .\"
-.TH PS "1" "2021-03-29" "procps-ng" "User Commands"
+.TH PS "1" "2021-06-16" "procps-ng" "User Commands"
 .\"
 .\" To render this page:
 .\"    groff -t -b -man -X -P-resolution -P100 -Tps ps.1 &
@@ -1524,6 +1524,11 @@ psr      PSR     T{
 processor that process last executed on.
 T}
 
+pss    PSS     T{
+Proportional share size, the non-swapped physical memory, with shared memory
+proportionally accounted to all tasks mapping it.
+T}
+
 rbytes RBYTES  T{
 Number of bytes which this process really did cause to be fetched from the storage layer.
 T}
@@ -1855,6 +1860,11 @@ See
 .IR namespaces (7).
 T}
 
+uss    USS     T{
+Unique set size, the non-swapped physical memory, which
+is not shared with an another task.
+T}
+
 utsns  UTSNS   T{
 Unique inode number describing the namespace the process belongs to.
 See