@@ -111,7 +111,19 @@ jlong CgroupV1Subsystem::read_memory_limit_in_bytes() {
111
111
}
112
112
}
113
113
114
- jlong CgroupV1Subsystem::memory_and_swap_limit_in_bytes () {
114
+ /* read_mem_swap
115
+ *
116
+ * Determine the memory and swap limit metric. Returns a positive limit value strictly
117
+ * lower than the physical memory and swap limit iff there is a limit. Otherwise a
118
+ * negative value is returned indicating the determined status.
119
+ *
120
+ * returns:
121
+ * * A number > 0 if the limit is available and lower than a physical upper bound.
122
+ * * OSCONTAINER_ERROR if the limit cannot be retrieved (i.e. not supported) or
123
+ * * -1 if there isn't any limit in place (note: includes values which exceed a physical
124
+ * upper bound)
125
+ */
126
+ jlong CgroupV1Subsystem::read_mem_swap () {
115
127
julong host_total_memsw;
116
128
GET_CONTAINER_INFO (julong, _memory->controller (), " /memory.memsw.limit_in_bytes" ,
117
129
" Memory and Swap Limit is: " , JULONG_FORMAT, JULONG_FORMAT, memswlimit);
@@ -126,29 +138,36 @@ jlong CgroupV1Subsystem::memory_and_swap_limit_in_bytes() {
126
138
if (hier_memswlimit >= host_total_memsw) {
127
139
log_trace (os, container)(" Hierarchical Memory and Swap Limit is: Unlimited" );
128
140
} else {
129
- jlong swappiness = read_mem_swappiness ();
130
- if (swappiness == 0 ) {
131
- const char * matchmemline = " hierarchical_memory_limit" ;
132
- GET_CONTAINER_INFO_LINE (julong, _memory->controller (), " /memory.stat" , matchmemline,
133
- " Hierarchical Memory Limit is : " JULONG_FORMAT, JULONG_FORMAT, hier_memlimit)
134
- log_trace (os, container)(" Memory and Swap Limit has been reset to " JULONG_FORMAT " because swappiness is 0" , hier_memlimit);
135
- return (jlong)hier_memlimit;
136
- }
137
141
return (jlong)hier_memswlimit;
138
142
}
139
143
}
140
144
return (jlong)-1 ;
141
145
} else {
142
- jlong swappiness = read_mem_swappiness ();
143
- if (swappiness == 0 ) {
144
- jlong memlimit = read_memory_limit_in_bytes ();
145
- log_trace (os, container)(" Memory and Swap Limit has been reset to " JULONG_FORMAT " because swappiness is 0" , memlimit);
146
- return memlimit;
147
- }
148
146
return (jlong)memswlimit;
149
147
}
150
148
}
151
149
150
+ jlong CgroupV1Subsystem::memory_and_swap_limit_in_bytes () {
151
+ jlong memory_swap = read_mem_swap ();
152
+ if (memory_swap == -1 ) {
153
+ return memory_swap;
154
+ }
155
+ // If there is a swap limit, but swappiness == 0, reset the limit
156
+ // to the memory limit. Do the same for cases where swap isn't
157
+ // supported.
158
+ jlong swappiness = read_mem_swappiness ();
159
+ if (swappiness == 0 || memory_swap == OSCONTAINER_ERROR) {
160
+ jlong memlimit = read_memory_limit_in_bytes ();
161
+ if (memory_swap == OSCONTAINER_ERROR) {
162
+ log_trace (os, container)(" Memory and Swap Limit has been reset to " JLONG_FORMAT " because swap is not supported" , memlimit);
163
+ } else {
164
+ log_trace (os, container)(" Memory and Swap Limit has been reset to " JLONG_FORMAT " because swappiness is 0" , memlimit);
165
+ }
166
+ return memlimit;
167
+ }
168
+ return memory_swap;
169
+ }
170
+
152
171
jlong CgroupV1Subsystem::read_mem_swappiness () {
153
172
GET_CONTAINER_INFO (julong, _memory->controller (), " /memory.swappiness" ,
154
173
" Swappiness is: " , JULONG_FORMAT, JULONG_FORMAT, swappiness);
0 commit comments