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

Unified Diff: base/process_util_linux.cc

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
Index: base/process_util_linux.cc
diff --git a/base/process_util_linux.cc b/base/process_util_linux.cc
index 1f71f4dc080ccf629ddc04bb3bdd03e1ecf42c52..eb90a423424a9f3c5c63a87e7f6eac5da464a0ba 100644
--- a/base/process_util_linux.cc
+++ b/base/process_util_linux.cc
@@ -730,20 +730,38 @@ 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 > 1000)
stevenjb 2011/08/18 00:20:07 bit: kMaxOOMScore instead of 1000
Greg Spencer (Chromium) 2011/08/18 23:10:50 Done.
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;
+ return (static_cast<int>(score_str.length()) ==
stevenjb 2011/08/18 00:20:07 nit: size_t bytes = score_str.length() would make
Greg Spencer (Chromium) 2011/08/18 23:10:50 Can't be a size_t, it has to be an int, but I did
+ file_util::WriteFile(oom_file, score_str.c_str(),
+ score_str.length()));
+ }
- 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 * 15 / 1000);
stevenjb 2011/08/18 00:20:07 nit: const for old score range also
Greg Spencer (Chromium) 2011/08/18 23:10:50 Done.
+ VLOG(1) << "Adjusting oom_adj of " << process << " to " << score_str;
+ return (static_cast<int>(score_str.length()) ==
+ file_util::WriteFile(oom_file, score_str.c_str(),
+ score_str.length()));
+ }
- 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
« no previous file with comments | « base/process_util.h ('k') | chrome/app/chrome_main.cc » ('j') | chrome/app/chrome_main.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698