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,
61  const mesos::slave::ContainerConfig& containerConfig) override;
62 
64  const ContainerID& containerId,
65  const std::string& cgroup,
66  pid_t pid) override;
67 
69  const ContainerID& containerId,
70  const std::string& cgroup) override;
71 
73  const ContainerID& containerId,
74  const std::string& cgroup) override;
75 
77  const ContainerID& containerId,
78  const std::string& cgroup,
79  const Resources& resourceRequests,
80  const google::protobuf::Map<
81  std::string, Value::Scalar>& resourceLimits = {}) override;
82 
84  const ContainerID& containerId,
85  const std::string& cgroup) override;
86 
88  const ContainerID& containerId,
89  const std::string& cgroup) override;
90 
91 private:
92  struct Info
93  {
94  // Used to cancel the OOM listening.
95  process::Future<Nothing> oomNotifier;
96 
97  hashmap<
100 
102 
103  // Indicate whether the memory hard limit of this container has
104  // already been updated.
105  bool hardLimitUpdated;
106 
107  // Indicates whether this is a command task container. Please note
108  // that we only need to use this field in isolating phase, so we do
109  // not recover it after agent restarts, that means its value may not
110  // be correct after agent recovery.
111  bool isCommandTask;
112  };
113 
114  MemorySubsystemProcess(const Flags& flags, const std::string& hierarchy);
115 
117  const ContainerID& containerId,
118  ResourceStatistics result,
119  const std::vector<cgroups::memory::pressure::Level>& levels,
120  const std::vector<process::Future<uint64_t>>& values);
121 
122  // Start listening on OOM events. This function will create an
123  // eventfd and start polling on it.
124  void oomListen(
125  const ContainerID& containerId,
126  const std::string& cgroup);
127 
128  // This function is invoked when the polling on eventfd has a
129  // result.
130  void oomWaited(
131  const ContainerID& containerId,
132  const std::string& cgroup,
133  const process::Future<Nothing>& future);
134 
135  // Start listening on memory pressure events.
136  void pressureListen(
137  const ContainerID& containerId,
138  const std::string& cgroup);
139 
140  // Stores cgroups associated information for container.
142 };
143 
144 } // namespace slave {
145 } // namespace internal {
146 } // namespace mesos {
147 
148 #endif // __CGROUPS_ISOLATOR_SUBSYSTEMS_MEMORY_HPP__
static Try< process::Owned< SubsystemProcess > > create(const Flags &flags, const std::string &hierarchy)
const std::string CGROUP_SUBSYSTEM_MEMORY_NAME
Definition: constants.hpp:48
Definition: check.hpp:33
Definition: resources.hpp:83
Definition: flags.hpp:39
std::string name() const override
Definition: memory.hpp:53
Definition: hashmap.hpp:38
DWORD pid_t
Definition: windows.hpp:181
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: agent.hpp:25
Result< std::string > cgroup(pid_t pid)
Definition: subsystem.hpp:190
process::Future< Nothing > prepare(const ContainerID &containerId, const std::string &cgroup, const mesos::slave::ContainerConfig &containerConfig) override
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:245
process::Future< Nothing > update(const ContainerID &containerId, const std::string &cgroup, const Resources &resourceRequests, const google::protobuf::Map< std::string, Value::Scalar > &resourceLimits={}) override
Level
Definition: cgroups.hpp:878
process::Future< Nothing > isolate(const ContainerID &containerId, const std::string &cgroup, pid_t pid) override
Definition: owned.hpp:36
Definition: parse.hpp:33