1 |
tdb |
1.2 |
VM Statistics |
2 |
|
|
============= |
3 |
|
|
|
4 |
|
|
$Id$ |
5 |
|
|
|
6 |
|
|
Data Structures |
7 |
|
|
--------------- |
8 |
|
|
|
9 |
|
|
These two structures can be returned by the VM system calls: |
10 |
pajs |
1.1 |
|
11 |
|
|
typedef struct{ |
12 |
|
|
long long total; |
13 |
|
|
long long free; |
14 |
|
|
long long used; |
15 |
|
|
long long cache; |
16 |
|
|
}mem_stat_t; |
17 |
|
|
|
18 |
tdb |
1.2 |
total contains the total memory in bytes. |
19 |
|
|
free is the total free memory in bytes. |
20 |
|
|
used is the total used memory in bytes. |
21 |
|
|
cache is the cache used in bytes. |
22 |
pajs |
1.1 |
|
23 |
tdb |
1.2 |
nb: Cache is not available on all operating systems (for example, |
24 |
|
|
Solaris). Free memory and cache memory can sometimes be linked. |
25 |
pajs |
1.1 |
|
26 |
|
|
typedef struct{ |
27 |
|
|
long long total; |
28 |
|
|
long long used; |
29 |
|
|
long long free; |
30 |
|
|
}swap_stat_t; |
31 |
|
|
|
32 |
tdb |
1.2 |
total contains the total swap space in bytes. |
33 |
|
|
used is the used swap in bytes. |
34 |
|
|
free is the free swap in bytes. |
35 |
|
|
|
36 |
|
|
Functions |
37 |
|
|
--------- |
38 |
|
|
|
39 |
|
|
mem_stat_t *get_memory_stats(); |
40 |
|
|
|
41 |
|
|
swap_stat_t *get_swap_stats(); |
42 |
|
|
|
43 |
|
|
Memory statistics are accessed through the first call. It returns |
44 |
|
|
a pointer to a static mem_stat_t. |
45 |
|
|
|
46 |
|
|
The second call returns swap statistics. It returns a pointer to |
47 |
|
|
a static swap_stat_t. |
48 |
|
|
|
49 |
|
|
On the FreeBSD operating system elevated privileges are required |
50 |
|
|
to access the swap statistics. Making the program setgid kmem should |
51 |
|
|
be sufficient. Programs running as root will not have this problem. |
52 |
|
|
|
53 |
|
|
Todo |
54 |
|
|
---- |
55 |
|
|
|
56 |
|
|
Add a function to hold open the file descriptor to the kernel memory |
57 |
|
|
structures. Doing this would allow the elevated privileges to be |
58 |
|
|
dropped early on. |
59 |
pajs |
1.1 |
|
60 |
tdb |
1.2 |
Example |
61 |
|
|
------- |
62 |
pajs |
1.1 |
|
63 |
tdb |
1.2 |
An example can be found in examples/vm_stats. |