Path: blob/master/src/hotspot/os/linux/osContainer_linux.cpp
40951 views
/*1* Copyright (c) 2017, 2020, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*22*/2324#include <string.h>25#include <math.h>26#include <errno.h>27#include "runtime/globals.hpp"28#include "runtime/os.hpp"29#include "logging/log.hpp"30#include "osContainer_linux.hpp"31#include "cgroupSubsystem_linux.hpp"323334bool OSContainer::_is_initialized = false;35bool OSContainer::_is_containerized = false;36CgroupSubsystem* cgroup_subsystem;3738/* init39*40* Initialize the container support and determine if41* we are running under cgroup control.42*/43void OSContainer::init() {44jlong mem_limit;4546assert(!_is_initialized, "Initializing OSContainer more than once");4748_is_initialized = true;49_is_containerized = false;5051log_trace(os, container)("OSContainer::init: Initializing Container Support");52if (!UseContainerSupport) {53log_trace(os, container)("Container Support not enabled");54return;55}5657cgroup_subsystem = CgroupSubsystemFactory::create();58if (cgroup_subsystem == NULL) {59return; // Required subsystem files not found or other error60}61// We need to update the amount of physical memory now that62// cgroup subsystem files have been processed.63if ((mem_limit = cgroup_subsystem->memory_limit_in_bytes()) > 0) {64os::Linux::set_physical_memory(mem_limit);65log_info(os, container)("Memory Limit is: " JLONG_FORMAT, mem_limit);66}6768_is_containerized = true;6970}7172const char * OSContainer::container_type() {73assert(cgroup_subsystem != NULL, "cgroup subsystem not available");74return cgroup_subsystem->container_type();75}7677jlong OSContainer::memory_limit_in_bytes() {78assert(cgroup_subsystem != NULL, "cgroup subsystem not available");79return cgroup_subsystem->memory_limit_in_bytes();80}8182jlong OSContainer::memory_and_swap_limit_in_bytes() {83assert(cgroup_subsystem != NULL, "cgroup subsystem not available");84return cgroup_subsystem->memory_and_swap_limit_in_bytes();85}8687jlong OSContainer::memory_soft_limit_in_bytes() {88assert(cgroup_subsystem != NULL, "cgroup subsystem not available");89return cgroup_subsystem->memory_soft_limit_in_bytes();90}9192jlong OSContainer::memory_usage_in_bytes() {93assert(cgroup_subsystem != NULL, "cgroup subsystem not available");94return cgroup_subsystem->memory_usage_in_bytes();95}9697jlong OSContainer::memory_max_usage_in_bytes() {98assert(cgroup_subsystem != NULL, "cgroup subsystem not available");99return cgroup_subsystem->memory_max_usage_in_bytes();100}101102char * OSContainer::cpu_cpuset_cpus() {103assert(cgroup_subsystem != NULL, "cgroup subsystem not available");104return cgroup_subsystem->cpu_cpuset_cpus();105}106107char * OSContainer::cpu_cpuset_memory_nodes() {108assert(cgroup_subsystem != NULL, "cgroup subsystem not available");109return cgroup_subsystem->cpu_cpuset_memory_nodes();110}111112int OSContainer::active_processor_count() {113assert(cgroup_subsystem != NULL, "cgroup subsystem not available");114return cgroup_subsystem->active_processor_count();115}116117int OSContainer::cpu_quota() {118assert(cgroup_subsystem != NULL, "cgroup subsystem not available");119return cgroup_subsystem->cpu_quota();120}121122int OSContainer::cpu_period() {123assert(cgroup_subsystem != NULL, "cgroup subsystem not available");124return cgroup_subsystem->cpu_period();125}126127int OSContainer::cpu_shares() {128assert(cgroup_subsystem != NULL, "cgroup subsystem not available");129return cgroup_subsystem->cpu_shares();130}131132133