diff options
author | Giampaolo Rodola <g.rodola@gmail.com> | 2016-09-18 16:55:51 +0200 |
---|---|---|
committer | Giampaolo Rodola <g.rodola@gmail.com> | 2016-09-18 16:55:51 +0200 |
commit | a956b5fe2aa270b48ae04c41e7b105205488ef5b (patch) | |
tree | 8128e905aa39325270d2c7df33eb3308a57d6c61 | |
parent | 1ad19c4e969a40580215f5923139c9dadc73c25a (diff) | |
download | psutil-a956b5fe2aa270b48ae04c41e7b105205488ef5b.tar.gz |
#887 correctly calculate shared mem
-rw-r--r-- | psutil/_pslinux.py | 17 |
1 files 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 |