From c036017db373d03f927b1cefccd2d477a4386f35 Mon Sep 17 00:00:00 2001 From: Tony Narlock Date: Sat, 9 Jan 2016 10:41:28 -0600 Subject: [PATCH] Fix FreeBSD memory usage Total memory would go out of bounds for machines ~ > 3.5gB of memory due to the limit of what u_int can hold. Use ``getpagesize()`` and bitshift pagesize so it fits. See also: https://github.com/thewtex/tmux-mem-cpu-load/issues/29 --- freebsd/memory.cc | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/freebsd/memory.cc b/freebsd/memory.cc index 4c3ce9c..315b203 100644 --- a/freebsd/memory.cc +++ b/freebsd/memory.cc @@ -22,6 +22,7 @@ #include #include #include +#include #include "getsysctl.h" #include "memory.h" @@ -45,7 +46,7 @@ std::string mem_string( bool use_colors = false ) // instead of using realmem which reports quantity of ram installed on // platform, use physmem which reports ram available to system. //GETSYSCTL( "hw.physmem", total ); - GETSYSCTL( "hw.pagesize", page_size ); + page_size = getpagesize(); // page count reflects actual size of memory we have available for // applications. it will be less than realmem or physmem, since it doesn't // include what's been allocated for kernel, but it will be equal to @@ -72,7 +73,7 @@ std::string mem_string( bool use_colors = false ) } oss << convert_unit( used, MEGABYTES ) << '/' - << convert_unit( page_count * page_size, MEGABYTES ) << "MB"; + << convert_unit( page_count * (page_size >> 10), MEGABYTES, KILOBYTES) << "MB"; if( use_colors ) {