Skip to content

Commit c18bb63

Browse files
filipe-norte-redmagomez
authored andcommitted
MemoryPressure: add dedicated memory pressure settings for service worker process
1 parent 4a73d89 commit c18bb63

File tree

5 files changed

+56
-3
lines changed

5 files changed

+56
-3
lines changed

Source/WTF/wtf/MemoryPressureHandler.cpp

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,7 @@ void MemoryPressureHandler::setMemoryUsagePolicyBasedOnFootprints(size_t footpri
308308
if (newPolicy == m_memoryUsagePolicy)
309309
return;
310310

311-
RELEASE_LOG(MemoryPressure, "Memory usage policy changed: %s -> %s", toString(m_memoryUsagePolicy).characters(), toString(newPolicy).characters());
311+
RELEASE_LOG(MemoryPressure, "Memory usage policy changed (PID=%d): %s -> %s", getpid(), toString(m_memoryUsagePolicy).characters(), toString(newPolicy).characters());
312312
m_memoryUsagePolicy = newPolicy;
313313
memoryPressureStatusChanged();
314314
}
@@ -329,7 +329,7 @@ void MemoryPressureHandler::measurementTimerFired()
329329
size_t footprint = memoryFootprint();
330330
size_t footprintVideo = memoryFootprintVideo();
331331
#if PLATFORM(COCOA)
332-
RELEASE_LOG(MemoryPressure, "Current memory footprint: %zu MB", footprint / MB);
332+
RELEASE_LOG(MemoryPressure, "Current memory footprint (PID=%d): %zu MB", getpid(), footprint / MB);
333333
#endif
334334

335335
while (m_memoryFootprintNotificationThresholds.size() && footprint > m_memoryFootprintNotificationThresholds.last()) {
@@ -424,13 +424,31 @@ void MemoryPressureHandler::setConfiguration(Configuration&& configuration)
424424
m_configuration = WTFMove(configuration);
425425
if (s_envBaseThresholdVideo)
426426
m_configuration.baseThresholdVideo = s_envBaseThresholdVideo;
427+
428+
RELEASE_LOG(MemoryPressure, "New memory pressure settings (PID=%d): bt=%u, btv=%u, ctf=%lf, stf=%lf, ktf=%lf, pi=%lf",
429+
getpid(),
430+
m_configuration.baseThreshold,
431+
m_configuration.baseThresholdVideo,
432+
m_configuration.conservativeThresholdFraction,
433+
m_configuration.strictThresholdFraction,
434+
m_configuration.killThresholdFraction ? *(m_configuration.killThresholdFraction) : -1.0,
435+
m_configuration.pollInterval.value());
427436
}
428437

429438
void MemoryPressureHandler::setConfiguration(const Configuration& configuration)
430439
{
431440
m_configuration = configuration;
432441
if (s_envBaseThresholdVideo)
433442
m_configuration.baseThresholdVideo = s_envBaseThresholdVideo;
443+
444+
RELEASE_LOG(MemoryPressure, "New memory pressure settings (PID=%d): bt=%u, btv=%u, ctf=%lf, stf=%lf, ktf=%lf, pi=%lf",
445+
getpid(),
446+
m_configuration.baseThreshold,
447+
m_configuration.baseThresholdVideo,
448+
m_configuration.conservativeThresholdFraction,
449+
m_configuration.strictThresholdFraction,
450+
m_configuration.killThresholdFraction ? *(m_configuration.killThresholdFraction) : -1.0,
451+
m_configuration.pollInterval.value());
434452
}
435453

436454
void MemoryPressureHandler::releaseMemory(Critical critical, Synchronous synchronous)

Source/WebKit/UIProcess/API/APIProcessPoolConfiguration.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ Ref<ProcessPoolConfiguration> ProcessPoolConfiguration::copy()
7777
#if PLATFORM(GTK) || PLATFORM(WPE)
7878
copy->m_memoryPressureHandlerConfiguration = this->m_memoryPressureHandlerConfiguration;
7979
copy->m_disableFontHintingForTesting = this->m_disableFontHintingForTesting;
80+
copy->m_serviceWorkerMemoryPressureHandlerConfiguration = this->m_serviceWorkerMemoryPressureHandlerConfiguration;
8081
#endif
8182
#if HAVE(AUDIT_TOKEN)
8283
copy->m_presentingApplicationProcessToken = this->m_presentingApplicationProcessToken;

Source/WebKit/UIProcess/API/APIProcessPoolConfiguration.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,9 @@ class ProcessPoolConfiguration final : public ObjectImpl<Object::Type::ProcessPo
153153

154154
bool disableFontHintingForTesting() const { return m_disableFontHintingForTesting; }
155155
void setDisableFontHintingForTesting(bool override) { m_disableFontHintingForTesting = override; }
156+
157+
void setServiceWorkerMemoryPressureHandlerConfiguration(const MemoryPressureHandler::Configuration& configuration) { m_serviceWorkerMemoryPressureHandlerConfiguration = configuration; }
158+
const std::optional<MemoryPressureHandler::Configuration>& serviceWorkerMemoryPressureHandlerConfiguration() const { return m_serviceWorkerMemoryPressureHandlerConfiguration; }
156159
#endif
157160

