Bug 239432

Summary: Suspend storage operations when network process is in background and will be suspended
Product: WebKit Reporter: Sihui Liu <sihui_liu>
Component: New BugsAssignee: Sihui Liu <sihui_liu>
Status: RESOLVED DUPLICATE    
Severity: Normal CC: cdumez, ggaren, webkit-bug-importer
Priority: P2 Keywords: InRadar
Version: WebKit Nightly Build   
Hardware: Unspecified   
OS: Unspecified   
Attachments:
Description Flags
Patch
none
Patch
none
Patch
none
Patch
none
Patch
none
Patch
none
Patch
none
Patch
none
Patch
none
Patch
ews-feeder: commit-queue-
Patch
ews-feeder: commit-queue-
Patch
ews-feeder: commit-queue-
Patch
none
Patch
ews-feeder: commit-queue-
Patch
none
Patch
none
Patch
none
Patch
ews-feeder: commit-queue-
Patch none

Sihui Liu
Reported 2022-04-17 00:34:15 PDT
...
Attachments
Patch (14.33 KB, patch)
2022-04-17 00:49 PDT, Sihui Liu
no flags
Patch (25.03 KB, patch)
2022-04-17 17:56 PDT, Sihui Liu
no flags
Patch (25.26 KB, patch)
2022-04-17 22:26 PDT, Sihui Liu
no flags
Patch (27.40 KB, patch)
2022-04-18 16:18 PDT, Sihui Liu
no flags
Patch (25.68 KB, patch)
2022-04-18 16:52 PDT, Sihui Liu
no flags
Patch (29.80 KB, patch)
2022-04-18 18:25 PDT, Sihui Liu
no flags
Patch (28.11 KB, patch)
2022-04-19 09:13 PDT, Sihui Liu
no flags
Patch (36.63 KB, patch)
2022-04-21 12:49 PDT, Sihui Liu
no flags
Patch (36.98 KB, patch)
2022-04-21 13:42 PDT, Sihui Liu
no flags
Patch (49.59 KB, patch)
2022-04-22 14:41 PDT, Sihui Liu
ews-feeder: commit-queue-
Patch (48.78 KB, patch)
2022-04-22 15:15 PDT, Sihui Liu
ews-feeder: commit-queue-
Patch (48.78 KB, patch)
2022-04-22 15:29 PDT, Sihui Liu
ews-feeder: commit-queue-
Patch (48.14 KB, patch)
2022-04-22 15:46 PDT, Sihui Liu
no flags
Patch (40.62 KB, patch)
2022-04-25 14:08 PDT, Sihui Liu
ews-feeder: commit-queue-
Patch (41.41 KB, patch)
2022-04-25 15:14 PDT, Sihui Liu
no flags
Patch (43.17 KB, patch)
2022-04-27 17:29 PDT, Sihui Liu
no flags
Patch (50.45 KB, patch)
2022-04-29 10:56 PDT, Sihui Liu
no flags
Patch (47.08 KB, patch)
2022-04-29 11:02 PDT, Sihui Liu
ews-feeder: commit-queue-
Patch (53.73 KB, patch)
2022-04-29 11:38 PDT, Sihui Liu
no flags
Sihui Liu
Comment 1 2022-04-17 00:49:37 PDT
Sihui Liu
Comment 2 2022-04-17 17:56:24 PDT
Sihui Liu
Comment 3 2022-04-17 22:26:15 PDT
Sihui Liu
Comment 4 2022-04-18 16:18:07 PDT
Sihui Liu
Comment 5 2022-04-18 16:52:35 PDT
Sihui Liu
Comment 6 2022-04-18 18:25:11 PDT
Sihui Liu
Comment 7 2022-04-19 09:13:56 PDT
Chris Dumez
Comment 8 2022-04-19 09:22:56 PDT
Comment on attachment 457906 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=457906&action=review > Source/WebKit/ChangeLog:9 > + However, this is not a very reliable singal, because UI process may not send the message before process typo: singal > Source/WebKit/ChangeLog:13 > + background notification as signal of suspension. It's possible that application process holds special assertion I can think of 2 issues here: 1. We are not supposed to use RunningBoard in child processes for security reasons AFAIK. 2. What if an app gets backgrounded, the timer starts (you suspend the db thread), then the app starts playing audible media and the RunningBoard timer stops? Presumably then, your db thread says suspended and we'll end up with the same old hangs when the page's JS does DB operations? I say "same old" because this is the kind of bug I caused the last time I tried to rely on app visibility to make suspension decisions (as mentioned off-line).
Sihui Liu
Comment 9 2022-04-21 12:49:58 PDT
Sihui Liu
Comment 10 2022-04-21 13:42:25 PDT
Sihui Liu
Comment 11 2022-04-22 14:41:39 PDT
Sihui Liu
Comment 12 2022-04-22 15:15:06 PDT
Sihui Liu
Comment 13 2022-04-22 15:29:05 PDT
Sihui Liu
Comment 14 2022-04-22 15:46:35 PDT
Radar WebKit Bug Importer
Comment 15 2022-04-24 00:35:15 PDT
Sihui Liu
Comment 16 2022-04-25 14:08:46 PDT
Sihui Liu
Comment 17 2022-04-25 15:14:05 PDT
Chris Dumez
Comment 18 2022-04-27 16:48:59 PDT
Comment on attachment 458302 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=458302&action=review > Source/WebKit/ChangeLog:10 > + However, this is not a very reliable singal, because UI process may not send the message before process typo: singal > Source/WebKit/ChangeLog:20 > + may send the suspend message earlier if ProcessThrottler says there is no activity left. So, the odds are that the WebContent process will keep running for those 5 seconds where the network process db thread is suspended. As a result, wouldn't it cause a WebContent process hang in case of Webstorage usage (which does sync IPC to the network process). If so, the WebProcess likely won't process the PrepareToSuspend IPC from the UIProcess. This means the WebProcess will not free its memory or make itself eligible for the freezer, making it way more likely to get jetsammed in the background. I wouldn't want to trade network process kills on suspensions with increased WebProcess jetsams (which are more noticeable to the user IMO). Or am I wrong and your patch deals with this in some way? > Source/WebKit/NetworkProcess/NetworkProcess.cpp:1536 > + WTFLogAlways("sihuil: [%p]NetworkProcess::deleteWebsiteData will removeAllPushSubscriptions session[%llu]", this, sessionID.toUInt64()); Oops.
Sihui Liu
Comment 19 2022-04-27 17:25:36 PDT
Comment on attachment 458302 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=458302&action=review >> Source/WebKit/ChangeLog:10 >> + However, this is not a very reliable singal, because UI process may not send the message before process > > typo: singal Will change. >> Source/WebKit/ChangeLog:20 >> + may send the suspend message earlier if ProcessThrottler says there is no activity left. > > So, the odds are that the WebContent process will keep running for those 5 seconds where the network process db thread is suspended. As a result, wouldn't it cause a WebContent process hang in case of Webstorage usage (which does sync IPC to the network process). > If so, the WebProcess likely won't process the PrepareToSuspend IPC from the UIProcess. This means the WebProcess will not free its memory or make itself eligible for the freezer, making it way more likely to get jetsammed in the background. > > I wouldn't want to trade network process kills on suspensions with increased WebProcess jetsams (which are more noticeable to the user IMO). > > Or am I wrong and your patch deals with this in some way? Yes, it's possible that this increases jetsam rate of web process, when: 1. web process needs to import StorageAreaMap syncly for executing localStorage or sessionStorage operations immediately (note we import it asyncly when an origin is loaded). 2. web process keeps running in background for over 25 seconds (with some background activities) and receives assertionWillInvalidate callback (sends prepareToSuspend) after ProcessStateMonitor's timer fires (note when process gets the assertion in less than 5s to the timeout, it will not receive invalidate message, thus not sending prepareToSuspend; leading to the process be jetsammed anyways). 3. web process will not be jetsammed if prepareToSuspend is called; and will be jetsammed if prepareToSuspend is not called. Considering the probability of meeting all conditions, the chance of increasing jetsam rate is not very likely to be noticeable. Also, if a web process uses much memory and runs for a long time in background, I think it's not surprising that it will get jetsammed at some point. A complete fix would be using ProcessStateMonitor to send prepareToSuspend and processDidResume messages (merging prepareToSuspend with setStorageOperationsSuspended message), and maybe ensure UI process gets the reply of prepareToSuspend from web processes before sending it to network process; but this change might be even more risky. I'd like to view the patch as a step towards the complete fix; and let's see how ProcessStateMonitor works in production. >> Source/WebKit/NetworkProcess/NetworkProcess.cpp:1536 >> + WTFLogAlways("sihuil: [%p]NetworkProcess::deleteWebsiteData will removeAllPushSubscriptions session[%llu]", this, sessionID.toUInt64()); > > Oops. :(
Sihui Liu
Comment 20 2022-04-27 17:29:47 PDT
Sihui Liu
Comment 21 2022-04-29 10:56:15 PDT
Sihui Liu
Comment 22 2022-04-29 11:02:07 PDT
Sihui Liu
Comment 23 2022-04-29 11:38:18 PDT
Sihui Liu
Comment 24 2022-05-17 14:33:07 PDT
*** This bug has been marked as a duplicate of bug 240359 ***
Note You need to log in before you can comment on or make changes to this bug.