From 9226bb304aab57afa84a95ae95c3abd3ea3e8451 Mon Sep 17 00:00:00 2001
From: Martijn Coenen <maco@google.com>
Date: Mon, 16 Dec 2019 09:59:08 +0100
Subject: [PATCH] Disable dm-verity hash prefetching.

Prefetching appears to have a slightly negative effect on boot time, and
actually makes boot time much worse when the available dm-bufio cache
shrinks. Since we anticipate the dm-bufio cache will shrink (because of
an increasing number of APEX dm-verity targets), disable prefetching
completely.

We've run this change on Pixel 2 since August, and haven't observed any
negative effects. Boot time slightly decreased. With the increased
amount of APEXes we already have, this should now result in an even more
significant boot time decrease.

Bug: 136247322
Test: atest google/perf/boottime/boottime-test
Change-Id: Id588669af1b0b9daaf15323dccf33411e03b8633
---
 rootdir/init.rc | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/rootdir/init.rc b/rootdir/init.rc
index 7a3339d8f..a63fbd2ab 100644
--- a/rootdir/init.rc
+++ b/rootdir/init.rc
@@ -42,6 +42,10 @@ on early-init
     mkdir /linkerconfig/bootstrap 0755
     mkdir /linkerconfig/default 0755
 
+    # Disable dm-verity hash prefetching, since it doesn't help performance
+    # Read more in b/136247322
+    write /sys/module/dm_verity/parameters/prefetch_cluster 0
+
     # Generate ld.config.txt for early executed processes
     exec -- /system/bin/linkerconfig --target /linkerconfig/bootstrap
     chmod 644 /linkerconfig/bootstrap/ld.config.txt