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

Side by Side Diff: base/process_util_linux.cc

Issue 467058: Linux: Adjust /proc/pid/oom_adj to sacrifice plugin and renderer processes to... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years 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) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2009 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 495 matching lines...) Expand 10 before | Expand all | Expand 10 after
506 CHECK(false) << "Out of memory."; 506 CHECK(false) << "Out of memory.";
507 } 507 }
508 508
509 void OnNoMemory() { 509 void OnNoMemory() {
510 OnNoMemorySize(0); 510 OnNoMemorySize(0);
511 } 511 }
512 512
513 } // namespace 513 } // namespace
514 514
515 extern "C" { 515 extern "C" {
516
517 #if !defined(LINUX_USE_TCMALLOC) 516 #if !defined(LINUX_USE_TCMALLOC)
518 517
519 typedef void* (*malloc_type)(size_t size); 518 typedef void* (*malloc_type)(size_t size);
520 typedef void* (*valloc_type)(size_t size); 519 typedef void* (*valloc_type)(size_t size);
521 typedef void* (*pvalloc_type)(size_t size); 520 typedef void* (*pvalloc_type)(size_t size);
522 521
523 typedef void* (*calloc_type)(size_t nmemb, size_t size); 522 typedef void* (*calloc_type)(size_t nmemb, size_t size);
524 typedef void* (*realloc_type)(void *ptr, size_t size); 523 typedef void* (*realloc_type)(void *ptr, size_t size);
525 typedef void* (*memalign_type)(size_t boundary, size_t size); 524 typedef void* (*memalign_type)(size_t boundary, size_t size);
526 525
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
593 int posix_memalign(void** ptr, size_t alignment, size_t size) { 592 int posix_memalign(void** ptr, size_t alignment, size_t size) {
594 static posix_memalign_type original_function = 593 static posix_memalign_type original_function =
595 reinterpret_cast<posix_memalign_type>(dlsym(RTLD_NEXT, "posix_memalign")); 594 reinterpret_cast<posix_memalign_type>(dlsym(RTLD_NEXT, "posix_memalign"));
596 int ret = original_function(ptr, alignment, size); 595 int ret = original_function(ptr, alignment, size);
597 if (ret == ENOMEM) 596 if (ret == ENOMEM)
598 OnNoMemorySize(size); 597 OnNoMemorySize(size);
599 return ret; 598 return ret;
600 } 599 }
601 600
602 #endif // !defined(LINUX_USE_TCMALLOC) 601 #endif // !defined(LINUX_USE_TCMALLOC)
603
604 } // extern C 602 } // extern C
605 603
606 void EnableTerminationOnOutOfMemory() { 604 void EnableTerminationOnOutOfMemory() {
607 // Set the new-out of memory handler. 605 // Set the new-out of memory handler.
608 std::set_new_handler(&OnNoMemory); 606 std::set_new_handler(&OnNoMemory);
609 // If we're using glibc's allocator, the above functions will override 607 // If we're using glibc's allocator, the above functions will override
610 // malloc and friends and make them die on out of memory. 608 // malloc and friends and make them die on out of memory.
611 } 609 }
612 610
611 bool AdjustOOMScore(ProcessId process, int score) {
612 if (score < 0 || score > 15)
613 return false;
614
615 FilePath oom_adj("/proc");
616 oom_adj = oom_adj.Append(Int64ToString(process));
617 oom_adj = oom_adj.AppendASCII("oom_adj");
618
619 if (!file_util::PathExists(oom_adj))
620 return false;
621
622 std::string score_str = IntToString(score);
623 return (static_cast<int>(score_str.length()) ==
624 file_util::WriteFile(oom_adj, score_str.c_str(), score_str.length()));
625 }
626
613 } // namespace base 627 } // namespace base
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698