Skip to content

Commit

Permalink
#714: [OpenBSD] return virtual cached memory
Browse files Browse the repository at this point in the history
  • Loading branch information
giampaolo committed Nov 25, 2015
1 parent 1c20a66 commit 8485b4e
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 13 deletions.
8 changes: 8 additions & 0 deletions HISTORY.rst
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
Bug tracker at https://github.com/giampaolo/psutil/issues

3.3.1 - XXXX-XX-XX
==================

**Bug fixes**

- #714: [OpenBSD] virtual_memory().cached value was always set to 0.


3.3.0 - 2015-11-25
==================

Expand Down
2 changes: 1 addition & 1 deletion psutil/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@
]
__all__.extend(_psplatform.__extra__all__)
__author__ = "Giampaolo Rodola'"
__version__ = "3.3.0"
__version__ = "3.3.1"
version_info = tuple([int(num) for num in __version__.split('.')])
AF_LINK = _psplatform.AF_LINK
_TOTAL_PHYMEM = None
Expand Down
33 changes: 21 additions & 12 deletions psutil/arch/bsd/openbsd.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include <sys/sysctl.h>
#include <sys/user.h>
#include <sys/proc.h>
#include <sys/mount.h> // for VFS_*
#include <sys/swap.h> // for swap_mem
#include <signal.h>
#include <kvm.h>
Expand Down Expand Up @@ -321,25 +322,33 @@ psutil_proc_threads(PyObject *self, PyObject *args) {

PyObject *
psutil_virtual_mem(PyObject *self, PyObject *args) {
unsigned int total;
size_t size = sizeof(total);
struct uvmexp uvmexp;
int mib[] = {CTL_VM, VM_UVMEXP};
long pagesize = getpagesize();
int uvmexp_mib[] = {CTL_VM, VM_UVMEXP};
int bcstats_mib[] = {CTL_VFS, VFS_GENERIC, VFS_BCACHESTAT};
size_t size;
struct uvmexp uvmexp;
struct bcachestats bcstats;
long pagesize = getpagesize();

size = sizeof(uvmexp);
if (sysctl(uvmexp_mib, 2, &uvmexp, &size, NULL, 0) < 0) {
PyErr_SetFromErrno(PyExc_OSError);
return NULL;
}

if (sysctl(mib, 2, &uvmexp, &size, NULL, 0) < 0) {
warn("failed to get vm.uvmexp");
// This is how "top" calculates cached memory.
size = sizeof(bcstats);
if (sysctl(bcstats_mib, 3, &bcstats, &size, NULL, 0) < 0) {
PyErr_SetFromErrno(PyExc_OSError);
return NULL;
}

return Py_BuildValue("KKKKKKKK",
(unsigned long long) uvmexp.npages * pagesize,
(unsigned long long) uvmexp.free * pagesize,
(unsigned long long) uvmexp.active * pagesize,
(unsigned long long) uvmexp.npages * pagesize,
(unsigned long long) uvmexp.free * pagesize,
(unsigned long long) uvmexp.active * pagesize,
(unsigned long long) uvmexp.inactive * pagesize,
(unsigned long long) uvmexp.wired * pagesize,
(unsigned long long) 0, // cached
(unsigned long long) uvmexp.wired * pagesize,
(unsigned long long) bcstats.numbufpages * pagesize, // cached
(unsigned long long) 0, // buffers
(unsigned long long) 0 // shared
);
Expand Down

0 comments on commit 8485b4e

Please sign in to comment.