brumi1024 commented on code in PR #6760:
URL: https://github.com/apache/hadoop/pull/6760#discussion_r1581108211
##########
hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/main/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/linux/resources/CGroupsMemoryResourceHandlerImpl.java:
##########
@@ -99,81 +66,31 @@ int getSwappiness() {
}
@Override
- public List<PrivilegedOperation> reacquireContainer(ContainerId containerId)
- throws ResourceHandlerException {
- return null;
- }
-
- @Override
- public List<PrivilegedOperation> updateContainer(Container container)
+ protected void updateMemoryHardLimit(String cgroupId, long
containerHardLimit)
throws ResourceHandlerException {
- String cgroupId = container.getContainerId().toString();
- File cgroup = new File(cGroupsHandler.getPathForCGroup(MEMORY, cgroupId));
- if (cgroup.exists()) {
- //memory is in MB
- long containerSoftLimit =
- (long) (container.getResource().getMemorySize() * this.softLimit);
- long containerHardLimit = container.getResource().getMemorySize();
- if (enforce) {
- try {
- cGroupsHandler.updateCGroupParam(MEMORY, cgroupId,
- CGroupsHandler.CGROUP_PARAM_MEMORY_HARD_LIMIT_BYTES,
- String.valueOf(containerHardLimit) + "M");
- ContainerTokenIdentifier id =
container.getContainerTokenIdentifier();
- if (id != null && id.getExecutionType() ==
- ExecutionType.OPPORTUNISTIC) {
- cGroupsHandler.updateCGroupParam(MEMORY, cgroupId,
- CGroupsHandler.CGROUP_PARAM_MEMORY_SOFT_LIMIT_BYTES,
- String.valueOf(OPPORTUNISTIC_SOFT_LIMIT) + "M");
- cGroupsHandler.updateCGroupParam(MEMORY, cgroupId,
- CGroupsHandler.CGROUP_PARAM_MEMORY_SWAPPINESS,
- String.valueOf(OPPORTUNISTIC_SWAPPINESS));
- } else {
- cGroupsHandler.updateCGroupParam(MEMORY, cgroupId,
- CGroupsHandler.CGROUP_PARAM_MEMORY_SOFT_LIMIT_BYTES,
- String.valueOf(containerSoftLimit) + "M");
- cGroupsHandler.updateCGroupParam(MEMORY, cgroupId,
- CGroupsHandler.CGROUP_PARAM_MEMORY_SWAPPINESS,
- String.valueOf(swappiness));
- }
- } catch (ResourceHandlerException re) {
- cGroupsHandler.deleteCGroup(MEMORY, cgroupId);
- LOG.warn("Could not update cgroup for container", re);
- throw re;
- }
- }
- }
- return null;
+ getCGroupsHandler().updateCGroupParam(MEMORY, cgroupId,
+ CGroupsHandler.CGROUP_PARAM_MEMORY_HARD_LIMIT_BYTES,
+ String.valueOf(containerHardLimit) + "M");
}
@Override
- public List<PrivilegedOperation> preStart(Container container)
- throws ResourceHandlerException {
- String cgroupId = container.getContainerId().toString();
- cGroupsHandler.createCGroup(MEMORY, cgroupId);
- updateContainer(container);
- List<PrivilegedOperation> ret = new ArrayList<>();
- ret.add(new PrivilegedOperation(
- PrivilegedOperation.OperationType.ADD_PID_TO_CGROUP,
- PrivilegedOperation.CGROUP_ARG_PREFIX
- + cGroupsHandler.getPathForCGroupTasks(MEMORY, cgroupId)));
- return ret;
+ protected void updateOpportunisticMemoryLimits(String cgroupId) throws
ResourceHandlerException {
+ getCGroupsHandler().updateCGroupParam(MEMORY, cgroupId,
+ CGroupsHandler.CGROUP_PARAM_MEMORY_SOFT_LIMIT_BYTES,
+ String.valueOf(OPPORTUNISTIC_SOFT_LIMIT) + "M");
+ getCGroupsHandler().updateCGroupParam(MEMORY, cgroupId,
Review Comment:
Can you please update the description of the jira and maybe explain in short
a comment what the [swappiness](https://access.redhat.com/solutions/103833)
controls, and that it's no longer available in cgroup v2 as most of the times
it didn't behave as expected?
##########
hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/main/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/linux/resources/CGroupsV2MemoryResourceHandlerImpl.java:
##########
@@ -0,0 +1,52 @@
+/**
+ * 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.
+ */
+
+package
org.apache.hadoop.yarn.server.nodemanager.containermanager.linux.resources;
+
+/**
+ * Handler class to handle the memory controller. YARN already ships a
+ * physical memory monitor in Java but it isn't as
+ * good as CGroups. This handler sets the soft and hard memory limits. The soft
+ * limit is set to 90% of the hard limit.
+ */
+public class CGroupsV2MemoryResourceHandlerImpl extends
AbstractCGroupsMemoryResourceHandler {
+
+ CGroupsV2MemoryResourceHandlerImpl(CGroupsHandler cGroupsHandler) {
+ super(cGroupsHandler);
+ }
+
+ @Override
+ protected void updateMemoryHardLimit(String cgroupId, long
containerHardLimit)
+ throws ResourceHandlerException {
+ getCGroupsHandler().updateCGroupParam(MEMORY, cgroupId,
+ CGroupsHandler.CGROUP_MEMORY_MAX, String.valueOf(containerHardLimit) +
"M");
+ }
+
+ @Override
+ protected void updateOpportunisticMemoryLimits(String cgroupId) throws
ResourceHandlerException {
+ getCGroupsHandler().updateCGroupParam(MEMORY, cgroupId,
+ CGroupsHandler.CGROUP_MEMORY_LOW,
String.valueOf(OPPORTUNISTIC_SOFT_LIMIT) + "M");
+ }
Review Comment:
Nit: for the sake of code reuse this essentially is
updateGuaranteedMemoryLimits with the value OPPORTUNISTIC_SOFT_LIMIT as the
containerSoftLimit, so this probably could call
updateGuaranteedMemoryLimits(cgroupId, OPPORTUNISTIC_SOFT_LIMIT)
--
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]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]