summaryrefslogtreecommitdiffstats
path: root/base/process_util_linux.cc
diff options
context:
space:
mode:
authorgspencer@google.com <gspencer@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2011-08-22 20:33:28 +0000
committergspencer@google.com <gspencer@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2011-08-22 20:33:28 +0000
commit07444bb8c0809f660286d12a384279c57f058bef (patch)
tree2914b4715f7e3ea8b9b7edbae475266566a56efa /base/process_util_linux.cc
parent601b9e5416e126d2684bb875cee0b433a25ab981 (diff)
downloadchromium_src-07444bb8c0809f660286d12a384279c57f058bef.zip
chromium_src-07444bb8c0809f660286d12a384279c57f058bef.tar.gz
chromium_src-07444bb8c0809f660286d12a384279c57f058bef.tar.bz2
Changing OOM range to 0, 1000 and tweaking OOM algorithm.
With this change, we now use the newer oom_score_adj file (with fallback to oom_adj when on a system that doesn't support it) so that we can take advantage of a finer range ([0, 1000] instead of [0, 15]). Also tweaked the OOM priority manager to prioritize things in a slightly different order, preferring (even more) not to kill tabs that the user has currently selected. BUG=chromium-os:18421, chromium:65009 TEST=Ran on device, observed OOM adj values, forced OOM conditions to watch kills. Review URL: http://codereview.chromium.org/7671033 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@97724 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base/process_util_linux.cc')
-rw-r--r--base/process_util_linux.cc43
1 files changed, 34 insertions, 9 deletions
diff --git a/base/process_util_linux.cc b/base/process_util_linux.cc
index b350517..f9d151b 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