qqvpp commented on code in PR #8726:
URL: https://github.com/apache/hadoop/pull/8726#discussion_r4147860703


##########
hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/main/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/linux/resources/CGroupsV2ResourceCalculator.java:
##########
@@ -110,11 +110,24 @@ public CGroupsV2ResourceCalculator(String pid) {
     super(
         pid,
         Collections.singletonList(CPU_STAT),
-        MEM_STAT,
-        MEMSW_STAT
+        MEM_STAT
     );
   }
 
+  @Override
+  protected long calculateVirtualMemory() {
+    // Unlike cgroup v1, cgroup v2 does not expose a combined memory+swap
+    // counter. The virtual memory has to be derived by adding the swap usage
+    // (memory.swap.current) to the resident anonymous memory
+    // (memory.stat#anon).
+    long anon = getStat(MEM_STAT);
+    long swap = getStat(MEMSW_STAT);
+    if (anon == UNAVAILABLE || swap == UNAVAILABLE) {

Review Comment:
   I looked at the kernel source code. If it is compiled with `CONFIG_SWAP=n`, 
the `memory.swap.current` file will not exist.
   
   If you agree, I will change it like this. (`mem` is memory.current)
   
   ```java    
       if (mem == UNAVAILABLE && swap == UNAVAILABLE) {
         return UNAVAILABLE;
       }
       //  This should never happen.
       if (mem == UNAVAILABLE) {
         return swap;
       }
       if (swap == UNAVAILABLE) {
         return mem;
       }
       return mem + swap;
   ```



-- 
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]

Reply via email to