Path: blob/master/src/hotspot/os/linux/cgroupV1Subsystem_linux.hpp
40951 views
/*1* Copyright (c) 2019, 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#ifndef CGROUP_V1_SUBSYSTEM_LINUX_HPP25#define CGROUP_V1_SUBSYSTEM_LINUX_HPP2627#include "runtime/os.hpp"28#include "memory/allocation.hpp"29#include "cgroupSubsystem_linux.hpp"3031// Cgroups version 1 specific implementation3233class CgroupV1Controller: public CgroupController {34private:35/* mountinfo contents */36char *_root;37char *_mount_point;3839/* Constructed subsystem directory */40char *_path;4142public:43CgroupV1Controller(char *root, char *mountpoint) {44_root = os::strdup(root);45_mount_point = os::strdup(mountpoint);46_path = NULL;47}4849virtual void set_subsystem_path(char *cgroup_path);50char *subsystem_path() { return _path; }51};5253class CgroupV1MemoryController: public CgroupV1Controller {5455public:56bool is_hierarchical() { return _uses_mem_hierarchy; }57void set_subsystem_path(char *cgroup_path);58private:59/* Some container runtimes set limits via cgroup60* hierarchy. If set to true consider also memory.stat61* file if everything else seems unlimited */62bool _uses_mem_hierarchy;63jlong uses_mem_hierarchy();64void set_hierarchical(bool value) { _uses_mem_hierarchy = value; }6566public:67CgroupV1MemoryController(char *root, char *mountpoint) : CgroupV1Controller(root, mountpoint) {68_uses_mem_hierarchy = false;69}7071};7273class CgroupV1Subsystem: public CgroupSubsystem {7475public:76jlong read_memory_limit_in_bytes();77jlong memory_and_swap_limit_in_bytes();78jlong memory_soft_limit_in_bytes();79jlong memory_usage_in_bytes();80jlong memory_max_usage_in_bytes();81char * cpu_cpuset_cpus();82char * cpu_cpuset_memory_nodes();8384int cpu_quota();85int cpu_period();8687int cpu_shares();8889const char * container_type() {90return "cgroupv1";91}92CachingCgroupController * memory_controller() { return _memory; }93CachingCgroupController * cpu_controller() { return _cpu; }9495private:96julong _unlimited_memory;9798/* controllers */99CachingCgroupController* _memory = NULL;100CgroupV1Controller* _cpuset = NULL;101CachingCgroupController* _cpu = NULL;102CgroupV1Controller* _cpuacct = NULL;103104public:105CgroupV1Subsystem(CgroupV1Controller* cpuset,106CgroupV1Controller* cpu,107CgroupV1Controller* cpuacct,108CgroupV1MemoryController* memory) {109_cpuset = cpuset;110_cpu = new CachingCgroupController(cpu);111_cpuacct = cpuacct;112_memory = new CachingCgroupController(memory);113_unlimited_memory = (LONG_MAX / os::vm_page_size()) * os::vm_page_size();114}115};116117#endif // CGROUP_V1_SUBSYSTEM_LINUX_HPP118119120