Apache Mesos
memory.hpp
Go to the documentation of this file.
1 // Licensed to the Apache Software Foundation (ASF) under one
2 // or more contributor license agreements. See the NOTICE file
3 // distributed with this work for additional information
4 // regarding copyright ownership. The ASF licenses this file
5 // to you under the Apache License, Version 2.0 (the
6 // "License"); you may not use this file except in compliance
7 // with the License. You may obtain a copy of the License at
8 //
9 // http://www.apache.org/licenses/LICENSE-2.0
10 //
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
16 
17 #ifndef __CGROUPS_ISOLATOR_SUBSYSTEMS_MEMORY_HPP__
18 #define __CGROUPS_ISOLATOR_SUBSYSTEMS_MEMORY_HPP__
19 
20 #include <string>
21 #include <vector>
22 
23 #include <process/future.hpp>
24 #include <process/owned.hpp>
25 
26 #include <stout/hashmap.hpp>
27 #include <stout/nothing.hpp>
28 #include <stout/try.hpp>
29 
30 #include "linux/cgroups.hpp"
31 
32 #include "slave/flags.hpp"
33 
36 
37 namespace mesos {
38 namespace internal {
39 namespace slave {
40 
45 {
46 public:
48  const Flags& flags,
49  const std::string& hierarchy);
50 
51  ~MemorySubsystemProcess() override = default;
52 
53  std::string name() const override
54  {
56  }
57 
59  const ContainerID& containerId,
60  const std::string& cgroup) override;
61 
63  const ContainerID& containerId,
64  const std::string& cgroup) override;
65 
67  const ContainerID& containerId,
68  const std::string& cgroup) override;
69 
71  const ContainerID& containerId,
72  const std::string& cgroup,
73  const Resources& resources) override;
74 
76  const ContainerID& containerId,
77  const std::string& cgroup) override;
78 
80  const ContainerID& containerId,
81  const std::string& cgroup) override;
82 
83 private:
84  struct Info
85  {
86  // Used to cancel the OOM listening.
87  process::Future<Nothing> oomNotifier;
88 
89  hashmap<
92 
94  };
95 
96  MemorySubsystemProcess(const Flags& flags, const std::string& hierarchy);
97 
99  const ContainerID& containerId,
100  ResourceStatistics result,
101  const std::vector<cgroups::memory::pressure::Level>& levels,
102  const std::vector<process::Future<uint64_t>>& values);
103 
104  // Start listening on OOM events. This function will create an
105  // eventfd and start polling on it.
106  void oomListen(
107  const ContainerID& containerId,
108  const std::string& cgroup);
109 
110  // This function is invoked when the polling on eventfd has a
111  // result.
112  void oomWaited(
113  const ContainerID& containerId,
114  const std::string& cgroup,
115  const process::Future<Nothing>& future);
116 
117  // Start listening on memory pressure events.
118  void pressureListen(
119  const ContainerID& containerId,
120  const std::string& cgroup);
121 
122  // Stores cgroups associated information for container.
124 };
125 
126 } // namespace slave {
127 } // namespace internal {
128 } // namespace mesos {
129 
130 #endif // __CGROUPS_ISOLATOR_SUBSYSTEMS_MEMORY_HPP__
static Try< process::Owned< SubsystemProcess > > create(const Flags &flags, const std::string &hierarchy)
process::Future< Nothing > prepare(const ContainerID &containerId, const std::string &cgroup) override
const std::string CGROUP_SUBSYSTEM_MEMORY_NAME
Definition: constants.hpp:48
Definition: check.hpp:33
process::Future< Nothing > update(const ContainerID &containerId, const std::string &cgroup, const Resources &resources) override
Definition: resources.hpp:81
Definition: flags.hpp:39
std::string name() const override
Definition: memory.hpp:53
Definition: hashmap.hpp:38
process::Future< Nothing > cleanup(const ContainerID &containerId, const std::string &cgroup) override
Represent cgroups memory subsystem.
Definition: memory.hpp:44
process::Future< ResourceStatistics > usage(const ContainerID &containerId, const std::string &cgroup) override
Definition: spec.hpp:26
Result< std::string > cgroup(pid_t pid)
Definition: subsystem.hpp:186
process::Future< mesos::slave::ContainerLimitation > watch(const ContainerID &containerId, const std::string &cgroup) override
process::Future< Nothing > recover(const ContainerID &containerId, const std::string &cgroup) override
Definition: attributes.hpp:24
const std::string hierarchy
The hierarchy path of cgroups subsystem.
Definition: subsystem.hpp:238
Level
Definition: cgroups.hpp:875
Definition: owned.hpp:36
Definition: parse.hpp:33