Merge "Make libexpresslog apex available" into main
diff --git a/PREUPLOAD.cfg b/PREUPLOAD.cfg
index 9b96f36..f47c317 100644
--- a/PREUPLOAD.cfg
+++ b/PREUPLOAD.cfg
@@ -1,6 +1,7 @@
 [Builtin Hooks]
 clang_format = true
 rustfmt = true
+bpfmt = true
 
 [Builtin Hooks Options]
 clang_format = --commit ${PREUPLOAD_COMMIT} --style file --extensions c,h,cc,cpp
diff --git a/debuggerd/crash_dump.cpp b/debuggerd/crash_dump.cpp
index 1c1fb8a..8dd2b0d 100644
--- a/debuggerd/crash_dump.cpp
+++ b/debuggerd/crash_dump.cpp
@@ -83,7 +83,7 @@
 
 // This stores guest architecture. When the architecture is supported, tombstone file will output
 // guest state information.
-static Architecture g_guest_arch;
+static Architecture g_guest_arch = Architecture::NONE;
 
 static bool pid_contains_tid(int pid_proc_fd, pid_t tid) {
   struct stat st;
@@ -789,10 +789,6 @@
       ATRACE_NAME("engrave_tombstone");
       unwindstack::ArchEnum regs_arch = unwindstack::ARCH_UNKNOWN;
       switch (g_guest_arch) {
-        case Architecture::ARM32: {
-          regs_arch = unwindstack::ARCH_ARM;
-          break;
-        }
         case Architecture::ARM64: {
           regs_arch = unwindstack::ARCH_ARM64;
           break;
diff --git a/debuggerd/proto/tombstone.proto b/debuggerd/proto/tombstone.proto
index 6f9cd96..b662d36 100644
--- a/debuggerd/proto/tombstone.proto
+++ b/debuggerd/proto/tombstone.proto
@@ -18,6 +18,8 @@
 message CrashDetail {
   bytes name = 1;
   bytes data = 2;
+
+  reserved 3 to 999;
 }
 
 message Tombstone {
diff --git a/fs_mgr/fs_mgr_overlayfs_mount.cpp b/fs_mgr/fs_mgr_overlayfs_mount.cpp
index a1ec63b..bd0fcfd 100644
--- a/fs_mgr/fs_mgr_overlayfs_mount.cpp
+++ b/fs_mgr/fs_mgr_overlayfs_mount.cpp
@@ -412,6 +412,8 @@
     bool retval = true;
     bool move_dir_shared = true;
     bool parent_shared = true;
+    bool parent_have_parent = false;
+    bool parent_made_private = false;
     bool root_shared = true;
     bool root_made_private = false;
 
@@ -443,6 +445,10 @@
         if (entry.mount_point == "/") {
             root_shared = entry.shared_flag;
         }
+        // Ignore "/" as we don't overlay "/" directly.
+        if (entry.mount_point != "/") {
+            parent_have_parent |= android::base::StartsWith(mount_point, entry.mount_point + "/");
+        }
     }
 
     // Precondition is that kMoveMountTempDir is MS_PRIVATE, otherwise don't try to move any
@@ -453,11 +459,13 @@
 
     // Need to make the original mountpoint MS_PRIVATE, so that the overlayfs can be MS_MOVE.
     // This could happen if its parent mount is remounted later.
-    if (!fs_mgr_overlayfs_set_shared_mount(mount_point, false)) {
-        // If failed to set "/system" mount type, it might be due to "/system" not being a valid
-        // mountpoint after switch root. Retry with "/" in this case.
-        if (errno == EINVAL && mount_point == "/system") {
-            root_made_private = fs_mgr_overlayfs_set_shared_mount("/", false);
+    if (parent_have_parent) {
+        parent_made_private |= fs_mgr_overlayfs_set_shared_mount(mount_point, false);
+        if (!parent_made_private && errno == EINVAL && mount_point == "/system") {
+            // If failed to set "/system" mount type, it might be due to "/system" not being a valid
+            // mountpoint after switch root. Retry with "/" in this case.
+            parent_made_private |= fs_mgr_overlayfs_set_shared_mount("/", false);
+            root_made_private |= parent_made_private;
         }
     }
 
@@ -496,6 +504,15 @@
                 continue;
             }
         }
+        if (!parent_made_private) {
+            parent_made_private |= fs_mgr_overlayfs_set_shared_mount(mount_point, false);
+            if (!parent_made_private && errno == EINVAL && mount_point == "/system") {
+                // If failed to set "/system" mount type, it might be due to "/system" not being a
+                // valid mountpoint after switch root. Retry with "/" in this case.
+                parent_made_private |= fs_mgr_overlayfs_set_shared_mount("/", false);
+                root_made_private |= parent_made_private;
+            }
+        }
 
         if (new_entry.shared_flag) {
             new_entry.shared_flag = fs_mgr_overlayfs_set_shared_mount(new_entry.mount_point, false);
@@ -524,7 +541,7 @@
         rmdir(entry.dir.c_str());
     }
     // If the original (overridden) mount was MS_SHARED, then set the overlayfs mount to MS_SHARED.
-    if (parent_shared) {
+    if (parent_shared && parent_made_private) {
         fs_mgr_overlayfs_set_shared_mount(mount_point, true);
     }
     if (root_shared && root_made_private) {
diff --git a/fs_mgr/libsnapshot/android/snapshot/snapshot.proto b/fs_mgr/libsnapshot/android/snapshot/snapshot.proto
index d04c9c1..2e948dd 100644
--- a/fs_mgr/libsnapshot/android/snapshot/snapshot.proto
+++ b/fs_mgr/libsnapshot/android/snapshot/snapshot.proto
@@ -124,8 +124,7 @@
     // Default value is 32, can be set lower for low mem devices
     uint32 read_ahead_size = 17;
 
-    // Enable direct reads on source device
-    bool o_direct = 18;
+    reserved 18;
 
     // Blocks size to be verified at once
     uint64 verify_block_size = 19;
@@ -227,6 +226,9 @@
 
     // legacy dm-snapshot based snapuserd
     bool legacy_snapuserd = 11;
+
+    // Enable direct reads from source device
+    bool o_direct = 12;
 }
 
 // Next: 10
diff --git a/fs_mgr/libsnapshot/include/libsnapshot/snapshot.h b/fs_mgr/libsnapshot/include/libsnapshot/snapshot.h
index 3ccc3db..6d422c6 100644
--- a/fs_mgr/libsnapshot/include/libsnapshot/snapshot.h
+++ b/fs_mgr/libsnapshot/include/libsnapshot/snapshot.h
@@ -410,6 +410,7 @@
     FRIEND_TEST(SnapshotTest, CreateSnapshot);
     FRIEND_TEST(SnapshotTest, FirstStageMountAfterRollback);
     FRIEND_TEST(SnapshotTest, FirstStageMountAndMerge);
+    FRIEND_TEST(SnapshotTest, FlagCheck);
     FRIEND_TEST(SnapshotTest, FlashSuperDuringMerge);
     FRIEND_TEST(SnapshotTest, FlashSuperDuringUpdate);
     FRIEND_TEST(SnapshotTest, MapPartialSnapshot);
@@ -425,6 +426,7 @@
     FRIEND_TEST(SnapshotUpdateTest, DataWipeAfterRollback);
     FRIEND_TEST(SnapshotUpdateTest, DataWipeRollbackInRecovery);
     FRIEND_TEST(SnapshotUpdateTest, DataWipeWithStaleSnapshots);
+    FRIEND_TEST(SnapshotUpdateTest, FlagCheck);
     FRIEND_TEST(SnapshotUpdateTest, FullUpdateFlow);
     FRIEND_TEST(SnapshotUpdateTest, MergeCannotRemoveCow);
     FRIEND_TEST(SnapshotUpdateTest, MergeInRecovery);
@@ -822,6 +824,9 @@
     // Check if io_uring API's need to be used
     bool UpdateUsesIouring(LockedFile* lock);
 
+    // Check if direct reads are enabled for the source image
+    bool UpdateUsesODirect(LockedFile* lock);
+
     // Wrapper around libdm, with diagnostics.
     bool DeleteDeviceIfExists(const std::string& name,
                               const std::chrono::milliseconds& timeout_ms = {});
diff --git a/fs_mgr/libsnapshot/partition_cow_creator.h b/fs_mgr/libsnapshot/partition_cow_creator.h
index a75d993..1adbba2 100644
--- a/fs_mgr/libsnapshot/partition_cow_creator.h
+++ b/fs_mgr/libsnapshot/partition_cow_creator.h
@@ -62,6 +62,9 @@
     uint64_t compression_factor;
     uint32_t read_ahead_size;
 
+    // Enable direct reads on source device
+    bool o_direct;
+
     // True if multi-threaded compression should be enabled
     bool enable_threading;
 
diff --git a/fs_mgr/libsnapshot/snapshot.cpp b/fs_mgr/libsnapshot/snapshot.cpp
index 8620620..c01360e 100644
--- a/fs_mgr/libsnapshot/snapshot.cpp
+++ b/fs_mgr/libsnapshot/snapshot.cpp
@@ -1697,6 +1697,9 @@
         if (UpdateUsesIouring(lock.get())) {
             snapuserd_argv->emplace_back("-io_uring");
         }
+        if (UpdateUsesODirect(lock.get())) {
+            snapuserd_argv->emplace_back("-o_direct");
+        }
     }
 
     size_t num_cows = 0;
@@ -2114,6 +2117,11 @@
     return update_status.io_uring_enabled();
 }
 
+bool SnapshotManager::UpdateUsesODirect(LockedFile* lock) {
+    SnapshotUpdateStatus update_status = ReadSnapshotUpdateStatus(lock);
+    return update_status.o_direct();
+}
+
 /*
  * Please see b/304829384 for more details.
  *
@@ -3016,6 +3024,7 @@
         status.set_userspace_snapshots(old_status.userspace_snapshots());
         status.set_io_uring_enabled(old_status.io_uring_enabled());
         status.set_legacy_snapuserd(old_status.legacy_snapuserd());
+        status.set_o_direct(old_status.o_direct());
     }
     return WriteSnapshotUpdateStatus(lock, status);
 }
@@ -3310,17 +3319,19 @@
     }
     auto read_ahead_size =
             android::base::GetUintProperty<uint>("ro.virtual_ab.read_ahead_size", kReadAheadSizeKb);
-    PartitionCowCreator cow_creator{.target_metadata = target_metadata.get(),
-                                    .target_suffix = target_suffix,
-                                    .target_partition = nullptr,
-                                    .current_metadata = current_metadata.get(),
-                                    .current_suffix = current_suffix,
-                                    .update = nullptr,
-                                    .extra_extents = {},
-                                    .using_snapuserd = using_snapuserd,
-                                    .compression_algorithm = compression_algorithm,
-                                    .compression_factor = compression_factor,
-                                    .read_ahead_size = read_ahead_size};
+    PartitionCowCreator cow_creator{
+            .target_metadata = target_metadata.get(),
+            .target_suffix = target_suffix,
+            .target_partition = nullptr,
+            .current_metadata = current_metadata.get(),
+            .current_suffix = current_suffix,
+            .update = nullptr,
+            .extra_extents = {},
+            .using_snapuserd = using_snapuserd,
+            .compression_algorithm = compression_algorithm,
+            .compression_factor = compression_factor,
+            .read_ahead_size = read_ahead_size,
+    };
 
     if (dap_metadata.vabc_feature_set().has_threaded()) {
         cow_creator.enable_threading = dap_metadata.vabc_feature_set().threaded();
@@ -3388,10 +3399,13 @@
             status.set_io_uring_enabled(true);
             LOG(INFO) << "io_uring for snapshots enabled";
         }
-
+        if (GetODirectEnabledProperty()) {
+            status.set_o_direct(true);
+            LOG(INFO) << "o_direct for source image enabled";
+        }
         if (is_legacy_snapuserd) {
-            LOG(INFO) << "Setting legacy_snapuserd to true";
             status.set_legacy_snapuserd(true);
+            LOG(INFO) << "Setting legacy_snapuserd to true";
         }
     } else if (legacy_compression) {
         LOG(INFO) << "Virtual A/B using legacy snapuserd";
@@ -3827,6 +3841,7 @@
     ss << "Using snapuserd: " << update_status.using_snapuserd() << 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 o_direct: " << update_status.o_direct() << std::endl;
     ss << "Using XOR compression: " << GetXorCompressionEnabledProperty() << std::endl;
     ss << "Current slot: " << device_->GetSlotSuffix() << std::endl;
     ss << "Boot indicator: booting from " << GetCurrentSlot() << " slot" << std::endl;
diff --git a/fs_mgr/libsnapshot/snapshot_test.cpp b/fs_mgr/libsnapshot/snapshot_test.cpp
index 80dad17..3299ec5 100644
--- a/fs_mgr/libsnapshot/snapshot_test.cpp
+++ b/fs_mgr/libsnapshot/snapshot_test.cpp
@@ -2647,6 +2647,41 @@
     ASSERT_TRUE(sm->CreateUpdateSnapshots(manifest_));
 }
 
+TEST_F(SnapshotTest, FlagCheck) {
+    if (!snapuserd_required_) {
+        GTEST_SKIP() << "Skipping snapuserd test";
+    }
+    ASSERT_TRUE(AcquireLock());
+
+    SnapshotUpdateStatus status = sm->ReadSnapshotUpdateStatus(lock_.get());
+
+    // Set flags in proto
+    status.set_o_direct(true);
+    status.set_io_uring_enabled(true);
+    status.set_userspace_snapshots(true);
+
+    sm->WriteSnapshotUpdateStatus(lock_.get(), status);
+    // Ensure a connection to the second-stage daemon, but use the first-stage
+    // code paths thereafter.
+    ASSERT_TRUE(sm->EnsureSnapuserdConnected());
+    sm->set_use_first_stage_snapuserd(true);
+
+    auto init = NewManagerForFirstStageMount("_b");
+    ASSERT_NE(init, nullptr);
+
+    lock_ = nullptr;
+
+    std::vector<std::string> snapuserd_argv;
+    ASSERT_TRUE(init->PerformInitTransition(SnapshotManager::InitTransition::SELINUX_DETACH,
+                                            &snapuserd_argv));
+    ASSERT_TRUE(std::find(snapuserd_argv.begin(), snapuserd_argv.end(), "-o_direct") !=
+                snapuserd_argv.end());
+    ASSERT_TRUE(std::find(snapuserd_argv.begin(), snapuserd_argv.end(), "-io_uring") !=
+                snapuserd_argv.end());
+    ASSERT_TRUE(std::find(snapuserd_argv.begin(), snapuserd_argv.end(), "-user_snapshot") !=
+                snapuserd_argv.end());
+}
+
 class FlashAfterUpdateTest : public SnapshotUpdateTest,
                              public WithParamInterface<std::tuple<uint32_t, bool>> {
   public:
diff --git a/fs_mgr/libsnapshot/snapuserd/snapuserd_daemon.cpp b/fs_mgr/libsnapshot/snapuserd/snapuserd_daemon.cpp
index 0ebe543..67e9e52 100644
--- a/fs_mgr/libsnapshot/snapuserd/snapuserd_daemon.cpp
+++ b/fs_mgr/libsnapshot/snapuserd/snapuserd_daemon.cpp
@@ -29,6 +29,7 @@
             "If true, perform a socket hand-off with an existing snapuserd instance, then exit.");
 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(o_direct, false, "If true, enable direct reads on source device");
 
 namespace android {
 namespace snapshot {
@@ -67,7 +68,6 @@
     if (!user_snapshots) {
         user_snapshots = IsUserspaceSnapshotsEnabled();
     }
-
     if (user_snapshots) {
         LOG(INFO) << "Starting daemon for user-space snapshots.....";
         return StartServerForUserspaceSnapshots(arg_start, argc, argv);
@@ -109,11 +109,13 @@
 
     for (int i = arg_start; i < argc; i++) {
         auto parts = android::base::Split(argv[i], ",");
+
         if (parts.size() != 4) {
-            LOG(ERROR) << "Malformed message, expected four sub-arguments.";
+            LOG(ERROR) << "Malformed message, expected at least four sub-arguments.";
             return false;
         }
-        auto handler = user_server_.AddHandler(parts[0], parts[1], parts[2], parts[3]);
+        auto handler =
+                user_server_.AddHandler(parts[0], parts[1], parts[2], parts[3], FLAGS_o_direct);
         if (!handler || !user_server_.StartHandler(parts[0])) {
             return false;
         }
diff --git a/fs_mgr/libsnapshot/snapuserd/user-space-merge/snapuserd_verify.cpp b/fs_mgr/libsnapshot/snapuserd/user-space-merge/snapuserd_verify.cpp
index 6817340..957c6a8 100644
--- a/fs_mgr/libsnapshot/snapuserd/user-space-merge/snapuserd_verify.cpp
+++ b/fs_mgr/libsnapshot/snapuserd/user-space-merge/snapuserd_verify.cpp
@@ -20,6 +20,7 @@
 #include <android-base/scopeguard.h>
 #include <android-base/strings.h>
 
+#include "android-base/properties.h"
 #include "snapuserd_core.h"
 
 namespace android {
@@ -104,7 +105,9 @@
     }
 
     loff_t file_offset = offset;
-    const uint64_t read_sz = kBlockSizeVerify;
+    auto verify_block_size = android::base::GetUintProperty<uint>("ro.virtual_ab.verify_block_size",
+                                                                  kBlockSizeVerify);
+    const uint64_t read_sz = verify_block_size;
 
     void* addr;
     ssize_t page_size = getpagesize();
@@ -130,7 +133,7 @@
         }
 
         bytes_read += to_read;
-        file_offset += (skip_blocks * kBlockSizeVerify);
+        file_offset += (skip_blocks * verify_block_size);
         if (file_offset >= dev_sz) {
             break;
         }
@@ -184,7 +187,9 @@
      * latency.
      */
     int num_threads = kMinThreadsToVerify;
-    if (dev_sz > kThresholdSize) {
+    auto verify_threshold_size = android::base::GetUintProperty<uint>(
+            "ro.virtual_ab.verify_threshold_size", kThresholdSize);
+    if (dev_sz > verify_threshold_size) {
         num_threads = kMaxThreadsToVerify;
     }
 
@@ -192,11 +197,13 @@
     off_t start_offset = 0;
     const int skip_blocks = num_threads;
 
+    auto verify_block_size =
+            android::base::GetUintProperty("ro.virtual_ab.verify_block_size", kBlockSizeVerify);
     while (num_threads) {
         threads.emplace_back(std::async(std::launch::async, &UpdateVerify::VerifyBlocks, this,
                                         partition_name, dm_block_device, start_offset, skip_blocks,
                                         dev_sz));
-        start_offset += kBlockSizeVerify;
+        start_offset += verify_block_size;
         num_threads -= 1;
         if (start_offset >= dev_sz) {
             break;
diff --git a/fs_mgr/libsnapshot/utility.cpp b/fs_mgr/libsnapshot/utility.cpp
index fe2d95c..7eaaca9 100644
--- a/fs_mgr/libsnapshot/utility.cpp
+++ b/fs_mgr/libsnapshot/utility.cpp
@@ -199,7 +199,7 @@
 }
 
 std::ostream& operator<<(std::ostream& os, const Now&) {
-    struct tm now {};
+    struct tm now{};
     time_t t = time(nullptr);
     localtime_r(&t, &now);
     return os << std::put_time(&now, "%Y%m%d-%H%M%S");
@@ -272,6 +272,11 @@
     return fetcher->GetBoolProperty("ro.virtual_ab.compression.xor.enabled", false);
 }
 
+bool GetODirectEnabledProperty() {
+    auto fetcher = IPropertyFetcher::GetInstance();
+    return fetcher->GetBoolProperty("ro.virtual_ab.o_direct.enabled", false);
+}
+
 std::string GetOtherPartitionName(const std::string& name) {
     auto suffix = android::fs_mgr::GetPartitionSlotSuffix(name);
     CHECK(suffix == "_a" || suffix == "_b");
diff --git a/fs_mgr/libsnapshot/utility.h b/fs_mgr/libsnapshot/utility.h
index f956a05..7dae942 100644
--- a/fs_mgr/libsnapshot/utility.h
+++ b/fs_mgr/libsnapshot/utility.h
@@ -133,6 +133,7 @@
 bool GetUserspaceSnapshotsEnabledProperty();
 bool GetIouringEnabledProperty();
 bool GetXorCompressionEnabledProperty();
+bool GetODirectEnabledProperty();
 
 bool CanUseUserspaceSnapshots();
 bool IsDmSnapshotTestingEnabled();
diff --git a/fs_mgr/tests/Android.bp b/fs_mgr/tests/Android.bp
index 2aeba0a..041762f 100644
--- a/fs_mgr/tests/Android.bp
+++ b/fs_mgr/tests/Android.bp
@@ -14,6 +14,7 @@
 
 package {
     default_applicable_licenses: ["Android-Apache-2.0"],
+    default_team: "trendy_team_android_kernel",
 }
 
 cc_test {
diff --git a/init/Android.bp b/init/Android.bp
index 57e5a68..6526a93 100644
--- a/init/Android.bp
+++ b/init/Android.bp
@@ -162,7 +162,7 @@
         },
         release_write_appcompat_override_system_properties: {
             cflags: ["-DWRITE_APPCOMPAT_OVERRIDE_SYSTEM_PROPERTIES"],
-        }
+        },
     },
     static_libs: [
         "libavb",
@@ -663,3 +663,23 @@
     src: "extra_free_kbytes.sh",
     filename_from_src: true,
 }
+
+soong_config_module_type {
+    name: "board_use_recovery_as_boot_phony",
+    module_type: "phony",
+    config_namespace: "ANDROID",
+    bool_variables: ["BOARD_USES_RECOVERY_AS_BOOT"],
+    properties: ["required"],
+}
+
+board_use_recovery_as_boot_phony {
+    name: "init_vendor",
+    soong_config_variables: {
+        BOARD_USES_RECOVERY_AS_BOOT: {
+            required: [],
+            conditions_default: {
+                required: ["init_first_stage"],
+            },
+        },
+    },
+}
diff --git a/init/Android.mk b/init/Android.mk
deleted file mode 100644
index 4b85c15..0000000
--- a/init/Android.mk
+++ /dev/null
@@ -1,16 +0,0 @@
-# Copyright 2005 The Android Open Source Project
-
-LOCAL_PATH:= $(call my-dir)
-
-include $(CLEAR_VARS)
-
-LOCAL_MODULE := init_vendor
-LOCAL_LICENSE_KINDS := SPDX-license-identifier-Apache-2.0
-LOCAL_LICENSE_CONDITIONS := notice
-LOCAL_NOTICE_FILE := $(LOCAL_PATH)/NOTICE
-ifneq ($(BOARD_USES_RECOVERY_AS_BOOT),true)
-LOCAL_REQUIRED_MODULES := \
-   init_first_stage \
-
-endif  # BOARD_USES_RECOVERY_AS_BOOT
-include $(BUILD_PHONY_PACKAGE)
diff --git a/init/apex_init_util.cpp b/init/apex_init_util.cpp
index 6d17f36..e5a7fbc 100644
--- a/init/apex_init_util.cpp
+++ b/init/apex_init_util.cpp
@@ -107,8 +107,9 @@
     }
     // APEXes can have versioned RC files. These should be filtered based on
     // SDK version.
-    auto filtered = FilterVersionedConfigs(
-            files, android::base::GetIntProperty("ro.build.version.sdk", INT_MAX));
+    int sdk = android::base::GetIntProperty("ro.build.version.sdk", INT_MAX);
+    if (sdk < 35) sdk = 35;  // aosp/main merges only into sdk=35+ (ie. __ANDROID_API_V__+)
+    auto filtered = FilterVersionedConfigs(files, sdk);
     if (filtered.empty()) {
         return {};
     }
diff --git a/libprocessgroup/cgroup_map.cpp b/libprocessgroup/cgroup_map.cpp
index c8ae216..ebc0599 100644
--- a/libprocessgroup/cgroup_map.cpp
+++ b/libprocessgroup/cgroup_map.cpp
@@ -18,33 +18,19 @@
 #define LOG_TAG "libprocessgroup"
 
 #include <errno.h>
-#include <fcntl.h>
-#include <grp.h>
-#include <pwd.h>
-#include <sys/mman.h>
-#include <sys/mount.h>
-#include <sys/stat.h>
-#include <sys/types.h>
-#include <time.h>
 #include <unistd.h>
 
 #include <regex>
 
 #include <android-base/file.h>
 #include <android-base/logging.h>
-#include <android-base/properties.h>
 #include <android-base/stringprintf.h>
 #include <android-base/strings.h>
-#include <android-base/unique_fd.h>
 #include <cgroup_map.h>
-#include <json/reader.h>
-#include <json/value.h>
 #include <processgroup/processgroup.h>
 
-using android::base::GetBoolProperty;
 using android::base::StartsWith;
 using android::base::StringPrintf;
-using android::base::unique_fd;
 using android::base::WriteStringToFile;
 
 static constexpr const char* CGROUP_PROCS_FILE = "/cgroup.procs";
diff --git a/libprocessgroup/cgroup_map.h b/libprocessgroup/cgroup_map.h
index 5c6d3e2..31925d5 100644
--- a/libprocessgroup/cgroup_map.h
+++ b/libprocessgroup/cgroup_map.h
@@ -16,14 +16,9 @@
 
 #pragma once
 
-#include <sys/cdefs.h>
 #include <sys/types.h>
 
-#include <map>
-#include <memory>
-#include <mutex>
 #include <string>
-#include <vector>
 
 #include <android/cgrouprc.h>
 
@@ -32,7 +27,7 @@
   public:
     // Does not own controller
     explicit CgroupController(const ACgroupController* controller)
-        : controller_(controller), state_(UNKNOWN) {}
+        : controller_(controller) {}
 
     uint32_t version() const;
     const char* name() const;
@@ -53,7 +48,7 @@
     };
 
     const ACgroupController* controller_ = nullptr;
-    ControllerState state_;
+    ControllerState state_ = ControllerState::UNKNOWN;
 };
 
 class CgroupMap {
diff --git a/libprocessgroup/cgrouprc_format/cgroup_controller.cpp b/libprocessgroup/cgrouprc_format/cgroup_controller.cpp
index 202b23e..56e67df 100644
--- a/libprocessgroup/cgrouprc_format/cgroup_controller.cpp
+++ b/libprocessgroup/cgrouprc_format/cgroup_controller.cpp
@@ -20,14 +20,9 @@
 namespace cgrouprc {
 namespace format {
 
-CgroupController::CgroupController() : version_(0), flags_(0) {
-    memset(name_, 0, sizeof(name_));
-    memset(path_, 0, sizeof(path_));
-}
-
 CgroupController::CgroupController(uint32_t version, uint32_t flags, const std::string& name,
                                    const std::string& path)
-    : CgroupController() {
+{
     // strlcpy isn't available on host. Although there is an implementation
     // in licutils, libcutils itself depends on libcgrouprc_format, causing
     // a circular dependency.
diff --git a/libprocessgroup/cgrouprc_format/include/processgroup/format/cgroup_controller.h b/libprocessgroup/cgrouprc_format/include/processgroup/format/cgroup_controller.h
index 40d8548..9427a1c 100644
--- a/libprocessgroup/cgrouprc_format/include/processgroup/format/cgroup_controller.h
+++ b/libprocessgroup/cgrouprc_format/include/processgroup/format/cgroup_controller.h
@@ -16,7 +16,8 @@
 
 #pragma once
 
-#include <stdint.h>
+#include <cstddef>
+#include <cstdint>
 #include <string>
 
 namespace android {
@@ -26,7 +27,7 @@
 // Minimal controller description to be mmapped into process address space
 struct CgroupController {
   public:
-    CgroupController();
+    CgroupController() = default;
     CgroupController(uint32_t version, uint32_t flags, const std::string& name,
                      const std::string& path);
 
@@ -41,10 +42,10 @@
     static constexpr size_t CGROUP_NAME_BUF_SZ = 16;
     static constexpr size_t CGROUP_PATH_BUF_SZ = 32;
 
-    uint32_t version_;
-    uint32_t flags_;
-    char name_[CGROUP_NAME_BUF_SZ];
-    char path_[CGROUP_PATH_BUF_SZ];
+    uint32_t version_ = 0;
+    uint32_t flags_ = 0;
+    char name_[CGROUP_NAME_BUF_SZ] = {};
+    char path_[CGROUP_PATH_BUF_SZ] = {};
 };
 
 }  // namespace format
diff --git a/libprocessgroup/cgrouprc_format/include/processgroup/format/cgroup_file.h b/libprocessgroup/cgrouprc_format/include/processgroup/format/cgroup_file.h
index f1678a1..2d9786f 100644
--- a/libprocessgroup/cgrouprc_format/include/processgroup/format/cgroup_file.h
+++ b/libprocessgroup/cgrouprc_format/include/processgroup/format/cgroup_file.h
@@ -16,6 +16,8 @@
 
 #pragma once
 
+#include <cstdint>
+
 #include <processgroup/format/cgroup_controller.h>
 
 namespace android {
diff --git a/libprocessgroup/sched_policy.cpp b/libprocessgroup/sched_policy.cpp
index 1005b1e..0f2640a 100644
--- a/libprocessgroup/sched_policy.cpp
+++ b/libprocessgroup/sched_policy.cpp
@@ -19,6 +19,7 @@
 #define LOG_TAG "SchedPolicy"
 
 #include <errno.h>
+#include <fcntl.h>
 #include <unistd.h>
 
 #include <android-base/logging.h>
diff --git a/libprocessgroup/setup/cgroup_descriptor.h b/libprocessgroup/setup/cgroup_descriptor.h
index 699c03c..9982bfc 100644
--- a/libprocessgroup/setup/cgroup_descriptor.h
+++ b/libprocessgroup/setup/cgroup_descriptor.h
@@ -16,6 +16,11 @@
 
 #pragma once
 
+#include <cstdint>
+#include <string>
+
+#include <sys/stat.h>
+
 #include <processgroup/format/cgroup_controller.h>
 
 namespace android {
diff --git a/libprocessgroup/task_profiles.cpp b/libprocessgroup/task_profiles.cpp
index 0c2252b..4870548 100644
--- a/libprocessgroup/task_profiles.cpp
+++ b/libprocessgroup/task_profiles.cpp
@@ -17,7 +17,9 @@
 //#define LOG_NDEBUG 0
 #define LOG_TAG "libprocessgroup"
 
+#include <dirent.h>
 #include <fcntl.h>
+#include <unistd.h>
 #include <task_profiles.h>
 #include <string>
 
diff --git a/libprocessgroup/task_profiles.h b/libprocessgroup/task_profiles.h
index 7e3c50d..184e9e3 100644
--- a/libprocessgroup/task_profiles.h
+++ b/libprocessgroup/task_profiles.h
@@ -16,10 +16,10 @@
 
 #pragma once
 
-#include <sys/cdefs.h>
 #include <sys/types.h>
-#include <functional>
+
 #include <map>
+#include <memory>
 #include <mutex>
 #include <span>
 #include <string>
diff --git a/libutils/Android.bp b/libutils/Android.bp
index ba19ace..4877cae 100644
--- a/libutils/Android.bp
+++ b/libutils/Android.bp
@@ -371,6 +371,7 @@
                 "libunwindstack_no_dex",
                 "libutils",
                 "libutilscallstack",
+                "libz",
             ],
         },
     },
diff --git a/rootdir/Android.bp b/rootdir/Android.bp
index bd24f22..e8f7627 100644
--- a/rootdir/Android.bp
+++ b/rootdir/Android.bp
@@ -62,7 +62,7 @@
     name: "public.libraries.android.txt",
     src: "etc/public.libraries.android.txt",
     filename: "public.libraries.txt",
-    installable: false,
+    no_full_install: true,
 }
 
 // adb_debug.prop in debug ramdisk
diff --git a/rootdir/init.rc b/rootdir/init.rc
index 5953769..2443b7c 100644
--- a/rootdir/init.rc
+++ b/rootdir/init.rc
@@ -247,7 +247,6 @@
     write /dev/blkio/background/blkio.bfq.weight 10
     write /dev/blkio/blkio.group_idle 0
     write /dev/blkio/background/blkio.group_idle 0
-    write /dev/blkio/blkio.prio.class promote-to-rt
     write /dev/blkio/background/blkio.prio.class restrict-to-be
 
     restorecon_recursive /mnt
diff --git a/rootdir/init.zygote32.rc b/rootdir/init.zygote32.rc
index 442bd15..862afb6 100644
--- a/rootdir/init.zygote32.rc
+++ b/rootdir/init.zygote32.rc
@@ -16,5 +16,5 @@
     onrestart restart --only-if-running media.tuner
     onrestart restart netd
     onrestart restart wificond
-    task_profiles ProcessCapacityHigh
+    task_profiles ProcessCapacityHigh MaxPerformance
     critical window=${zygote.critical_window.minute:-off} target=zygote-fatal
diff --git a/toolbox/modprobe.cpp b/toolbox/modprobe.cpp
index b0e76ea..13026ac 100644
--- a/toolbox/modprobe.cpp
+++ b/toolbox/modprobe.cpp
@@ -15,9 +15,9 @@
  */
 
 #include <ctype.h>
-#include <fcntl.h>
 #include <getopt.h>
 #include <stdlib.h>
+#include <unistd.h>
 
 #include <string>
 
@@ -28,7 +28,6 @@
 #include <modprobe/modprobe.h>
 
 #include <sys/utsname.h>
-#include <unistd.h>
 
 namespace {
 
@@ -87,6 +86,20 @@
     }
 }
 
+static bool ModDirMatchesKernelPageSize(const char* mod_dir) {
+    static const unsigned int kernel_pgsize_kb = getpagesize() / 1024;
+    const char* mod_sfx = strrchr(mod_dir, '_');
+    unsigned int mod_pgsize_kb;
+    int mod_sfx_len;
+
+    if (mod_sfx == NULL || sscanf(mod_sfx, "_%uk%n", &mod_pgsize_kb, &mod_sfx_len) != 1 ||
+        strlen(mod_sfx) != mod_sfx_len) {
+        mod_pgsize_kb = 4;
+    }
+
+    return kernel_pgsize_kb == mod_pgsize_kb;
+}
+
 // Find directories in format of "/lib/modules/x.y.z-*".
 static int KernelVersionNameFilter(const dirent* de) {
     unsigned int major, minor;
@@ -102,16 +115,11 @@
     }
 
     if (android::base::StartsWith(de->d_name, kernel_version)) {
-        return 1;
+        return ModDirMatchesKernelPageSize(de->d_name);
     }
     return 0;
 }
 
-std::string GetPageSizeSuffix() {
-    static const size_t page_size = sysconf(_SC_PAGE_SIZE);
-    return android::base::StringPrintf("_%zuk", page_size / 1024);
-}
-
 }  // anonymous namespace
 
 extern "C" int modprobe_main(int argc, char** argv) {
@@ -237,20 +245,9 @@
         }
         free(kernel_dirs);
 
-        // Allow modules to be directly inside /lib/modules
-        mod_dirs.emplace_back(LIB_MODULES_PREFIX);
-    }
-    if (getpagesize() != 4096) {
-        struct utsname uts {};
-        if (uname(&uts)) {
-            PLOG(FATAL) << "Failed to get kernel version";
-        }
-        const auto module_dir = android::base::StringPrintf("/lib/modules/%s%s", uts.release,
-                                                            GetPageSizeSuffix().c_str());
-        struct stat st {};
-        if (stat(module_dir.c_str(), &st) == 0 && S_ISDIR(st.st_mode)) {
-            mod_dirs.clear();
-            mod_dirs.emplace_back(module_dir);
+        if (mod_dirs.empty() || getpagesize() == 4096) {
+            // Allow modules to be directly inside /lib/modules
+            mod_dirs.emplace_back(LIB_MODULES_PREFIX);
         }
     }