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

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: 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
« content/browser/zygote_host_linux.cc ('K') | « sandbox/linux/suid/process_util.h ('k') | no next file » | 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..31886e285cf4dac44398418703deddafcb96e470 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.
@@ -20,7 +20,7 @@
#include <unistd.h>
bool AdjustOOMScore(pid_t process, int score) {
- if (score < 0 || score > 15)
+ if (score < 0 || score > 1000)
stevenjb 2011/08/18 00:20:07 And in the darkness bind them?
Greg Spencer (Chromium) 2011/08/18 23:10:50 Also moved into a constant.
return false;
char oom_adj[27]; // "/proc/" + log_10(2**64) + "\0"
@@ -41,13 +41,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, 15], so we scale the score. This may result in some
+ // aliasing of values, of course.
+ score = score * 15 / 1000;
+ }
+ }
close(dirfd);
- if (fd < 0)
- return false;
-
- char buf[3]; // 0 <= |score| <= 15;
+ char buf[5]; // 0 <= |score| <= 1000;
stevenjb 2011/08/18 00:20:07 Maybe size this for any 32 bit range?
Greg Spencer (Chromium) 2011/08/18 23:10:50 Done.
snprintf(buf, sizeof(buf), "%d", score);
size_t len = strlen(buf);
« content/browser/zygote_host_linux.cc ('K') | « sandbox/linux/suid/process_util.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698