Commit 4c203cc5 authored by Brian Geffon's avatar Brian Geffon Committed by Commit Bot

chromeos: Add SwapSetParamter dbus message and Feature.

Add a SwapSetParameter dbus message and then add a feature
with the corresponding parameter for changing min_filelist.

BUG=chromium:1014871
TESTED=On a betty VM CrOS image.

Change-Id: I2c875d0d2963fdbc253ae1c4419e6ad6794e5de0
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1880966Reviewed-by: default avatarSteven Bennetts <stevenjb@chromium.org>
Reviewed-by: default avatarJay Civelli <jcivelli@chromium.org>
Commit-Queue: Brian Geffon <bgeffon@chromium.org>
Cr-Commit-Position: refs/heads/master@{#710510}
parent a23518d2
......@@ -12,7 +12,7 @@ include_rules = [
"+chrome/utility/chrome_content_utility_client.h",
"+chromeos/constants",
"+chromeos/hugepage_text/hugepage_text.h",
"+chromeos/memory/kstaled.h",
"+chromeos/memory",
"+components/browser_watcher",
"+components/component_updater",
"+components/content_settings/core/common/content_settings_pattern.h",
......
......@@ -114,6 +114,7 @@
#include "chromeos/constants/chromeos_switches.h"
#include "chromeos/hugepage_text/hugepage_text.h"
#include "chromeos/memory/kstaled.h"
#include "chromeos/memory/swap_configuration.h"
#endif
#if defined(OS_ANDROID)
......@@ -601,6 +602,7 @@ void ChromeMainDelegate::PostFieldTrialInitialization() {
heap_profiler_controller_->Start();
#if defined(OS_CHROMEOS)
chromeos::ConfigureSwap();
chromeos::InitializeKstaled();
#endif
}
......
......@@ -46,6 +46,8 @@ component("chromeos") {
"hugepage_text/hugepage_text.h",
"memory/kstaled.cc",
"memory/kstaled.h",
"memory/swap_configuration.cc",
"memory/swap_configuration.h",
"policy/weekly_time/time_utils.cc",
"policy/weekly_time/time_utils.h",
"policy/weekly_time/weekly_time.cc",
......
......@@ -600,6 +600,19 @@ class DebugDaemonClientImpl : public DebugDaemonClient {
weak_ptr_factory_.GetWeakPtr(), std::move(callback)));
}
void SetSwapParameter(const std::string& parameter,
int32_t value,
DBusMethodCallback<std::string> callback) override {
dbus::MethodCall method_call(debugd::kDebugdInterface, "SwapSetParameter");
dbus::MessageWriter writer(&method_call);
writer.AppendString(parameter);
writer.AppendInt32(value);
debugdaemon_proxy_->CallMethod(
&method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT,
base::BindOnce(&DebugDaemonClientImpl::OnSetSwapParameter,
weak_ptr_factory_.GetWeakPtr(), std::move(callback)));
}
protected:
void Init(dbus::Bus* bus) override {
debugdaemon_proxy_ =
......@@ -626,6 +639,24 @@ class DebugDaemonClientImpl : public DebugDaemonClient {
std::move(callback).Run(std::move(routes));
}
void OnSetSwapParameter(DBusMethodCallback<std::string> callback,
dbus::Response* response) {
if (!response) {
std::move(callback).Run(base::nullopt);
return;
}
std::string res;
dbus::MessageReader reader(response);
if (!reader.PopString(&res)) {
LOG(ERROR) << "Received a non-string response from dbus";
std::move(callback).Run(base::nullopt);
return;
}
std::move(callback).Run(std::move(res));
}
void OnGetAllLogs(GetLogsCallback callback, dbus::Response* response) {
std::map<std::string, std::string> logs;
bool broken = false; // did we see a broken (k,v) pair?
......
......@@ -269,6 +269,11 @@ class COMPONENT_EXPORT(DEBUG_DAEMON) DebugDaemonClient
virtual void GetU2fFlags(
DBusMethodCallback<std::set<std::string>> callback) = 0;
// Set Swap Parameter
virtual void SetSwapParameter(const std::string& parameter,
int32_t value,
DBusMethodCallback<std::string> callback) = 0;
// Factory function, creates a new instance and returns ownership.
// For normal usage, access the singleton via DBusThreadManager::Get().
static std::unique_ptr<DebugDaemonClient> Create();
......
......@@ -56,6 +56,13 @@ void FakeDebugDaemonClient::SetKstaledRatio(uint8_t val,
std::move(callback).Run(true /* success */);
}
void FakeDebugDaemonClient::SetSwapParameter(
const std::string& parameter,
int32_t value,
DBusMethodCallback<std::string> callback) {
std::move(callback).Run(std::string());
}
std::string FakeDebugDaemonClient::GetTracingAgentName() {
return kCrOSTracingAgentName;
}
......
......@@ -36,6 +36,9 @@ class COMPONENT_EXPORT(DEBUG_DAEMON) FakeDebugDaemonClient
VoidDBusMethodCallback callback) override;
std::string GetTracingAgentName() override;
std::string GetTraceEventLabel() override;
void SetSwapParameter(const std::string& parameter,
int32_t value,
DBusMethodCallback<std::string> callback) override;
void StartAgentTracing(const base::trace_event::TraceConfig& trace_config,
StartAgentTracingCallback callback) override;
void StopAgentTracing(StopAgentTracingCallback callback) override;
......
// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chromeos/memory/swap_configuration.h"
#include "base/bind.h"
#include "base/feature_list.h"
#include "base/metrics/field_trial_params.h"
#include "chromeos/dbus/dbus_thread_manager.h"
#include "chromeos/dbus/debug_daemon/debug_daemon_client.h"
namespace chromeos {
const base::Feature kCrOSTuneMinFilelist{"CrOSTuneMinFilelist",
base::FEATURE_DISABLED_BY_DEFAULT};
const base::FeatureParam<int> kCrOSMinFilelistMb{&kCrOSTuneMinFilelist,
"CrOSMinFilelistMb", -1};
namespace {
constexpr const char kMinFilelist[] = "min_filelist";
void OnSwapParameterSet(std::string parameter,
base::Optional<std::string> res) {
LOG_IF(ERROR, !res.has_value())
<< "Setting swap paramter " << parameter << " failed.";
}
void ConfigureMinFilelistIfEnabled() {
if (!base::FeatureList::IsEnabled(kCrOSTuneMinFilelist)) {
return;
}
chromeos::DebugDaemonClient* debugd_client =
chromeos::DBusThreadManager::Get()->GetDebugDaemonClient();
CHECK(debugd_client);
int min_mb = kCrOSMinFilelistMb.Get();
if (min_mb < 0) {
LOG(ERROR) << "Min Filelist MB is enabled with an invalid value: "
<< min_mb;
return;
}
VLOG(1) << "Setting min filelist to " << min_mb << "MB";
debugd_client->SetSwapParameter(
kMinFilelist, min_mb, base::BindOnce(&OnSwapParameterSet, kMinFilelist));
}
} // namespace
void ConfigureSwap() {
ConfigureMinFilelistIfEnabled();
}
} // namespace chromeos
// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROMEOS_MEMORY_SWAP_CONFIGURATION_H_
#define CHROMEOS_MEMORY_SWAP_CONFIGURATION_H_
#include "base/feature_list.h"
#include "base/metrics/field_trial_params.h"
#include "chromeos/chromeos_export.h"
namespace chromeos {
// Controls the ChromeOS /proc/sys/vm/min_filelist_kb swap tunable, if the
// feature is enabled it will use the value (in MB) from the feature param.
extern const base::Feature kCrOSTuneMinFilelist;
extern const base::FeatureParam<int> kCrOSTuneMinFilelistMb;
// Configure swap will configure any swap related experiments that this user may
// be opted into.
CHROMEOS_EXPORT void ConfigureSwap();
} // namespace chromeos
#endif // CHROMEOS_MEMORY_SWAP_CONFIGURATION_H_
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment