3 #if __NetBSD_Version__ > 103080000
6 #if defined(__OpenBSD__)
12 #include <sys/types.h>
13 #include <sys/sysctl.h>
15 #include <uvm/uvm_extern.h>
17 #include <vm/vm_swap.h>
20 void KCMMemory::fetchValues()
25 #if __NetBSD_Version__ > 106000000
26 struct uvmexp_sysctl uvmexp
;
31 struct swapent
*swaplist
;
32 int64_t nswap
, rnswap
, totalswap
, freeswap
, usedswap
;
34 #if __NetBSD_Version__ > 106170000 /* 1.6Q+ */
41 #if __NetBSD_Version__ > 106170000 /* 1.6Q+ */
43 mib
[1] = HW_PHYSMEM64
;
49 if( sysctl(mib
,2,&memory
,&len
,NULL
,0)< 0 )
50 memoryInfos
[TOTAL_MEM
] = NO_MEMORY_INFO
;
52 memoryInfos
[TOTAL_MEM
] = memory
;
56 #if __NetBSD_Version__ > 106000000
62 if ( sysctl(mib
, 2, &uvmexp
, &len
, NULL
, 0) < 0 ) {
63 memoryInfos
[FREE_MEM
] = NO_MEMORY_INFO
;
64 memoryInfos
[ACTIVE_MEM
] = NO_MEMORY_INFO
;
65 memoryInfos
[INACTIVE_MEM
] = NO_MEMORY_INFO
;
66 memoryInfos
[SWAP_MEM
] = NO_MEMORY_INFO
;
67 memoryInfos
[FREESWAP_MEM
] = NO_MEMORY_INFO
;
68 memoryInfos
[CACHED_MEM
] = NO_MEMORY_INFO
;
70 t_memsize pgsz
= MEMORY(uvmexp
.pagesize
);
71 memoryInfos
[FREE_MEM
] = pgsz
* uvmexp
.free
;
72 memoryInfos
[ACTIVE_MEM
] = pgsz
* uvmexp
.active
;
73 memoryInfos
[INACTIVE_MEM
] = pgsz
* uvmexp
.inactive
;
74 memoryInfos
[SWAP_MEM
] = pgsz
* uvmexp
.swpages
;
75 memoryInfos
[FREESWAP_MEM
] = pgsz
* (uvmexp
.swpages
- uvmexp
.swpginuse
);
76 #if __NetBSD_Version__ > 106000000
77 memoryInfos
[CACHED_MEM
] = pgsz
* (uvmexp
.filepages
+ uvmexp
.execpages
);
79 memoryInfos
[CACHED_MEM
] = NO_MEMORY_INFO
;
83 memoryInfos
[FREE_MEM
] = NO_MEMORY_INFO
;
84 memoryInfos
[ACTIVE_MEM
] = NO_MEMORY_INFO
;
85 memoryInfos
[INACTIVE_MEM
] = NO_MEMORY_INFO
;
88 totalswap
= freeswap
= usedswap
= 0;
89 nswap
= swapctl(SWAP_NSWAP
,0,0);
91 if ( (swaplist
= (struct swapent
*)malloc(nswap
* sizeof(*swaplist
))) ) {
92 rnswap
= swapctl(SWAP_STATS
,swaplist
,nswap
);
93 if ( rnswap
< 0 || rnswap
> nswap
)
94 totalswap
= freeswap
= -1; /* Error */
96 while ( rnswap
-- > 0 ) {
97 totalswap
+= swaplist
[rnswap
].se_nblks
;
98 usedswap
+= swaplist
[rnswap
].se_inuse
;
100 freeswap
= totalswap
- usedswap
;
103 totalswap
= freeswap
= -1; /* Error */
105 if ( totalswap
== -1 ) {
106 memoryInfos
[SWAP_MEM
] = NO_MEMORY_INFO
;
107 memoryInfos
[FREESWAP_MEM
] = NO_MEMORY_INFO
;
109 memoryInfos
[SWAP_MEM
] = MEMORY(totalswap
);
110 memoryInfos
[FREESWAP_MEM
] = MEMORY(freeswap
);