summaryrefslogtreecommitdiff
blob: 33723375e4dd4156ed1dab8aa4803e0b948fe725 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
From: Ole Streicher <olebole@debian.org>
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<size_t>::max() on error
+// returns std::numeric_limits<uInt64>::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<size_t>::max();
+    uInt64 result = std::numeric_limits<uInt64>::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 {