Skip to content

Commit 44cb95d

Browse files
authored
Merge pull request #1340 from filipe-norte-red/wpe-2.38-service-worker-pressure-settings
Add dedicated memory pressure settings for service worker process
2 parents 6448608 + 447d9f2 commit 44cb95d

5 files changed

Lines changed: 56 additions & 3 deletions

File tree

Source/WTF/wtf/MemoryPressureHandler.cpp

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,7 @@ void MemoryPressureHandler::setMemoryUsagePolicyBasedOnFootprints(size_t footpri
297297
if (newPolicy == m_memoryUsagePolicy)
298298
return;
299299

300-
RELEASE_LOG(MemoryPressure, "Memory usage policy changed: %s -> %s", toString(m_memoryUsagePolicy), toString(newPolicy));
300+
RELEASE_LOG(MemoryPressure, "Memory usage policy changed (PID=%d): %s -> %s", getpid(), toString(m_memoryUsagePolicy), toString(newPolicy));
301301
m_memoryUsagePolicy = newPolicy;
302302
memoryPressureStatusChanged();
303303
}
@@ -307,7 +307,7 @@ void MemoryPressureHandler::measurementTimerFired()
307307
size_t footprint = memoryFootprint();
308308
size_t footprintVideo = memoryFootprintVideo();
309309
#if PLATFORM(COCOA)
310-
RELEASE_LOG(MemoryPressure, "Current memory footprint: %zu MB", footprint / MB);
310+
RELEASE_LOG(MemoryPressure, "Current memory footprint (PID=%d): %zu MB", getpid(), footprint / MB);
311311
#endif
312312
auto killThreshold = thresholdForMemoryKill(MemoryType::Normal);
313313
auto killThresholdVideo = thresholdForMemoryKill(MemoryType::Video);
@@ -385,13 +385,31 @@ void MemoryPressureHandler::setConfiguration(Configuration&& configuration)
385385
m_configuration = WTFMove(configuration);
386386
if (s_envBaseThresholdVideo)
387387
m_configuration.baseThresholdVideo = s_envBaseThresholdVideo;
388+
389+
RELEASE_LOG(MemoryPressure, "New memory pressure settings (PID=%d): bt=%u, btv=%u, ctf=%lf, stf=%lf, ktf=%lf, pi=%lf",
390+
getpid(),
391+
m_configuration.baseThreshold,
392+
m_configuration.baseThresholdVideo,
393+
m_configuration.conservativeThresholdFraction,
394+
m_configuration.strictThresholdFraction,
395+
m_configuration.killThresholdFraction ? *(m_configuration.killThresholdFraction) : -1.0,
396+
m_configuration.pollInterval.value());
388397
}
389398

390399
void MemoryPressureHandler::setConfiguration(const Configuration& configuration)
391400
{
392401
m_configuration = configuration;
393402
if (s_envBaseThresholdVideo)
394403
m_configuration.baseThresholdVideo = s_envBaseThresholdVideo;
404+
405+
RELEASE_LOG(MemoryPressure, "New memory pressure settings (PID=%d): bt=%u, btv=%u, ctf=%lf, stf=%lf, ktf=%lf, pi=%lf",
406+
getpid(),
407+
m_configuration.baseThreshold,
408+
m_configuration.baseThresholdVideo,
409+
m_configuration.conservativeThresholdFraction,
410+
m_configuration.strictThresholdFraction,
411+
m_configuration.killThresholdFraction ? *(m_configuration.killThresholdFraction) : -1.0,
412+
m_configuration.pollInterval.value());
395413
}
396414

397415
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
@@ -79,6 +79,7 @@ Ref<ProcessPoolConfiguration> ProcessPoolConfiguration::copy()
7979
#endif
8080
#if PLATFORM(GTK) || PLATFORM(WPE)
8181
copy->m_memoryPressureHandlerConfiguration = this->m_memoryPressureHandlerConfiguration;
82+
copy->m_serviceWorkerMemoryPressureHandlerConfiguration = this->m_serviceWorkerMemoryPressureHandlerConfiguration;
8283
#endif
8384
#if HAVE(AUDIT_TOKEN)
8485
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
@@ -159,6 +159,9 @@ class ProcessPoolConfiguration final : public ObjectImpl<Object::Type::ProcessPo
159159
#if PLATFORM(GTK) || PLATFORM(WPE)
160160
void setMemoryPressureHandlerConfiguration(const MemoryPressureHandler::Configuration& configuration) { m_memoryPressureHandlerConfiguration = configuration; }
161161
const std::optional<MemoryPressureHandler::Configuration>& memoryPressureHandlerConfiguration() const { return m_memoryPressureHandlerConfiguration; }
162+
163+
void setServiceWorkerMemoryPressureHandlerConfiguration(const MemoryPressureHandler::Configuration& configuration) { m_serviceWorkerMemoryPressureHandlerConfiguration = configuration; }
164+
const std::optional<MemoryPressureHandler::Configuration>& serviceWorkerMemoryPressureHandlerConfiguration() const { return m_serviceWorkerMemoryPressureHandlerConfiguration; }
162165
#endif
163166

