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-23 17:58:21 +0000
committergspencer@google.com <gspencer@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2011-08-23 17:58:21 +0000
commit03eb9d27a79f876a039ca30eba54d1155ab5500b (patch)
tree91c377e970b5e117c09f657a01a172e5bf993709 /base/process_util_linux.cc
parentc25c7be488ea694d9173374b985e73a5a6eed867 (diff)
downloadchromium_src-03eb9d27a79f876a039ca30eba54d1155ab5500b.zip
chromium_src-03eb9d27a79f876a039ca30eba54d1155ab5500b.tar.gz
chromium_src-03eb9d27a79f876a039ca30eba54d1155ab5500b.tar.bz2
Trying again to land OOM priority manager changes.
First landing failed because of an obscure problem with building linux_shared. This change passes the linux_shared trybot (and linux and linux_chromeos trybots). 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. Original review: http://codereview.chromium.org/7671033/ 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/7708020 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@97888 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