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

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

Issue 3235007: This adds periodic OOM score adjustment, based on the last access time (Closed)
Patch Set: Final review changes Created 10 years, 3 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
« no previous file with comments | « chrome/browser/zygote_host_linux.h ('k') | chrome/chrome_browser.gypi » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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 "chrome/browser/zygote_host_linux.h" 5 #include "chrome/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 218 matching lines...) Expand 10 before | Expand all | Expand 10 after
229 pid_t pid; 229 pid_t pid;
230 { 230 {
231 AutoLock lock(control_lock_); 231 AutoLock lock(control_lock_);
232 if (!base::SendMsg(control_fd_, pickle.data(), pickle.size(), fds)) 232 if (!base::SendMsg(control_fd_, pickle.data(), pickle.size(), fds))
233 return base::kNullProcessHandle; 233 return base::kNullProcessHandle;
234 234
235 if (ReadReply(&pid, sizeof(pid)) != sizeof(pid)) 235 if (ReadReply(&pid, sizeof(pid)) != sizeof(pid))
236 return base::kNullProcessHandle; 236 return base::kNullProcessHandle;
237 } 237 }
238 238
239 const int kRendererScore = 5;
240 AdjustRendererOOMScore(pid, kRendererScore);
241
242 return pid;
243 }
244
245 void ZygoteHost::AdjustRendererOOMScore(base::ProcessHandle pid, int score) {
239 // 1) You can't change the oom_adj of a non-dumpable process (EPERM) unless 246 // 1) You can't change the oom_adj of a non-dumpable process (EPERM) unless
240 // you're root. Because of this, we can't set the oom_adj from the browser 247 // you're root. Because of this, we can't set the oom_adj from the browser
241 // process. 248 // process.
242 // 249 //
243 // 2) We can't set the oom_adj before entering the sandbox because the 250 // 2) We can't set the oom_adj before entering the sandbox because the
244 // zygote is in the sandbox and the zygote is as critical as the browser 251 // zygote is in the sandbox and the zygote is as critical as the browser
245 // process. Its oom_adj value shouldn't be changed. 252 // process. Its oom_adj value shouldn't be changed.
246 // 253 //
247 // 3) A non-dumpable process can't even change its own oom_adj because it's 254 // 3) A non-dumpable process can't even change its own oom_adj because it's
248 // root owned 0644. The sandboxed processes don't even have /proc, but one 255 // root owned 0644. The sandboxed processes don't even have /proc, but one
(...skipping 12 matching lines...) Expand all
261 // and it's easy. 268 // and it's easy.
262 269
263 static bool selinux; 270 static bool selinux;
264 static bool selinux_valid = false; 271 static bool selinux_valid = false;
265 272
266 if (!selinux_valid) { 273 if (!selinux_valid) {
267 selinux = access("/selinux", X_OK) == 0; 274 selinux = access("/selinux", X_OK) == 0;
268 selinux_valid = true; 275 selinux_valid = true;
269 } 276 }
270 277
271 const int kRendererScore = 5;
272 if (using_suid_sandbox_ && !selinux) { 278 if (using_suid_sandbox_ && !selinux) {
273 base::ProcessHandle sandbox_helper_process; 279 base::ProcessHandle sandbox_helper_process;
274 base::file_handle_mapping_vector dummy_map;
275 std::vector<std::string> adj_oom_score_cmdline; 280 std::vector<std::string> adj_oom_score_cmdline;
276 281
277 adj_oom_score_cmdline.push_back(sandbox_binary_); 282 adj_oom_score_cmdline.push_back(sandbox_binary_);
278 adj_oom_score_cmdline.push_back(base::kAdjustOOMScoreSwitch); 283 adj_oom_score_cmdline.push_back(base::kAdjustOOMScoreSwitch);
279 adj_oom_score_cmdline.push_back(base::Int64ToString(pid)); 284 adj_oom_score_cmdline.push_back(base::Int64ToString(pid));
280 adj_oom_score_cmdline.push_back(base::IntToString(kRendererScore)); 285 adj_oom_score_cmdline.push_back(base::IntToString(score));
281 CommandLine adj_oom_score_cmd(adj_oom_score_cmdline); 286 CommandLine adj_oom_score_cmd(adj_oom_score_cmdline);
282 if (base::LaunchApp(adj_oom_score_cmdline, dummy_map, false, 287 if (base::LaunchApp(adj_oom_score_cmd, false, true,
283 &sandbox_helper_process)) { 288 &sandbox_helper_process)) {
284 ProcessWatcher::EnsureProcessGetsReaped(sandbox_helper_process); 289 ProcessWatcher::EnsureProcessGetsReaped(sandbox_helper_process);
285 } 290 }
286 } else if (!using_suid_sandbox_) { 291 } else if (!using_suid_sandbox_) {
287 if (!base::AdjustOOMScore(pid, kRendererScore)) 292 if (!base::AdjustOOMScore(pid, score))
288 LOG(ERROR) << "Failed to adjust OOM score of renderer"; 293 LOG(ERROR) << "Failed to adjust OOM score of renderer with pid " << pid;
289 } 294 }
290
291 return pid;
292 } 295 }
293 296
294 void ZygoteHost::EnsureProcessTerminated(pid_t process) { 297 void ZygoteHost::EnsureProcessTerminated(pid_t process) {
295 DCHECK(init_); 298 DCHECK(init_);
296 Pickle pickle; 299 Pickle pickle;
297 300
298 pickle.WriteInt(kCmdReap); 301 pickle.WriteInt(kCmdReap);
299 pickle.WriteInt(process); 302 pickle.WriteInt(process);
300 303
301 if (HANDLE_EINTR(write(control_fd_, pickle.data(), pickle.size())) < 0) 304 if (HANDLE_EINTR(write(control_fd_, pickle.data(), pickle.size())) < 0)
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
335 !read_pickle.ReadBool(&iter, &tmp_child_exited)) { 338 !read_pickle.ReadBool(&iter, &tmp_child_exited)) {
336 LOG(WARNING) << "Error parsing DidProcessCrash response from zygote."; 339 LOG(WARNING) << "Error parsing DidProcessCrash response from zygote.";
337 return false; 340 return false;
338 } 341 }
339 342
340 if (child_exited) 343 if (child_exited)
341 *child_exited = tmp_child_exited; 344 *child_exited = tmp_child_exited;
342 345
343 return did_crash; 346 return did_crash;
344 } 347 }
OLDNEW
« no previous file with comments | « chrome/browser/zygote_host_linux.h ('k') | chrome/chrome_browser.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698