164167
void setTimeZoneOverride(const WTF::String& timeZoneOverride) { m_timeZoneOverride = timeZoneOverride; }
@@ -201,6 +204,7 @@ class ProcessPoolConfiguration final : public ObjectImpl<Object::Type::ProcessPo
201204
#endif
202205
#if PLATFORM(GTK) || PLATFORM(WPE)
203206
std::optional<MemoryPressureHandler::Configuration> m_memoryPressureHandlerConfiguration;
207+
std::optional<MemoryPressureHandler::Configuration> m_serviceWorkerMemoryPressureHandlerConfiguration;
204208
#endif
205209
#if HAVE(AUDIT_TOKEN)
206210
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
@@ -130,6 +130,7 @@ enum {
130130
#endif
131131
PROP_MEMORY_PRESSURE_SETTINGS,
132132
PROP_TIME_ZONE_OVERRIDE,
133+
PROP_SERVICE_WORKER_MEMORY_PRESSURE_SETTINGS,
133134
N_PROPERTIES,
134135
};
135136

@@ -248,6 +249,7 @@ struct _WebKitWebContextPrivate {
248249
PAL::HysteresisActivity dnsPrefetchHystereris;
249250

250251
WebKitMemoryPressureSettings* memoryPressureSettings;
252+
WebKitMemoryPressureSettings* serviceWorkerMemoryPressureSettings;
251253

252254
CString timeZoneOverride;
253255
};
@@ -393,6 +395,11 @@ static void webkitWebContextSetProperty(GObject* object, guint propID, const GVa
393395
context->priv->memoryPressureSettings = settings ? webkit_memory_pressure_settings_copy(static_cast<WebKitMemoryPressureSettings*>(settings)) : nullptr;
394396
break;
395397
}
398+
case PROP_SERVICE_WORKER_MEMORY_PRESSURE_SETTINGS: {
399+
gpointer settings = g_value_get_boxed(value);
400+
context->priv->serviceWorkerMemoryPressureSettings = settings ? webkit_memory_pressure_settings_copy(static_cast<WebKitMemoryPressureSettings*>(settings)) : nullptr;
401+
break;
402+
}
396403
case PROP_TIME_ZONE_OVERRIDE: {
397404
const auto* timeZone = g_value_get_string(value);
398405
if (isTimeZoneValid(StringView::fromLatin1(timeZone)))
@@ -430,6 +437,11 @@ static void webkitWebContextConstructed(GObject* object)
430437
// Once the settings have been passed to the ProcessPoolConfiguration, we don't need them anymore so we can free them.
431438
g_clear_pointer(&priv->memoryPressureSettings, webkit_memory_pressure_settings_free);
432439
}
440+
if (priv->serviceWorkerMemoryPressureSettings) {
441+
configuration.setServiceWorkerMemoryPressureHandlerConfiguration(webkitMemoryPressureSettingsGetMemoryPressureHandlerConfiguration(priv->serviceWorkerMemoryPressureSettings));
442+
// Once the settings have been passed to the ProcessPoolConfiguration, we don't need them anymore so we can free them.
443+
g_clear_pointer(&priv->serviceWorkerMemoryPressureSettings, webkit_memory_pressure_settings_free);
444+
}
433445
configuration.setTimeZoneOverride(String::fromUTF8(priv->timeZoneOverride.data(), priv->timeZoneOverride.length()));
434446

435447
if (!priv->websiteDataManager)
@@ -593,6 +605,21 @@ static void webkit_web_context_class_init(WebKitWebContextClass* webContextClass
593605
WEBKIT_TYPE_MEMORY_PRESSURE_SETTINGS,
594606
static_cast<GParamFlags>(WEBKIT_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY));
595607

608+
/**
609+
* WebKitWebContext:service-worker-memory-pressure-settings:
610+
*
611+
* The #WebKitMemoryPressureSettings applied to the service worker web processes created by this context.
612+
*
613+
* Since: 2.38
614+
*/
615+
sObjProperties[PROP_SERVICE_WORKER_MEMORY_PRESSURE_SETTINGS] =
616+
g_param_spec_boxed(
617+
"service-worker-memory-pressure-settings",
618+
_("Service Worker Memory Pressure Settings"),
619+
_("The WebKitMemoryPressureSettings applied to the service worker web processes created by this context"),
620+
WEBKIT_TYPE_MEMORY_PRESSURE_SETTINGS,
621+
static_cast<GParamFlags>(WEBKIT_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY));
622+
596623
/**
597624
* WebKitWebContext:time-zone-override:
598625
*

Source/WebKit/UIProcess/glib/WebProcessPoolGLib.cpp

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

119-
parameters.memoryPressureHandlerConfiguration = m_configuration->memoryPressureHandlerConfiguration();
119+
if (process.isRunningServiceWorkers() && m_configuration->serviceWorkerMemoryPressureHandlerConfiguration())
120+
parameters.memoryPressureHandlerConfiguration = m_configuration->serviceWorkerMemoryPressureHandlerConfiguration();
121+
else
122+
parameters.memoryPressureHandlerConfiguration = m_configuration->memoryPressureHandlerConfiguration();
120123

121124
GApplication* app = g_application_get_default();
122125
if (app)

0 commit comments

Comments
 (0)