From: Ole Streicher Date: Fri, 2 Dec 2016 13:16:42 +0100 Subject: Fix too small int type for memory on 32-bit machines See https://github.com/casacore/casacore/issues/542#issuecomment-264440161 --- casa/OS/HostInfoLinux.h | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/casa/OS/HostInfoLinux.h b/casa/OS/HostInfoLinux.h index f792b71..4edf61d 100644 --- a/casa/OS/HostInfoLinux.h +++ b/casa/OS/HostInfoLinux.h @@ -132,13 +132,13 @@ skip_token(const char *p) // get integer value from v1 cgroup hierarchy of current processes, if // sub_value is set it returns the entry of a collection identified by value, // e.g. total_rss from memory.stat -// returns std::numeric_limits::max() on error +// returns std::numeric_limits::max() on error // note unset cgroup limits usually have intptr_t.max() // does not support v2 cgroups -static inline size_t +static inline uInt64 get_cgroup_limit(std::string group, std::string value, std::string sub_value="") { - size_t result = std::numeric_limits::max(); + uInt64 result = std::numeric_limits::max(); // assume common location, technically one needs to search for mounts const std::string cgroup = std::string("/sys/fs/cgroup/") + group + "/"; @@ -280,12 +280,12 @@ void HostMachineInfo::update_info( ) } /* can't use more memory than allowed by cgroups, enforced */ - size_t proc_mem_max = get_cgroup_limit("memory", "memory.limit_in_bytes") / 1024; + uInt64 proc_mem_max = get_cgroup_limit("memory", "memory.limit_in_bytes") / 1024; /* usage_in_bytes also includes cache so use memory.stat */ - size_t proc_mem_used = get_cgroup_limit("memory", "memory.stat", "total_rss") / 1024; + uInt64 proc_mem_used = get_cgroup_limit("memory", "memory.stat", "total_rss") / 1024; /* set HostInfo memoryTotal() */ - memory_total = std::min((size_t)sys_mem_total, proc_mem_max); + memory_total = std::min((uInt64)sys_mem_total, proc_mem_max); /* if we have a valid cgroup limit we can determine memoryFree() exactly */ if (proc_mem_max <= sys_mem_total && proc_mem_used <= proc_mem_max) { @@ -293,7 +293,7 @@ void HostMachineInfo::update_info( ) } else { /* no cgroups so we have to assume all memory of host is available */ - memory_free = std::min((size_t)sys_mem_avail, (size_t)memory_total); + memory_free = std::min((uInt64)sys_mem_avail, (uInt64)memory_total); } memory_used = memory_total - memory_free; @@ -303,17 +303,17 @@ void HostMachineInfo::update_info( ) cerr << "Error parsing SwapTotal and SwapFree in /proc/meminfo\n"; /* can't use more swap than allowed by cgroups */ - size_t proc_swap_max = get_cgroup_limit("memory", "memory.memsw.limit_in_bytes") / 1024; - size_t proc_swap_used = get_cgroup_limit("memory", "memory.stat", "total_swap") / 1024; + uInt64 proc_swap_max = get_cgroup_limit("memory", "memory.memsw.limit_in_bytes") / 1024; + uInt64 proc_swap_used = get_cgroup_limit("memory", "memory.stat", "total_swap") / 1024; /* limit is mem + swap */ if (proc_mem_max <= sys_mem_total && proc_mem_max <= proc_swap_max) { proc_swap_max = proc_swap_max - proc_mem_max; } /* set swapTotal() */ - swap_total = std::min((size_t)sys_swap_total, proc_swap_max); + swap_total = std::min((uInt64)sys_swap_total, proc_swap_max); - if (proc_swap_max <= (size_t)swap_total && proc_swap_used <= proc_swap_max) { + if (proc_swap_max <= (uInt64)swap_total && proc_swap_used <= proc_swap_max) { swap_free = proc_swap_max - proc_swap_used; } else {