From nobody Wed Dec 29 23:06:29 2021 X-Original-To: dev-commits-src-branches@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 BFEEE191FE43; Wed, 29 Dec 2021 23:06:32 +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 4JPRqB2mpqz3kFf; Wed, 29 Dec 2021 23:06:30 +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 07F2854D3; Wed, 29 Dec 2021 23:06:30 +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 1BTN6TZr090361; Wed, 29 Dec 2021 23:06:29 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 1BTN6TFU090360; Wed, 29 Dec 2021 23:06:29 GMT (envelope-from git) Date: Wed, 29 Dec 2021 23:06:29 GMT Message-Id: <202112292306.1BTN6TFU090360@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: 57e897ec3d49 - stable/13 - Only trigger read-ahead if two adjacent blocks have been requested. List-Id: Commits to the stable branches of the FreeBSD src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-branches List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-branches@freebsd.org X-BeenThere: dev-commits-src-branches@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: 57e897ec3d49664f1d9c0a6545660dda4c1e4fc0 Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1640819191; 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=dEMwPWqbM5fMXVRX6TK1EyG9yiV2m+/BuALVT8Wifcc=; b=aXQa/a2pnTqcgf4gMBA0IetsjS1lGqpZxUPtArTSB8/srXu5PRDn7igsLGHA1Ma8+37ri3 qnqVkx469ImquxO8DeyoLeIhydbyKq7edYgV8FzZ26EEhc43nGWnre+YuPF57SvxU0y8XP oKTQVJpjfJWPORv49+p5q4298dvIAXkHfFAjzY4/gQUyPJyLt4V2lCQILErxzORtt3KiKs 1/q3/2zfoSwmzMAvS+8gdkpp7Y3sQcXT0O335lClQQNkB9GUPUujH5aRo52135TD4eAO6j ZcvpKcpT7ANkyWDFo/1ZoBh+sgdhObp8pJOhyxau8Ezbahj395FPTbM8ycPycQ== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1640819191; a=rsa-sha256; cv=none; b=upLh61dMZnlreW9ks/s+nvktF5hTirWiGS3Z45jdIefJTWOLOGm9AqTwmWw5BHzen7/nsI C5drJJLHlqd6j7GsOsTCVe6pm7Qd9TqOZN4aXG7TWCmqbazfQkYa/Lcg5thU5JkillEzPn X2ipIHQNeNszkBeoqyJZLT8Lc1CeKq5jCIClONXOKcFmV7KjOlvYE4fTwCG2MRvx8FgcrW AQ14Yhn/lfLLRgXsDdKnoThFP3zIt/wLCKeNppI27TarhvnOh/qpGqxwAn+o07rqY02/rY mnLf68sv0g5QpPQMbd5SeZuEA42a8L8c4/axfgMY9Bf/cH+L0iiiypZfsPXwog== 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=57e897ec3d49664f1d9c0a6545660dda4c1e4fc0 commit 57e897ec3d49664f1d9c0a6545660dda4c1e4fc0 Author: Maxim Sobolev AuthorDate: 2021-08-20 19:33:51 +0000 Commit: Colin Percival CommitDate: 2021-12-29 22:53:19 +0000 Only trigger read-ahead if two adjacent blocks have been requested. The change makes block caching algorithm to work better for remote media on low-BW/high-delay links. This cuts boot time over IP KVMs noticeably, since the initialization stage reads bunch of small 4th (and now lua) files that are not in the same cache stripe (usually), thus wasting lot of bandwidth and increasing latency even further. The original regression came in 2017 with revision 87ed2b7f5. We've seen increase of time it takes for the loader to get to the kernel loading from under a minute to 10-15 minutes in many cases. Reviewed by: tsoome MFC after: 1 month Differential Revision: https://reviews.freebsd.org/D31623 (cherry picked from commit 0d13f5343fafbf3067ffc33a507ffca0375c4417) --- stand/common/bcache.c | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/stand/common/bcache.c b/stand/common/bcache.c index a020f3c3c53c..526f9fe3fa5c 100644 --- a/stand/common/bcache.c +++ b/stand/common/bcache.c @@ -66,6 +66,7 @@ struct bcache { caddr_t bcache_data; size_t bcache_nblks; size_t ra; + daddr_t bcache_nextblkno; }; static u_int bcache_total_nblks; /* set by bcache_init */ @@ -163,6 +164,7 @@ bcache_allocate(void) } bcache_units++; bc->ra = BCACHE_READAHEAD; /* optimistic read ahead */ + bc->bcache_nextblkno = -1; return (bc); } @@ -291,6 +293,14 @@ read_strategy(void *devdata, int rw, daddr_t blk, size_t size, else ra = bc->bcache_nblks - BHASH(bc, p_blk + p_size); + /* + * Only trigger read-ahead if we detect two blocks being read + * sequentially. + */ + if ((bc->bcache_nextblkno != blk) && ra != 0) { + ra = 0; + } + 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 */ @@ -342,8 +352,11 @@ read_strategy(void *devdata, int rw, daddr_t blk, size_t size, } done: - if ((result == 0) && (rsize != NULL)) - *rsize = size; + if (result == 0) { + if (rsize != NULL) + *rsize = size; + bc->bcache_nextblkno = blk + (size / DEV_BSIZE); + } return(result); }