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

Commit 3f3162c2 authored by Daniel Zheng's avatar Daniel Zheng
Browse files

libsnapshot: get options from protobuf fields

Update snapshot.cpp to grab estimate_op_buffer_size &
estimate_sequence_buffer_size from update_engine. Update v3 writer to
use these options to size the buffers appropriately.

we probably don't need the fields for merge metrics yet but will leave
it here for now

Test: th
Bug: 313962438
Change-Id: I08252ff66174de9bafaf8dbe9115d9d049084c4c
parent d0c3a04c
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
@@ -114,6 +114,9 @@ message SnapshotStatus {

    // Enable batching for COW writes
    bool batched_writes = 14;

    // Size of v3 operation buffer. Needs to be determined during writer initialization
    uint64 estimated_ops_buffer_size = 15;
}

// Next: 8
@@ -250,4 +253,7 @@ message SnapshotMergeReport {

    // Whether this update attempt used io_uring.
    bool iouring_used = 13;

    // Size of v3 operation buffer. Needs to be determined during writer initialization
    uint64 estimated_op_count_max = 14;
}
+1 −1
Original line number Diff line number Diff line
@@ -59,7 +59,7 @@ struct CowOptions {
    bool batch_write = false;

    // Size of the cow operation buffer; used in v3 only.
    uint32_t op_count_max = 0;
    uint64_t op_count_max = 0;
};

// Interface for writing to a snapuserd COW. All operations are ordered; merges
+0 −1
Original line number Diff line number Diff line
@@ -392,7 +392,6 @@ bool CowWriterV3::EmitLabel(uint64_t label) {
}

bool CowWriterV3::EmitSequenceData(size_t num_ops, const uint32_t* data) {
    // TODO: size sequence buffer based on options
    if (header_.op_count > 0 || !cached_ops_.empty()) {
        LOG(ERROR) << "There's " << header_.op_count << " operations written to disk and "
                   << cached_ops_.size()
+1 −0
Original line number Diff line number Diff line
@@ -217,6 +217,7 @@ std::optional<PartitionCowCreator::Return> PartitionCowCreator::Run() {

    if (update && update->has_estimate_cow_size()) {
        ret.snapshot_status.set_estimated_cow_size(update->estimate_cow_size());
        ret.snapshot_status.set_estimated_ops_buffer_size(update->estimate_op_count_max());
    }

    if (ret.snapshot_status.snapshot_size() == 0) {
+4 −3
Original line number Diff line number Diff line
@@ -3551,6 +3551,9 @@ Return SnapshotManager::InitializeUpdateSnapshots(
                options.scratch_space = false;
            }
            options.compression = it->second.compression_algorithm();
            if (cow_version >= 3) {
                options.op_count_max = it->second.estimated_ops_buffer_size();
            }

            auto writer = CreateCowWriter(cow_version, options, std::move(fd));
            if (!writer->Finalize()) {
@@ -3662,9 +3665,7 @@ std::unique_ptr<ICowWriter> SnapshotManager::OpenCompressedSnapshotWriter(
    cow_options.max_blocks = {status.device_size() / cow_options.block_size};
    cow_options.batch_write = status.batched_writes();
    cow_options.num_compress_threads = status.enable_threading() ? 2 : 1;
    // TODO(b/313962438) Improve op_count estimate. For now, use number of
    // blocks as an upper bound.
    cow_options.op_count_max = status.device_size() / cow_options.block_size;
    cow_options.op_count_max = status.estimated_ops_buffer_size();
    // Disable scratch space for vts tests
    if (device()->IsTestDevice()) {
        cow_options.scratch_space = false;