Changeset 263589 in webkit
- Timestamp:
- Jun 26, 2020 2:53:36 PM (4 years ago)
- Location:
- trunk/Source/WebKit
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebKit/ChangeLog
r263588 r263589 1 2020-06-26 Pablo Saavedra <psaavedra@igalia.com> 2 3 [GTK][WPE] Fix the matching of an empty value in getCgroupControllerPath() when only cgroupsV2 hierarchy is found 4 https://bugs.webkit.org/show_bug.cgi?id=213646 5 6 Reviewed by Adrian Perez de Castro. 7 8 * UIProcess/linux/MemoryPressureMonitor.cpp: 9 (WebKit::getCgroupFile): 10 (WebKit::getCgroupControllerPath): 11 (WebKit::systemMemoryUsedAsPercentage): 12 1 13 2020-06-26 Jason Lawrence <lawrence.j@apple.com> 2 14 -
trunk/Source/WebKit/UIProcess/linux/MemoryPressureMonitor.cpp
r262217 r263589 61 61 static const unsigned maxCgroupPath = 4096; // PATH_MAX = 4096 from (Linux) include/uapi/linux/limits.h 62 62 63 #define CGROUP_V2_HIERARCHY 0 63 64 #define CGROUP_NAME_BUFFER_SIZE 40 64 65 #define MEMINFO_TOKEN_BUFFER_SIZE 50 … … 175 176 char cgroupPath[maxCgroupPath]; 176 177 snprintf(cgroupPath, maxCgroupPath, s_cgroupMemoryPath, cgroupControllerName.data(), cgroupControllerPath.data(), cgroupFileName.data()); 178 LOG_VERBOSE(MemoryPressure, "Open: %s", cgroupPath); 177 179 FILE* file = fopen(cgroupPath, "r"); 178 180 if (file) … … 203 205 static CString getCgroupControllerPath(FILE* cgroupControllerFile, const char* controllerName) 204 206 { 205 CString cgroupMemoryControllerPath;206 207 if (!cgroupControllerFile || fseek(cgroupControllerFile, 0, SEEK_SET)) 207 208 return CString(); 208 209 210 CString cgroupMemoryControllerPath; 209 211 while (!feof(cgroupControllerFile)) { 212 unsigned hierarchyId; 210 213 char name[CGROUP_NAME_BUFFER_SIZE + 1]; 211 214 char path[maxCgroupPath + 1]; 212 int scanResult = fscanf(cgroupControllerFile, "%*u:%" STRINGIFY(CGROUP_NAME_BUFFER_SIZE) "[^:]:%" STRINGIFY(PATH_MAX) "[^\n]", name, path); 213 if (scanResult != 2) 215 name[0] = path[0] = '\0'; 216 int scanResult = fscanf(cgroupControllerFile, "%u:", &hierarchyId); 217 if (scanResult != 1) 214 218 return CString(); 219 if (hierarchyId == CGROUP_V2_HIERARCHY) { 220 scanResult = fscanf(cgroupControllerFile, ":%" STRINGIFY(PATH_MAX) "[^\n]", path); 221 if (scanResult != 1) 222 return CString(); 223 } else { 224 scanResult = fscanf(cgroupControllerFile, "%" STRINGIFY(CGROUP_NAME_BUFFER_SIZE) "[^:]:%" STRINGIFY(PATH_MAX) "[^\n]", name, path); 225 if (scanResult != 2) 226 return CString(); 227 } 215 228 if (!strcmp(name, controllerName)) { 216 return CString(path);217 }218 if (!strcmp(name, "name=systemd"))219 229 cgroupMemoryControllerPath = CString(path); 220 } 221 return cgroupMemoryControllerPath; 230 LOG_VERBOSE(MemoryPressure, "memoryControllerName - %s namespace (hierarchy: %d): %s", controllerName, hierarchyId, cgroupMemoryControllerPath.data()); 231 return cgroupMemoryControllerPath; 232 } 233 if (!strcmp(name, "name=systemd")) { 234 cgroupMemoryControllerPath = CString(path); 235 LOG_VERBOSE(MemoryPressure, "memoryControllerName - systemd namespace (hierarchy: %d): %s", hierarchyId, cgroupMemoryControllerPath.data()); 236 return cgroupMemoryControllerPath; 237 } 238 if (!strcmp(name, "")) { 239 cgroupMemoryControllerPath = CString(path); 240 LOG_VERBOSE(MemoryPressure, "memoryControllerName - empty namespace (hierarchy: %d): %s", hierarchyId, cgroupMemoryControllerPath.data()); 241 return cgroupMemoryControllerPath; 242 } 243 } 244 return CString(); 222 245 } 223 246 … … 266 289 267 290 int memoryUsagePercentage = ((memoryTotal - memoryAvailable) * 100) / memoryTotal; 291 LOG_VERBOSE(MemoryPressure, "MemoryPressureMonitor::memory: real (memory total=%zu MB) (memory available=%zu MB) (memory usage percentage=%d MB)", memoryTotal, memoryAvailable, memoryUsagePercentage); 268 292 if (memoryController->isActive()) { 269 293 memoryTotal = memoryController->getMemoryTotalWithCgroup(); … … 271 295 if (memoryTotal != notSet && memoryUsage != notSet) { 272 296 int memoryUsagePercentageWithCgroup = 100 * ((float) memoryUsage / (float) memoryTotal); 297 LOG_VERBOSE(MemoryPressure, "MemoryPressureMonitor::memory: cgroup (memory total=%zu bytes) (memory usage=%zu bytes) (memory usage percentage=%d bytes)", memoryTotal, memoryUsage, memoryUsagePercentageWithCgroup); 273 298 if (memoryUsagePercentageWithCgroup > memoryUsagePercentage) 274 299 memoryUsagePercentage = memoryUsagePercentageWithCgroup; 275 300 } 276 301 } 302 LOG_VERBOSE(MemoryPressure, "MemoryPressureMonitor::memory: memoryUsagePercentage (%d)", memoryUsagePercentage); 277 303 return memoryUsagePercentage; 278 304 }
Note: See TracChangeset
for help on using the changeset viewer.