summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGiampaolo Rodola <g.rodola@gmail.com>2016-09-18 17:36:25 +0200
committerGiampaolo Rodola <g.rodola@gmail.com>2016-09-18 17:36:25 +0200
commit4b4e8282ea60840f48f0fe797da76d7d5598b9da (patch)
treeac2b4101a7c31e566b301a413695832125eb2b4d
parentec6ee5560f815e4cfdcf672464d7b1851b209f59 (diff)
downloadpsutil-4b4e8282ea60840f48f0fe797da76d7d5598b9da.tar.gz
refactoring
-rw-r--r--psutil/_pslinux.py30
1 files changed, 11 insertions, 19 deletions
diff --git a/psutil/_pslinux.py b/psutil/_pslinux.py
index 7d2935a3..1a6a6ba0 100644
--- a/psutil/_pslinux.py
+++ b/psutil/_pslinux.py
@@ -314,12 +314,21 @@ def virtual_memory():
fields = line.split()
mems[fields[0]] = int(fields[1]) * 1024
- # shared
+ cached = mems[b"Cached:"]
+ # "free" cmdline utility sums cached + reclamaible:
+ # https://gitlab.com/procps-ng/procps/
+ # blob/195565746136d09333ded280cf3ba93853e855b8/proc/sysinfo.c#L761
+ # Older versions of procps added slab memory instead.
+ # This got changed in:
+ # https://gitlab.com/procps-ng/procps/commit/
+ # 05d751c4f076a2f0118b914c5e51cfbb4762ad8e
+ cached += mems.get(b"SReclaimable:", 0) # kernel 2.6.19
+
if shared == 0:
# Note: if 0 (e.g. Ubuntu 14.04, kernel 3.13) this can be
# determined from /proc/meminfo.
try:
- shared = mems['Shmem:'] # kernel 2.6.32
+ shared = mems['Shmem:'] # since kernel 2.6.32
except KeyError:
try:
shared = mems['MemShared:'] # kernels 2.4
@@ -327,29 +336,12 @@ def virtual_memory():
shared = 0
missing_fields.append('shared')
- # "free" cmdline utility sums cached + reclamaible:
- # https://gitlab.com/procps-ng/procps/
- # blob/195565746136d09333ded280cf3ba93853e855b8/proc/sysinfo.c#L761
- # Older versions of procps added slab memory instead.
- # This got changed in:
- # https://gitlab.com/procps-ng/procps/commit/
- # 05d751c4f076a2f0118b914c5e51cfbb4762ad8e
- try:
- cached = mems[b"Cached:"]
- except KeyError:
- cached = 0
- missing_fields.append('cached')
- else:
- cached += mems.get(b"SReclaimable:", 0)
-
- # active
try:
active = mems[b"Active:"]
except KeyError:
active = 0
missing_fields.append('active')
- # inactive
# https://gitlab.com/procps-ng/procps/
# blob/195565746136d09333ded280cf3ba93853e855b8/proc/sysinfo.c#L758
try: