35 #include "memory/allocation.inline.hpp" |
35 #include "memory/allocation.inline.hpp" |
36 #include "memory/filemap.hpp" |
36 #include "memory/filemap.hpp" |
37 #include "mutex_linux.inline.hpp" |
37 #include "mutex_linux.inline.hpp" |
38 #include "oops/oop.inline.hpp" |
38 #include "oops/oop.inline.hpp" |
39 #include "os_share_linux.hpp" |
39 #include "os_share_linux.hpp" |
|
40 #include "osContainer_linux.hpp" |
40 #include "prims/jniFastGetField.hpp" |
41 #include "prims/jniFastGetField.hpp" |
41 #include "prims/jvm.h" |
42 #include "prims/jvm.h" |
42 #include "prims/jvm_misc.hpp" |
43 #include "prims/jvm_misc.hpp" |
43 #include "runtime/arguments.hpp" |
44 #include "runtime/arguments.hpp" |
44 #include "runtime/extendedPC.hpp" |
45 #include "runtime/extendedPC.hpp" |
177 } |
178 } |
178 |
179 |
179 julong os::Linux::available_memory() { |
180 julong os::Linux::available_memory() { |
180 // values in struct sysinfo are "unsigned long" |
181 // values in struct sysinfo are "unsigned long" |
181 struct sysinfo si; |
182 struct sysinfo si; |
|
183 julong avail_mem; |
|
184 |
|
185 if (OSContainer::is_containerized()) { |
|
186 jlong mem_limit, mem_usage; |
|
187 if ((mem_limit = OSContainer::memory_limit_in_bytes()) < 1) { |
|
188 if (PrintContainerInfo) { |
|
189 tty->print_cr("container memory limit %s: " JLONG_FORMAT ", using host value", |
|
190 mem_limit == OSCONTAINER_ERROR ? "failed" : "unlimited", mem_limit); |
|
191 } |
|
192 } |
|
193 |
|
194 if (mem_limit > 0 && (mem_usage = OSContainer::memory_usage_in_bytes()) < 1) { |
|
195 if (PrintContainerInfo) { |
|
196 tty->print_cr("container memory usage failed: " JLONG_FORMAT ", using host value", mem_usage); |
|
197 } |
|
198 } |
|
199 |
|
200 if (mem_limit > 0 && mem_usage > 0 ) { |
|
201 avail_mem = mem_limit > mem_usage ? (julong)mem_limit - (julong)mem_usage : 0; |
|
202 if (PrintContainerInfo) { |
|
203 tty->print_cr("available container memory: " JULONG_FORMAT, avail_mem); |
|
204 } |
|
205 return avail_mem; |
|
206 } |
|
207 } |
|
208 |
182 sysinfo(&si); |
209 sysinfo(&si); |
183 |
210 avail_mem = (julong)si.freeram * si.mem_unit; |
184 return (julong)si.freeram * si.mem_unit; |
211 if (Verbose) { |
|
212 tty->print_cr("available memory: " JULONG_FORMAT, avail_mem); |
|
213 } |
|
214 return avail_mem; |
185 } |
215 } |
186 |
216 |
187 julong os::physical_memory() { |
217 julong os::physical_memory() { |
188 return Linux::physical_memory(); |
218 jlong phys_mem = 0; |
|
219 if (OSContainer::is_containerized()) { |
|
220 jlong mem_limit; |
|
221 if ((mem_limit = OSContainer::memory_limit_in_bytes()) > 0) { |
|
222 if (PrintContainerInfo) { |
|
223 tty->print_cr("total container memory: " JLONG_FORMAT, mem_limit); |
|
224 } |
|
225 return mem_limit; |
|
226 } |
|
227 |
|
228 if (PrintContainerInfo) { |
|
229 tty->print_cr("container memory limit %s: " JLONG_FORMAT ", using host value", |
|
230 mem_limit == OSCONTAINER_ERROR ? "failed" : "unlimited", mem_limit); |
|
231 } |
|
232 } |
|
233 |
|
234 phys_mem = Linux::physical_memory(); |
|
235 if (Verbose) { |
|
236 tty->print_cr("total system memory: " JLONG_FORMAT, phys_mem); |
|
237 } |
|
238 return phys_mem; |
189 } |
239 } |
190 |
240 |
191 //////////////////////////////////////////////////////////////////////////////// |
241 //////////////////////////////////////////////////////////////////////////////// |
192 // environment support |
242 // environment support |
193 |
243 |
2112 os::Posix::print_rlimit_info(st); |
2162 os::Posix::print_rlimit_info(st); |
2113 |
2163 |
2114 os::Posix::print_load_average(st); |
2164 os::Posix::print_load_average(st); |
2115 |
2165 |
2116 os::Linux::print_full_memory_info(st); |
2166 os::Linux::print_full_memory_info(st); |
|
2167 |
|
2168 os::Linux::print_container_info(st); |
2117 } |
2169 } |
2118 |
2170 |
2119 // Try to identify popular distros. |
2171 // Try to identify popular distros. |
2120 // Most Linux distributions have a /etc/XXX-release file, which contains |
2172 // Most Linux distributions have a /etc/XXX-release file, which contains |
2121 // the OS version string. Newer Linux distributions have a /etc/lsb-release |
2173 // the OS version string. Newer Linux distributions have a /etc/lsb-release |
2177 st->print("\n/proc/meminfo:\n"); |
2229 st->print("\n/proc/meminfo:\n"); |
2178 _print_ascii_file("/proc/meminfo", st); |
2230 _print_ascii_file("/proc/meminfo", st); |
2179 st->cr(); |
2231 st->cr(); |
2180 } |
2232 } |
2181 |
2233 |
|
2234 void os::Linux::print_container_info(outputStream* st) { |
|
2235 if (!OSContainer::is_containerized()) { |
|
2236 return; |
|
2237 } |
|
2238 |
|
2239 st->print("container (cgroup) information:\n"); |
|
2240 |
|
2241 const char *p_ct = OSContainer::container_type(); |
|
2242 st->print("container_type: %s\n", p_ct != NULL ? p_ct : "failed"); |
|
2243 |
|
2244 char *p = OSContainer::cpu_cpuset_cpus(); |
|
2245 st->print("cpu_cpuset_cpus: %s\n", p != NULL ? p : "failed"); |
|
2246 free(p); |
|
2247 |
|
2248 p = OSContainer::cpu_cpuset_memory_nodes(); |
|
2249 st->print("cpu_memory_nodes: %s\n", p != NULL ? p : "failed"); |
|
2250 free(p); |
|
2251 |
|
2252 int i = OSContainer::active_processor_count(); |
|
2253 if (i > 0) { |
|
2254 st->print("active_processor_count: %d\n", i); |
|
2255 } else { |
|
2256 st->print("active_processor_count: failed\n"); |
|
2257 } |
|
2258 |
|
2259 i = OSContainer::cpu_quota(); |
|
2260 st->print("cpu_quota: %d\n", i); |
|
2261 |
|
2262 i = OSContainer::cpu_period(); |
|
2263 st->print("cpu_period: %d\n", i); |
|
2264 |
|
2265 i = OSContainer::cpu_shares(); |
|
2266 st->print("cpu_shares: %d\n", i); |
|
2267 |
|
2268 jlong j = OSContainer::memory_limit_in_bytes(); |
|
2269 st->print("memory_limit_in_bytes: " JLONG_FORMAT "\n", j); |
|
2270 |
|
2271 j = OSContainer::memory_and_swap_limit_in_bytes(); |
|
2272 st->print("memory_and_swap_limit_in_bytes: " JLONG_FORMAT "\n", j); |
|
2273 |
|
2274 j = OSContainer::memory_soft_limit_in_bytes(); |
|
2275 st->print("memory_soft_limit_in_bytes: " JLONG_FORMAT "\n", j); |
|
2276 |
|
2277 j = OSContainer::OSContainer::memory_usage_in_bytes(); |
|
2278 st->print("memory_usage_in_bytes: " JLONG_FORMAT "\n", j); |
|
2279 |
|
2280 j = OSContainer::OSContainer::memory_max_usage_in_bytes(); |
|
2281 st->print("memory_max_usage_in_bytes: " JLONG_FORMAT "\n", j); |
|
2282 st->cr(); |
|
2283 } |
|
2284 |
2182 void os::print_memory_info(outputStream* st) { |
2285 void os::print_memory_info(outputStream* st) { |
2183 |
2286 |
2184 st->print("Memory:"); |
2287 st->print("Memory:"); |
2185 st->print(" %dk page", os::vm_page_size()>>10); |
2288 st->print(" %dk page", os::vm_page_size()>>10); |
2186 |
2289 |
5129 // Get the current number of available processors for this process. |
5236 // Get the current number of available processors for this process. |
5130 // This value can change at any time during a process's lifetime. |
5237 // This value can change at any time during a process's lifetime. |
5131 // sched_getaffinity gives an accurate answer as it accounts for cpusets. |
5238 // sched_getaffinity gives an accurate answer as it accounts for cpusets. |
5132 // If anything goes wrong we fallback to returning the number of online |
5239 // If anything goes wrong we fallback to returning the number of online |
5133 // processors - which can be greater than the number available to the process. |
5240 // processors - which can be greater than the number available to the process. |
5134 int os::active_processor_count() { |
5241 int os::Linux::active_processor_count() { |
5135 cpu_set_t cpus; // can represent at most 1024 (CPU_SETSIZE) processors |
5242 cpu_set_t cpus; // can represent at most 1024 (CPU_SETSIZE) processors |
5136 int cpus_size = sizeof(cpu_set_t); |
5243 int cpus_size = sizeof(cpu_set_t); |
5137 int cpu_count = 0; |
5244 int cpu_count = 0; |
5138 |
5245 |
5139 // pid 0 means the current thread - which we have to assume represents the process |
5246 // pid 0 means the current thread - which we have to assume represents the process |
5147 cpu_count = ::sysconf(_SC_NPROCESSORS_ONLN); |
5254 cpu_count = ::sysconf(_SC_NPROCESSORS_ONLN); |
5148 warning("sched_getaffinity failed (%s)- using online processor count (%d) " |
5255 warning("sched_getaffinity failed (%s)- using online processor count (%d) " |
5149 "which may exceed available processors", strerror(errno), cpu_count); |
5256 "which may exceed available processors", strerror(errno), cpu_count); |
5150 } |
5257 } |
5151 |
5258 |
5152 assert(cpu_count > 0 && cpu_count <= processor_count(), "sanity check"); |
5259 assert(cpu_count > 0 && cpu_count <= os::processor_count(), "sanity check"); |
5153 return cpu_count; |
5260 return cpu_count; |
|
5261 } |
|
5262 |
|
5263 // Determine the active processor count from one of |
|
5264 // three different sources: |
|
5265 // |
|
5266 // 1. User option -XX:ActiveProcessorCount |
|
5267 // 2. kernel os calls (sched_getaffinity or sysconf(_SC_NPROCESSORS_ONLN) |
|
5268 // 3. extracted from cgroup cpu subsystem (shares and quotas) |
|
5269 // |
|
5270 // Option 1, if specified, will always override. |
|
5271 // If the cgroup subsystem is active and configured, we |
|
5272 // will return the min of the cgroup and option 2 results. |
|
5273 // This is required since tools, such as numactl, that |
|
5274 // alter cpu affinity do not update cgroup subsystem |
|
5275 // cpuset configuration files. |
|
5276 int os::active_processor_count() { |
|
5277 // User has overridden the number of active processors |
|
5278 if (ActiveProcessorCount > 0) { |
|
5279 if (PrintActiveCpus) { |
|
5280 tty->print_cr("active_processor_count: " |
|
5281 "active processor count set by user : %d", |
|
5282 ActiveProcessorCount); |
|
5283 } |
|
5284 return ActiveProcessorCount; |
|
5285 } |
|
5286 |
|
5287 int active_cpus; |
|
5288 if (OSContainer::is_containerized()) { |
|
5289 active_cpus = OSContainer::active_processor_count(); |
|
5290 if (PrintActiveCpus) { |
|
5291 tty->print_cr("active_processor_count: determined by OSContainer: %d", |
|
5292 active_cpus); |
|
5293 } |
|
5294 } else { |
|
5295 active_cpus = os::Linux::active_processor_count(); |
|
5296 } |
|
5297 |
|
5298 return active_cpus; |
5154 } |
5299 } |
5155 |
5300 |
5156 void os::set_native_thread_name(const char *name) { |
5301 void os::set_native_thread_name(const char *name) { |
5157 // Not yet implemented. |
5302 // Not yet implemented. |
5158 return; |
5303 return; |