0

I've been able to calculate unshared memory use by summing anonymous and stack mappings from pmap -x e.g.

sudo pmap -x $THE_PID |egrep 'anon|stack' | awk '{print $2}' | paste -sd+ | bc

but can't find any way to get similar info from ps at all. top shows a SHR column, but doesn't appear to offer a way to sort by UNshared memory. Sorting by RSS isn't useful since RSS contains shared pages but only AFAICS those shared pages the process has touched.

So if you have two processes, both using the same 16GB shared address space, they'll sort based on which has touched more of the shared memory. Not by which has allocated more private (unshared) memory, unless both have touched the same amount of shmem or close to it.

Similar issues arise with read/write mappings of shared libraries, and with forked-but-not-exec'd processes that share copy-on-write pages from their ancestor.

This is ... unhelpful.

I've looked into ways to sort top output by expressions. But if it supports it in its sort syntax I can't figure it out.

This seems like such an obvious thing, but ps doesn't even expose shared info at all!

Please tell me I'm missing something.

Craig Ringer
  • 11,083
  • 9
  • 40
  • 61
  • May be `sort` command will help you. To sort by the second column use `sort -k2 -n`. – Mikhail Khirgiy Feb 20 '18 at 15:32
  • @MikhailKhirgiy `ps` has no way to show shared pages at all. And `top` can already sort by RSS or SHR, but not as far as I can see by an *expression* like `RSS - SHR`. – Craig Ringer Feb 22 '18 at 05:41
  • @MikhailKhirgiy However, I could probably use `top` in report mode, postprocess it with `awk` to compute the sort expression as an extra column, and `sort` that... Ugh :( – Craig Ringer Feb 22 '18 at 05:42

0 Answers0