src/hotspot/os/linux/os_linux.cpp
Index
Unified diffs
Context diffs
Sdiffs
Wdiffs
Patch
New
Old
Previous File
Next File
*** old/src/hotspot/os/linux/os_linux.cpp Wed Oct 11 14:34:36 2017
--- new/src/hotspot/os/linux/os_linux.cpp Wed Oct 11 14:34:35 2017
*** 36,45 ****
--- 36,46 ----
#include "memory/allocation.inline.hpp"
#include "memory/filemap.hpp"
#include "oops/oop.inline.hpp"
#include "os_linux.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/atomic.hpp"
*** 170,186 ****
--- 171,226 ----
}
julong os::Linux::available_memory() {
// values in struct sysinfo are "unsigned long"
struct sysinfo si;
! sysinfo(&si);
! julong avail_mem;
return (julong)si.freeram * si.mem_unit;
+ if (OSContainer::is_containerized()) {
+ jlong mem_limit, mem_usage;
+ if ((mem_limit = OSContainer::memory_limit_in_bytes()) > 0) {
+ if ((mem_usage = OSContainer::memory_usage_in_bytes()) > 0) {
+ if (mem_limit > mem_usage) {
+ avail_mem = (julong)mem_limit - (julong)mem_usage;
+ } else {
+ avail_mem = 0;
+ }
+ log_trace(os)("available container memory: " JULONG_FORMAT, avail_mem);
+ return avail_mem;
+ } else {
+ log_debug(os,container)("container memory usage call failed: " JLONG_FORMAT, mem_usage);
+ }
+ } else {
+ log_debug(os,container)("container memory unlimited or failed: " JLONG_FORMAT, mem_limit);
+ }
+ }
+
+ sysinfo(&si);
+ avail_mem = (julong)si.freeram * si.mem_unit;
+ log_trace(os)("available memory: " JULONG_FORMAT, avail_mem);
+ return avail_mem;
}
julong os::physical_memory() {
return Linux::physical_memory();
+ if (OSContainer::is_containerized()) {
+ jlong mem_limit;
+ if ((mem_limit = OSContainer::memory_limit_in_bytes()) > 0) {
+ log_trace(os)("total container memory: " JLONG_FORMAT, mem_limit);
+ return (julong)mem_limit;
+ } else {
+ if (mem_limit == OSCONTAINER_ERROR) {
+ log_debug(os,container)("container memory limit call failed");
+ }
+ if (mem_limit == -1) {
+ log_debug(os,container)("container memory unlimited, using host value");
+ }
+ }
+ }
+
+ jlong phys_mem = Linux::physical_memory();
+ log_trace(os)("total system memory: " JLONG_FORMAT, phys_mem);
+ return phys_mem;
}
// Return true if user is running as root.
bool os::have_special_privileges() {
*** 1949,1958 ****
--- 1989,2000 ----
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
*** 2086,2095 ****
--- 2128,2197 ----
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()) {
+ st->print("container (cgroup) information:\n");
+
+ char *p = OSContainer::container_type();
+ if (p == NULL)
+ st->print("container_type() failed\n");
+ else {
+ st->print("container_type: %s\n", p);
+ }
+
+ p = OSContainer::cpu_cpuset_cpus();
+ if (p == NULL)
+ st->print("cpu_cpuset_cpus() failed\n");
+ else {
+ st->print("cpu_cpuset_cpus: %s", p);
+ free(p);
+ }
+
+ p = OSContainer::cpu_cpuset_memory_nodes();
+ if (p < 0)
+ st->print("cpu_memory_nodes() failed\n");
+ else {
+ st->print("cpu_memory_nodes: %s", p);
+ free(p);
+ }
+
+ int i = OSContainer::active_processor_count();
+ if (i < 0)
+ st->print("active_processor_count() failed\n");
+ else
+ st->print("active_processor_count: %d\n", i);
+
+ 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);
*** 4797,4806 ****
--- 4899,4912 ----
static void perfMemory_exit_helper() {
perfMemory_exit();
}
}
+ void os::pd_initialize_container_support() {
+ OSContainer::init();
+ }
+
// this is called _after_ the global arguments have been parsed
jint os::init_2(void) {
os::Posix::init_2();
*** 4959,4974 ****
--- 5065,5080 ----
// sched_getaffinity gives an accurate answer as it accounts for cpusets.
// If it appears there may be more than 1024 processors then we do a
// dynamic check - see 6515172 for details.
// 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
cpu_set_t* cpus_p = &cpus;
int cpus_size = sizeof(cpu_set_t);
! int configured_cpus = os::processor_count(); // upper bound on available cpus
int cpu_count = 0;
// old build platforms may not support dynamic cpu sets
#ifdef CPU_ALLOC
*** 5027,5040 ****
--- 5133,5180 ----
if (cpus_p != &cpus) { // can only be true when CPU_ALLOC used
CPU_FREE(cpus_p);
}
! 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) {
+ log_trace(os)("active_processor_count: "
+ "active processor count set by user : %d",
+ (int)ActiveProcessorCount);
+ return ActiveProcessorCount;
+ }
+
+ int active_cpus;
+ if (OSContainer::is_containerized()) {
+ active_cpus = OSContainer::active_processor_count();
+ log_trace(os)("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) {
if (Linux::_pthread_setname_np) {
char buf [16]; // according to glibc manpage, 16 chars incl. '/0'
snprintf(buf, sizeof(buf), "%s", name);
buf[sizeof(buf) - 1] = '\0';
src/hotspot/os/linux/os_linux.cpp
Index
Unified diffs
Context diffs
Sdiffs
Wdiffs
Patch
New
Old
Previous File
Next File