Project

General

Profile

Actions

Bug #1805

closed

sysctl needed for taking swap statistics

Added by Hazel over 14 years ago. Updated over 14 years ago.

Status:
Closed
Priority:
Low
Assignee:
-
Category:
-
Target version:
-
Start date:
Due date:
% Done:

0%

Estimated time:

Description

I'm developing a library and I need to take the total/free swap space from a
sysctl() call (i can use kvm but in this case my lib will need the suid bit).
This kind of call already exists on FreeBSD (vm.swap_info plus struct xswdev).
Also in Open/NetBSD.

Actions #1

Updated by dillon over 14 years ago

:New submission from Carlos Olmedo Escobar <>:
:
:I'm developing a library and I need to take the total/free swap space from a
:sysctl() call (i can use kvm but in this case my lib will need the suid bit).
:This kind of call already exists on FreeBSD (vm.swap_info plus struct xswdev).
:Also in Open/NetBSD.

We currently have (in HEAD):
vm.swap_anon_use    # of pages of anonymous memory swapped out to swap.
vm.swap_cache_use    # of pages of clean data swapped out by swapcache
(for people with SSDs).
There is no total swap sysctl but I will add one right now.  I will
call it 'vm.swap_size'. You will then be able to calculate the
amount of free swap with (vm.swap_size - vm.anon_use - vm.cache_use).
Currently the list of individual swap devices is not exported.
-Matt
Matthew Dillon
&lt;&gt;
Actions #2

Updated by Hazel over 14 years ago

Hi! Thanks for your quick answer.

The new sysctl will be useful, but i'll need to retrieve individual swap device
stats too. Are you (or anybody else) going to create this one?

In that case, can we leave this issue open until it's created?

Regards.

Actions #3

Updated by dillon over 14 years ago

:Hi! Thanks for your quick answer.
:
:The new sysctl will be useful, but i'll need to retrieve individual swap device
:stats too. Are you (or anybody else) going to create this one?
:
:In that case, can we leave this issue open until it's created?
:
:Regards.

Hmm.  We don't record individual stats at the moment, which is why
the libkvm code has to scan the blist (which is slow) to figure
it out. It would be fairly easy to add tracking for each device,
I'll see if I can work something up quickly.
-Matt
Matthew Dillon
&lt;&gt;
Actions #4

Updated by dillon over 14 years ago

::The new sysctl will be useful, but i'll need to retrieve individual swap device
::stats too. Are you (or anybody else) going to create this one?
::
::In that case, can we leave this issue open until it's created?
::
::Regards.

Ok, I took a look at FreeBSD's vm.swap_info sysctl and implemented
something similar. Ours is slightly different so I named it differently,
vm.swap_info_array. Ours takes no arguments and returns the entire
array.
I adjusted our libkvm code in the DragonFly HEAD so you can get example
usage from that (/usr/src/lib/libkvm/kvm_getswapinfo.c) if you want
to call the sysctl directly.
Or you can use the kvm_getswapinfo() call in libkvm and it will use
the new sysctl if it is available (presuming you recompile libkvm,
of course, and run a fresh kernel).
-Matt
Matthew Dillon
&lt;&gt;
Actions

Also available in: Atom PDF