Branch: refs/heads/main
  Home:   https://github.com/WebKit/WebKit
  Commit: 23997cdd825d50528bcc77d7b532e44541d6bf45
      
https://github.com/WebKit/WebKit/commit/23997cdd825d50528bcc77d7b532e44541d6bf45
  Author: Ben Nham <[email protected]>
  Date:   2026-08-25 (Tue, 25 Aug 2026)

  Changed paths:
    M Source/WebKit/UIProcess/API/Cocoa/WKWebViewPrivateForTesting.h
    M Source/WebKit/UIProcess/API/Cocoa/WKWebViewTesting.mm
    M Source/WebKit/UIProcess/AuxiliaryProcessProxy.cpp
    M Source/WebKit/UIProcess/AuxiliaryProcessProxy.h
    M Source/WebKit/UIProcess/Cocoa/ProcessAssertionCocoa.mm
    M Source/WebKit/UIProcess/ProcessAssertion.cpp
    M Source/WebKit/UIProcess/ProcessAssertion.h
    M Source/WebKit/UIProcess/ProcessThrottler.cpp
    M Source/WebKit/UIProcess/ProcessThrottler.h
    M Source/WebKit/UIProcess/WebProcessProxy.cpp
    M Tools/TestWebKitAPI/SourcesCocoa.txt
    A Tools/TestWebKitAPI/Tests/WebKit/WKWebView/ProcessJetsamPriority.mm

  Log Message:
  -----------
  Make prewarmed and cached processes run in idle jetsam band
https://bugs.webkit.org/show_bug.cgi?id=322336
rdar://185594943

Reviewed by Per Arne Vollan.

On Mac, cached and prewarmed processes run at the background rather than the 
idle jetsam priority
level for a few reasons:

- All processes run with a permanent jetsam boost assertion.
- Prewarmed processes run with a background lifetime activity until the first 
page attaches to the
  process (mostly due to the complexity around the 
setRunningBoardThrottlingEnabled pref).
- Cached processes purposely hold a background activity for ~30s (see 
cachedProcessSuspensionDelay)
  as a PLT optimization, which boosts the process to the background jetsam 
level for that period.

Ideally, cached and prewarmed processes would always be at the idle jetsam 
level, because that
allows the kernel jetsam to kill them to reclaim memory as necessary instead of 
needing to wait
until the memory pressure handler fires in the UIProcess (which can take a 
while since the system
purposely spaces out sending memory pressure notifications to avoid thundering 
herd issues).

(Note that processes in the WebBackForwardCache are already at idle jetsam 
level, since we only
insert them in to that cache if they are holding no activities.)

The cleanest way I could figure out how to shoehorn this in to the existing 
ProcessThrottler
machinery was to add a new ProcessThrottler property that makes background 
activities use the idle
jetsam band. This maps to a new BackgroundIdleBand assertion type.

One confusing thing is that the BackgroundIdleBand assertion type maps to the 
existing "Suspended"
assertion in LifecyclePolicy. Despite the name, this is an assertion type that 
allows the process,
to run, but at the idle jetsam priority, which is what we want here.

Testing that cached and prewarmed processes actually get to idle jetsam level 
reliably is pretty
tricky because we may refuse to spawn those types of processes while under 
memory pressure, and the
system might kill those processes before we can read their jetsam level. Also, 
reading the jetsam
level of a process as an unprivileged user can basically only done via `top`. 
Instead, the API test
here just makes sure that `setJetsamBoost` itself works.

Test: Tools/TestWebKitAPI/Tests/WebKit/WKWebView/ProcessJetsamPriority.mm

* Source/WebKit/UIProcess/API/Cocoa/WKWebViewPrivateForTesting.h:
* Source/WebKit/UIProcess/API/Cocoa/WKWebViewTesting.mm:
(-[WKWebView _processAssertionTypeForTesting]):
(-[WKWebView _setJetsamBoostEnabledForTesting:]):
* Source/WebKit/UIProcess/AuxiliaryProcessProxy.cpp:
(WebKit::AuxiliaryProcessProxy::didFinishLaunching):
(WebKit::AuxiliaryProcessProxy::setJetsamBoostEnabled):
(WebKit::AuxiliaryProcessProxy::updateJetsamBoostAssertion):
* Source/WebKit/UIProcess/AuxiliaryProcessProxy.h:
* Source/WebKit/UIProcess/Cocoa/ProcessAssertionCocoa.mm:
(WebKit::runningBoardNameForAssertionType):
(WebKit::runningBoardDomainForAssertionType):
(WebKit::ProcessAndUIAssertion::updateRunInBackgroundCount):
* Source/WebKit/UIProcess/ProcessAssertion.cpp:
(WebKit::processAssertionTypeDescription):
* Source/WebKit/UIProcess/ProcessAssertion.h:
* Source/WebKit/UIProcess/ProcessThrottler.cpp:
(WebKit::ProcessThrottler::assertionName const):
(WebKit::ProcessThrottler::assertionTypeForState):
(WebKit::ProcessThrottler::setThrottleState):
(WebKit::ProcessThrottler::acquireAssertion):
(WebKit::ProcessThrottler::setShouldBackgroundActivitiesUseIdleJetsamBand):
* Source/WebKit/UIProcess/ProcessThrottler.h:
(WebKit::ProcessThrottler::assertionTypeForTesting const):
* Source/WebKit/UIProcess/WebProcessProxy.cpp:
(WebKit::WebProcessProxy::create):
(WebKit::WebProcessProxy::setIsInProcessCache):
(WebKit::WebProcessProxy::markIsNoLongerInPrewarmedPool):
* Tools/TestWebKitAPI/SourcesCocoa.txt:
* Tools/TestWebKitAPI/Tests/WebKit/WKWebView/ProcessJetsamPriority.mm: Added.
(waitForAssertionType):
(TEST(ProcessJetsamPriority, 
DisablingJetsamBoostMovesBackgroundAssertionToIdleBand)):
(TEST(ProcessJetsamPriority, 
DisablingJetsamBoostDoesNotAffectForegroundAssertion)):

Canonical link: https://commits.webkit.org/319809@main



To unsubscribe from these emails, change your notification settings at 
https://github.com/WebKit/WebKit/settings/notifications

Reply via email to