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

Unified Diff: base/process_util_linux.cc

Issue 7708020: Trying again to land OOM priority manager changes. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Moving switch closer to use location 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
Index: base/process_util_linux.cc
diff --git a/base/process_util_linux.cc b/base/process_util_linux.cc
index b3505170dd11970df62160e590e79c9791db5f16..f9d151ba5deccbc54189ab21b2bd812946617f38 100644
--- a/base/process_util_linux.cc
+++ b/base/process_util_linux.cc
@@ -27,6 +27,10 @@
namespace {
+// Max score for the old oom_adj range. Used for conversion of new
+// values to old values.
+const int kMaxOldOomScore = 15;
+
enum ParsingState {
KEY_NAME,
KEY_VALUE
@@ -734,20 +738,41 @@ void EnableTerminationOnOutOfMemory() {
#endif
}
+// NOTE: This is not the only version of this function in the source:
+// the setuid sandbox (in process_util_linux.c, in the sandbox source)
+// also has it's own C version.
bool AdjustOOMScore(ProcessId process, int score) {
- if (score < 0 || score > 15)
+ if (score < 0 || score > kMaxOomScore)
return false;
- FilePath oom_adj("/proc");
- oom_adj = oom_adj.Append(base::Int64ToString(process));
- oom_adj = oom_adj.AppendASCII("oom_adj");
+ FilePath oom_path("/proc");
+ oom_path = oom_path.Append(base::Int64ToString(process));
+
+ // Attempt to write the newer oom_score_adj file first.
+ FilePath oom_file = oom_path.AppendASCII("oom_score_adj");
+ if (file_util::PathExists(oom_file)) {
+ std::string score_str = base::IntToString(score);
+ VLOG(1) << "Adjusting oom_score_adj of " << process << " to " << score_str;
+ int score_len = static_cast<int>(score_str.length());
+ return (score_len == file_util::WriteFile(oom_file,
+ score_str.c_str(),
+ score_len));
+ }
- if (!file_util::PathExists(oom_adj))
- return false;
+ // If the oom_score_adj file doesn't exist, then we write the old
+ // style file and translate the oom_adj score to the range 0-15.
+ oom_file = oom_path.AppendASCII("oom_adj");
+ if (file_util::PathExists(oom_file)) {
+ std::string score_str = base::IntToString(
+ score * kMaxOldOomScore / kMaxOomScore);
+ VLOG(1) << "Adjusting oom_adj of " << process << " to " << score_str;
+ int score_len = static_cast<int>(score_str.length());
+ return (score_len == file_util::WriteFile(oom_file,
+ score_str.c_str(),
+ score_len));
+ }
- std::string score_str = base::IntToString(score);
- return (static_cast<int>(score_str.length()) ==
- file_util::WriteFile(oom_adj, score_str.c_str(), score_str.length()));
+ return false;
}
} // namespace base
« base/process_util.h ('K') | « base/process_util.cc ('k') | chrome/app/chrome_main.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698