From nobody Sun Dec 11 00:38:13 2022 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 4NV5TL1lcDz4jgfW; Sun, 11 Dec 2022 00:38:14 +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 4NV5TL0lBrz4H6M; Sun, 11 Dec 2022 00:38:14 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1670719094; 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=YbjyCMSBtkZ8ITFsmb+jmpY184hU+YcPiFyXHesqfVI=; b=u5xve0bxtbCvykkpqIp7xiJGrPW7a9wd3UoZ+8X6IKYQJcH2pGORfb9I+X1sF1iPdXnzMx 3jsLq3Qyc4JimqEqx2zr1EFcI4hpPRIrmm5BzU2d/z1Pbn0yJYAeB1dYQr54If6nZkV9IR 1ukB8jKYIrfGuz0UPAhP44I84YqA7o/W9O1JhVJec0F6MF4X3eaELYeDV9R3H2cCddwfQr 2mF+BPpfzqH98U2x2Ab08VA5lpfUgruIROjmgXT45Gr1mGrCGhp/h+sTmPTDQwsDdn6u3D 7jXqQcM2xUjd3wrKg8//242+N2DudiiODRpNWno0fPJKD3zseGaG4aZbgn3P/Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1670719094; 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=YbjyCMSBtkZ8ITFsmb+jmpY184hU+YcPiFyXHesqfVI=; b=QgFz+KsF2eBoWTswDZkUV1FU9wdVAfbcuVFrEM2LQo8duBUfI+C/XkFuK5+z+NVxKYDjXR KdMohw00PP1+xqh6AfzESqw+rP22DLFh1pEFpPUPi9sLTf2eco+d7bZMATpspj2XtSBPkB CUUBMY0S6dkAo6u7GxmKrCdGk9AE89khLQgy/YvJrrN2gs+TzXXcA1rMWWeCKcjb+9ezF+ Cka+aA2rScVIFtgLA3dYM8u0b1FjOkkOnQuzyhmClsloy4t0UaFfCTK5M98luVEasj1Lo/ 9l3BruJYXk8GfZsbk2urZ5Vts4w0IgpC9NGEqsmRuDpOrQlwBvLUadx5OHpp0A== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1670719094; a=rsa-sha256; cv=none; b=O8k4J6qHH8ojTwV33hA9NC5KTc9o3K7vFCBVPTI+JWfsyfxP+vqruHTweNjkEuSvDjhQI4 tJOBNVOTiPO6/OYT6ttnWprUt16Go+0RvTuv6qJm4mZBn+hV/Bx32lGvrpLpuYeF5afglj go/clS3d85JQ/UHKBVWGVSC8TzXy8JILxoOFAgZGKGyfEGstGxnAq7Lx45KlGgDnfoVzau 1r0euh+eGyR03tNHB2di+0e0/s2DDJeOpPbIWDGtlNPFWxoPte0KQ8Ma2mzm8+L7m3HI8b VHswbA+mI4n21iBXq6NUH0IS0Ce2NPc+njEgusjIvTCJEyP1HprqA9tA318Dqw== 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 4NV5TK6tqnzbmh; Sun, 11 Dec 2022 00:38:13 +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 2BB0cDok003816; Sun, 11 Dec 2022 00:38:13 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 2BB0cD5Z003815; Sun, 11 Dec 2022 00:38:13 GMT (envelope-from git) Date: Sun, 11 Dec 2022 00:38:13 GMT Message-Id: <202212110038.2BB0cD5Z003815@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Kirk McKusick Subject: git: f4d2a3098c91 - stable/13 - Provide cache coherency between getnextinode() and ginode() 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: mckusick X-Git-Repository: src X-Git-Refname: refs/heads/stable/13 X-Git-Reftype: branch X-Git-Commit: f4d2a3098c91434d51d0257b183c834347f01d94 Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch stable/13 has been updated by mckusick: URL: https://cgit.FreeBSD.org/src/commit/?id=f4d2a3098c91434d51d0257b183c834347f01d94 commit f4d2a3098c91434d51d0257b183c834347f01d94 Author: Kirk McKusick AuthorDate: 2022-08-24 06:48:40 +0000 Commit: Kirk McKusick CommitDate: 2022-12-11 00:37:17 +0000 Provide cache coherency between getnextinode() and ginode() (cherry picked from commit 345bfec1090571ea219263c99eed29de27e143c8) Sponsored by: The FreeBSD Foundation --- sbin/fsck_ffs/inode.c | 35 +++++++++++++++++++++++++++-------- 1 file changed, 27 insertions(+), 8 deletions(-) diff --git a/sbin/fsck_ffs/inode.c b/sbin/fsck_ffs/inode.c index 8a93ad092a4a..ae7124784415 100644 --- a/sbin/fsck_ffs/inode.c +++ b/sbin/fsck_ffs/inode.c @@ -415,21 +415,35 @@ chkrange(ufs2_daddr_t blk, int cnt) /* * General purpose interface for reading inodes. + * + * firstinum and lastinum track contents of getnextino() cache (below). */ +static ino_t firstinum, lastinum; +static struct bufarea inobuf; + void ginode(ino_t inumber, struct inode *ip) { ufs2_daddr_t iblk; + ino_t numinodes; if (inumber < UFS_ROOTINO || inumber > maxino) errx(EEXIT, "bad inode number %ju to ginode", (uintmax_t)inumber); ip->i_number = inumber; - if (icachebp != NULL && + if (inumber >= firstinum && inumber < lastinum) { + /* contents in getnextino() cache */ + ip->i_bp = &inobuf; + inobuf.b_refcnt++; + inobuf.b_index = firstinum; + numinodes = lastinum - firstinum; + } else if (icachebp != NULL && inumber >= icachebp->b_index && inumber < icachebp->b_index + INOPB(&sblock)) { /* take an additional reference for the returned inode */ icachebp->b_refcnt++; + ip->i_bp = icachebp; + numinodes = INOPB(&sblock); } else { iblk = ino_to_fsba(&sblock, inumber); /* release our cache-hold reference on old icachebp */ @@ -445,15 +459,16 @@ ginode(ino_t inumber, struct inode *ip) /* take a cache-hold reference on new icachebp */ icachebp->b_refcnt++; icachebp->b_index = rounddown(inumber, INOPB(&sblock)); + ip->i_bp = icachebp; + numinodes = INOPB(&sblock); } - ip->i_bp = icachebp; if (sblock.fs_magic == FS_UFS1_MAGIC) { ip->i_dp = (union dinode *) - &icachebp->b_un.b_dinode1[inumber % INOPB(&sblock)]; + &ip->i_bp->b_un.b_dinode1[inumber % numinodes]; return; } ip->i_dp = (union dinode *) - &icachebp->b_un.b_dinode2[inumber % INOPB(&sblock)]; + &ip->i_bp->b_un.b_dinode2[inumber % numinodes]; if (ffs_verify_dinode_ckhash(&sblock, (struct ufs2_dinode *)ip->i_dp)) { pwarn("INODE CHECK-HASH FAILED"); prtinode(ip); @@ -487,9 +502,8 @@ irelse(struct inode *ip) * Special purpose version of ginode used to optimize first pass * over all the inodes in numerical order. */ -static ino_t nextino, lastinum, lastvalidinum; +static ino_t nextinum, lastvalidinum; static long readcount, readpercg, fullcnt, inobufsize, partialcnt, partialsize; -static struct bufarea inobuf; union dinode * getnextinode(ino_t inumber, int rebuildcg) @@ -502,11 +516,12 @@ getnextinode(ino_t inumber, int rebuildcg) struct inode ip; static caddr_t nextinop; - if (inumber != nextino++ || inumber > lastvalidinum) + if (inumber != nextinum++ || inumber > lastvalidinum) errx(EEXIT, "bad inode number %ju to nextinode", (uintmax_t)inumber); if (inumber >= lastinum) { readcount++; + firstinum = lastinum; blk = ino_to_fsba(&sblock, lastinum); if (readcount % readpercg == 0) { size = partialsize; @@ -520,6 +535,9 @@ getnextinode(ino_t inumber, int rebuildcg) * If getblk encounters an error, it will already have zeroed * out the buffer, so we do not need to do so here. */ + if (inobuf.b_refcnt != 0) + pfatal("Non-zero getnextinode() ref count %d\n", + inobuf.b_refcnt); flush(fswritefd, &inobuf); getblk(&inobuf, blk, size); nextinop = inobuf.b_un.b_buf; @@ -604,7 +622,7 @@ setinodebuf(int cg, ino_t inosused) inum = cg * sblock.fs_ipg; lastvalidinum = inum + inosused - 1; - nextino = inum; + nextinum = inum; lastinum = inum; readcount = 0; /* Flush old contents in case they have been updated */ @@ -674,6 +692,7 @@ freeinodebuf(void) if (inobuf.b_un.b_buf != NULL) free((char *)inobuf.b_un.b_buf); inobuf.b_un.b_buf = NULL; + firstinum = lastinum = 0; } /*