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

chromeos: Add a kstaled configuration via Debugd.

Kstaled is a new swap subsystem for CrOS. This CL will send dbus
messages to debugd based on the user's experimental group.

BUG=b/123039911
TESTED=With a 4.14 kernel and a new debugd build.

Change-Id: Ide79d61050e2d916d8d9907d37856746ef12c29d
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1858463
Commit-Queue: Brian Geffon <bgeffon@chromium.org>
Reviewed-by: default avatarSteven Bennetts <stevenjb@chromium.org>
Reviewed-by: default avatarJay Civelli <jcivelli@chromium.org>
Cr-Commit-Position: refs/heads/master@{#709588}
parent e4e7e9b8
...@@ -12,6 +12,7 @@ include_rules = [ ...@@ -12,6 +12,7 @@ include_rules = [
"+chrome/utility/chrome_content_utility_client.h", "+chrome/utility/chrome_content_utility_client.h",
"+chromeos/constants", "+chromeos/constants",
"+chromeos/hugepage_text/hugepage_text.h", "+chromeos/hugepage_text/hugepage_text.h",
"+chromeos/memory/kstaled.h",
"+components/browser_watcher", "+components/browser_watcher",
"+components/component_updater", "+components/component_updater",
"+components/content_settings/core/common/content_settings_pattern.h", "+components/content_settings/core/common/content_settings_pattern.h",
......
...@@ -113,6 +113,7 @@ ...@@ -113,6 +113,7 @@
#include "chromeos/constants/chromeos_paths.h" #include "chromeos/constants/chromeos_paths.h"
#include "chromeos/constants/chromeos_switches.h" #include "chromeos/constants/chromeos_switches.h"
#include "chromeos/hugepage_text/hugepage_text.h" #include "chromeos/hugepage_text/hugepage_text.h"
#include "chromeos/memory/kstaled.h"
#endif #endif
#if defined(OS_ANDROID) #if defined(OS_ANDROID)
...@@ -598,6 +599,10 @@ void ChromeMainDelegate::PostFieldTrialInitialization() { ...@@ -598,6 +599,10 @@ void ChromeMainDelegate::PostFieldTrialInitialization() {
if (is_browser_process) { if (is_browser_process) {
heap_profiler_controller_ = std::make_unique<HeapProfilerController>(); heap_profiler_controller_ = std::make_unique<HeapProfilerController>();
heap_profiler_controller_->Start(); heap_profiler_controller_->Start();
#if defined(OS_CHROMEOS)
chromeos::InitializeKstaled();
#endif
} }
} }
......
...@@ -44,6 +44,8 @@ component("chromeos") { ...@@ -44,6 +44,8 @@ component("chromeos") {
sources = [ sources = [
"hugepage_text/hugepage_text.cc", "hugepage_text/hugepage_text.cc",
"hugepage_text/hugepage_text.h", "hugepage_text/hugepage_text.h",
"memory/kstaled.cc",
"memory/kstaled.h",
"policy/weekly_time/time_utils.cc", "policy/weekly_time/time_utils.cc",
"policy/weekly_time/time_utils.h", "policy/weekly_time/time_utils.h",
"policy/weekly_time/weekly_time.cc", "policy/weekly_time/weekly_time.cc",
......
...@@ -551,6 +551,17 @@ class DebugDaemonClientImpl : public DebugDaemonClient { ...@@ -551,6 +551,17 @@ class DebugDaemonClientImpl : public DebugDaemonClient {
weak_ptr_factory_.GetWeakPtr(), std::move(callback))); weak_ptr_factory_.GetWeakPtr(), std::move(callback)));
} }
void SetKstaledRatio(uint8_t val, KstaledRatioCallback callback) override {
dbus::MethodCall method_call(debugd::kDebugdInterface,
debugd::kKstaledSetRatio);
dbus::MessageWriter writer(&method_call);
writer.AppendByte(val);
debugdaemon_proxy_->CallMethod(
&method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT,
base::BindOnce(&DebugDaemonClientImpl::OnSetKstaledRatio,
weak_ptr_factory_.GetWeakPtr(), std::move(callback)));
}
void SetSchedulerConfigurationV2( void SetSchedulerConfigurationV2(
const std::string& config_name, const std::string& config_name,
bool lock_policy, bool lock_policy,
...@@ -844,6 +855,25 @@ class DebugDaemonClientImpl : public DebugDaemonClient { ...@@ -844,6 +855,25 @@ class DebugDaemonClientImpl : public DebugDaemonClient {
std::move(callback).Run(result); std::move(callback).Run(result);
} }
void OnSetKstaledRatio(KstaledRatioCallback callback,
dbus::Response* response) {
if (!response) {
LOG(ERROR) << "Failed to read debugd response";
std::move(callback).Run(false);
return;
}
bool result = false;
dbus::MessageReader reader(response);
if (!reader.PopBool(&result)) {
LOG(ERROR) << "Debugd response did not contain a bool";
std::move(callback).Run(false);
return;
}
std::move(callback).Run(result);
}
void OnSetSchedulerConfigurationV2( void OnSetSchedulerConfigurationV2(
SetSchedulerConfigurationV2Callback callback, SetSchedulerConfigurationV2Callback callback,
dbus::Response* response) { dbus::Response* response) {
......
...@@ -109,6 +109,12 @@ class COMPONENT_EXPORT(DEBUG_DAEMON) DebugDaemonClient ...@@ -109,6 +109,12 @@ class COMPONENT_EXPORT(DEBUG_DAEMON) DebugDaemonClient
virtual void SetStopAgentTracingTaskRunner( virtual void SetStopAgentTracingTaskRunner(
scoped_refptr<base::TaskRunner> task_runner) = 0; scoped_refptr<base::TaskRunner> task_runner) = 0;
using KstaledRatioCallback = base::OnceCallback<void(bool)>;
// Sets the kstaled ratio to the provided value, for more information
// see chromeos/memory/README.md.
virtual void SetKstaledRatio(uint8_t val, KstaledRatioCallback) = 0;
// Called once TestICMP() is complete. Takes an optional string. // Called once TestICMP() is complete. Takes an optional string.
// - The optional string has value if information was obtained successfully. // - The optional string has value if information was obtained successfully.
// - The string value contains information about ICMP connectivity to a // - The string value contains information about ICMP connectivity to a
......
...@@ -18,6 +18,7 @@ ...@@ -18,6 +18,7 @@
#include "base/optional.h" #include "base/optional.h"
#include "base/single_thread_task_runner.h" #include "base/single_thread_task_runner.h"
#include "base/stl_util.h" #include "base/stl_util.h"
#include "base/strings/string_number_conversions.h"
#include "base/threading/thread_task_runner_handle.h" #include "base/threading/thread_task_runner_handle.h"
#include "chromeos/dbus/constants/dbus_switches.h" #include "chromeos/dbus/constants/dbus_switches.h"
...@@ -49,6 +50,12 @@ void FakeDebugDaemonClient::SetDebugMode(const std::string& subsystem, ...@@ -49,6 +50,12 @@ void FakeDebugDaemonClient::SetDebugMode(const std::string& subsystem,
std::move(callback).Run(false); std::move(callback).Run(false);
} }
void FakeDebugDaemonClient::SetKstaledRatio(uint8_t val,
KstaledRatioCallback callback) {
// We just return true.
std::move(callback).Run(true /* success */);
}
std::string FakeDebugDaemonClient::GetTracingAgentName() { std::string FakeDebugDaemonClient::GetTracingAgentName() {
return kCrOSTracingAgentName; return kCrOSTracingAgentName;
} }
......
...@@ -45,6 +45,7 @@ class COMPONENT_EXPORT(DEBUG_DAEMON) FakeDebugDaemonClient ...@@ -45,6 +45,7 @@ class COMPONENT_EXPORT(DEBUG_DAEMON) FakeDebugDaemonClient
bool numeric, bool numeric,
bool ipv6, bool ipv6,
DBusMethodCallback<std::vector<std::string>> callback) override; DBusMethodCallback<std::vector<std::string>> callback) override;
void SetKstaledRatio(uint8_t val, KstaledRatioCallback callback) override;
void GetNetworkStatus(DBusMethodCallback<std::string> callback) override; void GetNetworkStatus(DBusMethodCallback<std::string> callback) override;
void GetNetworkInterfaces(DBusMethodCallback<std::string> callback) override; void GetNetworkInterfaces(DBusMethodCallback<std::string> callback) override;
void GetPerfOutput(base::TimeDelta duration, void GetPerfOutput(base::TimeDelta duration,
......
bgeffon@chromium.org
sonnyrao@chromium.org
yuzaho@chromium.org
kstaled is a replacement for kswapd on ChromeOS. It will result in more
proactive swapping based on a configurable ratio. The default ratio is 4
and a ratio of 0 will disable the feature. For more information, see
the ChromeOS kernel source include/linux/kstaled.h.
// 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/kstaled.h"
#include "base/bind.h"
#include "base/feature_list.h"
#include "base/files/file_util.h"
#include "base/metrics/field_trial_params.h"
#include "base/strings/string_number_conversions.h"
#include "chromeos/dbus/dbus_thread_manager.h"
#include "chromeos/dbus/debug_daemon/debug_daemon_client.h"
namespace chromeos {
namespace {
constexpr char kKstaledRatioFile[] = "/sys/kernel/mm/kstaled/ratio";
// KernelSupportsKstaled will check if the kernel supports kstaled this is as
// easy as checking for the kstaled sysfs node.
bool KernelSupportsKstaled() {
static const bool supported =
base::PathExists(base::FilePath(kKstaledRatioFile));
return supported;
}
void OnRatioSet(bool success) {
if (!success) {
LOG(ERROR) << "Unable to configure kstaled";
return;
}
VLOG(1) << "Debugd configured kstaled with value: " << kKstaledRatio.Get();
}
} // namespace
const base::Feature kKstaled{"KstaledSwap", base::FEATURE_DISABLED_BY_DEFAULT};
const base::FeatureParam<int> kKstaledRatio = {&kKstaled, "KstaledRatio", 4};
// InitializeKstaled will attempt to configure kstaled with the experimental
// parameters for this user.
void InitializeKstaled() {
bool feature_enabled = base::FeatureList::IsEnabled(kKstaled);
if (!feature_enabled) {
VLOG(1) << "Kstaled is disabled";
return;
}
if (!KernelSupportsKstaled()) {
LOG(ERROR) << "Unable to configure kstaled: no kernel support";
return;
}
int feature_ratio = kKstaledRatio.Get();
if (feature_ratio <= 0 || feature_ratio > 255) {
LOG(ERROR) << "Configuring kstaled with a ratio of 0 disables the "
"feature, the valid range is 1-255.";
return;
}
chromeos::DebugDaemonClient* debugd_client =
chromeos::DBusThreadManager::Get()->GetDebugDaemonClient();
DCHECK(debugd_client);
debugd_client->SetKstaledRatio(static_cast<uint8_t>(feature_ratio),
base::Bind(&OnRatioSet));
}
} // 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_KSTALED_H_
#define CHROMEOS_MEMORY_KSTALED_H_
#include "base/feature_list.h"
#include "base/metrics/field_trial_params.h"
#include "chromeos/chromeos_export.h"
namespace chromeos {
// The Kstaled experimental feature.
extern const base::Feature kKstaled;
// The ratio parameter used for kstaled.
extern const base::FeatureParam<int> kKstaledRatio;
// InitializeKstaled will attempt to configure kstaled with the experimental
// parameters for this user.
CHROMEOS_EXPORT void InitializeKstaled();
} // namespace chromeos
#endif // CHROMEOS_MEMORY_KSTALED_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