Bug 785171 - Support OOM adjustment via /proc/<pid>/oom_score_adj. r=dhylands
authorThomas Zimmermann <tdz@users.sourceforge.net>
Fri, 14 Sep 2012 11:52:07 -0700
changeset 107215 b4ce18b3224175c69b3228a83d3022956effccde
parent 107214 54f940cf6d6514b03416890d4f5216dcfde12509
child 107216 0b3f5ceb618a55680997e1ca470585c526182f14
push id74
push usershu@rfrn.org
push dateTue, 18 Sep 2012 19:23:47 +0000
reviewersdhylands
bugs785171
milestone18.0a1
Bug 785171 - Support OOM adjustment via /proc/<pid>/oom_score_adj. r=dhylands The interface /proc/<pid>/oom_score_adj has been added as a replacement for /proc/<pid>/oom_adj. It is now supported and used by default within Gonk. If oom_scrore_adj is not available, the code falls back to the old interface.
hal/gonk/GonkHal.cpp
--- a/hal/gonk/GonkHal.cpp
+++ b/hal/gonk/GonkHal.cpp
@@ -902,20 +902,27 @@ SetProcessPriority(int aPid, ProcessPrio
     if(clampedOomScoreAdj != oomScoreAdj) {
       HAL_LOG(("Clamping OOM adjustment for pid %d to %d",
                aPid, clampedOomScoreAdj));
     } else {
       HAL_LOG(("Setting OOM adjustment for pid %d to %d",
                aPid, clampedOomScoreAdj));
     }
 
-    int oomAdj = oomAdjOfOomScoreAdj(clampedOomScoreAdj);
+    // We try the newer interface first, and fall back to the older interface
+    // on failure.
 
-    WriteToFile(nsPrintfCString("/proc/%d/oom_adj", aPid).get(),
-                nsPrintfCString("%d", oomAdj).get());
+    if (!WriteToFile(nsPrintfCString("/proc/%d/oom_score_adj", aPid).get(),
+                     nsPrintfCString("%d", clampedOomScoreAdj).get()))
+    {
+      int oomAdj = oomAdjOfOomScoreAdj(clampedOomScoreAdj);
+
+      WriteToFile(nsPrintfCString("/proc/%d/oom_adj", aPid).get(),
+                  nsPrintfCString("%d", oomAdj).get());
+    }
   }
 
   int32_t nice = 0;
   rv = Preferences::GetInt(nsPrintfCString(
     "hal.processPriorityManager.gonk.%sNice", priorityStr).get(), &nice);
   if (NS_SUCCEEDED(rv)) {
     HAL_LOG(("Setting nice for pid %d to %d", aPid, nice));