Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(777)

Unified Diff: sandbox/linux/suid/process_util_linux.c

Issue 7671033: Changing OOM range to 0, 1000 and tweaking OOM algorithm. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: More review changes Created 9 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « sandbox/linux/suid/process_util.h ('k') | sandbox/linux/suid/sandbox.c » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sandbox/linux/suid/process_util_linux.c
diff --git a/sandbox/linux/suid/process_util_linux.c b/sandbox/linux/suid/process_util_linux.c
index 17453def621006ca2d824c45c21cb922d6849d60..13f45ce92cf79c4b8d58a40512b99a5381317cb3 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);
« no previous file with comments | « sandbox/linux/suid/process_util.h ('k') | sandbox/linux/suid/sandbox.c » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698