Closed Bug 1142806 Opened 10 years ago Closed 10 years ago

Follow-up Bug 852925 OOM_ADJ should not change for the topmost foreground task in the card view

Categories

(Firefox OS Graveyard :: Performance, defect)

ARM
Gonk (Firefox OS)
defect
Not set
normal

Tracking

(blocking-b2g:2.2+, firefox38 wontfix, firefox39 wontfix, firefox40 fixed, b2g-v2.2 fixed, b2g-master fixed)

RESOLVED FIXED
2.2 S10 (17apr)
blocking-b2g 2.2+
Tracking Status
firefox38 --- wontfix
firefox39 --- wontfix
firefox40 --- fixed
b2g-v2.2 --- fixed
b2g-master --- fixed

People

(Reporter: m1, Assigned: kanru)

References

Details

(Whiteboard: [caf priority: p2][CR 807539])

Attachments

(2 files, 2 obsolete files)

+++ This bug was initially created as a clone of Bug #852925 +++ This is follow-up of bug 852925 and should address the issue defined in the title and discussed in bug 852925. When the card view is entered, the OOM_ADJ value for the (previously) foreground application drops below the homescreen, preallocated process, and higher priority background processes. This makes it highly likely in a RAM constrained device that the (previously) foreground application will be killed in the simple scenario of: 1. User is in some app (say composing an email). 2. User press and holds home to enter the card view 3. User decides to "abort" the card view and returns to the app. (email is gone) Instead the OOM_ADJ values could be frozen in the card view until the user selects a different application.
blocking-b2g: --- → 2.2?
Whiteboard: [CR 807539]
Whiteboard: [CR 807539] → [caf priority: p2][CR 807539]
Hi Gabriele, As this is a follow-up to your work in bug 852925, what's the plan for fixing this and do you plan to create the fix within the fxOS 2.2 FC timeline? Thanks, Mike
Flags: needinfo?(gsvelto)
(In reply to Mike Lee [:mlee] from comment #1) > As this is a follow-up to your work in bug 852925, what's the plan for > fixing this and do you plan to create the fix within the fxOS 2.2 FC > timeline? I will try but I'm not sure if I'll have enough spare cycles.
Flags: needinfo?(gsvelto)
Hi Francisco, Since Gabriele is currently occupied with other critical issues please have someone else pick this up. Per CAF the scenario described in comment 0 leads to user data being lost if a user was composing an email before going to card view. Thanks, Mike
Flags: needinfo?(francisco)
Hi Mike, I wish we could find another candidate to pick this up, but our team is out of resources. Gabrielle do you have any suggestion for someone to picking this up, even if it's not in our team? (In reply to Mike Lee [:mlee] from comment #3) > Hi Francisco, > > Since Gabriele is currently occupied with other critical issues please have > someone else pick this up. Per CAF the scenario described in comment 0 leads > to user data being lost if a user was composing an email before going to > card view. > > Thanks, > Mike
Flags: needinfo?(francisco) → needinfo?(gsvelto)
There's two ways of fixing this: the first is in the system not to mark the former foreground card as hidden when entering the cards view. This second can be achieved in the process priority manager by demoting the homescreen to a regular background priority before the last foreground task is sent into the background (when no other foreground tasks are present which is the scenario we have here). I think I might be able to do this between today and tomorrow but if I can't the person who's looked at this code more lately is Kyle Huey who's done most of my reviews. Ting-Yu Chou, Kan-Ru Chen and Sean Lin have also landed patches in the past so they might be able to handle this too.
Flags: needinfo?(gsvelto)
I've tried working on this today but couldn't because I've had yet another dialer blocker landing in my lap yesterday. I'll be on PTO until the 6th of April so so I won't be able to be of further help before the FC date.
Thinker & Marco, As Gabriele & Kyle are both on PTO can you have someone on your team (i.e. Ting-Yu, Kan-Ru, or Sean) pick this up? Thanks, Mike
Flags: needinfo?(tlee)
Flags: needinfo?(mchen)
blocking-b2g: 2.2? → 2.2+
Hi Thinker, Could you help this issue because my team are working on different form-factors other then phone now?
Flags: needinfo?(mchen)
I'll take a look.
Assignee: nobody → kchen
Whoever available please review. I used third approach: try to keep at least one foreground process at any time. When a process is set to lower than foreground priority but it's the last foreground process, we delay the priority change until another process is set to foreground. That we could ensure "all processes are background" will not happen in normal operation.
Flags: needinfo?(tlee)
Attachment #8589543 - Flags: review?(khuey)
Attachment #8589543 - Flags: review?(gsvelto)
Comment on attachment 8589543 [details] [diff] [review] Try to keep at least one foreground process Review of attachment 8589543 [details] [diff] [review]: ----------------------------------------------------------------- This is a valid approach too but it has a few complications I've highlighted below. There's another problem besides the actual changes and that's modifying the existing mochitests. This is going to break quite a few of them since they expect that a foreground process which goes into the background is demoted immediately; you should modify them to comply with your changes, possibly by always using two iframes when there's only one so that when one is sent into the background you bring the other one to the foreground. Additionally you should a new test to cover the new scenarios introduced by your patch. ::: dom/ipc/ProcessPriorityManager.cpp @@ +678,5 @@ > + nsRefPtr<ParticularProcessPriorityManager> aValue, > + void* aUserData) > +{ > + uint32_t* accumulator = static_cast<uint32_t*>(aUserData); > + if (aValue->CurrentPriority() == PROCESS_PRIORITY_FOREGROUND) { You should count PROCESS_PRIORITY_FOREGROUND_HIGH processes too and not delay the priority downgrade if one is present. @@ +1125,5 @@ > + aPriority < PROCESS_PRIORITY_FOREGROUND && > + ProcessPriorityManagerImpl::GetSingleton()-> > + NumberOfForegroundProcesses() == 1) { > + LOGP("Attempting to demote the last foreground process is delayed."); > + ProcessPriorityManagerImpl::GetSingleton()-> You should also consider the case where the single process that was supposed to go into the background comes to the foreground again and the operation needs to be canceled.
Attachment #8589543 - Flags: review?(gsvelto) → review-
Comment on attachment 8590658 [details] [diff] [review] patch v2 Review of attachment 8590658 [details] [diff] [review]: ----------------------------------------------------------------- Great work fixing the tests and adding the new one but there's still a couple of issues to iron out. ::: dom/browser-element/mochitest/priority/test_Audio.html @@ +17,5 @@ > browserElementTestHelpers.setEnabledPref(true); > browserElementTestHelpers.addPermission(); > browserElementTestHelpers.enableProcessPriorityManager(); > > +function setupTest() { nit: Put a comment explaining why we have to do this here otherwise somebody who didn't know the rationale would find this odd. This applies to all other test files. ::: dom/ipc/ProcessPriorityManager.cpp @@ +678,5 @@ > + nsRefPtr<ParticularProcessPriorityManager> aValue, > + void* aUserData) > +{ > + uint32_t* accumulator = static_cast<uint32_t*>(aUserData); > + if (aValue->CurrentPriority() == PROCESS_PRIORITY_FOREGROUND) { As I mentioned in my previous review comment you should also count FOREGROUND_HIGH processes. If one is present there is no point in delaying the priority change and in fact it could regress performance (though only marginally now that we have cgroup support). @@ +1153,5 @@ > ProcessPriorityToString(mPriority)); > + > + if (aPriority >= PROCESS_PRIORITY_FOREGROUND) { > + LOGP("More than one foreground processes. Run delayed priority change"); > + ProcessPriorityManagerImpl::GetSingleton()-> What happens if the same process is sent into the background - thus delaying the priority change - and then back into the foreground? I get the feeling that this code will trigger and send it back into the background which is something we don't want. I think we should explicitly cancel the delayed change when this happens.
Attachment #8590658 - Flags: review?(gsvelto) → review-
(In reply to Gabriele Svelto [:gsvelto] from comment #13) > Comment on attachment 8590658 [details] [diff] [review] > patch v2 > > Review of attachment 8590658 [details] [diff] [review]: > ----------------------------------------------------------------- > > Great work fixing the tests and adding the new one but there's still a > couple of issues to iron out. > > ::: dom/browser-element/mochitest/priority/test_Audio.html > @@ +17,5 @@ > > browserElementTestHelpers.setEnabledPref(true); > > browserElementTestHelpers.addPermission(); > > browserElementTestHelpers.enableProcessPriorityManager(); > > > > +function setupTest() { > > nit: Put a comment explaining why we have to do this here otherwise somebody > who didn't know the rationale would find this odd. This applies to all other > test files. > > ::: dom/ipc/ProcessPriorityManager.cpp > @@ +678,5 @@ > > + nsRefPtr<ParticularProcessPriorityManager> aValue, > > + void* aUserData) > > +{ > > + uint32_t* accumulator = static_cast<uint32_t*>(aUserData); > > + if (aValue->CurrentPriority() == PROCESS_PRIORITY_FOREGROUND) { > > As I mentioned in my previous review comment you should also count > FOREGROUND_HIGH processes. If one is present there is no point in delaying > the priority change and in fact it could regress performance (though only > marginally now that we have cgroup support). > > @@ +1153,5 @@ > > ProcessPriorityToString(mPriority)); > > + > > + if (aPriority >= PROCESS_PRIORITY_FOREGROUND) { > > + LOGP("More than one foreground processes. Run delayed priority change"); > > + ProcessPriorityManagerImpl::GetSingleton()-> > > What happens if the same process is sent into the background - thus delaying > the priority change - and then back into the foreground? I get the feeling > that this code will trigger and send it back into the background which is > something we don't want. I think we should explicitly cancel the delayed > change when this happens. ouch. I did fix the first and second issues but failed to refresh my patch.. new patch on the way.
Attached patch patch v3Splinter Review
Attachment #8589543 - Attachment is obsolete: true
Attachment #8590658 - Attachment is obsolete: true
Attachment #8589543 - Flags: review?(khuey)
Attachment #8590747 - Flags: review?(gsvelto)
Comment on attachment 8590747 [details] [diff] [review] patch v3 Review of attachment 8590747 [details] [diff] [review]: ----------------------------------------------------------------- Looks good to me, excellent stuff!
Attachment #8590747 - Flags: review?(gsvelto) → review+
Thanks guys, dom/ipc/ProcessPriorityManager.cpp from comment 17 doesn't apply to v2.2. Could you please rebase so I can take it for a spin here before uplifting?
Status: NEW → RESOLVED
Closed: 10 years ago
Resolution: --- → FIXED
Target Milestone: --- → 2.2 S10 (17apr)
Attached patch patch for v2.2Splinter Review
Here you go.
Flags: needinfo?(mvines)
Flags: needinfo?(mvines)
Attachment #8592016 - Flags: feedback+
Comment on attachment 8592016 [details] [diff] [review] patch for v2.2 [Approval Request Comment] Bug caused by (feature/regressing bug #): Long standing bug User impact if declined: On low memory devices the current foreground app can be killed when switching to card view even though there should be enough memory to keep it around Testing completed: Tested on a device and in testsuite Risk to taking this patch (and alternatives if risky): This delays changes in the priorities of processes when there is only one foreground process, if this is buggy or does not work as advertised after switching processes foreground/background some priorities might be wrong. String or UUID changes made by this patch: None
Attachment #8592016 - Flags: approval-mozilla-b2g37?
:kanru, any additional testing that QA can help with here? Do you think its worth letting this bake on m-c for a few days before we uplift to the branch?
Flags: needinfo?(kchen)
(In reply to bhavana bajaj [:bajaj] from comment #22) > :kanru, any additional testing that QA can help with here? I'm not sure.. maybe some smoke test? I think we could leverage Michael's QA resource here. > Do you think its > worth letting this bake on m-c for a few days before we uplift to the branch? A few more days will definitely help us identify potential problems. So yes if we are not in a hurry.
Flags: needinfo?(kchen)
(In reply to Kan-Ru Chen [:kanru] from comment #23) > (In reply to bhavana bajaj [:bajaj] from comment #22) > > :kanru, any additional testing that QA can help with here? > > I'm not sure.. maybe some smoke test? I think we could leverage Michael's QA > resource here. > > > Do you think its > > worth letting this bake on m-c for a few days before we uplift to the branch? > > A few more days will definitely help us identify potential problems. So yes > if we are not in a hurry. :mvines/Inder, while we let this bake on our side, we think it'll be helpful if you guys can do some sanity testing around it to see if we discover any stability issues. The b2g37 patch is ready for you to pull into your repo, in-case you can help here. Thanks!
Flags: needinfo?(mvines)
Flags: needinfo?(ikumar)
We've had attachment 8592016 [details] [diff] [review] in our tree since 4/14, so far no issues we've seen since have been traced back to it. http://shipitsquirrel.github.io
Flags: needinfo?(mvines)
Flags: needinfo?(ikumar)
One behaviour I've observed is that even with this patch is that OOM_ADJ is not adjusted for all foreground apps. eg: 1. Start Contacts 2. Add new Contact. 3. Select contact picture 4. Camera app starts. 5. Hold task switcher |b2g-ps --oom| then looks something like this: APPLICATION SEC OOM_ADJ OOM_SCORE OOM_SCORE_ADJ USER PID PPID NAME b2g 0 0 200 0 root 5878 1 /system/b2g/b2g (Nuwa) 0 -17 0 -1000 root 5886 5878 /system/b2g/b2g Communications 2 12 768 667 u0_a10071 10071 5886 /system/b2g/b2g Camera 2 3 217 134 u0_a12730 12730 5886 /system/b2g/b2g (Preallocated a 2 6 334 300 u0_a13121 13121 5886 /system/b2g/b2g Communications is OOM_ADJ=12, ripe for the killing. This is about the worst possible thing we could do in this situation. Instead first kill "(Preallocated a", then "Camera" if needed.
(In reply to Michael Vines [:m1] [:evilmachines] from comment #26) > Communications is OOM_ADJ=12, ripe for the killing. This is about the worst > possible thing we could do in this situation. Instead first kill > "(Preallocated a", then "Camera" if needed. Ouch. This is unexpected and looks like a genuine regression. In this scenario both Camera and Communications should have OOM_ADJ set to 2. Can you check if backing out this patch solves the problem?
Flags: needinfo?(mvines)
(In reply to Gabriele Svelto [:gsvelto] from comment #27) > > Ouch. This is unexpected and looks like a genuine regression. In this > scenario both Camera and Communications should have OOM_ADJ set to 2. Can > you check if backing out this patch solves the problem? The OOM_ADJ values remain correct when not in the card view, I don't think this is a regression. When in the card view, if the logical foreground app is actually comprised of more than one content processes (eg, Camera picker from Contacts app) then the app that launched the picker moves to the background but not the picker itself. That's probably per-design of the current patch? Ideally the "oldest" content process that forms the logical for an application remains at the foreground process priority instead the "newest" (ie, the "picker" and least valuable to the user).
Flags: needinfo?(mvines)
(In reply to Michael Vines [:m1] [:evilmachines] from comment #28) > The OOM_ADJ values remain correct when not in the card view, I don't think > this is a regression. OK, I misunderstood that part. > When in the card view, if the logical foreground app is actually comprised > of more than one content processes (eg, Camera picker from Contacts app) > then the app that launched the picker moves to the background but not the > picker itself. That's probably per-design of the current patch? Ideally > the "oldest" content process that forms the logical for an application > remains at the foreground process priority instead the "newest" (ie, the > "picker" and least valuable to the user). Yes, the patch does indeed work this way. Unfortunately that's a situation where it's hard to tell which is the most important app. In the picker case (attach an image to a message) it's the older app, in the action case (sending a message from the contact list) it's the younger one. I'll file a follow up to address this stuff in a more thorough way but I'm not sure if I can make it in the 2.2+ timeframe.
(In reply to Gabriele Svelto [:gsvelto] from comment #29) > > Yes, the patch does indeed work this way. Unfortunately that's a situation > where it's hard to tell which is the most important app. In the picker case > (attach an image to a message) it's the older app, in the action case > (sending a message from the contact list) it's the younger one. I'll file a > follow up to address this stuff in a more thorough way but I'm not sure if I > can make it in the 2.2+ timeframe. SGTM, thanks.
Attachment #8592016 - Flags: approval-mozilla-b2g37? → approval-mozilla-b2g37+
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: