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

Commit 1ab17cc2 authored by Akilesh Kailash's avatar Akilesh Kailash
Browse files

snapuserd: Cut down worker threads



We don't need 4 threads per partition all the time.
Cut down to 1 thread for all purposes except during boot time.

During boot, we need multiple worker threads to serve
I/O's to speed up the booting process. For all other
purposes, single thread is sufficient. It will cut
down memory usage ~25MB.

Bug: 214340811
Test: OTA
Signed-off-by: default avatarAkilesh Kailash <akailash@google.com>
Change-Id: Ib36bf44c63676d3f3169fbda04b7fc3d1760cfbf
parent b7f0a042
Loading
Loading
Loading
Loading
+15 −1
Original line number Diff line number Diff line
@@ -39,7 +39,21 @@ SnapshotHandler::SnapshotHandler(std::string misc_name, std::string cow_device,
}

bool SnapshotHandler::InitializeWorkers() {
    for (int i = 0; i < kNumWorkerThreads; i++) {
    int num_worker_threads = kNumWorkerThreads;

    // We will need multiple worker threads only during
    // device boot after OTA. For all other purposes,
    // one thread is sufficient. We don't want to consume
    // unnecessary memory especially during OTA install phase
    // when daemon will be up during entire post install phase.
    //
    // During boot up, we need multiple threads primarily for
    // update-verification.
    if (is_socket_present_) {
        num_worker_threads = 1;
    }

    for (int i = 0; i < num_worker_threads; i++) {
        std::unique_ptr<Worker> wt =
                std::make_unique<Worker>(cow_device_, backing_store_device_, control_device_,
                                         misc_name_, base_path_merge_, GetSharedPtr());
+2 −1
Original line number Diff line number Diff line
@@ -293,7 +293,6 @@ bool UserSnapshotServer::Receivemsg(android::base::borrowed_fd fd, const std::st
void UserSnapshotServer::RunThread(std::shared_ptr<UserSnapshotDmUserHandler> handler) {
    LOG(INFO) << "Entering thread for handler: " << handler->misc_name();

    handler->snapuserd()->SetSocketPresent(is_socket_present_);
    if (!handler->snapuserd()->Start()) {
        LOG(ERROR) << " Failed to launch all worker threads";
    }
@@ -471,6 +470,8 @@ std::shared_ptr<UserSnapshotDmUserHandler> UserSnapshotServer::AddHandler(
        return nullptr;
    }

    snapuserd->SetSocketPresent(is_socket_present_);

    if (!snapuserd->InitializeWorkers()) {
        LOG(ERROR) << "Failed to initialize workers";
        return nullptr;