/** * @file * @brief * Buffer Ram * * @details * This function looks up the amount of ram allocated for buffers in bytes. * * @param totalram * Output, passed by reference. On successful return, the value * is set to the amount of ram used for buffers (in bytes) available on the system. * * @return * The return value indicates the status of the function. */ int meminfo_bufferram(memsize_t *bufferram) { int ret = MEMINFO_OK; *bufferram = 0L; #if OS_LINUX struct sysinfo info; int test = sysinfo(&info); chkret(test, FAILURE); *bufferram = info.bufferram * info.mem_unit; #elif OS_FREEBSD memsize_t v = 0L; int test = sysctl_val("vfs.bufspace", &v); chkret(test, FAILURE); *bufferram = v; #else ret = PLATFORM_ERROR; #endif return ret; }
/** * @file * @brief * Cached Ram * * @details * This function looks up the amount of ram used for cache in bytes. * * @param totalram * Output, passed by reference. On successful return, the value * is set to the amount of ram used for disk cache (in bytes) available on the system. * * @return * The return value indicates the status of the function. */ int meminfo_cachedram(memsize_t *cachedram) { int ret = MEMINFO_OK; *cachedram = 0L; #if OS_LINUX int test = read_proc_file("/proc/meminfo", cachedram, "Cached:", 7); chkret(test, FAILURE); *cachedram *= 1024L; #elif OS_FREEBSD int page; memsize_t v = 0; page = sysconf(_SC_PAGESIZE); if (page == -1) return FAILURE; int test = sysctl_val("vm.stats.vm.v_cache_count", &v); chkret(test, FAILURE); *cachedram = (memsize_t) v*page; #else ret = PLATFORM_ERROR; #endif return ret; }
/** * @file * @brief * Total Ram * * @details * This function looks up the total ram in bytes. * * @param totalram * Output, passed by reference. On successful return, the value * is set to the total ram (in bytes) available on the system. * * @return * The return value indicates the status of the function. */ int meminfo_totalram(memsize_t *totalram) { int ret = MEMINFO_OK; *totalram = 0L; #if OS_LINUX struct sysinfo info; int test = sysinfo(&info); chkret(test, FAILURE); *totalram = (memsize_t) info.totalram * info.mem_unit; #elif OS_MAC int test = sysctl_val("hw.memsize", totalram); chkret(test, FAILURE); #elif OS_WINDOWS MEMORYSTATUSEX status; status.dwLength = sizeof(status); int test = GlobalMemoryStatusEx(&status); winchkret(test, FAILURE); *totalram = (memsize_t) status.ullTotalPhys; #elif OS_FREEBSD int test = sysctl_val("hw.physmem", totalram); chkret(test, FAILURE); #elif OS_NIX memsize_t npages, pagesize; npages = sysconf(_SC_PHYS_PAGES); if (npages == FAILURE) return FAILURE; pagesize = sysconf(_SC_PAGESIZE); if (pagesize == FAILURE) return FAILURE; *totalram = (memsize_t) npages * pagesize; #else ret = PLATFORM_ERROR; #endif return ret; }
/** * Compute an interval from an value. * @ret: Ref. The returned value. * @value: The value. * @env: The environment. * &returns: Error. */ char *amp_mode_ival(struct ml_value_t **ret, struct ml_value_t *value, struct ml_env_t *env) { int mode, off; int16_t ival = 0; chkret(amp_match_unpack(value, "(d,d)", &mode, &off)); if((mode < 1) || (mode > 7)) return mprintf("Invalid mode. Mode must be between 1 and 7."); else if((off < -255) || (off > 255)) return mprintf("Invalid offset. Mode must be between -255 and 255."); switch(mode) { case amp_mode_maj_v: ival = amp_ival_maj(off); break; case amp_mode_min_v: ival = amp_ival_min(off); break; } *ret = ml_value_num(ival, ml_tag_copy(value->tag)); return NULL; }
/** * @file * @brief * Free Ram * * @details * This function looks up the available ram in bytes. * * @param totalram * Output, passed by reference. On successful return, the value * is set to the free ram (in bytes) available on the system. * * @note * TODO explain "free" * * @return * The return value indicates the status of the function. */ int meminfo_freeram(memsize_t *freeram) { int ret = MEMINFO_OK; *freeram = 0L; #if OS_LINUX struct sysinfo info; int test = sysinfo(&info); chkret(test, FAILURE); *freeram = (memsize_t) info.freeram * info.mem_unit; #elif OS_MAC vm_size_t page_size; mach_port_t mach_port; mach_msg_type_number_t count; vm_statistics_data_t vm_stats; mach_port = mach_host_self(); count = sizeof(vm_stats) / sizeof(natural_t); int test = host_page_size(mach_port, &page_size); if (test != KERN_SUCCESS) return FAILURE; test = host_statistics(mach_port, HOST_VM_INFO, (host_info_t)&vm_stats, &count); if (test != KERN_SUCCESS) return FAILURE; *freeram = (memsize_t) vm_stats.free_count * (memsize_t) page_size; #elif OS_WINDOWS MEMORYSTATUSEX status; status.dwLength = sizeof(status); int test = GlobalMemoryStatusEx(&status); winchkret(test, FAILURE); *freeram = (memsize_t) status.ullAvailPhys; #elif OS_FREEBSD int page = sysconf(_SC_PAGESIZE); if (page == -1) return FAILURE; int test = sysctl_val("vm.stats.vm.v_free_count", freeram); chkret(test, FAILURE); *freeram *= (memsize_t) page; #elif OS_NIX memsize_t pagesize, freepages; pagesize = (memsize_t) sysconf(_SC_PAGESIZE); if (pagesize == FAILURE) return FAILURE; freepages = (memsize_t) sysconf(_SC_AVPHYS_PAGES); if (freepages == FAILURE) return FAILURE; *freeram = pagesize * freepages; #else ret = PLATFORM_ERROR; #endif return ret; }