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 |