Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 3 Oct 2021 21:56:59 GMT
From:      Colin Percival <cperciva@FreeBSD.org>
To:        src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org
Subject:   git: b841148bbbdc - main - loader: Refactor readahead adjustment in bcache
Message-ID:  <202110032156.193Luxix041352@gitrepo.freebsd.org>

next in thread | raw e-mail | index | archive | help
The branch main has been updated by cperciva:

URL: https://cgit.FreeBSD.org/src/commit/?id=b841148bbbdc967c871e8742a6f0b7b17b2d1d91

commit b841148bbbdc967c871e8742a6f0b7b17b2d1d91
Author:     Colin Percival <cperciva@FreeBSD.org>
AuthorDate: 2021-10-03 19:10:36 +0000
Commit:     Colin Percival <cperciva@FreeBSD.org>
CommitDate: 2021-10-03 19:10:36 +0000

    loader: Refactor readahead adjustment in bcache
    
    While I'm here, add an explanatory comment.
    
    No functional change intended.
    
    Reviewed by:    imp, tsoome (previous version)
    MFC after:      1 week
    Sponsored by:   https://patreon.com/cperciva
    Differential Revision:  https://reviews.freebsd.org/D32249
---
 stand/common/bcache.c | 18 ++++++++++++++----
 1 file changed, 14 insertions(+), 4 deletions(-)

diff --git a/stand/common/bcache.c b/stand/common/bcache.c
index 0eeb7e74ee96..b3b8b22c7d21 100644
--- a/stand/common/bcache.c
+++ b/stand/common/bcache.c
@@ -238,17 +238,27 @@ read_strategy(void *devdata, int rw, daddr_t blk, size_t size,
 	if (BCACHE_LOOKUP(bc, (daddr_t)(blk + i))) {
 	    bcache_misses += (nblk - i);
 	    complete = 0;
-	    if (nblk - i > BCACHE_MINREADAHEAD && bc->ra > BCACHE_MINREADAHEAD)
-		bc->ra >>= 1;	/* reduce read ahead */
 	    break;
 	} else {
 	    bcache_hits++;
 	}
     }
 
-    if (complete) {	/* whole set was in cache, return it */
+    /*
+     * Adjust read-ahead size if appropriate.  Subject to the requirement
+     * that bc->ra must stay in between MINREADAHEAD and READAHEAD, we
+     * increase it when we notice that readahead was useful and decrease
+     * it when we notice that readahead was not useful.
+     */
+    if (complete) {
 	if (bc->ra < BCACHE_READAHEAD)
-		bc->ra <<= 1;	/* increase read ahead */
+	    bc->ra <<= 1;	/* increase read ahead */
+    } else {
+	if (nblk - i > BCACHE_MINREADAHEAD && bc->ra > BCACHE_MINREADAHEAD)
+	    bc->ra >>= 1;	/* reduce read ahead */
+    }
+
+    if (complete) {	/* whole set was in cache, return it */
 	bcopy(bc->bcache_data + (bcache_blksize * BHASH(bc, blk)), buf, size);
 	goto done;
     }



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202110032156.193Luxix041352>