From e57ef38bb2fbf213ec7e23ca659f731ef4b517ab Mon Sep 17 00:00:00 2001 From: Akilesh Kailash Date: Sun, 26 Nov 2023 13:55:56 -0800 Subject: [PATCH] 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 --- fs_mgr/libsnapshot/snapuserd/Android.bp | 20 +++++++++++++++++++ .../user-space-merge/merge_worker.cpp | 10 +++++++--- .../user-space-merge/snapuserd_readahead.cpp | 4 ++++ fs_mgr/libsnapshot/snapuserd/utility.cpp | 14 +++++++++++++ fs_mgr/libsnapshot/snapuserd/utility.h | 4 ++++ 5 files changed, 49 insertions(+), 3 deletions(-) diff --git a/fs_mgr/libsnapshot/snapuserd/Android.bp b/fs_mgr/libsnapshot/snapuserd/Android.bp index 6b8e08417..bd296a396 100644 --- a/fs_mgr/libsnapshot/snapuserd/Android.bp +++ b/fs_mgr/libsnapshot/snapuserd/Android.bp @@ -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", ], } diff --git a/fs_mgr/libsnapshot/snapuserd/user-space-merge/merge_worker.cpp b/fs_mgr/libsnapshot/snapuserd/user-space-merge/merge_worker.cpp index bcf9aabe9..1e7d0c0a2 100644 --- a/fs_mgr/libsnapshot/snapuserd/user-space-merge/merge_worker.cpp +++ b/fs_mgr/libsnapshot/snapuserd/user-space-merge/merge_worker.cpp @@ -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); diff --git a/fs_mgr/libsnapshot/snapuserd/user-space-merge/snapuserd_readahead.cpp b/fs_mgr/libsnapshot/snapuserd/user-space-merge/snapuserd_readahead.cpp index c08c1b196..2baf20ddd 100644 --- a/fs_mgr/libsnapshot/snapuserd/user-space-merge/snapuserd_readahead.cpp +++ b/fs_mgr/libsnapshot/snapuserd/user-space-merge/snapuserd_readahead.cpp @@ -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()) { diff --git a/fs_mgr/libsnapshot/snapuserd/utility.cpp b/fs_mgr/libsnapshot/snapuserd/utility.cpp index fcdb69dd1..684ca3d7b 100644 --- a/fs_mgr/libsnapshot/snapuserd/utility.cpp +++ b/fs_mgr/libsnapshot/snapuserd/utility.cpp @@ -19,6 +19,9 @@ #include #include +#include + +#include namespace android { namespace snapshot { @@ -33,6 +36,17 @@ bool SetThreadPriority([[maybe_unused]] int priority) { #endif } +bool SetProfiles([[maybe_unused]] std::initializer_list 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; diff --git a/fs_mgr/libsnapshot/snapuserd/utility.h b/fs_mgr/libsnapshot/snapuserd/utility.h index 255aee195..c3c3cbae9 100644 --- a/fs_mgr/libsnapshot/snapuserd/utility.h +++ b/fs_mgr/libsnapshot/snapuserd/utility.h @@ -14,10 +14,14 @@ #pragma once +#include +#include + namespace android { namespace snapshot { bool SetThreadPriority(int priority); +bool SetProfiles(std::initializer_list profiles); bool KernelSupportsIoUring(); } // namespace snapshot