Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 0381ebef authored by Daniel Zheng's avatar Daniel Zheng Committed by Gerrit Code Review
Browse files

Merge changes I115b6b98,Iff84c0df,Ice13f58e,I5302a9a2 into main

* changes:
  libsnapshot: set num merge threads
  snapshot_proto add build configuration variables
  update supported compression methods
  libsnapshot: get read_ahead_size from build
parents 24e39aff 43b2abf7
Loading
Loading
Loading
Loading
+13 −1
Original line number Original line Diff line number Diff line
@@ -103,7 +103,7 @@ message SnapshotStatus {
    // The old partition size (if none existed, this will be zero).
    // The old partition size (if none existed, this will be zero).
    uint64 old_partition_size = 10;
    uint64 old_partition_size = 10;


    // Compression algorithm (none, gz, lz4, zstd, or brotli).
    // Compression algorithm (none, lz4, zstd).
    string compression_algorithm = 11;
    string compression_algorithm = 11;


    // Estimated COW size from OTA manifest.
    // Estimated COW size from OTA manifest.
@@ -120,6 +120,18 @@ message SnapshotStatus {


    // Max bytes to be compressed at once (4k, 8k, 16k, 32k, 64k, 128k)
    // Max bytes to be compressed at once (4k, 8k, 16k, 32k, 64k, 128k)
    uint64 compression_factor = 16;
    uint64 compression_factor = 16;

    // 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
// Next: 8
+1 −0
Original line number Original line Diff line number Diff line
@@ -60,6 +60,7 @@ struct PartitionCowCreator {
    bool using_snapuserd = false;
    bool using_snapuserd = false;
    std::string compression_algorithm;
    std::string compression_algorithm;
    uint64_t compression_factor;
    uint64_t compression_factor;
    uint32_t read_ahead_size;


    // True if multi-threaded compression should be enabled
    // True if multi-threaded compression should be enabled
    bool enable_threading;
    bool enable_threading;
+21 −22
Original line number Original line Diff line number Diff line
@@ -101,8 +101,7 @@ static constexpr auto kUpdateStateCheckInterval = 2s;
 * time, they could use O_DIRECT functionality wherein the I/O to the source
 * time, they could use O_DIRECT functionality wherein the I/O to the source
 * block device will be O_DIRECT.
 * block device will be O_DIRECT.
 */
 */
static constexpr auto kCowReadAheadSizeKb = 32;
static constexpr auto kReadAheadSizeKb = 32;
static constexpr auto kSourceReadAheadSizeKb = 32;


// Note: IImageManager is an incomplete type in the header, so the default
// Note: IImageManager is an incomplete type in the header, so the default
// destructor doesn't work.
// 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_using_snapuserd(cow_creator->using_snapuserd);
    status->set_compression_algorithm(cow_creator->compression_algorithm);
    status->set_compression_algorithm(cow_creator->compression_algorithm);
    status->set_compression_factor(cow_creator->compression_factor);
    status->set_compression_factor(cow_creator->compression_factor);
    status->set_read_ahead_size(cow_creator->read_ahead_size);
    if (cow_creator->enable_threading) {
    if (cow_creator->enable_threading) {
        status->set_enable_threading(cow_creator->enable_threading);
        status->set_enable_threading(cow_creator->enable_threading);
    }
    }
@@ -1142,8 +1142,8 @@ auto SnapshotManager::CheckMergeState(const std::function<bool()>& before_cancel
    return result;
    return result;
}
}


auto SnapshotManager::CheckMergeState(LockedFile* lock, const std::function<bool()>& before_cancel)
auto SnapshotManager::CheckMergeState(LockedFile* lock,
        -> MergeResult {
                                      const std::function<bool()>& before_cancel) -> MergeResult {
    SnapshotUpdateStatus update_status = ReadSnapshotUpdateStatus(lock);
    SnapshotUpdateStatus update_status = ReadSnapshotUpdateStatus(lock);
    switch (update_status.state()) {
    switch (update_status.state()) {
        case UpdateState::None:
        case UpdateState::None:
@@ -1765,9 +1765,8 @@ bool SnapshotManager::PerformInitTransition(InitTransition transition,
                               base_path_merge;
                               base_path_merge;
                snapuserd_argv->emplace_back(std::move(message));
                snapuserd_argv->emplace_back(std::move(message));
            }
            }

            SetReadAheadSize(cow_image_device, snapshot_status.read_ahead_size());
            SetReadAheadSize(cow_image_device, kCowReadAheadSizeKb);
            SetReadAheadSize(source_device, snapshot_status.read_ahead_size());
            SetReadAheadSize(source_device, kSourceReadAheadSizeKb);


            // Do not attempt to connect to the new snapuserd yet, it hasn't
            // 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
            // been started. We do however want to wait for the misc device
@@ -2852,8 +2851,8 @@ bool SnapshotManager::UnmapAllSnapshots(LockedFile* lock) {
    return true;
    return true;
}
}


auto SnapshotManager::OpenFile(const std::string& file, int lock_flags)
auto SnapshotManager::OpenFile(const std::string& file,
        -> std::unique_ptr<LockedFile> {
                               int lock_flags) -> std::unique_ptr<LockedFile> {
    unique_fd fd(open(file.c_str(), O_RDONLY | O_CLOEXEC | O_NOFOLLOW));
    unique_fd fd(open(file.c_str(), O_RDONLY | O_CLOEXEC | O_NOFOLLOW));
    if (fd < 0) {
    if (fd < 0) {
        PLOG(ERROR) << "Open failed: " << file;
        PLOG(ERROR) << "Open failed: " << file;
@@ -3309,9 +3308,9 @@ Return SnapshotManager::CreateUpdateSnapshots(const DeltaArchiveManifest& manife
        LOG(INFO) << "using compression algorithm: " << compression_algorithm
        LOG(INFO) << "using compression algorithm: " << compression_algorithm
                  << ", max compressible block size: " << compression_factor;
                  << ", max compressible block size: " << compression_factor;
    }
    }

    auto read_ahead_size =
    PartitionCowCreator cow_creator{
            android::base::GetUintProperty<uint>("ro.virtual_ab.read_ahead_size", kReadAheadSizeKb);
            .target_metadata = target_metadata.get(),
    PartitionCowCreator cow_creator{.target_metadata = target_metadata.get(),
                                    .target_suffix = target_suffix,
                                    .target_suffix = target_suffix,
                                    .target_partition = nullptr,
                                    .target_partition = nullptr,
                                    .current_metadata = current_metadata.get(),
                                    .current_metadata = current_metadata.get(),
@@ -3321,7 +3320,7 @@ Return SnapshotManager::CreateUpdateSnapshots(const DeltaArchiveManifest& manife
                                    .using_snapuserd = using_snapuserd,
                                    .using_snapuserd = using_snapuserd,
                                    .compression_algorithm = compression_algorithm,
                                    .compression_algorithm = compression_algorithm,
                                    .compression_factor = compression_factor,
                                    .compression_factor = compression_factor,
    };
                                    .read_ahead_size = read_ahead_size};


    if (dap_metadata.vabc_feature_set().has_threaded()) {
    if (dap_metadata.vabc_feature_set().has_threaded()) {
        cow_creator.enable_threading = dap_metadata.vabc_feature_set().threaded();
        cow_creator.enable_threading = dap_metadata.vabc_feature_set().threaded();
+4 −1
Original line number Original line Diff line number Diff line
@@ -19,6 +19,7 @@


#include <android-base/logging.h>
#include <android-base/logging.h>


#include "android-base/properties.h"
#include "merge_worker.h"
#include "merge_worker.h"
#include "read_worker.h"
#include "read_worker.h"
#include "snapuserd_core.h"
#include "snapuserd_core.h"
@@ -235,8 +236,10 @@ void SnapshotHandlerManager::MonitorMerge() {


        LOG(INFO) << "MonitorMerge: active-merge-threads: " << active_merge_threads_;
        LOG(INFO) << "MonitorMerge: active-merge-threads: " << active_merge_threads_;
        {
        {
            auto num_merge_threads = android::base::GetUintProperty<uint>(
                    "ro.virtual_ab.num_merge_threads", kMaxMergeThreads);
            std::lock_guard<std::mutex> lock(lock_);
            std::lock_guard<std::mutex> 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();
                auto handler = merge_handlers_.front();
                merge_handlers_.pop();
                merge_handlers_.pop();


+1 −1
Original line number Original line Diff line number Diff line
@@ -39,7 +39,7 @@ namespace android {
namespace snapshot {
namespace snapshot {


static constexpr uint32_t kMaxPacketSize = 512;
static constexpr uint32_t kMaxPacketSize = 512;
static constexpr uint8_t kMaxMergeThreads = 2;

static constexpr char kBootSnapshotsWithoutSlotSwitch[] =
static constexpr char kBootSnapshotsWithoutSlotSwitch[] =
        "/metadata/ota/snapshot-boot-without-slot-switch";
        "/metadata/ota/snapshot-boot-without-slot-switch";