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

Commit 1fbba3ed authored by Daniel Zheng's avatar Daniel Zheng
Browse files

libsnapshot: cap merge op count

Set op processing window during snapshot merge from the build. The lower
the merge count, the lower the memory strain during the merge process

Bug: 332255580
Test: verify merge_size propogates to snapuserd daemon
Change-Id: Ic7770115bca963d923a7a276897c5deac30f9faf
parent f2c1d4e7
Loading
Loading
Loading
Loading
+4 −0
Original line number Original line Diff line number Diff line
@@ -229,6 +229,10 @@ message SnapshotUpdateStatus {


    // Enable direct reads from source device
    // Enable direct reads from source device
    bool o_direct = 12;
    bool o_direct = 12;

    // Number of cow operations to be merged at once
    uint32 cow_op_merge_size = 13;

}
}


// Next: 10
// Next: 10
+2 −0
Original line number Original line Diff line number Diff line
@@ -831,6 +831,8 @@ class SnapshotManager final : public ISnapshotManager {
    // Check if direct reads are enabled for the source image
    // Check if direct reads are enabled for the source image
    bool UpdateUsesODirect(LockedFile* lock);
    bool UpdateUsesODirect(LockedFile* lock);


    // Get value of maximum cow op merge size
    uint32_t GetUpdateCowOpMergeSize(LockedFile* lock);
    // Wrapper around libdm, with diagnostics.
    // Wrapper around libdm, with diagnostics.
    bool DeleteDeviceIfExists(const std::string& name,
    bool DeleteDeviceIfExists(const std::string& name,
                              const std::chrono::milliseconds& timeout_ms = {});
                              const std::chrono::milliseconds& timeout_ms = {});
+13 −0
Original line number Original line Diff line number Diff line
@@ -1709,6 +1709,10 @@ bool SnapshotManager::PerformInitTransition(InitTransition transition,
        if (UpdateUsesODirect(lock.get())) {
        if (UpdateUsesODirect(lock.get())) {
            snapuserd_argv->emplace_back("-o_direct");
            snapuserd_argv->emplace_back("-o_direct");
        }
        }
        uint cow_op_merge_size = GetUpdateCowOpMergeSize(lock.get());
        if (cow_op_merge_size != 0) {
            snapuserd_argv->emplace_back("-cow_op_merge_size=" + std::to_string(cow_op_merge_size));
        }
    }
    }


    size_t num_cows = 0;
    size_t num_cows = 0;
@@ -2131,6 +2135,11 @@ bool SnapshotManager::UpdateUsesODirect(LockedFile* lock) {
    return update_status.o_direct();
    return update_status.o_direct();
}
}


uint32_t SnapshotManager::GetUpdateCowOpMergeSize(LockedFile* lock) {
    SnapshotUpdateStatus update_status = ReadSnapshotUpdateStatus(lock);
    return update_status.cow_op_merge_size();
}

