cros: Remove unused low memory margin code from sandbox and zygote
This code is unused - it was probably added long ago when we were trying to figure out the correct value for the memory margin. Removing it will make it easier to remove the setuid sandbox. BUG=312388 TEST=compiles, usual browser_tests R=jln@chromium.org TBR=joi@chromium.org for removing an unused method from content/public/browser/zygote_host_linux.h Review URL: https://codereview.chromium.org/49843002 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@231611 0039d316-1c4b-4281-b951-d872f2087c98
This commit is contained in:
content
sandbox/linux/suid
@ -407,41 +407,6 @@ void ZygoteHostImpl::AdjustRendererOOMScore(base::ProcessHandle pid,
|
||||
}
|
||||
#endif
|
||||
|
||||
void ZygoteHostImpl::AdjustLowMemoryMargin(int64 margin_mb) {
|
||||
#if defined(OS_CHROMEOS)
|
||||
// You can't change the low memory margin unless you're root. Because of this,
|
||||
// we can't set the low memory margin from the browser process.
|
||||
// So, we use the SUID binary to change it for us.
|
||||
if (using_suid_sandbox_) {
|
||||
#if defined(USE_TCMALLOC)
|
||||
// If heap profiling is running, these processes are not exiting, at least
|
||||
// on ChromeOS. The easiest thing to do is not launch them when profiling.
|
||||
// TODO(stevenjb): Investigate further and fix.
|
||||
if (IsHeapProfilerRunning())
|
||||
return;
|
||||
#endif
|
||||
std::vector<std::string> adj_low_mem_commandline;
|
||||
adj_low_mem_commandline.push_back(sandbox_binary_);
|
||||
adj_low_mem_commandline.push_back(sandbox::kAdjustLowMemMarginSwitch);
|
||||
adj_low_mem_commandline.push_back(base::Int64ToString(margin_mb));
|
||||
|
||||
base::ProcessHandle sandbox_helper_process;
|
||||
if (base::LaunchProcess(adj_low_mem_commandline, base::LaunchOptions(),
|
||||
&sandbox_helper_process)) {
|
||||
base::EnsureProcessGetsReaped(sandbox_helper_process);
|
||||
} else {
|
||||
LOG(ERROR) << "Unable to run suid sandbox to set low memory margin.";
|
||||
}
|
||||
}
|
||||
// Don't adjust memory margin if we're not running with the sandbox: this
|
||||
// isn't very common, and not doing it has little impact.
|
||||
#else
|
||||
// Low memory notification is currently only implemented on ChromeOS.
|
||||
NOTREACHED() << "AdjustLowMemoryMargin not implemented";
|
||||
#endif // defined(OS_CHROMEOS)
|
||||
}
|
||||
|
||||
|
||||
void ZygoteHostImpl::EnsureProcessTerminated(pid_t process) {
|
||||
DCHECK(init_);
|
||||
Pickle pickle;
|
||||
|
@ -55,7 +55,6 @@ class CONTENT_EXPORT ZygoteHostImpl : public ZygoteHost {
|
||||
virtual int GetSandboxStatus() const OVERRIDE;
|
||||
virtual void AdjustRendererOOMScore(base::ProcessHandle process_handle,
|
||||
int score) OVERRIDE;
|
||||
virtual void AdjustLowMemoryMargin(int64 margin_mb) OVERRIDE;
|
||||
|
||||
private:
|
||||
friend struct DefaultSingletonTraits<ZygoteHostImpl>;
|
||||
|
@ -38,12 +38,6 @@ class ZygoteHost {
|
||||
// likely to be killed by the OOM killer.
|
||||
virtual void AdjustRendererOOMScore(base::ProcessHandle process_handle,
|
||||
int score) = 0;
|
||||
|
||||
// Adjust the point at which the low memory notifier in the kernel tells
|
||||
// us that we're low on memory. When there is less than |margin_mb| left,
|
||||
// then the notifier will notify us. Set |margin_mb| to -1 to turn off
|
||||
// low memory notification altogether.
|
||||
virtual void AdjustLowMemoryMargin(int64 margin_mb) = 0;
|
||||
};
|
||||
|
||||
} // namespace content
|
||||
|
@ -12,9 +12,6 @@ namespace sandbox {
|
||||
// These are command line switches that may be used by other programs
|
||||
// (e.g. Chrome) to construct a command line for the sandbox.
|
||||
static const char kAdjustOOMScoreSwitch[] = "--adjust-oom-score";
|
||||
#if defined(OS_CHROMEOS)
|
||||
static const char kAdjustLowMemMarginSwitch[] = "--adjust-low-mem";
|
||||
#endif
|
||||
|
||||
static const char kSandboxDescriptorEnvironmentVarName[] = "SBX_D";
|
||||
static const char kSandboxHelperPidEnvironmentVarName[] = "SBX_HELPER_PID";
|
||||
|
@ -24,10 +24,6 @@
|
||||
static const int kMaxOomScore = 1000;
|
||||
static const int kMaxOldOomScore = 15;
|
||||
|
||||
// Kernel pseudo-file that allows setting of the low memory margin.
|
||||
static const char kLowMemMarginFile[] =
|
||||
"/sys/kernel/mm/chromeos-low_mem/margin";
|
||||
|
||||
// NOTE: This is not the only version of this function in the source:
|
||||
// the base library (in process_util_linux.cc) also has its own C++ version.
|
||||
bool AdjustOOMScore(pid_t process, int score) {
|
||||
@ -77,30 +73,3 @@ bool AdjustOOMScore(pid_t process, int score) {
|
||||
close(fd);
|
||||
return (bytes_written == len);
|
||||
}
|
||||
|
||||
bool AdjustLowMemoryMargin(int64_t margin_mb) {
|
||||
int file_descriptor = open(kLowMemMarginFile, O_WRONLY);
|
||||
if (file_descriptor < 0)
|
||||
return false;
|
||||
|
||||
// Only allow those values which are reasonable, to prevent mischief.
|
||||
char value[21];
|
||||
switch (margin_mb) {
|
||||
case -1L:
|
||||
snprintf(value, sizeof(value), "off");
|
||||
break;
|
||||
case 0L:
|
||||
case 25L:
|
||||
case 50L:
|
||||
case 100L:
|
||||
case 200L:
|
||||
snprintf(value, sizeof(value), "%lld", (long long int)margin_mb);
|
||||
break;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
|
||||
bool success = (write(file_descriptor, value, strlen(value)) >= 0);
|
||||
close(file_descriptor);
|
||||
return success;
|
||||
}
|
||||
|
@ -450,16 +450,6 @@ int main(int argc, char **argv) {
|
||||
return 1;
|
||||
return AdjustOOMScore(pid, score);
|
||||
}
|
||||
#if defined(OS_CHROMEOS)
|
||||
if (argc == 3 && (0 == strcmp(argv[1], kAdjustLowMemMarginSwitch))) {
|
||||
char* endptr = NULL;
|
||||
errno = 0;
|
||||
unsigned long margin_mb = strtoul(argv[2], &endptr, 10);
|
||||
if (!endptr || *endptr || errno != 0)
|
||||
return 1;
|
||||
return AdjustLowMemoryMargin(margin_mb);
|
||||
}
|
||||
#endif
|
||||
|
||||
// Protect the core setuid sandbox functionality with an API version
|
||||
if (!CheckAndExportApiVersion()) {
|
||||
|
Reference in New Issue
Block a user