Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(265)

Side by Side Diff: base/process_util_linux.cc

Issue 7671033: Changing OOM range to 0, 1000 and tweaking OOM algorithm. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 9 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "base/process_util.h" 5 #include "base/process_util.h"
6 6
7 #include <ctype.h> 7 #include <ctype.h>
8 #include <dirent.h> 8 #include <dirent.h>
9 #include <dlfcn.h> 9 #include <dlfcn.h>
10 #include <errno.h> 10 #include <errno.h>
(...skipping 712 matching lines...) Expand 10 before | Expand all | Expand 10 after
723 // Android doesn't support setting a new handler. 723 // Android doesn't support setting a new handler.
724 DLOG(WARNING) << "Not feasible."; 724 DLOG(WARNING) << "Not feasible.";
725 #else 725 #else
726 // Set the new-out of memory handler. 726 // Set the new-out of memory handler.
727 std::set_new_handler(&OnNoMemory); 727 std::set_new_handler(&OnNoMemory);
728 // If we're using glibc's allocator, the above functions will override 728 // If we're using glibc's allocator, the above functions will override
729 // malloc and friends and make them die on out of memory. 729 // malloc and friends and make them die on out of memory.
730 #endif 730 #endif
731 } 731 }
732 732
733 // NOTE: This is not the only version of this function in the source:
734 // the setuid sandbox (in process_util_linux.c, in the sandbox source)
735 // also has it's own C version.
733 bool AdjustOOMScore(ProcessId process, int score) { 736 bool AdjustOOMScore(ProcessId process, int score) {
734 if (score < 0 || score > 15) 737 if (score < 0 || score > 1000)
stevenjb 2011/08/18 00:20:07 bit: kMaxOOMScore instead of 1000
Greg Spencer (Chromium) 2011/08/18 23:10:50 Done.
735 return false; 738 return false;
736 739
737 FilePath oom_adj("/proc"); 740 FilePath oom_path("/proc");
738 oom_adj = oom_adj.Append(base::Int64ToString(process)); 741 oom_path = oom_path.Append(base::Int64ToString(process));
739 oom_adj = oom_adj.AppendASCII("oom_adj");
740 742
741 if (!file_util::PathExists(oom_adj)) 743 // Attempt to write the newer oom_score_adj file first.
742 return false; 744 FilePath oom_file = oom_path.AppendASCII("oom_score_adj");
745 if (file_util::PathExists(oom_file)) {
746 std::string score_str = base::IntToString(score);
747 VLOG(1) << "Adjusting oom_score_adj of " << process << " to " << score_str;
748 return (static_cast<int>(score_str.length()) ==
stevenjb 2011/08/18 00:20:07 nit: size_t bytes = score_str.length() would make
Greg Spencer (Chromium) 2011/08/18 23:10:50 Can't be a size_t, it has to be an int, but I did
749 file_util::WriteFile(oom_file, score_str.c_str(),
750 score_str.length()));
751 }
743 752
744 std::string score_str = base::IntToString(score); 753 // If the oom_score_adj file doesn't exist, then we write the old
745 return (static_cast<int>(score_str.length()) == 754 // style file and translate the oom_adj score to the range 0-15.
746 file_util::WriteFile(oom_adj, score_str.c_str(), score_str.length())); 755 oom_file = oom_path.AppendASCII("oom_adj");
756 if (file_util::PathExists(oom_file)) {
757 std::string score_str = base::IntToString(score * 15 / 1000);
stevenjb 2011/08/18 00:20:07 nit: const for old score range also
Greg Spencer (Chromium) 2011/08/18 23:10:50 Done.
758 VLOG(1) << "Adjusting oom_adj of " << process << " to " << score_str;
759 return (static_cast<int>(score_str.length()) ==
760 file_util::WriteFile(oom_file, score_str.c_str(),
761 score_str.length()));
762 }
763
764 return false;
747 } 765 }
748 766
749 } // namespace base 767 } // namespace base
OLDNEW
« no previous file with comments | « base/process_util.h ('k') | chrome/app/chrome_main.cc » ('j') | chrome/app/chrome_main.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698