Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 6c60f4ae authored by Mark Salyzyn's avatar Mark Salyzyn Committed by android-build-merger
Browse files

Merge "fs_mgr: Change scratch margin to 3 X logical_block_size." am: a30cff7f

am: 8d6ceedc

Change-Id: If86f32270c7e7d0c799b84ff04ccefdb348d8a05
parents 9fc9204d 8d6ceedc
Loading
Loading
Loading
Loading
+5 −0
Original line number Diff line number Diff line
@@ -89,4 +89,9 @@ Caveats
  if higher than 4.6.
- *adb enable-verity* will free up overlayfs and as a bonus the
  device will be reverted pristine to before any content was updated.
- If dynamic partitions runs out of space, resizing a logical
  partition larger may fail because of the scratch partition.
  If this happens, either fastboot flashall or adb enable-verity can
  be used to clear scratch storage to permit the flash.
  Then reinstate the overrides and continue.
- File bugs or submit fixes for review.
+15 −3
Original line number Diff line number Diff line
@@ -675,14 +675,26 @@ bool fs_mgr_overlayfs_setup_scratch(const fstab* fstab, bool* change) {
        }
        changed = true;
    }
    // Take half of free space, minimum 512MB or free space - 256KB margin.
    // Take half of free space, minimum 512MB or maximum free - margin.
    static constexpr auto kMinimumSize = uint64_t(512 * 1024 * 1024);
    static constexpr auto kMarginSize = uint64_t(256 * 1024);
    if (partition->size() < kMinimumSize) {
        auto partition_size =
                builder->AllocatableSpace() - builder->UsedSpace() + partition->size();
        if ((partition_size > kMinimumSize) || !partition->size()) {
            partition_size = std::max(std::min(kMinimumSize, partition_size - kMarginSize),
            // Leave some space for free space jitter of a few erase
            // blocks, in case they are needed for any individual updates
            // to any other partition that needs to be flashed while
            // overlayfs is in force.  Of course if margin_size is not
            // enough could normally get a flash failure, so
            // ResizePartition() will delete the scratch partition in
            // order to fulfill.  Deleting scratch will destroy all of
            // the adb remount overrides :-( .
            auto margin_size = uint64_t(3 * 256 * 1024);
            BlockDeviceInfo info;
            if (builder->GetBlockDeviceInfo(partition_name, &info)) {
                margin_size = 3 * info.logical_block_size;
            }
            partition_size = std::max(std::min(kMinimumSize, partition_size - margin_size),
                                      partition_size / 2);
            if (partition_size > partition->size()) {
                if (!builder->ResizePartition(partition, partition_size)) {