Changeset 263589 in webkit


Ignore:
Timestamp:
Jun 26, 2020 2:53:36 PM (4 years ago)
Author:
Pablo Saavedra
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):

Location:
trunk/Source/WebKit
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebKit/ChangeLog

    r263588 r263589  
     12020-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
    1132020-06-26  Jason Lawrence  <lawrence.j@apple.com>
    214
  • trunk/Source/WebKit/UIProcess/linux/MemoryPressureMonitor.cpp

    r262217 r263589  
    6161static const unsigned maxCgroupPath = 4096; // PATH_MAX = 4096 from (Linux) include/uapi/linux/limits.h
    6262
     63#define CGROUP_V2_HIERARCHY 0
    6364#define CGROUP_NAME_BUFFER_SIZE 40
    6465#define MEMINFO_TOKEN_BUFFER_SIZE 50
     
    175176    char cgroupPath[maxCgroupPath];
    176177    snprintf(cgroupPath, maxCgroupPath, s_cgroupMemoryPath, cgroupControllerName.data(), cgroupControllerPath.data(), cgroupFileName.data());
     178    LOG_VERBOSE(MemoryPressure, "Open: %s", cgroupPath);
    177179    FILE* file = fopen(cgroupPath, "r");
    178180    if (file)
     
    203205static CString getCgroupControllerPath(FILE* cgroupControllerFile, const char* controllerName)
    204206{
    205     CString cgroupMemoryControllerPath;
    206207    if (!cgroupControllerFile || fseek(cgroupControllerFile, 0, SEEK_SET))
    207208        return CString();
    208209
     210    CString cgroupMemoryControllerPath;
    209211    while (!feof(cgroupControllerFile)) {
     212        unsigned hierarchyId;
    210213        char name[CGROUP_NAME_BUFFER_SIZE + 1];
    211214        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)
    214218            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        }
    215228        if (!strcmp(name, controllerName)) {
    216             return CString(path);
    217         }
    218         if (!strcmp(name, "name=systemd"))
    219229            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();
    222245}
    223246
     
    266289
    267290    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);
    268292    if (memoryController->isActive()) {
    269293        memoryTotal = memoryController->getMemoryTotalWithCgroup();
     
    271295        if (memoryTotal != notSet && memoryUsage != notSet) {
    272296            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);
    273298            if (memoryUsagePercentageWithCgroup > memoryUsagePercentage)
    274299                memoryUsagePercentage = memoryUsagePercentageWithCgroup;
    275300        }
    276301    }
     302    LOG_VERBOSE(MemoryPressure, "MemoryPressureMonitor::memory: memoryUsagePercentage (%d)", memoryUsagePercentage);
    277303    return memoryUsagePercentage;
    278304}
Note: See TracChangeset for help on using the changeset viewer.