diff options
author | thestig@chromium.org <thestig@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-12-10 02:08:10 +0000 |
---|---|---|
committer | thestig@chromium.org <thestig@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-12-10 02:08:10 +0000 |
commit | e5856a7a015a8a4d790b51136881a32364ee912a (patch) | |
tree | c96a355ab2e2f663770f4c123244b28031a82b52 /base | |
parent | 8a0590e6696b0a6377cfc4cb71fa66beeef047d6 (diff) | |
download | chromium_src-e5856a7a015a8a4d790b51136881a32364ee912a.zip chromium_src-e5856a7a015a8a4d790b51136881a32364ee912a.tar.gz chromium_src-e5856a7a015a8a4d790b51136881a32364ee912a.tar.bz2 |
Linux: Adjust /proc/pid/oom_adj to sacrifice plugin and renderer processes to the OOM killer.
BUG=29752
TEST=During out of memory conditions, Linux kernel picks a plugin/renderer over the browser process.
Review URL: http://codereview.chromium.org/467058
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@34222 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base')
-rw-r--r-- | base/process_util.h | 7 | ||||
-rw-r--r-- | base/process_util_linux.cc | 18 |
2 files changed, 23 insertions, 2 deletions
diff --git a/base/process_util.h b/base/process_util.h index 41d1d17..1122de7 100644 --- a/base/process_util.h +++ b/base/process_util.h @@ -100,6 +100,13 @@ FilePath GetProcessExecutablePath(ProcessHandle process); // CPU-related ticks. Returns -1 on parse error. // Exposed for testing. int ParseProcStatCPU(const std::string& input); + +static const char kAdjustOOMScoreSwitch[] = "--adjust-oom-score"; + +// This adjusts /proc/process/oom_adj so the Linux OOM killer will prefer +// certain process types over others. The range for the adjustment is +// [-17,15], with [0,15] being user accessible. +bool AdjustOOMScore(ProcessId process, int score); #endif #if defined(OS_POSIX) diff --git a/base/process_util_linux.cc b/base/process_util_linux.cc index bd6bcf3..1a7e090 100644 --- a/base/process_util_linux.cc +++ b/base/process_util_linux.cc @@ -513,7 +513,6 @@ void OnNoMemory() { } // namespace extern "C" { - #if !defined(LINUX_USE_TCMALLOC) typedef void* (*malloc_type)(size_t size); @@ -600,7 +599,6 @@ int posix_memalign(void** ptr, size_t alignment, size_t size) { } #endif // !defined(LINUX_USE_TCMALLOC) - } // extern C void EnableTerminationOnOutOfMemory() { @@ -610,4 +608,20 @@ void EnableTerminationOnOutOfMemory() { // malloc and friends and make them die on out of memory. } +bool AdjustOOMScore(ProcessId process, int score) { + if (score < 0 || score > 15) + return false; + + FilePath oom_adj("/proc"); + oom_adj = oom_adj.Append(Int64ToString(process)); + oom_adj = oom_adj.AppendASCII("oom_adj"); + + if (!file_util::PathExists(oom_adj)) + return false; + + std::string score_str = IntToString(score); + return (static_cast<int>(score_str.length()) == + file_util::WriteFile(oom_adj, score_str.c_str(), score_str.length())); +} + } // namespace base |