From nobody Wed Dec 29 23:06:30 2021 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id D07A5191FFB7; Wed, 29 Dec 2021 23:06:33 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4JPRqC3Ps7z3kHt; Wed, 29 Dec 2021 23:06:31 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 1B3C0557A; Wed, 29 Dec 2021 23:06:31 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 1BTN6VJr090391; Wed, 29 Dec 2021 23:06:31 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 1BTN6UtJ090390; Wed, 29 Dec 2021 23:06:30 GMT (envelope-from git) Date: Wed, 29 Dec 2021 23:06:30 GMT Message-Id: <202112292306.1BTN6UtJ090390@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Colin Percival Subject: git: 3684bb89d520 - stable/13 - MFC: Improve readahead in loader List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: cperciva X-Git-Repository: src X-Git-Refname: refs/heads/stable/13 X-Git-Reftype: branch X-Git-Commit: 3684bb89d5208575b341833225a798d5b5c465de Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1640819192; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=K3YLAD9CL6eJ1Ipd+LiYdpSpj6qQH7MGtHX+yiLKxUY=; b=BuXejGFXgOSXtTU47aeDyKaUuzf5P8krNoeo7ETERtTgG9L0GShCngEgwBmNvnYDQaRhHA MDfOFEfyzrLamYQjalz1D8/bUWRKphR3ptuIbdTfWxfRM6FI4PRlUaMBIKKZpaPLyx1k+d rwjtTfFq1D++iyQGRaIUbPGJP19dhRkQrDLWbyWj4k1zm+avZpuJdiYr/r+vkyULJnMkEf kLcDrCDyoUdts3PvHbDSCSTyG4E83GT3oJdcVDmonhczuezrs1plWPgHA10jXOJtzarVB0 /sOp1sOaRHQdank+TvOB1IAXYpZ3imHcJQlKwo2wyrfi+G/GQE8TWc0AcX9tLQ== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1640819192; a=rsa-sha256; cv=none; b=DNvkPakn8QZ+AJYT9WkU/IkT+s6fcGfj0xXkr6VI81JnXruKv7oC+Awi1B79jKqrTxis3r 5eu4ykOuPjKpKCvWUOAbC/vXuvRR0fvMADhxizei2AIpo5G7vnhe2oY73vKLXpfKHWKe/v 1yOEpnaqXgNzaslXNiIi1CzUXO4U7I7bO0ViFfc9WUUvf4kAhpyMTi2r5Oj1yMIPhzbgpv WrWXlio4x6tQ2fF6L/c0QjV2jVLyY6eP0SCPFhdkS7bIC30BTkiEMMsXT3FcO4xUptRubp zvd3flA0QqXNHF4chmAB7pBpoYGK9hoME1TezxccdfvwC+W7TdkG6OZBZEeYXg== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch stable/13 has been updated by cperciva: URL: https://cgit.FreeBSD.org/src/commit/?id=3684bb89d5208575b341833225a798d5b5c465de commit 3684bb89d5208575b341833225a798d5b5c465de Author: Colin Percival AuthorDate: 2021-09-19 22:24:00 +0000 Commit: Colin Percival CommitDate: 2021-12-29 22:53:19 +0000 MFC: Improve readahead in loader style: Fix leading whitespace in bcache.c loader: Refactor readahead adjustment in bcache loader bcache: Track unconsumed readahead loader bcache: Allow readahead up to 256 kB I/Os Sponsored by: https://www.patreon.com/cperciva (cherry picked from commit 5a01dea7e8c9640605e5731a9fc7f600c07ace61) (cherry picked from commit b841148bbbdc967c871e8742a6f0b7b17b2d1d91) (cherry picked from commit 04b9b7c507c52daf7b2999329a50825db098151f) (cherry picked from commit 248682a589159619aa5f2019e415a423e849e327) --- stand/common/bcache.c | 40 +++++++++++++++++++++++++++++++++------- 1 file changed, 33 insertions(+), 7 deletions(-) diff --git a/stand/common/bcache.c b/stand/common/bcache.c index 526f9fe3fa5c..99c78b0346b7 100644 --- a/stand/common/bcache.c +++ b/stand/common/bcache.c @@ -67,6 +67,7 @@ struct bcache { size_t bcache_nblks; size_t ra; daddr_t bcache_nextblkno; + size_t ralen; }; static u_int bcache_total_nblks; /* set by bcache_init */ @@ -85,8 +86,9 @@ static u_int bcache_rablks; #define BHASH(bc, blkno) ((blkno) & ((bc)->bcache_nblks - 1)) #define BCACHE_LOOKUP(bc, blkno) \ ((bc)->bcache_ctl[BHASH((bc), (blkno))].bc_blkno != (blkno)) -#define BCACHE_READAHEAD 256 +#define BCACHE_READAHEAD 512 #define BCACHE_MINREADAHEAD 32 +#define BCACHE_MAXIOWRA 512 static void bcache_invalidate(struct bcache *bc, daddr_t blkno); static void bcache_insert(struct bcache *bc, daddr_t blkno); @@ -238,20 +240,39 @@ 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 || (i == bc->ralen && bc->ralen > 0)) { if (bc->ra < BCACHE_READAHEAD) - bc->ra <<= 1; /* increase read ahead */ + bc->ra <<= 1; /* increase read ahead */ + } else { + if (nblk - i > BCACHE_MINREADAHEAD && bc->ralen > 0 && + bc->ra > BCACHE_MINREADAHEAD) + bc->ra >>= 1; /* reduce read ahead */ + } + + /* Adjust our "unconsumed readahead" value. */ + if (blk == bc->bcache_nextblkno) { + if (nblk > bc->ralen) + bc->ralen = 0; + else + bc->ralen -= nblk; + } + + if (complete) { /* whole set was in cache, return it */ bcopy(bc->bcache_data + (bcache_blksize * BHASH(bc, blk)), buf, size); goto done; - } + } /* * Fill in any misses. From check we have i pointing to first missing @@ -304,7 +325,12 @@ read_strategy(void *devdata, int rw, daddr_t blk, size_t size, if (ra != 0 && ra != bc->bcache_nblks) { /* do we have RA space? */ ra = MIN(bc->ra, ra - 1); ra = rounddown(ra, 16); /* multiple of 16 blocks */ + if (ra + p_size > BCACHE_MAXIOWRA) + ra = BCACHE_MAXIOWRA - p_size; + bc->ralen = ra; p_size += ra; + } else { + bc->ralen = 0; } /* invalidate bcache */ @@ -351,7 +377,7 @@ read_strategy(void *devdata, int rw, daddr_t blk, size_t size, result = 0; } - done: +done: if (result == 0) { if (rsize != NULL) *rsize = size;