Path: blob/master/src/hotspot/os/linux/cgroupV2Subsystem_linux.hpp
40951 views
/*1* Copyright (c) 2020, Red Hat Inc.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_V2_SUBSYSTEM_LINUX_HPP25#define CGROUP_V2_SUBSYSTEM_LINUX_HPP2627#include "cgroupSubsystem_linux.hpp"2829class CgroupV2Controller: public CgroupController {30private:31/* the mount path of the cgroup v2 hierarchy */32char *_mount_path;33/* The cgroup path for the controller */34char *_cgroup_path;3536/* Constructed full path to the subsystem directory */37char *_path;38static char* construct_path(char* mount_path, char *cgroup_path);3940public:41CgroupV2Controller(char * mount_path, char *cgroup_path) {42_mount_path = mount_path;43_cgroup_path = os::strdup(cgroup_path);44_path = construct_path(mount_path, cgroup_path);45}4647char *subsystem_path() { return _path; }48};4950class CgroupV2Subsystem: public CgroupSubsystem {51private:52/* One unified controller */53CgroupController* _unified = NULL;54/* Caching wrappers for cpu/memory metrics */55CachingCgroupController* _memory = NULL;56CachingCgroupController* _cpu = NULL;5758char *mem_limit_val();59char *mem_swp_limit_val();60char *mem_soft_limit_val();61char *cpu_quota_val();62jlong limit_from_str(char* limit_str);6364public:65CgroupV2Subsystem(CgroupController * unified) {66_unified = unified;67_memory = new CachingCgroupController(unified);68_cpu = new CachingCgroupController(unified);69}7071jlong read_memory_limit_in_bytes();72int cpu_quota();73int cpu_period();74int cpu_shares();75jlong memory_and_swap_limit_in_bytes();76jlong memory_soft_limit_in_bytes();77jlong memory_usage_in_bytes();78jlong memory_max_usage_in_bytes();79char * cpu_cpuset_cpus();80char * cpu_cpuset_memory_nodes();81const char * container_type() {82return "cgroupv2";83}84CachingCgroupController * memory_controller() { return _memory; }85CachingCgroupController * cpu_controller() { return _cpu; }86};8788#endif // CGROUP_V2_SUBSYSTEM_LINUX_HPP899091