summaryrefslogtreecommitdiffstats
path: root/base/process_util_linux.cc
diff options
context:
space:
mode:
authorthestig@chromium.org <thestig@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-12-10 02:08:10 +0000
committerthestig@chromium.org <thestig@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-12-10 02:08:10 +0000
commite5856a7a015a8a4d790b51136881a32364ee912a (patch)
treec96a355ab2e2f663770f4c123244b28031a82b52 /base/process_util_linux.cc
parent8a0590e6696b0a6377cfc4cb71fa66beeef047d6 (diff)
downloadchromium_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/process_util_linux.cc')
-rw-r--r--base/process_util_linux.cc18
1 files changed, 16 insertions, 2 deletions
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