Simplify memory calculations on OpenBSD by using uvmexp.pageshift
This commit is contained in:
parent
68fd497108
commit
3f647a9b2b
@ -39,13 +39,6 @@
|
|||||||
#include "memory.h"
|
#include "memory.h"
|
||||||
#include "conversions.h"
|
#include "conversions.h"
|
||||||
|
|
||||||
static int pageshift;
|
|
||||||
|
|
||||||
#ifndef LOG1024
|
|
||||||
#define LOG1024 10
|
|
||||||
#endif
|
|
||||||
#define pagesh(size) ((size) << pageshift)
|
|
||||||
|
|
||||||
void mem_status( MemoryStatus & status )
|
void mem_status( MemoryStatus & status )
|
||||||
{
|
{
|
||||||
// These values are in bytes
|
// These values are in bytes
|
||||||
@ -63,16 +56,6 @@ void mem_status( MemoryStatus & status )
|
|||||||
error( "memory: error getting page size" );
|
error( "memory: error getting page size" );
|
||||||
}
|
}
|
||||||
|
|
||||||
// calculate how far we must shift the variables
|
|
||||||
pageshift = 0;
|
|
||||||
while( page_size > 1 )
|
|
||||||
{
|
|
||||||
pageshift++;
|
|
||||||
page_size >>= 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
pageshift -= LOG1024;
|
|
||||||
|
|
||||||
// get vm memory stats
|
// get vm memory stats
|
||||||
static int uvmexp_mib[] = { CTL_VM, VM_UVMEXP };
|
static int uvmexp_mib[] = { CTL_VM, VM_UVMEXP };
|
||||||
struct uvmexp uvmexp;
|
struct uvmexp uvmexp;
|
||||||
@ -92,16 +75,15 @@ void mem_status( MemoryStatus & status )
|
|||||||
}
|
}
|
||||||
|
|
||||||
// calculations based on libgtop
|
// calculations based on libgtop
|
||||||
used_mem = (uint64_t) pagesh (uvmexp.npages - uvmexp.free) << LOG1024;
|
used_mem = ( (uint64_t) uvmexp.npages - uvmexp.free ) << uvmexp.pageshift;
|
||||||
|
free_mem = ( (uint64_t) uvmexp.free ) << uvmexp.pageshift;
|
||||||
free_mem = (uint64_t) pagesh( uvmexp.free ) << LOG1024;
|
|
||||||
|
|
||||||
// from nagios-memory plugin
|
// from nagios-memory plugin
|
||||||
used_mem -= pagesh( bcstats.numbufpages );
|
used_mem -= ( (uint64_t) bcstats.numbufpages ) << uvmexp.pageshift;
|
||||||
free_mem += pagesh( bcstats.numbufpages );
|
free_mem += ( (uint64_t) bcstats.numbufpages ) << uvmexp.pageshift;
|
||||||
|
|
||||||
// calculate total memory
|
// calculate total memory
|
||||||
total_mem = (uint64_t) pagesh( uvmexp.npages ) << LOG1024;
|
total_mem = ( (uint64_t) uvmexp.npages ) << uvmexp.pageshift;
|
||||||
|
|
||||||
status.used_mem = convert_unit(static_cast< float >( used_mem ), MEGABYTES );
|
status.used_mem = convert_unit(static_cast< float >( used_mem ), MEGABYTES );
|
||||||
status.total_mem = convert_unit(static_cast< float >( total_mem ), MEGABYTES );
|
status.total_mem = convert_unit(static_cast< float >( total_mem ), MEGABYTES );
|
||||||
|
Loading…
Reference in New Issue
Block a user