summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGiampaolo Rodola <g.rodola@gmail.com>2016-10-17 19:42:58 +0200
committerGiampaolo Rodola <g.rodola@gmail.com>2016-10-17 19:42:58 +0200
commitc4d29a41cc075a2cbef9ac634989fd757ac188dd (patch)
treebdf298249d29199df4330ddc62714fe6d148443b
parentc01de936695e2c14c43cb7282748aaa289babf42 (diff)
downloadpsutil-c4d29a41cc075a2cbef9ac634989fd757ac188dd.tar.gz
fix #923: [OSX] free memory is wrong (does not match vm_stat command).
-rw-r--r--HISTORY.rst1
-rw-r--r--psutil/_psutil_osx.c8
-rwxr-xr-xpsutil/tests/test_osx.py3
3 files changed, 7 insertions, 5 deletions
diff --git a/HISTORY.rst b/HISTORY.rst
index 59cae040..f3e31a1c 100644
--- a/HISTORY.rst
+++ b/HISTORY.rst
@@ -39,6 +39,7 @@ Bug tracker at https://github.com/giampaolo/psutil/issues
- #918: [NetBSD] all memory metrics were wrong.
- #921: psutil.Popen now defines a __del__ special method which calls the
original one, hopefully helping the gc to free resources.
+- #923: [OSX] free memory is wrong (does not match vm_stat command).
4.3.1 - 2016-09-01
diff --git a/psutil/_psutil_osx.c b/psutil/_psutil_osx.c
index d1640714..672ec346 100644
--- a/psutil/_psutil_osx.c
+++ b/psutil/_psutil_osx.c
@@ -697,7 +697,10 @@ psutil_proc_num_ctx_switches(PyObject *self, PyObject *args) {
/*
- * Return system virtual memory stats
+ * Return system virtual memory stats.
+ * See:
+ * http://opensource.apple.com/source/system_cmds/system_cmds-498.2/
+ * vm_stat.tproj/vm_stat.c
*/
static PyObject *
psutil_virtual_mem(PyObject *self, PyObject *args) {
@@ -730,7 +733,8 @@ psutil_virtual_mem(PyObject *self, PyObject *args) {
(unsigned long long) vm.active_count * pagesize,
(unsigned long long) vm.inactive_count * pagesize,
(unsigned long long) vm.wire_count * pagesize,
- (unsigned long long) vm.free_count * pagesize
+ // this is how vm_stat cmd does it
+ (unsigned long long) (vm.free_count - vm.speculative_count) * pagesize
);
}
diff --git a/psutil/tests/test_osx.py b/psutil/tests/test_osx.py
index dc9676ba..8221dcae 100755
--- a/psutil/tests/test_osx.py
+++ b/psutil/tests/test_osx.py
@@ -21,7 +21,6 @@ from psutil.tests import reap_children
from psutil.tests import retry_before_failing
from psutil.tests import run_test_module_by_name
from psutil.tests import sh
-from psutil.tests import TRAVIS
from psutil.tests import unittest
@@ -153,8 +152,6 @@ class TestSystemAPIs(unittest.TestCase):
sysctl_hwphymem = sysctl('sysctl hw.memsize')
self.assertEqual(sysctl_hwphymem, psutil.virtual_memory().total)
- # XXX
- @unittest.skipIf(TRAVIS, "")
@retry_before_failing()
def test_vmem_free(self):
vmstat_val = vm_stat("free")