Closed Bug 1767346 Opened 3 years ago Closed 3 years ago

Fenix content process priority is never lowered when creating new tabs

Categories

(GeckoView Graveyard :: Sandboxing, defect, P1)

Unspecified
All

Tracking

(firefox-esr91 wontfix, firefox100 wontfix, firefox101 wontfix, firefox102 fixed)

RESOLVED FIXED
102 Branch
Tracking Status
firefox-esr91 --- wontfix
firefox100 --- wontfix
firefox101 --- wontfix
firefox102 --- fixed

People

(Reporter: agi, Assigned: emilio)

References

Details

(Whiteboard: [geckoview:m102])

Attachments

(1 file, 2 obsolete files)

Christian reported that the browser becomes unsable when opening a lot of new tabs. I looked into it a little bit and it looks like the process priority is never lowered when opening new tabs, this seems to be a bug around SetPriorityHint.

To reproduce:

  • Open new tab from the home screen in fenix (e.g. wikipedia.org)
  • Tap on Home button on the url bar
  • Open a new tab

Expected:

only one content process is high priority

Actual:

observe /proc/<content process id>/oom_score and notice that the score is low for both content processes

OK so the problem is that we're not actually setting mRenderLayers to false ever because of this line: https://searchfox.org/mozilla-central/rev/87ecd21d3ca517f8d90e49b32bf042a754ed8f18/dom/ipc/BrowserParent.cpp#3441-3447 since mIsPreservingLayers is always true for GeckoView.

Emilio, Mike, do you have opinions about letting renderLayers be false even when isPreservingLayers is true? or maybe we should change the name of renderLayers, the way the process manager uses it, it seems to be more like "is this tab visible" rather then "are we actually painting layers for this tab".

Flags: needinfo?(mconley)
Flags: needinfo?(emilio)

I'm confused, didn't such thing cause the tab previews not to work in the past? I might be misremembering.

(In reply to Emilio Cobos Álvarez (:emilio) from comment #2)

I'm confused, didn't such thing cause the tab previews not to work in the past? I might be misremembering.

I'm sure that's possibile. Perhaps we could make renderLayers read-only and have a separate property that can be read/written to, say, .active such that

renderLayers = active || isPreservingLayers;

?

But that property already exists and is .docshellIsActive, right?

Flags: needinfo?(emilio)

What kind of extra work are you seeing when in the background, are we not throttling the refresh driver and so on? Reading this we should be throttling the refresh driver and so on like we do on desktop.

Flags: needinfo?(agi)

Sorry I think there is a little bit of confusion here. This bug is not about doing too much work when in background, it's just specifically about the priority of background processes being incorrect.

The only content processes that should get high priority are the one that contain the current tab. We have a bug right now where we sometimes don't lower the priority of the background tabs processes on Android.

The process manager uses renderLayers and priorityHint to determine when a tab should be high priority: https://searchfox.org/mozilla-central/source/dom/ipc/BrowserHost.cpp#117-129

The problem is, when priorityHint is set, we try to read renderLayers to see if we should set the process to high priority, but if isPreservingLayers is true, renderLayers always return true, which means that we will never lower the priority of the process (even though we should): https://searchfox.org/mozilla-central/source/dom/ipc/BrowserHost.cpp#144-154

But that property already exists and is .docshellIsActive, right?

I see, so what you're suggesting is that instead of reading renderLayers we read docshellIsActive? is there an easy way in BrowserHost to know when active changes? It would be weird if we used the setter of renderLayers to know when active changes (or read renderLayers in the setter and active in the priorityHint setter).

Flags: needinfo?(agi)

Yes, something like what I attached should do.

Assignee: nobody → emilio
Attachment #9274851 - Attachment description: WIP: Bug 1767346 - Use browsing context activeness rather than renderLayers to determine process priority. → Bug 1767346 - Use browsing context activeness rather than renderLayers to determine process priority. r=mccr8
Status: NEW → ASSIGNED

Does this mean we're not running browser_ProcessPriorityManager.js on Android? Or is it not testing the right thing?

So apparently right now it is only run on windows: https://searchfox.org/mozilla-central/rev/997a56b018662e2940c99bbaf57a6ac9d1aa5422/dom/ipc/tests/browser.ini#12

But anyways I don't think browser tests run on Android (Geckoview doesn't have a TabBrowser and so on).

