Skip to content
This repository has been archived by the owner on Aug 4, 2022. It is now read-only.

Commit

Permalink
Bug 822325: Implement an LRU pool for background app processes. The L…
Browse files Browse the repository at this point in the history
…RU app will get the smallest oom_adj and get killed last. r=khuey
  • Loading branch information
AlanHuang committed Oct 1, 2013
1 parent 90f552b commit 980d515
Show file tree
Hide file tree
Showing 11 changed files with 441 additions and 18 deletions.
5 changes: 5 additions & 0 deletions b2g/app/b2g.js
Original file line number Diff line number Diff line change
Expand Up @@ -603,6 +603,11 @@ pref("dom.ipc.processPriorityManager.enabled", true);
pref("dom.ipc.processPriorityManager.backgroundGracePeriodMS", 1000);
pref("dom.ipc.processPriorityManager.temporaryPriorityLockMS", 5000);

// Number of different background levels for background processes. We use
// these different levels to force the low-memory killer to kill processes in
// a LRU order.
pref("dom.ipc.processPriorityManager.backgroundLRUPoolLevels", 5);

// Kernel parameters for process priorities. These affect how processes are
// killed on low-memory and their relative CPU priorities.
//
Expand Down
32 changes: 32 additions & 0 deletions dom/browser-element/mochitest/browserElementTestHelpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ const browserElementTestHelpers = {
enableProcessPriorityManager: function() {
this._setPref('dom.ipc.processPriorityManager.testMode', true);
this._setPref('dom.ipc.processPriorityManager.enabled', true);
this._setPref('dom.ipc.processPriorityManager.backgroundLRUPoolLevels', 2);
},

setEnabledPref: function(value) {
Expand Down Expand Up @@ -193,6 +194,37 @@ function expectPriorityChange(childID, expectedPriority,
return deferred.promise;
}

// Returns a promise which is resolved or rejected the next time the background
// process childID changes its priority. We resolve if the backgroundLRU
// matches expectedBackgroundLRU and we reject otherwise.

function expectPriorityWithBackgroundLRUSet(childID, expectedBackgroundLRU) {
var deferred = Promise.defer();

browserElementTestHelpers.addProcessPriorityObserver(
'process-priority-with-background-LRU-set',
function(subject, topic, data) {

[id, priority, cpuPriority, backgroundLRU] = data.split(":");
if (id != childID) {
return;
}

is(backgroundLRU, expectedBackgroundLRU,
'Expected backgroundLRU ' + backgroundLRU + ' of childID ' + childID +
' to change to ' + expectedBackgroundLRU);

if (backgroundLRU == expectedBackgroundLRU) {
deferred.resolve();
} else {
deferred.reject();
}
}
);

return deferred.promise;
}

// Returns a promise which is resolved the first time the given iframe fires
// the mozbrowser##eventName event.
function expectMozbrowserEvent(iframe, eventName) {
Expand Down
1 change: 1 addition & 0 deletions dom/browser-element/mochitest/priority/Makefile.in
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ MOCHITEST_FILES = \
test_HighPriorityDowngrade.html \
test_HighPriorityDowngrade2.html \
test_Background.html \
test_BackgroundLRU.html \
test_Audio.html \
file_Audio.html \
silence.ogg \
Expand Down
67 changes: 67 additions & 0 deletions dom/browser-element/mochitest/priority/test_BackgroundLRU.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
<!DOCTYPE HTML>
<html>
<!--
Test that calling setVisible('false') on two iframes causes the former one's priority with background LRU to
change.
-->
<head>
<script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
<script type="application/javascript" src="../browserElementTestHelpers.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
</head>
<body>

<script type="application/javascript;version=1.7">
"use strict";

SimpleTest.waitForExplicitFinish();
browserElementTestHelpers.setEnabledPref(true);
browserElementTestHelpers.addPermission();
browserElementTestHelpers.enableProcessPriorityManager();
SpecialPowers.addPermission("embed-apps", true, document);

function runTest() {
var iframe1 = document.createElement('iframe');
iframe1.setAttribute('mozbrowser', true);
iframe1.src = 'file_MultipleFrames.html';

var iframe2 = null;
var childID = null;

expectProcessCreated().then(function(chid) {
childID = chid;
return expectPriorityChange(childID, 'FOREGROUND');
}).then(function() {
return expectMozbrowserEvent(iframe1, 'openwindow');
}).then(function() {
var p = expectPriorityChange(childID, 'BACKGROUND');
iframe1.setVisible(false);
return p;
}).then(function() {
iframe2 = document.createElement('iframe');
iframe2.setAttribute('mozbrowser', true);
iframe2.setAttribute('mozapp', 'http://example.org/manifest.webapp');
iframe2.src = browserElementTestHelpers.emptyPage1;

document.body.appendChild(iframe2);

// At this point, we should have iframe1 in background already.
// We wait until another one is set to background, too.
// Once there are two in background, the first one (LRU order)
// should have 'backgroundLRU' equals 1
var p = expectPriorityWithBackgroundLRUSet(childID, '1');
iframe2.setVisible(false);
document.body.removeChild(iframe2);

return p;

}).then(SimpleTest.finish);

document.body.appendChild(iframe1);
}

addEventListener('testready', runTest);

</script>
</body>
</html>
Loading

0 comments on commit 980d515

Please sign in to comment.