4 * Torsten Kasch <tk@Genetik.Uni-Bielefeld.DE>
11 /* Stop <sys/swap.h> from crapping out on 32-bit architectures. */
13 #if !defined(_LP64) && _FILE_OFFSET_BITS == 64
14 # undef _FILE_OFFSET_BITS
15 # define _FILE_OFFSET_BITS 32
22 #define PAGETOK(a) (( (t_memsize) sysconf( _SC_PAGESIZE )) * (t_memsize) a)
24 void KCMMemory::fetchValues() {
31 * get a kstat handle first and update the user's kstat chain
33 if( (kctl
= kstat_open()) == NULL
)
35 while( kstat_chain_update( kctl
) != 0 )
39 * traverse the kstat chain to find the appropriate kstat
41 if( (ksp
= kstat_lookup( kctl
, "unix", 0, "system_pages" )) == NULL
)
44 if( kstat_read( kctl
, ksp
, NULL
) == -1 )
51 kdata
= (kstat_named_t
*) kstat_data_lookup( ksp
, "physmem" );
53 memoryInfos
[TOTAL_MEM
] = PAGETOK(kdata
->value
.ui32
);
56 memoryInfos
[TOTAL_MEM
] = PAGETOK(sysconf(_SC_PHYS_PAGES
));
58 kdata
= (kstat_named_t
*) kstat_data_lookup( ksp
, "freemem" );
60 memoryInfos
[FREE_MEM
] = PAGETOK(kdata
->value
.ui32
);
62 #warning "FIXME: memoryInfos[CACHED_MEM]"
64 memoryInfos
[CACHED_MEM
] = NO_MEMORY_INFO
; // cached memory in ram
72 struct anoninfo am_swap
;
77 swaptotal
= swapused
= swapfree
= 0L;
80 * Retrieve overall swap information from anonymous memory structure -
81 * which is the same way "swap -s" retrieves it's statistics.
83 * swapctl(SC_LIST, void *arg) does not return what we are looking for.
86 if (swapctl(SC_AINFO
, &am_swap
) == -1)
89 swaptotal
= am_swap
.ani_max
;
90 swapused
= am_swap
.ani_resv
;
91 swapfree
= swaptotal
- swapused
;
93 memoryInfos
[SWAP_MEM
] = PAGETOK(swaptotal
);
94 memoryInfos
[FREESWAP_MEM
] = PAGETOK(swapfree
);