summaryrefslogtreecommitdiffstats
path: root/sandbox
diff options
context:
space:
mode:
authorgspencer@google.com <gspencer@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2011-08-23 17:58:21 +0000
committergspencer@google.com <gspencer@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2011-08-23 17:58:21 +0000
commit03eb9d27a79f876a039ca30eba54d1155ab5500b (patch)
tree91c377e970b5e117c09f657a01a172e5bf993709 /sandbox
parentc25c7be488ea694d9173374b985e73a5a6eed867 (diff)
downloadchromium_src-03eb9d27a79f876a039ca30eba54d1155ab5500b.zip
chromium_src-03eb9d27a79f876a039ca30eba54d1155ab5500b.tar.gz
chromium_src-03eb9d27a79f876a039ca30eba54d1155ab5500b.tar.bz2
Trying again to land OOM priority manager changes.
First landing failed because of an obscure problem with building linux_shared. This change passes the linux_shared trybot (and linux and linux_chromeos trybots). Changing OOM range to 0, 1000 and tweaking OOM algorithm. With this change, we now use the newer oom_score_adj file (with fallback to oom_adj when on a system that doesn't support it) so that we can take advantage of a finer range ([0, 1000] instead of [0, 15]). Also tweaked the OOM priority manager to prioritize things in a slightly different order, preferring (even more) not to kill tabs that the user has currently selected. Original review: http://codereview.chromium.org/7671033/ BUG=chromium-os:18421, chromium:65009 TEST=Ran on device, observed OOM adj values, forced OOM conditions to watch kills. Review URL: http://codereview.chromium.org/7708020 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@97888 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'sandbox')
-rw-r--r--sandbox/linux/suid/process_util.h13
-rw-r--r--sandbox/linux/suid/process_util_linux.c30
-rw-r--r--sandbox/linux/suid/sandbox.c3
3 files changed, 33 insertions, 13 deletions
diff --git a/sandbox/linux/suid/process_util.h b/sandbox/linux/suid/process_util.h
index 6bab897..1826555 100644
--- a/sandbox/linux/suid/process_util.h
+++ b/sandbox/linux/suid/process_util.h
@@ -13,11 +13,14 @@
#include "base/base_export.h"
-static const char kAdjustOOMScoreSwitch[] = "--adjust-oom-score";
-
-// This adjusts /proc/process/oom_adj so the Linux OOM killer will prefer
-// certain process types over others. The range for the adjustment is
-// [-17,15], with [0,15] being user accessible.
+// This adjusts /proc/process/oom_score_adj so the Linux OOM killer
+// will prefer certain process types over others. The range for the
+// adjustment is [-1000, 1000], with [0, 1000] being user accessible.
+//
+// If the Linux system isn't new enough to use oom_score_adj, then we
+// try to set the older oom_adj value instead, scaling the score to
+// the required range of [0, 15]. This may result in some aliasing of
+// values, of course.
BASE_EXPORT bool AdjustOOMScore(pid_t process, int score);
#endif // SANDBOX_LINUX_SUID_PROCESS_UTIL_H_
diff --git a/sandbox/linux/suid/process_util_linux.c b/sandbox/linux/suid/process_util_linux.c
index 17453de..13f45ce 100644
--- a/sandbox/linux/suid/process_util_linux.c
+++ b/sandbox/linux/suid/process_util_linux.c
@@ -1,4 +1,4 @@
-// Copyright (c) 2009 The Chromium Authors. All rights reserved.
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -19,8 +19,13 @@
#include <sys/types.h>
#include <unistd.h>
+// Ranges for the current (oom_score_adj) and previous (oom_adj)
+// flavors of OOM score.
+static const int kMaxOomScore = 1000;
+static const int kMaxOldOomScore = 15;
+
bool AdjustOOMScore(pid_t process, int score) {
- if (score < 0 || score > 15)
+ if (score < 0 || score > kMaxOomScore)
return false;
char oom_adj[27]; // "/proc/" + log_10(2**64) + "\0"
@@ -41,13 +46,24 @@ bool AdjustOOMScore(pid_t process, int score) {
return false;
}
- const int fd = openat(dirfd, "oom_adj", O_WRONLY);
+ int fd = openat(dirfd, "oom_score_adj", O_WRONLY);
+ if (fd < 0) {
+ // We failed to open oom_score_adj, so let's try for the older
+ // oom_adj file instead.
+ fd = openat(dirfd, "oom_adj", O_WRONLY);
+ if (fd < 0) {
+ // Nope, that doesn't work either.
+ return false;
+ } else {
+ // If we're using the old oom_adj file, the allowed range is now
+ // [0, kMaxOldOomScore], so we scale the score. This may result in some
+ // aliasing of values, of course.
+ score = score * kMaxOldOomScore / kMaxOomScore;
+ }
+ }
close(dirfd);
- if (fd < 0)
- return false;
-
- char buf[3]; // 0 <= |score| <= 15;
+ char buf[11]; // 0 <= |score| <= kMaxOomScore; using log_10(2**32) + 1 size
snprintf(buf, sizeof(buf), "%d", score);
size_t len = strlen(buf);
diff --git a/sandbox/linux/suid/sandbox.c b/sandbox/linux/suid/sandbox.c
index 1cf95284..a545208 100644
--- a/sandbox/linux/suid/sandbox.c
+++ b/sandbox/linux/suid/sandbox.c
@@ -1,4 +1,4 @@
-// Copyright (c) 2009 The Chromium Authors. All rights reserved.
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -37,6 +37,7 @@
#define CLONE_NEWNET 0x40000000
#endif
+static const char kAdjustOOMScoreSwitch[] = "--adjust-oom-score";
static const char kSandboxDescriptorEnvironmentVarName[] = "SBX_D";
static const char kSandboxHelperPidEnvironmentVarName[] = "SBX_HELPER_PID";