bool SnapshotManager::MarkSnapuserdFromSystem() {
bool SnapshotManager::MarkSnapuserdFromSystem() {
    auto path = GetSnapuserdFromSystemPath();
    auto path = GetSnapuserdFromSystemPath();


@@ -3092,6 +3101,7 @@ bool SnapshotManager::WriteUpdateState(LockedFile* lock, UpdateState state,
        status.set_io_uring_enabled(old_status.io_uring_enabled());
        status.set_io_uring_enabled(old_status.io_uring_enabled());
        status.set_legacy_snapuserd(old_status.legacy_snapuserd());
        status.set_legacy_snapuserd(old_status.legacy_snapuserd());
        status.set_o_direct(old_status.o_direct());
        status.set_o_direct(old_status.o_direct());
        status.set_cow_op_merge_size(old_status.cow_op_merge_size());
    }
    }
    return WriteSnapshotUpdateStatus(lock, status);
    return WriteSnapshotUpdateStatus(lock, status);
}
}
@@ -3474,6 +3484,8 @@ Return SnapshotManager::CreateUpdateSnapshots(const DeltaArchiveManifest& manife
            status.set_legacy_snapuserd(true);
            status.set_legacy_snapuserd(true);
            LOG(INFO) << "Setting legacy_snapuserd to true";
            LOG(INFO) << "Setting legacy_snapuserd to true";
        }
        }
        status.set_cow_op_merge_size(
                android::base::GetUintProperty<uint32_t>("ro.virtual_ab.cow_op_merge_size", 0));
    } else if (legacy_compression) {
    } else if (legacy_compression) {
        LOG(INFO) << "Virtual A/B using legacy snapuserd";
        LOG(INFO) << "Virtual A/B using legacy snapuserd";
    } else {
    } else {
@@ -3909,6 +3921,7 @@ bool SnapshotManager::Dump(std::ostream& os) {
    ss << "Using userspace snapshots: " << update_status.userspace_snapshots() << std::endl;
    ss << "Using userspace snapshots: " << update_status.userspace_snapshots() << std::endl;
    ss << "Using io_uring: " << update_status.io_uring_enabled() << std::endl;
    ss << "Using io_uring: " << update_status.io_uring_enabled() << std::endl;
    ss << "Using o_direct: " << update_status.o_direct() << std::endl;
    ss << "Using o_direct: " << update_status.o_direct() << std::endl;
    ss << "Cow op merge size (0 for uncapped): " << update_status.cow_op_merge_size() << std::endl;
    ss << "Using XOR compression: " << GetXorCompressionEnabledProperty() << std::endl;
    ss << "Using XOR compression: " << GetXorCompressionEnabledProperty() << std::endl;
    ss << "Current slot: " << device_->GetSlotSuffix() << std::endl;
    ss << "Current slot: " << device_->GetSlotSuffix() << std::endl;
    ss << "Boot indicator: booting from " << GetCurrentSlot() << " slot" << std::endl;
    ss << "Boot indicator: booting from " << GetCurrentSlot() << " slot" << std::endl;
+3 −3
Original line number Original line Diff line number Diff line
@@ -30,6 +30,7 @@ DEFINE_bool(socket_handoff, false,
DEFINE_bool(user_snapshot, false, "If true, user-space snapshots are used");
DEFINE_bool(user_snapshot, false, "If true, user-space snapshots are used");
DEFINE_bool(io_uring, false, "If true, io_uring feature is enabled");
DEFINE_bool(io_uring, false, "If true, io_uring feature is enabled");
DEFINE_bool(o_direct, false, "If true, enable direct reads on source device");
DEFINE_bool(o_direct, false, "If true, enable direct reads on source device");
DEFINE_int32(cow_op_merge_size, 0, "number of operations to be processed at once");


namespace android {
namespace android {
namespace snapshot {
namespace snapshot {
@@ -106,7 +107,6 @@ bool Daemon::StartServerForUserspaceSnapshots(int arg_start, int argc, char** ar
        }
        }
        return user_server_.Run();
        return user_server_.Run();
    }
    }

    for (int i = arg_start; i < argc; i++) {
    for (int i = arg_start; i < argc; i++) {
        auto parts = android::base::Split(argv[i], ",");
        auto parts = android::base::Split(argv[i], ",");


@@ -114,8 +114,8 @@ bool Daemon::StartServerForUserspaceSnapshots(int arg_start, int argc, char** ar
            LOG(ERROR) << "Malformed message, expected at least four sub-arguments.";
            LOG(ERROR) << "Malformed message, expected at least four sub-arguments.";
            return false;
            return false;
        }
        }
        auto handler =
        auto handler = user_server_.AddHandler(parts[0], parts[1], parts[2], parts[3],
                user_server_.AddHandler(parts[0], parts[1], parts[2], parts[3], FLAGS_o_direct);
                                               FLAGS_o_direct, FLAGS_cow_op_merge_size);
        if (!handler || !user_server_.StartHandler(parts[0])) {
        if (!handler || !user_server_.StartHandler(parts[0])) {
            return false;
            return false;
        }
        }
+1 −1
Original line number Original line Diff line number Diff line
@@ -41,7 +41,7 @@ Extractor::Extractor(const std::string& base_path, const std::string& cow_path)
bool Extractor::Init() {
bool Extractor::Init() {
    auto opener = factory_.CreateTestOpener(control_name_);
    auto opener = factory_.CreateTestOpener(control_name_);
    handler_ = std::make_shared<SnapshotHandler>(control_name_, cow_path_, base_path_, base_path_,
    handler_ = std::make_shared<SnapshotHandler>(control_name_, cow_path_, base_path_, base_path_,
                                                 opener, 1, false, false, false);
                                                 opener, 1, false, false, false, 0);
    if (!handler_->InitCowDevice()) {
    if (!handler_->InitCowDevice()) {
        return false;
        return false;
    }
    }
Loading