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

Commit 5c008536 authored by Akilesh Kailash's avatar Akilesh Kailash Committed by Gerrit Code Review
Browse files

Merge changes I6791dd72,I887d5073

* changes:
  Reduce priority of merge threads
  Tune snapshot-merge performance
parents 73583331 1e46611c
Loading
Loading
Loading
Loading
+10 −1
Original line number Diff line number Diff line
@@ -2151,8 +2151,17 @@ bool SnapshotManager::ListSnapshots(LockedFile* lock, std::vector<std::string>*
        if (!suffix.empty() && !android::base::EndsWith(name, suffix)) {
            continue;
        }

        // Insert system and product partition at the beginning so that
        // during snapshot-merge, these partitions are merged first.
        if (name == "system_a" || name == "system_b" || name == "product_a" ||
            name == "product_b") {
            snapshots->insert(snapshots->begin(), std::move(name));
        } else {
            snapshots->emplace_back(std::move(name));
        }
    }

    return true;
}

+3 −2
Original line number Diff line number Diff line
@@ -147,17 +147,18 @@ void SnapshotHandler::PrepareReadAhead() {
    NotifyRAForMergeReady();
}

void SnapshotHandler::CheckMergeCompletionStatus() {
bool SnapshotHandler::CheckMergeCompletionStatus() {
    if (!merge_initiated_) {
        SNAP_LOG(INFO) << "Merge was not initiated. Total-data-ops: "
                       << reader_->get_num_total_data_ops();
        return;
        return false;
    }

    struct CowHeader* ch = reinterpret_cast<struct CowHeader*>(mapped_addr_);

    SNAP_LOG(INFO) << "Merge-status: Total-Merged-ops: " << ch->num_merge_ops
                   << " Total-data-ops: " << reader_->get_num_total_data_ops();
    return true;
}

bool SnapshotHandler::ReadMetadata() {
+10 −1
Original line number Diff line number Diff line
@@ -18,6 +18,9 @@
#include <stdint.h>
#include <stdlib.h>
#include <sys/mman.h>
#include <sys/resource.h>
#include <sys/time.h>
#include <unistd.h>

#include <condition_variable>
#include <cstring>
@@ -56,6 +59,8 @@ static_assert(PAYLOAD_BUFFER_SZ >= BLOCK_SZ);

static constexpr int kNumWorkerThreads = 4;

static constexpr int kNiceValueForMergeThreads = -5;

#define SNAP_LOG(level) LOG(level) << misc_name_ << ": "
#define SNAP_PLOG(level) PLOG(level) << misc_name_ << ": "

@@ -306,7 +311,7 @@ class SnapshotHandler : public std::enable_shared_from_this<SnapshotHandler> {
    const bool& IsAttached() const { return attached_; }
    void AttachControlDevice() { attached_ = true; }

    void CheckMergeCompletionStatus();
    bool CheckMergeCompletionStatus();
    bool CommitMerge(int num_merge_ops);

    void CloseFds() { cow_fd_ = {}; }
@@ -337,6 +342,8 @@ class SnapshotHandler : public std::enable_shared_from_this<SnapshotHandler> {

    // State transitions for merge
    void InitiateMerge();
    void MonitorMerge();
    void WakeupMonitorMergeThread();
    void WaitForMergeComplete();
    bool WaitForMergeBegin();
    void NotifyRAForMergeReady();
@@ -365,6 +372,7 @@ class SnapshotHandler : public std::enable_shared_from_this<SnapshotHandler> {
    void SetSocketPresent(bool socket) { is_socket_present_ = socket; }
    void SetIouringEnabled(bool io_uring_enabled) { is_io_uring_enabled_ = io_uring_enabled; }
    bool MergeInitiated() { return merge_initiated_; }
    bool MergeMonitored() { return merge_monitored_; }
    double GetMergePercentage() { return merge_completion_percentage_; }

    // Merge Block State Transitions
@@ -431,6 +439,7 @@ class SnapshotHandler : public std::enable_shared_from_this<SnapshotHandler> {
    double merge_completion_percentage_;

    bool merge_initiated_ = false;
    bool merge_monitored_ = false;
    bool attached_ = false;
    bool is_socket_present_;
    bool is_io_uring_enabled_ = false;
+4 −0
Original line number Diff line number Diff line
@@ -543,6 +543,10 @@ bool Worker::RunMergeThread() {
        return true;
    }

    if (setpriority(PRIO_PROCESS, gettid(), kNiceValueForMergeThreads)) {
        SNAP_PLOG(ERROR) << "Failed to set priority for TID: " << gettid();
    }

    SNAP_LOG(INFO) << "Merge starting..";

    if (!Init()) {
+4 −0
Original line number Diff line number Diff line
@@ -727,6 +727,10 @@ bool ReadAhead::RunThread() {

    InitializeIouring();

    if (setpriority(PRIO_PROCESS, gettid(), kNiceValueForMergeThreads)) {
        SNAP_PLOG(ERROR) << "Failed to set priority for TID: " << gettid();
    }

    while (!RAIterDone()) {
        if (!ReadAheadIOStart()) {
            break;
Loading