Set taskprofile to snapshot merge thread

Assign CPUSET_SP_BACKGROUND taskprofile to snapshot merge threads.
This will ensure that the threads will not run on big cores.

Additionally, reduce the flushing of data to 1MB after merging REPLACE ops.

No major regression observed on snashot merge time.

On Pixel 6 for incremental OTA of 500M, snapshot merge time increased
from 72 seconds to 76 seconds after this patch.

Bug: 311233916
Test: Full and incremental OTA on Pixel 6 - Verify merge threads not on big cores
Change-Id: I455afdac0b77227869d846d0c4472ea9eb34c41c
Signed-off-by: Akilesh Kailash <akailash@google.com>
This commit is contained in:
Akilesh Kailash 2023-11-26 13:55:56 -08:00
parent 7e2b6cc9fa
commit e57ef38bb2
5 changed files with 49 additions and 3 deletions

View file

@ -86,10 +86,15 @@ cc_library_static {
"libext4_utils",
"libsnapshot_cow",
"liburing",
"libprocessgroup",
"libjsoncpp",
"libcgrouprc",
"libcgrouprc_format",
],
include_dirs: ["bionic/libc/kernel"],
export_include_dirs: ["include"],
header_libs: [
"libcutils_headers",
"libstorage_literals_headers",
],
ramdisk_available: true,
@ -126,6 +131,10 @@ cc_defaults {
"liblog",
"libsnapshot_cow",
"libsnapuserd",
"libprocessgroup",
"libjsoncpp",
"libcgrouprc",
"libcgrouprc_format",
"libsnapuserd_client",
"libz",
"liblz4",
@ -135,6 +144,7 @@ cc_defaults {
],
header_libs: [
"libcutils_headers",
"libstorage_literals_headers",
],
@ -251,6 +261,10 @@ cc_defaults {
"libgtest",
"libsnapshot_cow",
"libsnapuserd",
"libprocessgroup",
"libjsoncpp",
"libcgrouprc",
"libcgrouprc_format",
"liburing",
"libz",
],
@ -261,6 +275,7 @@ cc_defaults {
header_libs: [
"libstorage_literals_headers",
"libfiemap_headers",
"libcutils_headers",
],
test_options: {
min_shipping_api_level: 30,
@ -320,6 +335,10 @@ cc_binary_host {
"libgflags",
"libsnapshot_cow",
"libsnapuserd",
"libprocessgroup",
"libjsoncpp",
"libcgrouprc",
"libcgrouprc_format",
"liburing",
"libz",
],
@ -330,5 +349,6 @@ cc_binary_host {
header_libs: [
"libstorage_literals_headers",
"libfiemap_headers",
"libcutils_headers",
],
}

View file

@ -80,16 +80,16 @@ int MergeWorker::PrepareMerge(uint64_t* source_offset, int* pending_ops,
}
bool MergeWorker::MergeReplaceZeroOps() {
// Flush after merging 2MB. Since all ops are independent and there is no
// Flush after merging 1MB. Since all ops are independent and there is no
// dependency between COW ops, we will flush the data and the number
// of ops merged in COW block device. If there is a crash, we will
// end up replaying some of the COW ops which were already merged. That is
// ok.
//
// Although increasing this greater than 2MB may help in improving merge
// Although increasing this greater than 1MB may help in improving merge
// times; however, on devices with low memory, this can be problematic
// when there are multiple merge threads in parallel.
int total_ops_merged_per_commit = (PAYLOAD_BUFFER_SZ / BLOCK_SZ) * 2;
int total_ops_merged_per_commit = (PAYLOAD_BUFFER_SZ / BLOCK_SZ);
int num_ops_merged = 0;
SNAP_LOG(INFO) << "MergeReplaceZeroOps started....";
@ -561,6 +561,10 @@ bool MergeWorker::Run() {
SNAP_PLOG(ERROR) << "Failed to set thread priority";
}
if (!SetProfiles({"CPUSET_SP_BACKGROUND"})) {
SNAP_PLOG(ERROR) << "Failed to assign task profile to Mergeworker thread";
}
SNAP_LOG(INFO) << "Merge starting..";
bufsink_.Initialize(PAYLOAD_BUFFER_SZ);

View file

@ -782,6 +782,10 @@ bool ReadAhead::RunThread() {
SNAP_PLOG(ERROR) << "Failed to set thread priority";
}
if (!SetProfiles({"CPUSET_SP_BACKGROUND"})) {
SNAP_PLOG(ERROR) << "Failed to assign task profile to readahead thread";
}
SNAP_LOG(INFO) << "ReadAhead processing.";
while (!RAIterDone()) {
if (!ReadAheadIOStart()) {

View file

@ -19,6 +19,9 @@
#include <unistd.h>
#include <android-base/file.h>
#include <processgroup/processgroup.h>
#include <private/android_filesystem_config.h>
namespace android {
namespace snapshot {
@ -33,6 +36,17 @@ bool SetThreadPriority([[maybe_unused]] int priority) {
#endif
}
bool SetProfiles([[maybe_unused]] std::initializer_list<std::string_view> profiles) {
#ifdef __ANDROID__
if (setgid(AID_SYSTEM)) {
return false;
}
return SetTaskProfiles(gettid(), profiles);
#else
return true;
#endif
}
bool KernelSupportsIoUring() {
struct utsname uts {};
unsigned int major, minor;

View file

@ -14,10 +14,14 @@
#pragma once
#include <initializer_list>
#include <string_view>
namespace android {
namespace snapshot {
bool SetThreadPriority(int priority);
bool SetProfiles(std::initializer_list<std::string_view> profiles);
bool KernelSupportsIoUring();
} // namespace snapshot