Blame SOURCES/0003-readahead-Fix-test.patch

3cdd4c
From b41b7d7ddf6d3fba23ac7978c8b272f2ff84265d Mon Sep 17 00:00:00 2001
3cdd4c
From: "Richard W.M. Jones" <rjones@redhat.com>
3cdd4c
Date: Thu, 21 Apr 2022 16:14:46 +0100
3cdd4c
Subject: [PATCH] readahead: Fix test
3cdd4c
3cdd4c
The previous test turned out to be pretty bad at testing the new
3cdd4c
filter.  A specific problem is that the filter starts a background
3cdd4c
thread which issues .cache requests, while on the main connection
3cdd4c
.pread requests are being passed through.  The test used
3cdd4c
--filter=readahead --filter=cache with the cache filter only caching
3cdd4c
on .cache requests (since cache-on-read defaults to false), so only
3cdd4c
caching requests made by the background thread.
3cdd4c
3cdd4c
                       main thread
3cdd4c
  client ---- .pread ----- delay-filter -------> plugin
3cdd4c
             \
3cdd4c
              \     background thread
3cdd4c
               .cache --- cache-filter
3cdd4c
3cdd4c
Under very high load, the background thread could be starved.  This
3cdd4c
means no requests were being cached at all, and all requests were
3cdd4c
passing through the delay filter.  It would appear that readahead was
3cdd4c
failing (which it was, in a way).
3cdd4c
3cdd4c
It's not very easy to fix this since readahead is best-effort, but we
3cdd4c
can go back to using a simpler plugin that logs reads and caches and
3cdd4c
check that they look valid.
3cdd4c
3cdd4c
Update: commit 2ff548d66ad3eae87868402ec5b3319edd12090f
3cdd4c
(cherry picked from commit db1e3311727c6ecab3264a1811d33db1aa45a4d0)
3cdd4c
---
3cdd4c
 tests/test-readahead.sh | 61 +++++++++++++++++++++++------------------
3cdd4c
 1 file changed, 35 insertions(+), 26 deletions(-)
3cdd4c
3cdd4c
diff --git a/tests/test-readahead.sh b/tests/test-readahead.sh
3cdd4c
index 17126e5a..37f4a06f 100755
3cdd4c
--- a/tests/test-readahead.sh
3cdd4c
+++ b/tests/test-readahead.sh
3cdd4c
@@ -30,43 +30,52 @@
3cdd4c
 # OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
3cdd4c
 # SUCH DAMAGE.
3cdd4c
 
3cdd4c
-# Is the readahead filter faster?  Copy a blank disk with a custom
3cdd4c
-# plugin that sleeps on every request.  Because the readahead filter
3cdd4c
-# should result in fewer requests it should run faster.
3cdd4c
-
3cdd4c
 source ./functions.sh
3cdd4c
 set -e
3cdd4c
 set -x
3cdd4c
 
3cdd4c
-requires_filter delay
3cdd4c
+requires_plugin sh
3cdd4c
 requires nbdsh --version
3cdd4c
 requires dd iflag=count_bytes 
3cdd4c
 
3cdd4c
-files="readahead.img"
3cdd4c
+files="readahead.out"
3cdd4c
 rm -f $files
3cdd4c
 cleanup_fn rm -f $files
3cdd4c
 
3cdd4c
-test ()
3cdd4c
-{
3cdd4c
-    start_t=$SECONDS
3cdd4c
-    nbdkit -fv -U - "$@" null size=1M --filter=delay rdelay=5 \
3cdd4c
-           --run 'nbdsh --uri "$uri" -c "
3cdd4c
+nbdkit -fv -U - "$@" sh - \
3cdd4c
+       --filter=readahead \
3cdd4c
+       --run 'nbdsh --uri "$uri" -c "
3cdd4c
 for i in range(0, 512*10, 512):
3cdd4c
     h.pread(512, i)
3cdd4c
-"'
3cdd4c
+"' <<'EOF'
3cdd4c
+case "$1" in
3cdd4c
+     thread_model)
3cdd4c
+         echo parallel
3cdd4c
+         ;;
3cdd4c
+     can_cache)
3cdd4c
+         echo native
3cdd4c
+         ;;
3cdd4c
+     get_size)
3cdd4c
+         echo 1M
3cdd4c
+         ;;
3cdd4c
+     cache)
3cdd4c
+         echo "$@" >> readahead.out
3cdd4c
+         ;;
3cdd4c
+     pread)
3cdd4c
+         echo "$@" >> readahead.out
3cdd4c
+         dd if=/dev/zero count=$3 iflag=count_bytes
3cdd4c
+         ;;
3cdd4c
+     *)
3cdd4c
+         exit 2
3cdd4c
+         ;;
3cdd4c
+esac
3cdd4c
+EOF
3cdd4c
 
3cdd4c
-    end_t=$SECONDS
3cdd4c
-    echo $((end_t - start_t))
3cdd4c
-}
3cdd4c
+cat readahead.out
3cdd4c
 
3cdd4c
-t1=$(test --filter=readahead --filter=cache)
3cdd4c
-t2=$(test)
3cdd4c
-
3cdd4c
-# In the t1 case we should make only 1 request into the plugin,
3cdd4c
-# resulting in around 1 sleep period (5 seconds).  In the t2 case we
3cdd4c
-# make 10 requests so sleep for around 50 seconds.  t1 should be < t2
3cdd4c
-# is every reasonable scenario.
3cdd4c
-if [ $t1 -ge $t2 ]; then
3cdd4c
-    echo "$0: readahead filter took longer, should be shorter"
3cdd4c
-    exit 1
3cdd4c
-fi
3cdd4c
+# We should see the pread requests, and additional cache requests for
3cdd4c
+# the 32K region following each pread request.
3cdd4c
+for i in `seq 0 512 $((512*10 - 512))` ; do
3cdd4c
+    grep "pread  512 $i" readahead.out
3cdd4c
+    grep "cache  32768 $((i+512))" readahead.out
3cdd4c
+done
3cdd4c
-- 
3cdd4c
2.31.1
3cdd4c