summaryrefslogtreecommitdiffstats
path: root/base/process_util_linux.cc
diff options
context:
space:
mode:
authormattm@chromium.org <mattm@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-08-22 20:53:17 +0000
committermattm@chromium.org <mattm@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-08-22 20:53:17 +0000
commit1dcae06794d4875c9566ffdd5b335594ec3746a0 (patch)
treed9c341e873302205cd0854a3c0a02bdac80c2edf /base/process_util_linux.cc
parentab312f8e72b10eb20bdeef6bd79eb36ad995a05b (diff)
downloadchromium_src-1dcae06794d4875c9566ffdd5b335594ec3746a0.zip
chromium_src-1dcae06794d4875c9566ffdd5b335594ec3746a0.tar.gz
chromium_src-1dcae06794d4875c9566ffdd5b335594ec3746a0.tar.bz2
Revert 97724 - 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 TBR=gspencer@google.com Review URL: http://codereview.chromium.org/7685030 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@97728 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base/process_util_linux.cc')
-rw-r--r--base/process_util_linux.cc43
1 files changed, 9 insertions, 34 deletions
diff --git a/base/process_util_linux.cc b/base/process_util_linux.cc
index f9d151b..b350517 100644
--- a/base/process_util_linux.cc
+++ b/base/process_util_linux.cc
@@ -27,10 +27,6 @@
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
@@ -738,41 +734,20 @@ 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 > kMaxOomScore)
+ if (score < 0 || score > 15)
return false;
- 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));
- }
+ FilePath oom_adj("/proc");
+ oom_adj = oom_adj.Append(base::Int64ToString(process));
+ oom_adj = oom_adj.AppendASCII("oom_adj");
- // 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));
- }
+ if (!file_util::PathExists(oom_adj))
+ return false;
- return false;
+ 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()));
}
} // namespace base