Merge changes from topic "change_period" am: c0de6d8184

Original change: https://android-review.googlesource.com/c/platform/system/vold/+/2043104

Change-Id: I5f33ee1baa66c6278139ca9e17a7ef4c5836e674
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
diff --git a/IdleMaint.cpp b/IdleMaint.cpp
index 3efcb50..2bfe3d9 100644
--- a/IdleMaint.cpp
+++ b/IdleMaint.cpp
@@ -547,7 +547,9 @@
     std::string dirtySegmentsPath = f2fsSysfsPath + "/dirty_segments";
     std::string gcSleepTimePath = f2fsSysfsPath + "/gc_urgent_sleep_time";
     std::string gcUrgentModePath = f2fsSysfsPath + "/gc_urgent";
-    std::string freeSegmentsStr, dirtySegmentsStr;
+    std::string ovpSegmentsPath = f2fsSysfsPath + "/ovp_segments";
+    std::string reservedBlocksPath = f2fsSysfsPath + "/reserved_blocks";
+    std::string freeSegmentsStr, dirtySegmentsStr, ovpSegmentsStr, reservedBlocksStr;
 
     if (!ReadFileToString(freeSegmentsPath, &freeSegmentsStr)) {
         PLOG(WARNING) << "Reading failed in " << freeSegmentsPath;
@@ -559,9 +561,21 @@
         return;
     }
 
+    if (!ReadFileToString(ovpSegmentsPath, &ovpSegmentsStr)) {
+            PLOG(WARNING) << "Reading failed in " << ovpSegmentsPath;
+            return;
+        }
+
+    if (!ReadFileToString(reservedBlocksPath, &reservedBlocksStr)) {
+            PLOG(WARNING) << "Reading failed in " << reservedBlocksPath;
+            return;
+        }
+
     int32_t freeSegments = std::stoi(freeSegmentsStr);
     int32_t dirtySegments = std::stoi(dirtySegmentsStr);
+    int32_t reservedBlocks = std::stoi(ovpSegmentsStr) + std::stoi(reservedBlocksStr);
 
+    freeSegments = freeSegments > reservedBlocks ? freeSegments - reservedBlocks : 0;
     neededSegments *= reclaimWeight;
     if (freeSegments >= neededSegments) {
         LOG(INFO) << "Enough free segments: " << freeSegments