From 67ea4959a2391717f7149b6902e39631606a21c2 Mon Sep 17 00:00:00 2001 From: Daniel Zheng Date: Wed, 22 May 2024 12:18:45 -0700 Subject: [PATCH 1/4] libsnapshot: get read_ahead_size from build In the case that read ahead size is set by the build, we want to read that property rather than use our default. Bug: 332255580 Test: th Change-Id: I5302a9a275d284be6c68edab9e13aae1128eb699 --- .../android/snapshot/snapshot.proto | 3 ++ fs_mgr/libsnapshot/partition_cow_creator.h | 1 + fs_mgr/libsnapshot/snapshot.cpp | 43 +++++++++---------- 3 files changed, 25 insertions(+), 22 deletions(-) diff --git a/fs_mgr/libsnapshot/android/snapshot/snapshot.proto b/fs_mgr/libsnapshot/android/snapshot/snapshot.proto index 076a918fe..25f1d8847 100644 --- a/fs_mgr/libsnapshot/android/snapshot/snapshot.proto +++ b/fs_mgr/libsnapshot/android/snapshot/snapshot.proto @@ -120,6 +120,9 @@ message SnapshotStatus { // Max bytes to be compressed at once (4k, 8k, 16k, 32k, 64k, 128k) uint64 compression_factor = 16; + + // Default value is 32, can be set lower for low mem devices + uint32 read_ahead_size = 17; } // Next: 8 diff --git a/fs_mgr/libsnapshot/partition_cow_creator.h b/fs_mgr/libsnapshot/partition_cow_creator.h index cbd664fef..a75d993c7 100644 --- a/fs_mgr/libsnapshot/partition_cow_creator.h +++ b/fs_mgr/libsnapshot/partition_cow_creator.h @@ -60,6 +60,7 @@ struct PartitionCowCreator { bool using_snapuserd = false; std::string compression_algorithm; uint64_t compression_factor; + uint32_t read_ahead_size; // True if multi-threaded compression should be enabled bool enable_threading; diff --git a/fs_mgr/libsnapshot/snapshot.cpp b/fs_mgr/libsnapshot/snapshot.cpp index 7ca53ad42..8620620e4 100644 --- a/fs_mgr/libsnapshot/snapshot.cpp +++ b/fs_mgr/libsnapshot/snapshot.cpp @@ -101,8 +101,7 @@ static constexpr auto kUpdateStateCheckInterval = 2s; * time, they could use O_DIRECT functionality wherein the I/O to the source * block device will be O_DIRECT. */ -static constexpr auto kCowReadAheadSizeKb = 32; -static constexpr auto kSourceReadAheadSizeKb = 32; +static constexpr auto kReadAheadSizeKb = 32; // Note: IImageManager is an incomplete type in the header, so the default // destructor doesn't work. @@ -418,6 +417,7 @@ bool SnapshotManager::CreateSnapshot(LockedFile* lock, PartitionCowCreator* cow_ status->set_using_snapuserd(cow_creator->using_snapuserd); status->set_compression_algorithm(cow_creator->compression_algorithm); status->set_compression_factor(cow_creator->compression_factor); + status->set_read_ahead_size(cow_creator->read_ahead_size); if (cow_creator->enable_threading) { status->set_enable_threading(cow_creator->enable_threading); } @@ -1142,8 +1142,8 @@ auto SnapshotManager::CheckMergeState(const std::function& before_cancel return result; } -auto SnapshotManager::CheckMergeState(LockedFile* lock, const std::function& before_cancel) - -> MergeResult { +auto SnapshotManager::CheckMergeState(LockedFile* lock, + const std::function& before_cancel) -> MergeResult { SnapshotUpdateStatus update_status = ReadSnapshotUpdateStatus(lock); switch (update_status.state()) { case UpdateState::None: @@ -1765,9 +1765,8 @@ bool SnapshotManager::PerformInitTransition(InitTransition transition, base_path_merge; snapuserd_argv->emplace_back(std::move(message)); } - - SetReadAheadSize(cow_image_device, kCowReadAheadSizeKb); - SetReadAheadSize(source_device, kSourceReadAheadSizeKb); + SetReadAheadSize(cow_image_device, snapshot_status.read_ahead_size()); + SetReadAheadSize(source_device, snapshot_status.read_ahead_size()); // Do not attempt to connect to the new snapuserd yet, it hasn't // been started. We do however want to wait for the misc device @@ -2852,8 +2851,8 @@ bool SnapshotManager::UnmapAllSnapshots(LockedFile* lock) { return true; } -auto SnapshotManager::OpenFile(const std::string& file, int lock_flags) - -> std::unique_ptr { +auto SnapshotManager::OpenFile(const std::string& file, + int lock_flags) -> std::unique_ptr { unique_fd fd(open(file.c_str(), O_RDONLY | O_CLOEXEC | O_NOFOLLOW)); if (fd < 0) { PLOG(ERROR) << "Open failed: " << file; @@ -3309,19 +3308,19 @@ Return SnapshotManager::CreateUpdateSnapshots(const DeltaArchiveManifest& manife LOG(INFO) << "using compression algorithm: " << compression_algorithm << ", max compressible block size: " << compression_factor; } - - PartitionCowCreator cow_creator{ - .target_metadata = target_metadata.get(), - .target_suffix = target_suffix, - .target_partition = nullptr, - .current_metadata = current_metadata.get(), - .current_suffix = current_suffix, - .update = nullptr, - .extra_extents = {}, - .using_snapuserd = using_snapuserd, - .compression_algorithm = compression_algorithm, - .compression_factor = compression_factor, - }; + auto read_ahead_size = + android::base::GetUintProperty("ro.virtual_ab.read_ahead_size", kReadAheadSizeKb); + PartitionCowCreator cow_creator{.target_metadata = target_metadata.get(), + .target_suffix = target_suffix, + .target_partition = nullptr, + .current_metadata = current_metadata.get(), + .current_suffix = current_suffix, + .update = nullptr, + .extra_extents = {}, + .using_snapuserd = using_snapuserd, + .compression_algorithm = compression_algorithm, + .compression_factor = compression_factor, + .read_ahead_size = read_ahead_size}; if (dap_metadata.vabc_feature_set().has_threaded()) { cow_creator.enable_threading = dap_metadata.vabc_feature_set().threaded(); From 6c0800fbbdaa56c4d38cb24bcd0289cb0bf88e74 Mon Sep 17 00:00:00 2001 From: Daniel Zheng Date: Wed, 22 May 2024 12:36:36 -0700 Subject: [PATCH 2/4] update supported compression methods Test: th Change-Id: Ice13f58e6d29b8f28a4d43a86fb59e91ae9e9dde --- fs_mgr/libsnapshot/android/snapshot/snapshot.proto | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fs_mgr/libsnapshot/android/snapshot/snapshot.proto b/fs_mgr/libsnapshot/android/snapshot/snapshot.proto index 25f1d8847..c6c3aecb8 100644 --- a/fs_mgr/libsnapshot/android/snapshot/snapshot.proto +++ b/fs_mgr/libsnapshot/android/snapshot/snapshot.proto @@ -103,7 +103,7 @@ message SnapshotStatus { // The old partition size (if none existed, this will be zero). uint64 old_partition_size = 10; - // Compression algorithm (none, gz, lz4, zstd, or brotli). + // Compression algorithm (none, lz4, zstd). string compression_algorithm = 11; // Estimated COW size from OTA manifest. From 09e081f98eaa8da729ec7637afce0d0ecc9d84e1 Mon Sep 17 00:00:00 2001 From: Daniel Zheng Date: Thu, 23 May 2024 10:56:30 -0700 Subject: [PATCH 3/4] snapshot_proto add build configuration variables We are adding low memory device configurables. Post OTA reboot, these values need to be read during 1st stage init and set. Since .ro props aren't available at this stage, we need to flush these configurables to snapshot_protos that lives under /Metadata Bug: 332255580 Test: th Change-Id: Iff84c0dfe9c6931ea13165b380e11cee6343ce91 --- fs_mgr/libsnapshot/android/snapshot/snapshot.proto | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/fs_mgr/libsnapshot/android/snapshot/snapshot.proto b/fs_mgr/libsnapshot/android/snapshot/snapshot.proto index c6c3aecb8..d04c9c19d 100644 --- a/fs_mgr/libsnapshot/android/snapshot/snapshot.proto +++ b/fs_mgr/libsnapshot/android/snapshot/snapshot.proto @@ -123,6 +123,15 @@ message SnapshotStatus { // Default value is 32, can be set lower for low mem devices uint32 read_ahead_size = 17; + + // Enable direct reads on source device + bool o_direct = 18; + + // Blocks size to be verified at once + uint64 verify_block_size = 19; + + // Default value is 2, configures threads to do verification phase + uint32 num_verify_threads = 20; } // Next: 8 From 43b2abf797b0ce62e02717118facad559b49e00b Mon Sep 17 00:00:00 2001 From: Daniel Zheng Date: Thu, 23 May 2024 14:13:27 -0700 Subject: [PATCH 4/4] libsnapshot: set num merge threads Read number of merge threads from build. In the case that this isn't specified, fallback to our default. **THIS doesn't seem to be currently working. It looks like we can't directly read the property here? Test: th Change-Id: I115b6b987699759168d34239d030cfcd0238b1b4 --- .../snapuserd/user-space-merge/handler_manager.cpp | 5 ++++- .../snapuserd/user-space-merge/snapuserd_server.h | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/fs_mgr/libsnapshot/snapuserd/user-space-merge/handler_manager.cpp b/fs_mgr/libsnapshot/snapuserd/user-space-merge/handler_manager.cpp index 711e70473..ea11f0e6e 100644 --- a/fs_mgr/libsnapshot/snapuserd/user-space-merge/handler_manager.cpp +++ b/fs_mgr/libsnapshot/snapuserd/user-space-merge/handler_manager.cpp @@ -19,6 +19,7 @@ #include +#include "android-base/properties.h" #include "merge_worker.h" #include "read_worker.h" #include "snapuserd_core.h" @@ -235,8 +236,10 @@ void SnapshotHandlerManager::MonitorMerge() { LOG(INFO) << "MonitorMerge: active-merge-threads: " << active_merge_threads_; { + auto num_merge_threads = android::base::GetUintProperty( + "ro.virtual_ab.num_merge_threads", kMaxMergeThreads); std::lock_guard lock(lock_); - while (active_merge_threads_ < kMaxMergeThreads && merge_handlers_.size() > 0) { + while (active_merge_threads_ < num_merge_threads && merge_handlers_.size() > 0) { auto handler = merge_handlers_.front(); merge_handlers_.pop(); diff --git a/fs_mgr/libsnapshot/snapuserd/user-space-merge/snapuserd_server.h b/fs_mgr/libsnapshot/snapuserd/user-space-merge/snapuserd_server.h index 3013c47fc..d9cf97f9d 100644 --- a/fs_mgr/libsnapshot/snapuserd/user-space-merge/snapuserd_server.h +++ b/fs_mgr/libsnapshot/snapuserd/user-space-merge/snapuserd_server.h @@ -39,7 +39,7 @@ namespace android { namespace snapshot { static constexpr uint32_t kMaxPacketSize = 512; -static constexpr uint8_t kMaxMergeThreads = 2; + static constexpr char kBootSnapshotsWithoutSlotSwitch[] = "/metadata/ota/snapshot-boot-without-slot-switch";