From a956b5fe2aa270b48ae04c41e7b105205488ef5b Mon Sep 17 00:00:00 2001 From: Giampaolo Rodola Date: Sun, 18 Sep 2016 16:55:51 +0200 Subject: #887 correctly calculate shared mem --- psutil/_pslinux.py | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/psutil/_pslinux.py b/psutil/_pslinux.py index bf8f6baf..8208f75a 100644 --- a/psutil/_pslinux.py +++ b/psutil/_pslinux.py @@ -306,9 +306,7 @@ def virtual_memory(): buffers *= unit_multiplier # Note: this (on my Ubuntu 14.04, kernel 3.13 at least) may be 0. # If so, it will be determined from /proc/meminfo. - shared *= unit_multiplier or None - if shared == 0: - shared = None + shared *= unit_multiplier mems = {} with open_binary('%s/meminfo' % get_procfs_path()) as f: @@ -316,6 +314,19 @@ def virtual_memory(): fields = line.split() mems[fields[0]] = int(fields[1]) * 1024 + # shared + if shared == 0: + # Note: if 0 (e.g. my Ubuntu 14.04, kernel 3.13 at least) + # this can be determined from /proc/meminfo. + try: + shared = mems['Shmem:'] # kernel 2.6.32 + except KeyError: + try: + shared = mems['MemShared:'] # kernels 2.4 + except KeyError: + shared = 0 + missing_fields.append('shared') + # "free" cmdline utility sums cached + reclamaible: # https://gitlab.com/procps-ng/procps/ # blob/195565746136d09333ded280cf3ba93853e855b8/proc/sysinfo.c#L761 -- cgit v1.2.1