158161
void setTimeZoneOverride(const WTF::String& timeZoneOverride) { m_timeZoneOverride = timeZoneOverride; }
@@ -204,6 +207,7 @@ class ProcessPoolConfiguration final : public ObjectImpl<Object::Type::ProcessPo
204207
#if PLATFORM(GTK) || PLATFORM(WPE)
205208
std::optional<MemoryPressureHandler::Configuration> m_memoryPressureHandlerConfiguration;
206209
bool m_disableFontHintingForTesting { false };
210+
std::optional<MemoryPressureHandler::Configuration> m_serviceWorkerMemoryPressureHandlerConfiguration;
207211
#endif
208212
#if HAVE(AUDIT_TOKEN)
209213
std::optional<audit_token_t> m_presentingApplicationProcessToken;

Source/WebKit/UIProcess/API/glib/WebKitWebContext.cpp

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@ enum {
135135
#endif
136136
PROP_MEMORY_PRESSURE_SETTINGS,
137137
PROP_TIME_ZONE_OVERRIDE,
138+
PROP_SERVICE_WORKER_MEMORY_PRESSURE_SETTINGS,
138139
N_PROPERTIES,
139140
};
140141

@@ -292,6 +293,7 @@ struct _WebKitWebContextPrivate {
292293
#endif
293294

294295
WebKitMemoryPressureSettings* memoryPressureSettings;
296+
WebKitMemoryPressureSettings* serviceWorkerMemoryPressureSettings;
295297

296298
CString timeZoneOverride;
297299
};
@@ -419,6 +421,11 @@ static void webkitWebContextSetProperty(GObject* object, guint propID, const GVa
419421
context->priv->memoryPressureSettings = settings ? webkit_memory_pressure_settings_copy(static_cast<WebKitMemoryPressureSettings*>(settings)) : nullptr;
420422
break;
421423
}
424+
case PROP_SERVICE_WORKER_MEMORY_PRESSURE_SETTINGS: {
425+
gpointer settings = g_value_get_boxed(value);
426+
context->priv->serviceWorkerMemoryPressureSettings = settings ? webkit_memory_pressure_settings_copy(static_cast<WebKitMemoryPressureSettings*>(settings)) : nullptr;
427+
break;
428+
}
422429
case PROP_TIME_ZONE_OVERRIDE: {
423430
const auto* timeZone = g_value_get_string(value);
424431
if (isTimeZoneValid(StringView::fromLatin1(timeZone)))
@@ -460,6 +467,11 @@ static void webkitWebContextConstructed(GObject* object)
460467
g_clear_pointer(&priv->memoryPressureSettings, webkit_memory_pressure_settings_free);
461468
}
462469
configuration.setTimeZoneOverride(String::fromUTF8(priv->timeZoneOverride.span()));
470+
if (priv->serviceWorkerMemoryPressureSettings) {
471+
configuration.setServiceWorkerMemoryPressureHandlerConfiguration(webkitMemoryPressureSettingsGetMemoryPressureHandlerConfiguration(priv->serviceWorkerMemoryPressureSettings));
472+
// Once the settings have been passed to the ProcessPoolConfiguration, we don't need them anymore so we can free them.
473+
g_clear_pointer(&priv->serviceWorkerMemoryPressureSettings, webkit_memory_pressure_settings_free);
474+
}
463475

464476
#if !ENABLE(2022_GLIB_API)
465477
if (!priv->websiteDataManager)
@@ -623,6 +635,21 @@ static void webkit_web_context_class_init(WebKitWebContextClass* webContextClass
623635
WEBKIT_TYPE_MEMORY_PRESSURE_SETTINGS,
624636
static_cast<GParamFlags>(WEBKIT_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY));
625637

638+
/**
639+
* WebKitWebContext:service-worker-memory-pressure-settings:
640+
*
641+
* The #WebKitMemoryPressureSettings applied to the service worker web processes created by this context.
642+
*
643+
* Since: 2.38
644+
*/
645+
sObjProperties[PROP_SERVICE_WORKER_MEMORY_PRESSURE_SETTINGS] =
646+
g_param_spec_boxed(
647+
"service-worker-memory-pressure-settings",
648+
_("Service Worker Memory Pressure Settings"),
649+
_("The WebKitMemoryPressureSettings applied to the service worker web processes created by this context"),
650+
WEBKIT_TYPE_MEMORY_PRESSURE_SETTINGS,
651+
static_cast<GParamFlags>(WEBKIT_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY));
652+
626653
/**
627654
* WebKitWebContext:time-zone-override:
628655
*

Source/WebKit/UIProcess/glib/WebProcessPoolGLib.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,10 @@ void WebProcessPool::platformInitializeWebProcess(const WebProcessProxy& process
231231
parameters.useSystemAppearanceForScrollbars = m_configuration->useSystemAppearanceForScrollbars();
232232
#endif
233233

234-
parameters.memoryPressureHandlerConfiguration = m_configuration->memoryPressureHandlerConfiguration();
234+
if (process.isRunningServiceWorkers() && m_configuration->serviceWorkerMemoryPressureHandlerConfiguration())
235+
parameters.memoryPressureHandlerConfiguration = m_configuration->serviceWorkerMemoryPressureHandlerConfiguration();
236+
else
237+
parameters.memoryPressureHandlerConfiguration = m_configuration->memoryPressureHandlerConfiguration();
235238

236239
parameters.disableFontHintingForTesting = m_configuration->disableFontHintingForTesting();
237240

0 commit comments

Comments
 (0)