vold: do not set gc sleep time with zero dirty segments
When there is not enough dirty segments to reclaim, we don't have to set
gc sleep time.
Test: Run smart idle maint with zero dirty segments
Bug: 202283480
Bug: 181079477
Signed-off-by: Daeho Jeong <daehojeong@google.com>
Change-Id: If6a9965ecb9b1a91bf5d0dd763d5fa0af63348e0
diff --git a/IdleMaint.cpp b/IdleMaint.cpp
index 597d609..3efcb50 100644
--- a/IdleMaint.cpp
+++ b/IdleMaint.cpp
@@ -534,6 +534,7 @@
float reclaimWeight, int32_t gcPeriod) {
std::list<std::string> paths;
bool needGC = true;
+ int32_t sleepTime;
addFromFstab(&paths, PathTypes::kBlkDevice, true);
if (paths.empty()) {
@@ -570,6 +571,18 @@
LOG(INFO) << "The sum of free segments: " << freeSegments
<< ", dirty segments: " << dirtySegments << " is under " << minSegmentThreshold;
needGC = false;
+ } else {
+ neededSegments -= freeSegments;
+ neededSegments = std::min(neededSegments, (int32_t)(dirtySegments * dirtyReclaimRate));
+ if (neededSegments == 0) {
+ LOG(INFO) << "Low dirty segments: " << dirtySegments;
+ needGC = false;
+ } else {
+ sleepTime = gcPeriod * ONE_MINUTE_IN_MS / neededSegments;
+ if (sleepTime < MIN_GC_URGENT_SLEEP_TIME) {
+ sleepTime = MIN_GC_URGENT_SLEEP_TIME;
+ }
+ }
}
if (!needGC) {
@@ -579,18 +592,6 @@
return;
}
- int32_t sleepTime;
-
- neededSegments -= freeSegments;
- neededSegments = std::min(neededSegments, (int32_t)(dirtySegments * dirtyReclaimRate));
- if (neededSegments == 0) {
- sleepTime = MIN_GC_URGENT_SLEEP_TIME;
- } else {
- sleepTime = gcPeriod * ONE_MINUTE_IN_MS / neededSegments;
- if (sleepTime < MIN_GC_URGENT_SLEEP_TIME) {
- sleepTime = MIN_GC_URGENT_SLEEP_TIME;
- }
- }
if (!WriteStringToFile(std::to_string(sleepTime), gcSleepTimePath)) {
PLOG(WARNING) << "Writing failed in " << gcSleepTimePath;
return;