ZhouJas commented on code in PR #577: URL: https://github.com/apache/mesos/pull/577#discussion_r1594680567
########## src/slave/containerizer/mesos/isolators/cgroups2/controllers/memory.cpp: ########## @@ -0,0 +1,203 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#include <sstream> + +#include <process/defer.hpp> +#include <process/id.hpp> +#include <process/pid.hpp> + +#include <stout/bytes.hpp> + +#include "common/protobuf_utils.hpp" + +#include "linux/cgroups2.hpp" + +#include "slave/containerizer/mesos/isolators/cgroups2/constants.hpp" +#include "slave/containerizer/mesos/isolators/cgroups2/controllers/memory.hpp" + +using process::Failure; +using process::Future; +using process::PID; +using process::Owned; + +using cgroups2::memory::Stats; + +using mesos::slave::ContainerConfig; +using mesos::slave::ContainerLimitation; + +using std::ostringstream; +using std::string; + +namespace mesos { +namespace internal { +namespace slave { + +Try<Owned<ControllerProcess>> MemoryControllerProcess::create(const Flags& flags) +{ + return Owned<ControllerProcess>(new MemoryControllerProcess(flags)); +} + + +MemoryControllerProcess::MemoryControllerProcess(const Flags& _flags) + : ProcessBase(process::ID::generate("cgroups-v2-memory-controller")), + ControllerProcess(_flags) {} + + +string MemoryControllerProcess::name() const +{ + return CGROUPS_V2_CONTROLLER_MEMORY_NAME; +} + + +Future<Nothing> MemoryControllerProcess::prepare( + const ContainerID& containerId, + const string& cgroup, + const ContainerConfig& containerConfig) +{ + if (infos.contains(containerId)) { + return Failure("Already prepared"); + } + + infos.put(containerId, Info()); + + return Nothing(); +} + + +Future<Nothing> MemoryControllerProcess::isolate( + const ContainerID& containerId, + const string& cgroup, + pid_t pid) +{ + if (!infos.contains(containerId)) { + return Failure("Unknown container"); + } + + // TODO(dleamy): Implement manual OOM score adjustment, similar to as it done + // in the cgroups v1 isolator. + + return Nothing(); +} + + +Future<Nothing> MemoryControllerProcess::recover( + const ContainerID& containerId, + const string& cgroup) +{ + if (infos.contains(containerId)) { + return Failure("Already recovered"); + } + + infos.put(containerId, Info()); + infos[containerId].hardLimitUpdated = true; + + return Nothing(); +} + + +Future<Nothing> MemoryControllerProcess::update( + const ContainerID& containerId, + const string& cgroup, + const Resources& resourceRequests, + const google::protobuf::Map<string, Value::Scalar>& resourceLimits) +{ + if (!infos.contains(containerId)) { + return Failure("Unknown container"); + } + + if (resourceRequests.mem().isNone()) { + return Failure("No memory resources requested"); + } + + Bytes memory = *resourceRequests.mem(); + Bytes softLimit = std::max(memory, MIN_MEMORY); + + // Set the soft memory limit. + Try<Nothing> high = cgroups2::memory::set_high(cgroup, softLimit); Review Comment: This should be set_low instead for the same behavior as soft limit in v1 -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
