src/os/linux/vm/os_linux.cpp

Print this page

        

*** 35,44 **** --- 35,45 ---- #include "memory/allocation.inline.hpp" #include "memory/filemap.hpp" #include "mutex_linux.inline.hpp" #include "oops/oop.inline.hpp" #include "os_share_linux.hpp" + #include "osContainer_linux.hpp" #include "prims/jniFastGetField.hpp" #include "prims/jvm.h" #include "prims/jvm_misc.hpp" #include "runtime/arguments.hpp" #include "runtime/extendedPC.hpp"
*** 177,193 **** } julong os::Linux::available_memory() { // values in struct sysinfo are "unsigned long" struct sysinfo si; ! sysinfo(&si); ! return (julong)si.freeram * si.mem_unit; } julong os::physical_memory() { ! return Linux::physical_memory(); } //////////////////////////////////////////////////////////////////////////////// // environment support --- 178,243 ---- } julong os::Linux::available_memory() { // values in struct sysinfo are "unsigned long" struct sysinfo si; ! julong avail_mem; ! if (OSContainer::is_containerized()) { ! jlong mem_limit, mem_usage; ! if ((mem_limit = OSContainer::memory_limit_in_bytes()) < 1) { ! if (PrintContainerInfo) { ! tty->print_cr("container memory limit %s: " JLONG_FORMAT ", using host value", ! mem_limit == OSCONTAINER_ERROR ? "failed" : "unlimited", mem_limit); ! } ! } ! ! if (mem_limit > 0 && (mem_usage = OSContainer::memory_usage_in_bytes()) < 1) { ! if (PrintContainerInfo) { ! tty->print_cr("container memory usage failed: " JLONG_FORMAT ", using host value", mem_usage); ! } ! } ! ! if (mem_limit > 0 && mem_usage > 0 ) { ! avail_mem = mem_limit > mem_usage ? (julong)mem_limit - (julong)mem_usage : 0; ! if (PrintContainerInfo) { ! tty->print_cr("available container memory: " JULONG_FORMAT, avail_mem); ! } ! return avail_mem; ! } ! } ! ! sysinfo(&si); ! avail_mem = (julong)si.freeram * si.mem_unit; ! if (Verbose) { ! tty->print_cr("available memory: " JULONG_FORMAT, avail_mem); ! } ! return avail_mem; } julong os::physical_memory() { ! jlong phys_mem = 0; ! if (OSContainer::is_containerized()) { ! jlong mem_limit; ! if ((mem_limit = OSContainer::memory_limit_in_bytes()) > 0) { ! if (PrintContainerInfo) { ! tty->print_cr("total container memory: " JLONG_FORMAT, mem_limit); ! } ! return mem_limit; ! } ! ! if (PrintContainerInfo) { ! tty->print_cr("container memory limit %s: " JLONG_FORMAT ", using host value", ! mem_limit == OSCONTAINER_ERROR ? "failed" : "unlimited", mem_limit); ! } ! } ! ! phys_mem = Linux::physical_memory(); ! if (Verbose) { ! tty->print_cr("total system memory: " JLONG_FORMAT, phys_mem); ! } ! return phys_mem; } //////////////////////////////////////////////////////////////////////////////// // environment support
*** 2118,2127 **** --- 2168,2179 ---- os::Posix::print_rlimit_info(st); os::Posix::print_load_average(st); os::Linux::print_full_memory_info(st); + + os::Linux::print_container_info(st); } // Try to identify popular distros. // Most Linux distributions have a /etc/XXX-release file, which contains // the OS version string. Newer Linux distributions have a /etc/lsb-release
*** 2183,2192 **** --- 2235,2295 ---- st->print("\n/proc/meminfo:\n"); _print_ascii_file("/proc/meminfo", st); st->cr(); } + void os::Linux::print_container_info(outputStream* st) { + if (!OSContainer::is_containerized()) { + return; + } + + st->print("container (cgroup) information:\n"); + + const char *p_ct = OSContainer::container_type(); + st->print("container_type: %s\n", p_ct != NULL ? p_ct : "failed"); + + char *p = OSContainer::cpu_cpuset_cpus(); + st->print("cpu_cpuset_cpus: %s\n", p != NULL ? p : "failed"); + free(p); + + p = OSContainer::cpu_cpuset_memory_nodes(); + st->print("cpu_memory_nodes: %s\n", p != NULL ? p : "failed"); + free(p); + + int i = OSContainer::active_processor_count(); + if (i > 0) { + st->print("active_processor_count: %d\n", i); + } else { + st->print("active_processor_count: failed\n"); + } + + i = OSContainer::cpu_quota(); + st->print("cpu_quota: %d\n", i); + + i = OSContainer::cpu_period(); + st->print("cpu_period: %d\n", i); + + i = OSContainer::cpu_shares(); + st->print("cpu_shares: %d\n", i); + + jlong j = OSContainer::memory_limit_in_bytes(); + st->print("memory_limit_in_bytes: " JLONG_FORMAT "\n", j); + + j = OSContainer::memory_and_swap_limit_in_bytes(); + st->print("memory_and_swap_limit_in_bytes: " JLONG_FORMAT "\n", j); + + j = OSContainer::memory_soft_limit_in_bytes(); + st->print("memory_soft_limit_in_bytes: " JLONG_FORMAT "\n", j); + + j = OSContainer::OSContainer::memory_usage_in_bytes(); + st->print("memory_usage_in_bytes: " JLONG_FORMAT "\n", j); + + j = OSContainer::OSContainer::memory_max_usage_in_bytes(); + st->print("memory_max_usage_in_bytes: " JLONG_FORMAT "\n", j); + st->cr(); + } + void os::print_memory_info(outputStream* st) { st->print("Memory:"); st->print(" %dk page", os::vm_page_size()>>10);
*** 4954,4963 **** --- 5057,5070 ---- static void perfMemory_exit_helper() { perfMemory_exit(); } } + void os::pd_init_container_support() { + OSContainer::init(); + } + // this is called _after_ the global arguments have been parsed jint os::init_2(void) { Linux::fast_thread_clock_init();
*** 5134,5144 **** // Get the current number of available processors for this process. // This value can change at any time during a process's lifetime. // sched_getaffinity gives an accurate answer as it accounts for cpusets. // If anything goes wrong we fallback to returning the number of online // processors - which can be greater than the number available to the process. ! int os::active_processor_count() { cpu_set_t cpus; // can represent at most 1024 (CPU_SETSIZE) processors int cpus_size = sizeof(cpu_set_t); int cpu_count = 0; // pid 0 means the current thread - which we have to assume represents the process --- 5241,5251 ---- // Get the current number of available processors for this process. // This value can change at any time during a process's lifetime. // sched_getaffinity gives an accurate answer as it accounts for cpusets. // If anything goes wrong we fallback to returning the number of online // processors - which can be greater than the number available to the process. ! int os::Linux::active_processor_count() { cpu_set_t cpus; // can represent at most 1024 (CPU_SETSIZE) processors int cpus_size = sizeof(cpu_set_t); int cpu_count = 0; // pid 0 means the current thread - which we have to assume represents the process
*** 5152,5165 **** cpu_count = ::sysconf(_SC_NPROCESSORS_ONLN); warning("sched_getaffinity failed (%s)- using online processor count (%d) " "which may exceed available processors", strerror(errno), cpu_count); } ! assert(cpu_count > 0 && cpu_count <= processor_count(), "sanity check"); return cpu_count; } void os::set_native_thread_name(const char *name) { // Not yet implemented. return; } --- 5259,5310 ---- cpu_count = ::sysconf(_SC_NPROCESSORS_ONLN); warning("sched_getaffinity failed (%s)- using online processor count (%d) " "which may exceed available processors", strerror(errno), cpu_count); } ! assert(cpu_count > 0 && cpu_count <= os::processor_count(), "sanity check"); return cpu_count; } + // Determine the active processor count from one of + // three different sources: + // + // 1. User option -XX:ActiveProcessorCount + // 2. kernel os calls (sched_getaffinity or sysconf(_SC_NPROCESSORS_ONLN) + // 3. extracted from cgroup cpu subsystem (shares and quotas) + // + // Option 1, if specified, will always override. + // If the cgroup subsystem is active and configured, we + // will return the min of the cgroup and option 2 results. + // This is required since tools, such as numactl, that + // alter cpu affinity do not update cgroup subsystem + // cpuset configuration files. + int os::active_processor_count() { + // User has overridden the number of active processors + if (ActiveProcessorCount > 0) { + if (PrintActiveCpus) { + tty->print_cr("active_processor_count: " + "active processor count set by user : %d", + ActiveProcessorCount); + } + return ActiveProcessorCount; + } + + int active_cpus; + if (OSContainer::is_containerized()) { + active_cpus = OSContainer::active_processor_count(); + if (PrintActiveCpus) { + tty->print_cr("active_processor_count: determined by OSContainer: %d", + active_cpus); + } + } else { + active_cpus = os::Linux::active_processor_count(); + } + + return active_cpus; + } + void os::set_native_thread_name(const char *name) { // Not yet implemented. return; }