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 <list>
21 #include <string>
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 
44 class MemorySubsystem : public Subsystem
45 {
46 public:
48  const Flags& flags,
49  const std::string& hierarchy);
50 
51  virtual ~MemorySubsystem() {}
52 
53  virtual std::string name() const
54  {
56  }
57 
59  const ContainerID& containerId,
60  const std::string& cgroup);
61 
63  const ContainerID& containerId,
64  const std::string& cgroup);
65 
67  const ContainerID& containerId,
68  const std::string& cgroup);
69 
71  const ContainerID& containerId,
72  const std::string& cgroup,
73  const Resources& resources);
74 
76  const ContainerID& containerId,
77  const std::string& cgroup);
78 
80  const ContainerID& containerId,
81  const std::string& cgroup);
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  MemorySubsystem(const Flags& flags, const std::string& hierarchy);
97 
99  const ContainerID& containerId,
100  ResourceStatistics result,
101  const std::list<cgroups::memory::pressure::Level>& levels,
102  const std::list<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__
virtual ~MemorySubsystem()
Definition: memory.hpp:51
virtual process::Future< Nothing > cleanup(const ContainerID &containerId, const std::string &cgroup)
Clean up the cgroups subsystem for the associated container.
const std::string CGROUP_SUBSYSTEM_MEMORY_NAME
Definition: constants.hpp:48
Definition: try.hpp:34
Definition: resources.hpp:79
virtual process::Future< Nothing > recover(const ContainerID &containerId, const std::string &cgroup)
Recover the cgroups subsystem for the associated container.
const Flags flags
Flags used to launch the agent.
Definition: subsystem.hpp:176
Definition: flags.hpp:39
Definition: hashmap.hpp:38
Represent cgroups memory subsystem.
Definition: memory.hpp:44
Result< std::string > cgroup(pid_t pid)
Try< std::vector< Entry > > list(const std::string &hierarchy, const std::string &cgroup)
An abstraction for cgroups subsystem.
Definition: subsystem.hpp:42
static Try< process::Owned< Subsystem > > create(const Flags &flags, const std::string &hierarchy)
virtual std::string name() const
The cgroups subsystem name of this Subsystem object.
Definition: memory.hpp:53
Level
Definition: cgroups.hpp:826
const std::string hierarchy
The hierarchy path of cgroups subsystem.
Definition: subsystem.hpp:181
virtual process::Future< ResourceStatistics > usage(const ContainerID &containerId, const std::string &cgroup)
Gather resource usage statistics of the cgroups subsystem for the associated container.
Definition: owned.hpp:35
virtual process::Future< Nothing > update(const ContainerID &containerId, const std::string &cgroup, const Resources &resources)
Update resources allocated to the associated container in this cgroups subsystem. ...
virtual process::Future< Nothing > prepare(const ContainerID &containerId, const std::string &cgroup)
Prepare the cgroups subsystem for the associated container.
virtual process::Future< mesos::slave::ContainerLimitation > watch(const ContainerID &containerId, const std::string &cgroup)
Watch the container and report if any resource constraint impacts it.