Skip to content
This repository has been archived by the owner. It is now read-only.
Permalink
Browse files

sunos: look up free memory with sysconf(_SC_AVPHYS_PAGES)

  • Loading branch information...
bnoordhuis committed Oct 12, 2011
1 parent 7b01ad1 commit e0a4e726407a2baee6aecbfa6157e4a2f8c6fc4c
Showing with 6 additions and 21 deletions.
  1. +3 −21 src/unix/sunos.c
  2. +3 −0 test/test-get-memory.c
@@ -65,35 +65,17 @@ int uv_exepath(char* buffer, size_t* size) {
return (0);
}

double uv_get_free_memory(void) {
kstat_ctl_t *kc;
kstat_t *ksp;
kstat_named_t *knp;

ulong_t freemem;

if ((kc = kstat_open()) == NULL) return -1;

ksp = kstat_lookup(kc, (char *)"unix", 0, (char *)"system_pages");

if(kstat_read(kc, ksp, NULL) == -1){
return -1;
}
else {
knp = (kstat_named_t *) kstat_data_lookup(ksp, (char *)"freemem");
freemem = knp->value.ul;
}

kstat_close(kc);

return (double) freemem * sysconf(_SC_PAGESIZE);
double uv_get_free_memory(void) {
return (double) sysconf(_SC_PAGESIZE) * sysconf(_SC_AVPHYS_PAGES);
}


double uv_get_total_memory(void) {
return (double) sysconf(_SC_PAGESIZE) * sysconf(_SC_PHYS_PAGES);
}


void uv_loadavg(double avg[3]) {
(void) getloadavg(avg, 3);
}
@@ -26,8 +26,11 @@ TEST_IMPL(get_memory) {
double free_mem = uv_get_free_memory();
double total_mem = uv_get_total_memory();

printf("free_mem=%.0f, total_mem=%.0f\n", free_mem, total_mem);

ASSERT(free_mem > 0);
ASSERT(total_mem > 0);
ASSERT(total_mem > free_mem);

return 0;
}

0 comments on commit e0a4e72

Please sign in to comment.
You can’t perform that action at this time.