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

Unified Diff: base/process_linux.cc

Issue 6713089: Add support for the cgroups config we have in chromeos (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 9 years, 9 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « base/file_util_linux.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/process_linux.cc
diff --git a/base/process_linux.cc b/base/process_linux.cc
index 14c24240e38288251d925cca4c520695bb1a0da8..dbb50be7c7ad7a222f53ac18e1fcd825203ab4a5 100644
--- a/base/process_linux.cc
+++ b/base/process_linux.cc
@@ -7,8 +7,20 @@
#include <errno.h>
#include <sys/resource.h>
+#include "base/file_util.h"
#include "base/logging.h"
+#include "base/stringprintf.h"
agl 2011/03/24 00:02:08 #if defined(OS_CHROMEOS)
DaveMoore 2011/03/24 16:45:17 Done.
+namespace {
agl 2011/03/24 00:02:08 An anonymous namespace isn't needed if the variabl
DaveMoore 2011/03/24 16:45:17 Done.
+static bool use_cgroups = false;
+static bool inited = false;
agl 2011/03/24 00:02:08 s/inited/cgroups_inited/
DaveMoore 2011/03/24 16:45:17 Done.
+static const char kForegroundTasks[] =
+ "/tmp/cgroup/cpu/chrome_renderers/foreground/tasks";
+static const char kBackgroundTasks[] =
+ "/tmp/cgroup/cpu/chrome_renderers/background/tasks";
+static FilePath foreground_tasks;
+static FilePath background_tasks;
+}
namespace base {
#if defined(OS_CHROMEOS)
@@ -28,6 +40,51 @@ bool Process::IsProcessBackgrounded() const {
bool Process::SetProcessBackgrounded(bool background) {
DCHECK(process_);
+ // Check for cgroups files. ChromeOS supports these by default. It creates
+ // a cgroup mount in /tmp/cgroup and then configures two cpu task groups,
+ // one for at most single foreground renderer and the other for all
agl 2011/03/24 00:02:08 "one for at most single" <- doesn't read right.
DaveMoore 2011/03/24 16:45:17 Done.
+ // background renderers. This allows us to limit the impact of background
+ // renderers on foreground ones to a greater level than simple renicing.
+ if (!inited) {
+ inited = true;
+ foreground_tasks = FilePath(kForegroundTasks);
agl 2011/03/24 00:02:08 This probably is obviously not thread-safe. I gues
DaveMoore 2011/03/24 16:45:17 Done.
+ background_tasks = FilePath(kBackgroundTasks);
+ file_util::FileSystemType foreground_type;
+ file_util::FileSystemType background_type;
+ use_cgroups =
+ file_util::GetFileSystemType(foreground_tasks, &foreground_type) &&
+ file_util::GetFileSystemType(background_tasks, &background_type) &&
+ foreground_type == file_util::FILE_SYSTEM_CGROUP &&
+ background_type == file_util::FILE_SYSTEM_CGROUP;
+ }
+
+ if (use_cgroups) {
+ if (background) {
+ std::string pid = StringPrintf("%d", process_);
+ if (file_util::WriteFile(background_tasks, pid.c_str(), pid.size()) > 0) {
agl 2011/03/24 00:02:08 This doesn't DCHECK on the file checks?
DaveMoore 2011/03/24 16:45:17 I moved the in child_process_launcher to the PROCE
+ // With cgroups there's no real notion of priority as an int, but this
+ // will ensure we only move renderers back to the foreground group
+ // if we've ever put them in the background one.
+ saved_priority_ = 0;
+ return true;
+ } else {
+ return false;
+ }
+ } else {
+ if (saved_priority_ == kUnsetProcessPriority) {
+ // Can't restore if we were never backgrounded.
+ return false;
+ }
+ std::string pid = StringPrintf("%d", process_);
+ if (file_util::WriteFile(foreground_tasks, pid.c_str(), pid.size()) > 0) {
+ saved_priority_ = kUnsetProcessPriority;
+ return true;
+ } else {
+ return false;
+ }
+ }
+ }
+
if (background) {
// We won't be able to raise the priority if we don't have the right rlimit.
// The limit may be adjusted in /etc/security/limits.conf for PAM systems.
« no previous file with comments | « base/file_util_linux.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698