OSDN Git Service

ART: Check for more low-space situations in zygote
authorAndreas Gampe <agampe@google.com>
Wed, 10 Aug 2016 03:19:18 +0000 (20:19 -0700)
committerAndreas Gampe <agampe@google.com>
Wed, 10 Aug 2016 17:43:04 +0000 (10:43 -0700)
Even if a boot image exists and can be loaded, the rest of the
platform may not be able to boot. We previously only checked
after full image generation and missed this case.

Also prune the cache if there wasn't even space to put the boot
marker.

Bug: 30765660
Change-Id: Icd43746e681c62ce2e4e8745fb17bda65ca60372

runtime/gc/space/image_space.cc
runtime/gc/space/image_space_fs.h

index 5a52e9a..b7b9ffe 100644 (file)
@@ -505,6 +505,17 @@ ImageSpace* ImageSpace::CreateBootImage(const char* image_location,
                                error_msg);
     }
     if (space != nullptr) {
+      // Check whether there is enough space left over in the data partition. Even if we can load
+      // the image, we need to be conservative, as some parts of the platform are not very tolerant
+      // of space constraints.
+      // ImageSpace doesn't know about the data partition per se, it relies on the FindImageFilename
+      // helper (which relies on GetDalvikCache). So for now, if we load an image out of /system,
+      // ignore the check (as it would test for free space in /system instead).
+      if (!is_system && !CheckSpace(*image_filename, error_msg)) {
+        // No. Delete the generated image and try to run out of the dex files.
+        PruneDalvikCache(image_isa);
+        return nullptr;
+      }
       return space;
     }
 
index 57bf59f..fc9a3cf 100644 (file)
@@ -114,8 +114,21 @@ static void MarkZygoteStart(const InstructionSet isa, const uint32_t max_failed_
     file.reset(OS::CreateEmptyFile(file_name));
 
     if (file.get() == nullptr) {
+      int saved_errno = errno;
       PLOG(WARNING) << "Failed to create boot marker.";
-      return;
+      if (saved_errno != ENOSPC) {
+        return;
+      }
+
+      LOG(WARNING) << "Pruning dalvik cache because of low-memory situation.";
+      impl::DeleteDirectoryContents(isa_subdir, false);
+
+      // Try once more.
+      file.reset(OS::OpenFileReadWrite(file_name));
+      if (file == nullptr) {
+        PLOG(WARNING) << "Failed to create boot marker.";
+        return;
+      }
     }
   } else {
     if (!file->ReadFully(&num_failed_boots, sizeof(num_failed_boots))) {