Ah, ok. Well, it would be good to have even a basic test, which would have caught this kind of issue.

I hope we have tests for activeness (bc activeness is reflected in document.visibilityState and so). And my extension to that test should cover this, android basically has https://searchfox.org/mozilla-central/rev/997a56b018662e2940c99bbaf57a6ac9d1aa5422/mobile/android/chrome/geckoview/geckoview.js#86

But yeah, agi do you know where could I extend a test for Android background tabs or so?

Flags: needinfo?(agi)

(In reply to Andrew McCreight [:mccr8] from comment #9)

Does this mean we're not running browser_ProcessPriorityManager.js on Android? Or is it not testing the right thing?

The problem was that the test wasn't testing this specific case (preserveLayers = true). But also yes we don't run browser tests on Android.

(In reply to Emilio Cobos Álvarez (:emilio) from comment #12)

I hope we have tests for activeness (bc activeness is reflected in document.visibilityState and so). And my extension to that test should cover this, android basically has https://searchfox.org/mozilla-central/rev/997a56b018662e2940c99bbaf57a6ac9d1aa5422/mobile/android/chrome/geckoview/geckoview.js#86

But yeah, agi do you know where could I extend a test for Android background tabs or so?

We thought we couldn't write one because the priority was always high during tests, turns out it's a quirk of our process priority code which always starts out as FOREGROUND to prevent killing processes too early after creation (before Gecko has the chance to raise the priority)

I attached a patch that has a test that currently fails but should pass after your patch, extensionCurrentTabRaisesPriority.

Blocks: 1767855
Flags: needinfo?(agi)
Pushed by ealvarez@mozilla.com: https://hg.mozilla.org/integration/autoland/rev/7b715c304c65 Use browsing context activeness rather than renderLayers to determine process priority. r=mccr8,mconley
Status: ASSIGNED → RESOLVED
Closed: 3 years ago
Resolution: --- → FIXED
Target Milestone: --- → 102 Branch

Agi says we don't need to uplift this fix to Beta 101.

This actually broke priorityHint even further, so I'm gonna ask the sheriffs to revert.

To reproduce in Fenix:

  • Open Fenix and load a web page, verify that /proc/<pid>/oom_score is below 100 for the tab:XX process (can check the PID with ps -A | grep org.mozilla)
  • Background Fenix -> oom_score should still be below 100, in my testing it's around 770

reverting the patch fixes this.

I'll separately land a test that will cover this case.

Backed out changeset 7b715c304c65 (bug 1767346) for breaking Android process prioritization.

Backout link: https://hg.mozilla.org/integration/autoland/rev/e6d2fef65b87d2eeeac54c1c86f28a8236f709e3

Status: RESOLVED → REOPENED
Flags: needinfo?(emilio)
Resolution: FIXED → ---
Target Milestone: 102 Branch → ---

Comment on attachment 9275028 [details]
Bug 1767346 - Add process priority test for Android.

Revision D145476 was moved to bug 1768101. Setting attachment 9275028 [details] to obsolete.

Attachment #9275028 - Attachment is obsolete: true
Depends on: 1768101
Blocks: 1764998
Whiteboard: [geckoview:m102]
Severity: -- → S3
Priority: -- → P1
Attachment #9277321 - Attachment is obsolete: true
Flags: needinfo?(mconley)
Flags: needinfo?(emilio)
Pushed by ealvarez@mozilla.com: https://hg.mozilla.org/integration/autoland/rev/7b3a02a659ef Use browsing context activeness rather than renderLayers to determine process priority. r=mccr8,mconley,geckoview-reviewers,agi

Backed out changeset 7b3a02a659ef (Bug 1767346) for causing geckoview failures.
Backout link
Push with failures <--> gv-junit-fis
Failure Log

Flags: needinfo?(emilio)
Flags: needinfo?(emilio)
Pushed by ealvarez@mozilla.com: https://hg.mozilla.org/integration/autoland/rev/72f023837df4 Use browsing context activeness rather than renderLayers to determine process priority. r=mccr8,mconley,geckoview-reviewers,agi
Status: REOPENED → RESOLVED
Closed: 3 years ago3 years ago
Resolution: --- → FIXED
Target Milestone: --- → 102 Branch
Regressions: 1770458

Moving content process management bugs to the new GeckoView::Sandboxing component.

Component: General → Sandboxing
Product: GeckoView → GeckoView Graveyard
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: