Title: [263589] trunk/Source/WebKit
Revision
263589
Author
[email protected]
Date
2020-06-26 14:53:36 -0700 (Fri, 26 Jun 2020)

Log Message

[GTK][WPE] Fix the matching of an empty value in getCgroupControllerPath() when only cgroupsV2 hierarchy is found
https://bugs.webkit.org/show_bug.cgi?id=213646

Reviewed by Adrian Perez de Castro.

* UIProcess/linux/MemoryPressureMonitor.cpp:
(WebKit::getCgroupFile):
(WebKit::getCgroupControllerPath):
(WebKit::systemMemoryUsedAsPercentage):

Modified Paths

Diff

Modified: trunk/Source/WebKit/ChangeLog (263588 => 263589)


--- trunk/Source/WebKit/ChangeLog	2020-06-26 21:45:25 UTC (rev 263588)
+++ trunk/Source/WebKit/ChangeLog	2020-06-26 21:53:36 UTC (rev 263589)
@@ -1,3 +1,15 @@
+2020-06-26  Pablo Saavedra  <[email protected]>
+
+        [GTK][WPE] Fix the matching of an empty value in getCgroupControllerPath() when only cgroupsV2 hierarchy is found
+        https://bugs.webkit.org/show_bug.cgi?id=213646
+
+        Reviewed by Adrian Perez de Castro.
+
+        * UIProcess/linux/MemoryPressureMonitor.cpp:
+        (WebKit::getCgroupFile):
+        (WebKit::getCgroupControllerPath):
+        (WebKit::systemMemoryUsedAsPercentage):
+
 2020-06-26  Jason Lawrence  <[email protected]>
 
         Unreviewed, reverting r263511, r263514, and r263565.

Modified: trunk/Source/WebKit/UIProcess/linux/MemoryPressureMonitor.cpp (263588 => 263589)


--- trunk/Source/WebKit/UIProcess/linux/MemoryPressureMonitor.cpp	2020-06-26 21:45:25 UTC (rev 263588)
+++ trunk/Source/WebKit/UIProcess/linux/MemoryPressureMonitor.cpp	2020-06-26 21:53:36 UTC (rev 263589)
@@ -60,6 +60,7 @@
 static const char* s_procSelfCgroup = "/proc/self/cgroup";
 static const unsigned maxCgroupPath = 4096; // PATH_MAX = 4096 from (Linux) include/uapi/linux/limits.h
 
+#define CGROUP_V2_HIERARCHY 0
 #define CGROUP_NAME_BUFFER_SIZE 40
 #define MEMINFO_TOKEN_BUFFER_SIZE 50
 #define STRINGIFY_EXPANDED(val) #val
@@ -174,6 +175,7 @@
 {
     char cgroupPath[maxCgroupPath];
     snprintf(cgroupPath, maxCgroupPath, s_cgroupMemoryPath, cgroupControllerName.data(), cgroupControllerPath.data(), cgroupFileName.data());
+    LOG_VERBOSE(MemoryPressure, "Open: %s", cgroupPath);
     FILE* file = fopen(cgroupPath, "r");
     if (file)
         setbuf(file, nullptr);
@@ -202,23 +204,44 @@
 // 0::/user.slice/user-1000.slice/[email protected]/gnome-terminal-server.service
 static CString getCgroupControllerPath(FILE* cgroupControllerFile, const char* controllerName)
 {
-    CString cgroupMemoryControllerPath;
     if (!cgroupControllerFile || fseek(cgroupControllerFile, 0, SEEK_SET))
         return CString();
 
+    CString cgroupMemoryControllerPath;
     while (!feof(cgroupControllerFile)) {
+        unsigned hierarchyId;
         char name[CGROUP_NAME_BUFFER_SIZE + 1];
         char path[maxCgroupPath + 1];
-        int scanResult = fscanf(cgroupControllerFile, "%*u:%" STRINGIFY(CGROUP_NAME_BUFFER_SIZE) "[^:]:%" STRINGIFY(PATH_MAX) "[^\n]", name, path);
-        if (scanResult != 2)
+        name[0] = path[0] = '\0';
+        int scanResult = fscanf(cgroupControllerFile, "%u:", &hierarchyId);
+        if (scanResult != 1)
             return CString();
+        if (hierarchyId == CGROUP_V2_HIERARCHY) {
+            scanResult = fscanf(cgroupControllerFile, ":%" STRINGIFY(PATH_MAX) "[^\n]", path);
+            if (scanResult != 1)
+                return CString();
+        } else {
+            scanResult = fscanf(cgroupControllerFile, "%" STRINGIFY(CGROUP_NAME_BUFFER_SIZE) "[^:]:%" STRINGIFY(PATH_MAX) "[^\n]", name, path);
+            if (scanResult != 2)
+                return CString();
+        }
         if (!strcmp(name, controllerName)) {
-            return CString(path);
+            cgroupMemoryControllerPath = CString(path);
+            LOG_VERBOSE(MemoryPressure, "memoryControllerName - %s namespace (hierarchy: %d): %s", controllerName, hierarchyId, cgroupMemoryControllerPath.data());
+            return cgroupMemoryControllerPath;
         }
-        if (!strcmp(name, "name=systemd"))
+        if (!strcmp(name, "name=systemd")) {
             cgroupMemoryControllerPath = CString(path);
+            LOG_VERBOSE(MemoryPressure, "memoryControllerName - systemd namespace (hierarchy: %d): %s", hierarchyId, cgroupMemoryControllerPath.data());
+            return cgroupMemoryControllerPath;
+        }
+        if (!strcmp(name, "")) {
+            cgroupMemoryControllerPath = CString(path);
+            LOG_VERBOSE(MemoryPressure, "memoryControllerName - empty namespace (hierarchy: %d): %s", hierarchyId, cgroupMemoryControllerPath.data());
+            return cgroupMemoryControllerPath;
+        }
     }
-    return cgroupMemoryControllerPath;
+    return CString();
 }
 
 
@@ -265,15 +288,18 @@
         return -1;
 
     int memoryUsagePercentage = ((memoryTotal - memoryAvailable) * 100) / memoryTotal;
+    LOG_VERBOSE(MemoryPressure, "MemoryPressureMonitor::memory: real (memory total=%zu MB) (memory available=%zu MB) (memory usage percentage=%d MB)", memoryTotal, memoryAvailable, memoryUsagePercentage);
     if (memoryController->isActive()) {
         memoryTotal = memoryController->getMemoryTotalWithCgroup();
         size_t memoryUsage = memoryController->getMemoryUsageWithCgroup();
         if (memoryTotal != notSet && memoryUsage != notSet) {
             int memoryUsagePercentageWithCgroup = 100 * ((float) memoryUsage / (float) memoryTotal);
+            LOG_VERBOSE(MemoryPressure, "MemoryPressureMonitor::memory: cgroup (memory total=%zu bytes) (memory usage=%zu bytes) (memory usage percentage=%d bytes)", memoryTotal, memoryUsage, memoryUsagePercentageWithCgroup);
             if (memoryUsagePercentageWithCgroup > memoryUsagePercentage)
                 memoryUsagePercentage = memoryUsagePercentageWithCgroup;
         }
     }
+    LOG_VERBOSE(MemoryPressure, "MemoryPressureMonitor::memory: memoryUsagePercentage (%d)", memoryUsagePercentage);
     return memoryUsagePercentage;
 }
 
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to