| 1 |
< |
Memory stats are accessed through get_memory_stats() call. This |
| 2 |
< |
returns a pointer to a static mem_stat_t |
| 1 |
> |
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 |
+ |
|
| 11 |
|
typedef struct{ |
| 12 |
|
long long total; |
| 13 |
|
long long free; |
| 15 |
|
long long cache; |
| 16 |
|
}mem_stat_t; |
| 17 |
|
|
| 18 |
< |
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. |
| 18 |
> |
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 |
|
|
| 23 |
< |
cache is not available in all operating systems. Solaris being a key |
| 24 |
< |
one that it isn't. free memory and cache memory can sometimes be |
| 18 |
< |
linked. |
| 23 |
> |
nb: Cache is not available on all operating systems (for example, |
| 24 |
> |
Solaris). Free memory and cache memory can sometimes be linked. |
| 25 |
|
|
| 20 |
– |
Swap stats are accessed through get_swap_stats() call. This returns a |
| 21 |
– |
pointer to a static swap_stat_t |
| 22 |
– |
|
| 26 |
|
typedef struct{ |
| 27 |
|
long long total; |
| 28 |
|
long long used; |
| 29 |
|
long long free; |
| 30 |
|
}swap_stat_t; |
| 31 |
|
|
| 32 |
+ |
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 |
< |
Freebsd requires kmem privilages to be able to do this call. Making the |
| 37 |
< |
program setgid kmem should be sufficent. |
| 36 |
> |
Functions |
| 37 |
> |
--------- |
| 38 |
|
|
| 39 |
< |
TODO |
| 40 |
< |
Add a function to hold open the FD to kmem privilages could be dropped. |
| 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 |
> |
|
| 60 |
> |
Example |
| 61 |
> |
------- |
| 62 |
> |
|
| 63 |
> |
An example can be found in examples/vm_stats. |