ANDROID: dm: verity: add minimum prefetch size
authorKeun-young Park <keunyoung@google.com>
Tue, 15 Nov 2016 02:25:15 +0000 (18:25 -0800)
committerAmit Pundir <amit.pundir@linaro.org>
Mon, 18 Dec 2017 15:41:22 +0000 (21:11 +0530)
- For device like eMMC, it gives better performance to read more hash
  blocks at a time.
- For android, set it to default 128.
  For other devices, set it to 1 which is the same as now.
- saved boot-up time by 300ms in tested device

bug: 32246564

Change-Id: Ibc0401a0cddba64b862a80445844b4e595213621
Cc: Sami Tolvanen <samitolvanen@google.com>
Signed-off-by: Keun-young Park <keunyoung@google.com>
drivers/md/Kconfig
drivers/md/dm-verity-target.c

index d6862f09a40866e3db21f97744131c0745be9252..6ac0297db28c7e2b8d6d84725fe3dcf60d41c122 100644 (file)
@@ -460,6 +460,21 @@ config DM_VERITY
 
          If unsure, say N.
 
+config DM_VERITY_HASH_PREFETCH_MIN_SIZE_128
+       bool "Prefetch size 128"
+
+config DM_VERITY_HASH_PREFETCH_MIN_SIZE
+       int "Verity hash prefetch minimum size"
+       depends on DM_VERITY
+       range 1 4096
+       default 128 if DM_VERITY_HASH_PREFETCH_MIN_SIZE_128
+       default 1
+       ---help---
+         This sets minimum number of hash blocks to prefetch for dm-verity.
+         For devices like eMMC, having larger prefetch size like 128 can improve
+         performance with increased memory consumption for keeping more hashes
+         in RAM.
+
 config DM_VERITY_FEC
        bool "Verity forward error correction support"
        depends on DM_VERITY
@@ -549,6 +564,7 @@ config DM_ANDROID_VERITY
        depends on KEYS
        depends on ASYMMETRIC_KEY_TYPE
        depends on ASYMMETRIC_PUBLIC_KEY_SUBTYPE
+       select DM_VERITY_HASH_PREFETCH_MIN_SIZE_128
        ---help---
          This device-mapper target is virtually a VERITY target. This
          target is setup by reading the metadata contents piggybacked
index 7b1b02e27ece72453abae986af1dd2c658cd38ba..5c6d441a8a8a08e8f456316d127c54d2c6634e35 100644 (file)
@@ -582,6 +582,7 @@ static void verity_prefetch_io(struct work_struct *work)
                container_of(work, struct dm_verity_prefetch_work, work);
        struct dm_verity *v = pw->v;
        int i;
+       sector_t prefetch_size;
 
        for (i = v->levels - 2; i >= 0; i--) {
                sector_t hash_block_start;
@@ -604,8 +605,14 @@ static void verity_prefetch_io(struct work_struct *work)
                                hash_block_end = v->hash_blocks - 1;
                }
 no_prefetch_cluster:
+               // for emmc, it is more efficient to send bigger read
+               prefetch_size = max((sector_t)CONFIG_DM_VERITY_HASH_PREFETCH_MIN_SIZE,
+                       hash_block_end - hash_block_start + 1);
+               if ((hash_block_start + prefetch_size) >= (v->hash_start + v->hash_blocks)) {
+                       prefetch_size = hash_block_end - hash_block_start + 1;
+               }
                dm_bufio_prefetch(v->bufio, hash_block_start,
-                                 hash_block_end - hash_block_start + 1);
+                                 prefetch_size);
        }
 
        kfree(pw);