Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 20 additions & 1 deletion Source/WTF/wtf/MemoryPressureHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -258,8 +258,17 @@ size_t MemoryPressureHandler::calculateFootprintForPolicyDecision(size_t footpri
// Some devices accounts video memory into the process memory footprint (as file mappings - RSSFile).
// In such cases, we need to subtract the video memory from the process memory footprint
// to make the memory pressure policy decision based on the process memory footprint only.
if (s_videoMemoryInFootprint)
if (s_videoMemoryInFootprint) {
if (footprintVideo > footprint) {
// This means that s_videoMemoryInFootprint should not be set for this device
// or footprint and footprintVideo are coming from two different processes
// and shouldn't be compared with each other. Both cases are misconfigurations.
WTFLogAlways("Video memory footprint (%zu MB) is larger than total memory footprint (%zu MB). "
"Check MemoryPressureHandler configuration\n", footprintVideo / MB, footprint / MB);
return footprint;
}
footprint -= footprintVideo;
}
return footprint;
}

Expand Down Expand Up @@ -412,6 +421,16 @@ void MemoryPressureHandler::setConfiguration(const Configuration& configuration)
m_configuration.pollInterval.value());
}

void MemoryPressureHandler::disableGPUMemoryAccounting()
{
// Reset the GPU memory file to stop accounting video memory for this process
s_GPUMemoryFile = String();
s_envBaseThresholdVideo = 0;
s_videoMemoryInFootprint = false;

RELEASE_LOG(MemoryPressure, "GPU memory accounting disabled (PID=%d)", getpid());
}

void MemoryPressureHandler::releaseMemory(Critical critical, Synchronous synchronous)
{
if (!m_lowMemoryHandler)
Expand Down
1 change: 1 addition & 0 deletions Source/WTF/wtf/MemoryPressureHandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,7 @@ class MemoryPressureHandler {
};
void setConfiguration(Configuration&& configuration);
void setConfiguration(const Configuration& configuration);
void disableGPUMemoryAccounting();

WTF_EXPORT_PRIVATE void releaseMemory(Critical, Synchronous = Synchronous::No);

Expand Down
4 changes: 4 additions & 0 deletions Source/WebKit/WebProcess/glib/WebProcessGLib.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,10 @@ void WebProcess::platformInitializeWebProcess(WebProcessCreationParameters& para
if (parameters.memoryPressureHandlerConfiguration)
MemoryPressureHandler::singleton().setConfiguration(WTFMove(*parameters.memoryPressureHandlerConfiguration));

// Service worker processes are not expected to use GPU - disable GPU memory accounting
if (parameters.isServiceWorkerProcess)
MemoryPressureHandler::singleton().disableGPUMemoryAccounting();

if (!parameters.applicationID.isEmpty())
WebCore::setApplicationID(parameters.applicationID);

Expand Down