Skip to content

Commit

Permalink
#887 correctly calculate shared mem
Browse files Browse the repository at this point in the history
  • Loading branch information
giampaolo committed Sep 18, 2016
1 parent 1ad19c4 commit a956b5f
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions psutil/_pslinux.py
Original file line number Diff line number Diff line change
Expand Up @@ -306,16 +306,27 @@ 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:
for line in f:
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
Expand Down

0 comments on commit a956b5f

Please sign in to comment.