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

Side by Side Diff: content/browser/zygote_host_linux.cc

Issue 7708020: Trying again to land OOM priority manager changes. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Moving switch closer to use location 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 "content/browser/zygote_host_linux.h" 5 #include "content/browser/zygote_host_linux.h"
6 6
7 #include <sys/socket.h> 7 #include <sys/socket.h>
8 #include <sys/stat.h> 8 #include <sys/stat.h>
9 #include <sys/types.h> 9 #include <sys/types.h>
10 #include <unistd.h> 10 #include <unistd.h>
(...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after
265 if (!UnixDomainSocket::SendMsg(control_fd_, pickle.data(), pickle.size(), 265 if (!UnixDomainSocket::SendMsg(control_fd_, pickle.data(), pickle.size(),
266 fds)) 266 fds))
267 return base::kNullProcessHandle; 267 return base::kNullProcessHandle;
268 268
269 if (ReadReply(&pid, sizeof(pid)) != sizeof(pid)) 269 if (ReadReply(&pid, sizeof(pid)) != sizeof(pid))
270 return base::kNullProcessHandle; 270 return base::kNullProcessHandle;
271 if (pid <= 0) 271 if (pid <= 0)
272 return base::kNullProcessHandle; 272 return base::kNullProcessHandle;
273 } 273 }
274 274
275 const int kRendererScore = 5; 275 // This is just a starting score for a renderer or extension (the
276 AdjustRendererOOMScore(pid, kRendererScore); 276 // only types of processes that will be started this way). It will
277 // get adjusted as time goes on. (This is the same value as
278 // chrome::kLowestRendererOomScore in chrome/chrome_constants.h, but
279 // that's not something we can include here.)
280 const int kLowestRendererOomScore = 300;
281 AdjustRendererOOMScore(pid, kLowestRendererOomScore);
277 282
278 return pid; 283 return pid;
279 } 284 }
280 285
281 void ZygoteHost::AdjustRendererOOMScore(base::ProcessHandle pid, int score) { 286 void ZygoteHost::AdjustRendererOOMScore(base::ProcessHandle pid, int score) {
282 // 1) You can't change the oom_adj of a non-dumpable process (EPERM) unless 287 // 1) You can't change the oom_score_adj of a non-dumpable process
283 // you're root. Because of this, we can't set the oom_adj from the browser 288 // (EPERM) unless you're root. Because of this, we can't set the
284 // process. 289 // oom_adj from the browser process.
285 // 290 //
286 // 2) We can't set the oom_adj before entering the sandbox because the 291 // 2) We can't set the oom_score_adj before entering the sandbox
287 // zygote is in the sandbox and the zygote is as critical as the browser 292 // because the zygote is in the sandbox and the zygote is as
288 // process. Its oom_adj value shouldn't be changed. 293 // critical as the browser process. Its oom_adj value shouldn't
294 // be changed.
289 // 295 //
290 // 3) A non-dumpable process can't even change its own oom_adj because it's 296 // 3) A non-dumpable process can't even change its own oom_score_adj
291 // root owned 0644. The sandboxed processes don't even have /proc, but one 297 // because it's root owned 0644. The sandboxed processes don't
292 // could imagine passing in a descriptor from outside. 298 // even have /proc, but one could imagine passing in a descriptor
299 // from outside.
293 // 300 //
294 // So, in the normal case, we use the SUID binary to change it for us. 301 // So, in the normal case, we use the SUID binary to change it for us.
295 // However, Fedora (and other SELinux systems) don't like us touching other 302 // However, Fedora (and other SELinux systems) don't like us touching other
296 // process's oom_adj values 303 // process's oom_score_adj (or oom_adj) values
297 // (https://bugzilla.redhat.com/show_bug.cgi?id=581256). 304 // (https://bugzilla.redhat.com/show_bug.cgi?id=581256).
298 // 305 //
299 // The offical way to get the SELinux mode is selinux_getenforcemode, but I 306 // The offical way to get the SELinux mode is selinux_getenforcemode, but I
300 // don't want to add another library to the build as it's sure to cause 307 // don't want to add another library to the build as it's sure to cause
301 // problems with other, non-SELinux distros. 308 // problems with other, non-SELinux distros.
302 // 309 //
303 // So we just check for /selinux. This isn't foolproof, but it's not bad 310 // So we just check for /selinux. This isn't foolproof, but it's not bad
304 // and it's easy. 311 // and it's easy.
305 312
306 static bool selinux; 313 static bool selinux;
307 static bool selinux_valid = false; 314 static bool selinux_valid = false;
308 315
309 if (!selinux_valid) { 316 if (!selinux_valid) {
310 selinux = access("/selinux", X_OK) == 0; 317 selinux = access("/selinux", X_OK) == 0;
311 selinux_valid = true; 318 selinux_valid = true;
312 } 319 }
313 320
314 if (using_suid_sandbox_ && !selinux) { 321 if (using_suid_sandbox_ && !selinux) {
315 #if defined(USE_TCMALLOC) 322 #if defined(USE_TCMALLOC)
316 // If heap profiling is running, these processes are not exiting, at least 323 // If heap profiling is running, these processes are not exiting, at least
317 // on ChromeOS. The easiest thing to do is not launch them when profiling. 324 // on ChromeOS. The easiest thing to do is not launch them when profiling.
318 // TODO(stevenjb): Investigate further and fix. 325 // TODO(stevenjb): Investigate further and fix.
319 if (IsHeapProfilerRunning()) 326 if (IsHeapProfilerRunning())
320 return; 327 return;
321 #endif 328 #endif
329 // The command line switch used for supplying the OOM adjustment score
330 // to the setuid sandbox.
331 static const char kAdjustOOMScoreSwitch[] = "--adjust-oom-score";
332
322 std::vector<std::string> adj_oom_score_cmdline; 333 std::vector<std::string> adj_oom_score_cmdline;
323 adj_oom_score_cmdline.push_back(sandbox_binary_); 334 adj_oom_score_cmdline.push_back(sandbox_binary_);
324 adj_oom_score_cmdline.push_back(base::kAdjustOOMScoreSwitch); 335 adj_oom_score_cmdline.push_back(kAdjustOOMScoreSwitch);
325 adj_oom_score_cmdline.push_back(base::Int64ToString(pid)); 336 adj_oom_score_cmdline.push_back(base::Int64ToString(pid));
326 adj_oom_score_cmdline.push_back(base::IntToString(score)); 337 adj_oom_score_cmdline.push_back(base::IntToString(score));
327 338
328 base::ProcessHandle sandbox_helper_process; 339 base::ProcessHandle sandbox_helper_process;
329 if (base::LaunchProcess(adj_oom_score_cmdline, base::LaunchOptions(), 340 if (base::LaunchProcess(adj_oom_score_cmdline, base::LaunchOptions(),
330 &sandbox_helper_process)) { 341 &sandbox_helper_process)) {
331 ProcessWatcher::EnsureProcessGetsReaped(sandbox_helper_process); 342 ProcessWatcher::EnsureProcessGetsReaped(sandbox_helper_process);
332 } 343 }
333 } else if (!using_suid_sandbox_) { 344 } else if (!using_suid_sandbox_) {
334 if (!base::AdjustOOMScore(pid, score)) 345 if (!base::AdjustOOMScore(pid, score))
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
385 !read_pickle.ReadInt(&iter, &tmp_exit_code)) { 396 !read_pickle.ReadInt(&iter, &tmp_exit_code)) {
386 LOG(WARNING) << "Error parsing GetTerminationStatus response from zygote."; 397 LOG(WARNING) << "Error parsing GetTerminationStatus response from zygote.";
387 return base::TERMINATION_STATUS_NORMAL_TERMINATION; 398 return base::TERMINATION_STATUS_NORMAL_TERMINATION;
388 } 399 }
389 400
390 if (exit_code) 401 if (exit_code)
391 *exit_code = tmp_exit_code; 402 *exit_code = tmp_exit_code;
392 403
393 return static_cast<base::TerminationStatus>(status); 404 return static_cast<base::TerminationStatus>(status);
394 } 405 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698