From b22bcfe208ba3574213a454245848dbe60cd15ae Mon Sep 17 00:00:00 2001 From: Cervantes Yu Date: Thu, 13 Mar 2014 15:24:42 +0800 Subject: [PATCH] Bug 959966: prevent the preallocated process from being killed by the lowmem killer by rasing its priority. r=khuey,gsvelto --- b2g/app/b2g.js | 3 +++ .../mochitest/priority/test_Preallocated.html | 2 +- dom/ipc/ContentParent.cpp | 4 ++-- dom/ipc/ProcessPriorityManager.cpp | 4 ++++ hal/Hal.cpp | 9 +++++++++ hal/HalTypes.h | 3 +++ hal/gonk/GonkHal.cpp | 3 +++ 7 files changed, 25 insertions(+), 3 deletions(-) diff --git a/b2g/app/b2g.js b/b2g/app/b2g.js index bbc464bc799..d39a51089c8 100644 --- a/b2g/app/b2g.js +++ b/b2g/app/b2g.js @@ -650,6 +650,9 @@ pref("hal.processPriorityManager.gonk.MASTER.OomScoreAdjust", 0); pref("hal.processPriorityManager.gonk.MASTER.KillUnderKB", 4096); pref("hal.processPriorityManager.gonk.MASTER.Nice", 0); +pref("hal.processPriorityManager.gonk.PREALLOC.OomScoreAdjust", 67); +pref("hal.processPriorityManager.gonk.PREALLOC.Nice", 18); + pref("hal.processPriorityManager.gonk.FOREGROUND_HIGH.OomScoreAdjust", 67); pref("hal.processPriorityManager.gonk.FOREGROUND_HIGH.KillUnderKB", 5120); pref("hal.processPriorityManager.gonk.FOREGROUND_HIGH.Nice", 0); diff --git a/dom/browser-element/mochitest/priority/test_Preallocated.html b/dom/browser-element/mochitest/priority/test_Preallocated.html index f5f99683f8a..a85c481c82a 100644 --- a/dom/browser-element/mochitest/priority/test_Preallocated.html +++ b/dom/browser-element/mochitest/priority/test_Preallocated.html @@ -61,7 +61,7 @@ function runTest() // Ensure that the preallocated process initially gets BACKGROUND priority. // That's it. expectProcessCreated().then(function(childID) { - return expectPriorityChange(childID, 'BACKGROUND'); + return expectPriorityChange(childID, 'PREALLOC'); }).then(function() { cleanUp(); SimpleTest.finish(); diff --git a/dom/ipc/ContentParent.cpp b/dom/ipc/ContentParent.cpp index 69aeab87de2..8b8e2124629 100644 --- a/dom/ipc/ContentParent.cpp +++ b/dom/ipc/ContentParent.cpp @@ -448,7 +448,7 @@ ContentParent::PreallocateAppProcess() new ContentParent(/* app = */ nullptr, /* isForBrowserElement = */ false, /* isForPreallocated = */ true, - PROCESS_PRIORITY_BACKGROUND); + PROCESS_PRIORITY_PREALLOC); process->Init(); return process.forget(); } @@ -1464,7 +1464,7 @@ ContentParent::ContentParent(ContentParent* aTemplate, // memory priority, which it has inherited from this process. ProcessPriority priority; if (IsPreallocated()) { - priority = PROCESS_PRIORITY_BACKGROUND; + priority = PROCESS_PRIORITY_PREALLOC; } else { priority = PROCESS_PRIORITY_FOREGROUND; } diff --git a/dom/ipc/ProcessPriorityManager.cpp b/dom/ipc/ProcessPriorityManager.cpp index 5bad2420c5f..ac4633b65a9 100644 --- a/dom/ipc/ProcessPriorityManager.cpp +++ b/dom/ipc/ProcessPriorityManager.cpp @@ -945,6 +945,10 @@ ParticularProcessPriorityManager::ComputePriority() ProcessCPUPriority ParticularProcessPriorityManager::ComputeCPUPriority() { + if (mPriority == PROCESS_PRIORITY_PREALLOC) { + return PROCESS_CPU_PRIORITY_LOW; + } + if (mPriority >= PROCESS_PRIORITY_FOREGROUND_HIGH) { return PROCESS_CPU_PRIORITY_NORMAL; } diff --git a/hal/Hal.cpp b/hal/Hal.cpp index ced34278fb7..f08a4e34945 100644 --- a/hal/Hal.cpp +++ b/hal/Hal.cpp @@ -884,6 +884,8 @@ ProcessPriorityToString(ProcessPriority aPriority) switch (aPriority) { case PROCESS_PRIORITY_MASTER: return "MASTER"; + case PROCESS_PRIORITY_PREALLOC: + return "PREALLOC"; case PROCESS_PRIORITY_FOREGROUND_HIGH: return "FOREGROUND_HIGH"; case PROCESS_PRIORITY_FOREGROUND: @@ -934,6 +936,13 @@ ProcessPriorityToString(ProcessPriority aPriority, if (aCPUPriority == PROCESS_CPU_PRIORITY_LOW) { return "MASTER:CPU_LOW"; } + case PROCESS_PRIORITY_PREALLOC: + if (aCPUPriority == PROCESS_CPU_PRIORITY_NORMAL) { + return "PREALLOC:CPU_NORMAL"; + } + if (aCPUPriority == PROCESS_CPU_PRIORITY_LOW) { + return "PREALLOC:CPU_LOW"; + } case PROCESS_PRIORITY_FOREGROUND_HIGH: if (aCPUPriority == PROCESS_CPU_PRIORITY_NORMAL) { return "FOREGROUND_HIGH:CPU_NORMAL"; diff --git a/hal/HalTypes.h b/hal/HalTypes.h index 271dbc64c6e..35c0c2553c7 100644 --- a/hal/HalTypes.h +++ b/hal/HalTypes.h @@ -84,6 +84,9 @@ enum ProcessPriority { PROCESS_PRIORITY_BACKGROUND_HOMESCREEN, PROCESS_PRIORITY_BACKGROUND_PERCEIVABLE, PROCESS_PRIORITY_FOREGROUND_KEYBOARD, + // The special class for the preallocated process, high memory priority but + // low CPU priority. + PROCESS_PRIORITY_PREALLOC, // Any priority greater than or equal to FOREGROUND is considered // "foreground" for the purposes of priority testing, for example // CurrentProcessIsForeground(). diff --git a/hal/gonk/GonkHal.cpp b/hal/gonk/GonkHal.cpp index 36e91043b65..4c751926d5d 100644 --- a/hal/gonk/GonkHal.cpp +++ b/hal/gonk/GonkHal.cpp @@ -1258,6 +1258,9 @@ EnsureKernelLowMemKillerParamsSet() nsPrintfCString("hal.processPriorityManager.gonk.%s.KillUnderKB", ProcessPriorityToString(priority)).get(), &killUnderKB))) { + // ProcessPriority values like PROCESS_PRIORITY_FOREGROUND_KEYBOARD, + // which has only OomScoreAdjust but lacks KillUnderMB value, will not + // create new LMK parameters. continue; }