From 019d5163cc5de0070db177e7fbd8f303abec6179 Mon Sep 17 00:00:00 2001 From: Eric Biggers Date: Thu, 15 Oct 2020 16:54:38 -0700 Subject: [PATCH 1/2] IdleMaint: use fstab_default from VoldUtil vold already reads the default fstab into memory when starting up, and the default fstab isn't allowed to change later. So in IdleMaint.cpp, just use 'fstab_default' instead of reading it again. This also has the advantage that fstab entries for "logical partitions" now get a properly updated blk_device, which is needed in order to start using blk_device to exclude virtual filesystems in addFromFstab(). Change-Id: Id6457a2b7972d01dde4bca0c5f2da86374d930af --- Checkpoint.cpp | 1 - IdleMaint.cpp | 13 +++---------- 2 files changed, 3 insertions(+), 11 deletions(-) diff --git a/Checkpoint.cpp b/Checkpoint.cpp index 61035e5..755f0e3 100644 --- a/Checkpoint.cpp +++ b/Checkpoint.cpp @@ -47,7 +47,6 @@ using android::base::GetUintProperty; using android::base::SetProperty; using android::binder::Status; using android::fs_mgr::Fstab; -using android::fs_mgr::ReadDefaultFstab; using android::fs_mgr::ReadFstabFromFile; using android::hardware::hidl_string; using android::hardware::boot::V1_0::BoolResult; diff --git a/IdleMaint.cpp b/IdleMaint.cpp index 2b5a8f1..24a1ef9 100644 --- a/IdleMaint.cpp +++ b/IdleMaint.cpp @@ -17,6 +17,7 @@ #include "IdleMaint.h" #include "FileDeviceUtils.h" #include "Utils.h" +#include "VoldUtil.h" #include "VolumeManager.h" #include "model/PrivateVolume.h" @@ -45,8 +46,6 @@ using android::base::Realpath; using android::base::StringPrintf; using android::base::Timer; using android::base::WriteStringToFile; -using android::fs_mgr::Fstab; -using android::fs_mgr::ReadDefaultFstab; using android::hardware::Return; using android::hardware::Void; using android::hardware::health::storage::V1_0::IStorage; @@ -104,11 +103,8 @@ static void addFromVolumeManager(std::list* paths, PathTypes path_t } static void addFromFstab(std::list* paths, PathTypes path_type) { - Fstab fstab; - ReadDefaultFstab(&fstab); - std::string previous_mount_point; - for (const auto& entry : fstab) { + for (const auto& entry : fstab_default) { // Skip raw partitions. if (entry.fs_type == "emmc" || entry.fs_type == "mtd") { continue; @@ -253,11 +249,8 @@ static int stopGc(const std::list& paths) { } static void runDevGcFstab(void) { - Fstab fstab; - ReadDefaultFstab(&fstab); - std::string path; - for (const auto& entry : fstab) { + for (const auto& entry : fstab_default) { if (!entry.sysfs_path.empty()) { path = entry.sysfs_path; break; From 9a3dc8c709b15fe06e4a4babc0f1e32efb0a9955 Mon Sep 17 00:00:00 2001 From: Eric Biggers Date: Thu, 15 Oct 2020 16:54:38 -0700 Subject: [PATCH 2/2] IdleMaint: skip swap space, bind mounts, and virtual filesystems When the idle maintenance task runs on Cuttlefish, there are several warnings printed to logcat after the expected messages: D vold : Starting trim of /data I vold : Trimmed 0 bytes on /data in 36ms D vold : Starting trim of /cache I vold : Trimmed 58662912 bytes on /cache in 0ms D vold : Starting trim of /metadata I vold : Trimmed 7725056 bytes on /metadata in 12ms D vold : Starting trim of none W vold : Failed to open none: No such file or directory D vold : Starting trim of /sdcard W vold : Failed to open /sdcard: Not a directory D vold : Starting trim of /mnt/vendor/shared W vold : Trim failed on /mnt/vendor/shared: Inappropriate ioctl for device This is because vold gathers the filesystems to trim from the fstab, but it fails to exclude some entries that aren't appropriate to trim: /dev/block/zram0 none swap defaults zramsize=75% /tmp /sdcard none defaults,bind recoveryonly shared /mnt/vendor/shared virtiofs nosuid,nodev,noatime nofail These should be excluded because they are swap space, a bind mount, and a virtual filesystem respectively. Fix addFromFstab() to exclude the above cases. Afterwards, the messages on Cuttlefish are: D vold : Starting trim of /data I vold : Trimmed 0 bytes on /data in 39ms D vold : Starting trim of /cache I vold : Trimmed 58662912 bytes on /cache in 0ms D vold : Starting trim of /metadata I vold : Trimmed 9822208 bytes on /metadata in 12ms Change-Id: Idc575106fe6f81c737f684429d58dba4bd5478ad --- IdleMaint.cpp | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/IdleMaint.cpp b/IdleMaint.cpp index 24a1ef9..e4a1806 100644 --- a/IdleMaint.cpp +++ b/IdleMaint.cpp @@ -105,12 +105,16 @@ static void addFromVolumeManager(std::list* paths, PathTypes path_t static void addFromFstab(std::list* paths, PathTypes path_type) { std::string previous_mount_point; for (const auto& entry : fstab_default) { - // Skip raw partitions. - if (entry.fs_type == "emmc" || entry.fs_type == "mtd") { + // Skip raw partitions and swap space. + if (entry.fs_type == "emmc" || entry.fs_type == "mtd" || entry.fs_type == "swap") { continue; } - // Skip read-only filesystems - if (entry.flags & MS_RDONLY) { + // Skip read-only filesystems and bind mounts. + if (entry.flags & (MS_RDONLY | MS_BIND)) { + continue; + } + // Skip anything without an underlying block device, e.g. virtiofs. + if (entry.blk_device[0] != '/') { continue; } if (entry.fs_mgr_flags.vold_managed) {