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

Commit 682a1c13 authored by Jooyung Han's avatar Jooyung Han Committed by Android (Google) Code Review
Browse files

Merge "init: pre-create loop devices" into main

parents 50dc7d44 ebdd5bc7
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -369,6 +369,7 @@ init_first_stage_cc_defaults {
    ],

    static_libs: [
        "libapexd_flags",
        "libfs_avb",
        "libavf_cc_flags",
        "libfs_mgr",
+5 −0
Original line number Diff line number Diff line
@@ -79,6 +79,11 @@ bool BlockDevInitializer::InitBootDevicesFromPartUuid() {
    return true;
}

// Second_stage_init requires loop-control before ueventd starts.
void BlockDevInitializer::InitLoopDevices() {
    (void)InitMiscDevice("loop-control");
}

bool BlockDevInitializer::InitDeviceMapper() {
    return InitMiscDevice("device-mapper");
}
+1 −0
Original line number Diff line number Diff line
@@ -36,6 +36,7 @@ class BlockDevInitializer final {
    bool InitDmDevice(const std::string& device);
    bool InitPlatformDevice(const std::string& device);
    bool InitHvcDevice(const std::string& device);
    void InitLoopDevices();

  private:
    ListenerAction HandleUevent(const Uevent& uevent, std::set<std::string>* devices);
+6 −0
Original line number Diff line number Diff line
@@ -35,6 +35,7 @@
#include <android-base/stringprintf.h>
#include <android-base/strings.h>
#include <android/avf_cc_flags.h>
#include <com_android_apex_flags.h>
#include <fs_avb/fs_avb.h>
#include <fs_mgr.h>
#include <fs_mgr_dm_linear.h>
@@ -308,6 +309,11 @@ bool FirstStageMountVBootV2::InitDevices() {
            return false;
        }
    }

    if constexpr (com::android::apex::flags::mount_before_data()) {
        block_dev_init_.InitLoopDevices();
    }

    return true;
}

+23 −0
Original line number Diff line number Diff line
@@ -50,9 +50,11 @@
#include <android-base/stringprintf.h>
#include <android-base/strings.h>
#include <android-base/thread_annotations.h>
#include <com_android_apex_flags.h>
#include <fs_avb/fs_avb.h>
#include <fs_mgr_vendor_overlay.h>
#include <libavb/libavb.h>
#include <libdm/loop_control.h>
#include <libgsi/libgsi.h>
#include <libsnapshot/snapshot.h>
#include <logwrap/logwrap.h>
@@ -854,6 +856,22 @@ static void MountExtraFilesystems() {
#undef CHECKCALL
}

static void InitExtraDevices() {
    if constexpr (com::android::apex::flags::mount_before_data()) {
        // Pre-create a bunch of loop devices to accelerate apexd later. This effectively overrides
        // CONFIG_BLK_DEV_LOOP_MIN_COUNT. 128 loop devices should be enough for now because most
        // devices have < 100 apexes.
        constexpr int kMaxLoopDevices = 128;
        // Fire off a thread to pre-create the loop devices to avoid blocking the init.
        std::thread([]() {
            dm::LoopControl loop_control;
            for (int i = 0; i < kMaxLoopDevices; i++) {
                (void)loop_control.Add(i);
            }
        }).detach();
    }
}

static void RecordStageBoottimes(const boot_clock::time_point& second_stage_start_time) {
    int64_t first_stage_start_time_ns = -1;
    if (auto first_stage_start_time_str = getenv(kEnvFirstStageStartedAt);
@@ -1049,6 +1067,11 @@ int SecondStageMain(int argc, char** argv) {
    InstallInitNotifier(&epoll);
    StartPropertyService(&property_fd);

    // Initialize extra devices required during second stage init.
    // This may spawn threads for background work. Hence, this should be after
    // InstallSignalFdHandler() which needs to be called before spawning any threads.
    InitExtraDevices();

    // If boot_timeout property has been set in a debug build, start the boot monitor
    if (GetBoolProperty("ro.debuggable", false)) {
        int timeout = GetIntProperty("ro.boot.boot_timeout", 0);
Loading