1 /*
   2  * Copyright (c) 2019, Red Hat Inc.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *
  23  */
  24 
  25 #ifndef CGROUP_V2_SUBSYSTEM_LINUX_HPP
  26 #define CGROUP_V2_SUBSYSTEM_LINUX_HPP
  27 
  28 #include "cgroupSubsystem_linux.hpp"
  29 
  30 class CgroupV2Controller: public CgroupController {
  31   friend class CgroupSubsystemFactory;
  32   private:
  33     /* the mount path of the cgroup v2 hierarchy */
  34     char *_mount_path;
  35     /* The cgroup path for the controller */
  36     char *_cgroup_path;
  37 
  38     /* Constructed full path to the subsystem directory */
  39     char *_path;
  40     static char* construct_path(char* mount_path, char *cgroup_path);
  41 
  42   public:
  43     CgroupV2Controller(char * mount_path, char *cgroup_path) {
  44       _mount_path = mount_path;
  45       _cgroup_path = os::strdup(cgroup_path);
  46       _path = construct_path(mount_path, cgroup_path);
  47     }
  48 
  49     char *subsystem_path() { return _path; }
  50 };
  51 
  52 class CgroupV2Subsystem: CgroupSubsystem {
  53   friend class CgroupSubsystemFactory;
  54   private:
  55     /* One unified controller */
  56     CgroupController* _unified = NULL;
  57 
  58     CgroupV2Subsystem(CgroupController* unified) {
  59       _unified = unified;
  60     }
  61 
  62     char *mem_limit_val();
  63     char *mem_swp_limit_val();
  64     char *mem_soft_limit_val();
  65     char *cpu_quota_val();
  66     jlong limit_from_str(char* limit_str);
  67 
  68   public:
  69     jlong memory_limit_in_bytes();
  70     int cpu_quota();
  71     int cpu_period();
  72     int cpu_shares();
  73     jlong memory_and_swap_limit_in_bytes();
  74     jlong memory_soft_limit_in_bytes();
  75     jlong memory_usage_in_bytes();
  76     jlong memory_max_usage_in_bytes();
  77     char * cpu_cpuset_cpus();
  78     char * cpu_cpuset_memory_nodes();
  79     const char * container_type() {
  80       return "cgroupv2";
  81     }
  82 };
  83 
  84 #endif // CGROUP_V2_SUBSYSTEM_LINUX_HPP