Received: by 2002:a05:7412:b995:b0:f9:9502:5bb8 with SMTP id it21csp1247648rdb; Fri, 22 Dec 2023 22:40:00 -0800 (PST) X-Google-Smtp-Source: AGHT+IF5nCVXmqmPFhPNKGAyy2s3DP/Tb2U1GJMUJ3etNCLrR3Dwwq56v7BayaOi/CqAZGGuV1j2 X-Received: by 2002:a05:6871:8210:b0:203:c722:5210 with SMTP id sp16-20020a056871821000b00203c7225210mr3126045oab.74.1703313600396; Fri, 22 Dec 2023 22:40:00 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1703313600; cv=none; d=google.com; s=arc-20160816; b=xEBiMuDUPcyuW2PVjl93iJYEWumKJfsvWKSXyQmUff1jtYaz8BL0QX2mrgrjgjw8kM Tt4SPOEdMW/m+pavvjiEZGAWBTh0c4ZS89QpHRe/WaTDTQIA2AjTsb0Fn17YGFMkiV4s NQrjBKe8brdzGrmiMclu1FZiG5p4SnZ3OBjqe2OtzUL6mhBVhuvDf1jrj+8YLyHTdepd RonebHE/ybuzMzjZmikXoLRpWKIg/zixqEVF8PtFEDK4tR39cu7B4MnlZKi66RHB2gkz NQH3chOPd6Ilfnr4xS/GuXqh9wejRCwfsZr0wzTZHYN3uveHU//5OfEqNR+xQGEYWDap jIJQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from; bh=X21ODALJn/AHCwWyS859xOWXDXQUzgvIfZFQWutgmjk=; fh=zkcIwTk9sJN+dFrByvp4IZwwJkxOuOrldZrviqmXhTE=; b=SGF/QR4Hclyza9NOdgEOSKDtWZ6rEXAt8uJefVPF8TlPuF8FwZwxFs4vjAFXocqSyn yQvNbBD+A369WpyUT0Qkux19VUPuo/X5920Cf7V7okyNQzNHvjiya0UsOenUWy3J5ZPE xBmUdfgCo36xuA8NG4TL8vHN9kPJfyKctTonjNVdJhgoRSevGSsKXs6zAmxhxY/jZDBn 9LNSMiDtxdSkYERSovYBujeIcqopqmGJMTDq2fY4UWf3AXGGqJN5zhn0mNCPFeXMvHUz uMOXT1DtkQE8drSSaV20/qBQuexm05arXrPiM1KkiCEM8WFGHbgLTAUIJ/S8QmQ8Qftf tOFA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel+bounces-10320-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-10320-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id q18-20020a656252000000b005ce0764f139si102129pgv.770.2023.12.22.22.40.00 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Dec 2023 22:40:00 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-10320-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel+bounces-10320-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-10320-linux.lists.archive=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 107FB285838 for ; Sat, 23 Dec 2023 06:40:00 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id A66798C13; Sat, 23 Dec 2023 06:39:40 +0000 (UTC) X-Original-To: linux-kernel@vger.kernel.org Received: from dggsgout12.his.huawei.com (dggsgout12.his.huawei.com [45.249.212.56]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BCBDD15BD; Sat, 23 Dec 2023 06:39:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=huaweicloud.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=huaweicloud.com Received: from mail.maildlp.com (unknown [172.19.163.216]) by dggsgout12.his.huawei.com (SkyGuard) with ESMTP id 4SxvfD0Bzkz4f3kFm; Sat, 23 Dec 2023 14:39:32 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.112]) by mail.maildlp.com (Postfix) with ESMTP id DEC731A0997; Sat, 23 Dec 2023 14:39:34 +0800 (CST) Received: from huaweicloud.com (unknown [10.175.104.67]) by APP1 (Coremail) with SMTP id cCh0CgCXmhCjgIZlBfyaEQ--.4053S6; Sat, 23 Dec 2023 14:39:34 +0800 (CST) From: linan666@huaweicloud.com To: axboe@kernel.dk, geliang.tang@suse.com, xni@redhat.com, colyli@suse.de Cc: ira.weiny@intel.com, linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, linan666@huaweicloud.com, yukuai3@huawei.com, yi.zhang@huawei.com, houtao1@huawei.com, yangerkun@huawei.com Subject: [PATCH 2/4] badblocks: optimize _badblocks_check() Date: Sat, 23 Dec 2023 14:37:26 +0800 Message-Id: <20231223063728.3229446-3-linan666@huaweicloud.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20231223063728.3229446-1-linan666@huaweicloud.com> References: <20231223063728.3229446-1-linan666@huaweicloud.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-CM-TRANSID:cCh0CgCXmhCjgIZlBfyaEQ--.4053S6 X-Coremail-Antispam: 1UD129KBjvJXoWxJrWktw1UtrWDCFy7trWrXwb_y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DU0xZFpf9x0JUvAp5UUUUU= X-CM-SenderInfo: polqt0awwwqx5xdzvxpfor3voofrz/ From: Li Nan Check badblocks_empty earlier, and goto out if check range starts after all badblocks or badblocks is empty since no badblocks intersect with check range. Clean up redundant check '(prev + 1) < bb->count'. If it is true, it will enter the earlier branch. Signed-off-by: Li Nan --- block/badblocks.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/block/badblocks.c b/block/badblocks.c index ebf17a54851a..054d05b93641 100644 --- a/block/badblocks.c +++ b/block/badblocks.c @@ -1296,6 +1296,11 @@ static int _badblocks_check(struct badblocks *bb, sector_t s, int sectors, retry: seq = read_seqbegin(&bb->lock); + if (badblocks_empty(bb)) { + len = sectors; + goto out; + } + p = bb->page; acked_badblocks = 0; @@ -1303,17 +1308,12 @@ static int _badblocks_check(struct badblocks *bb, sector_t s, int sectors, bad.start = s; bad.len = sectors; - if (badblocks_empty(bb)) { - len = sectors; - goto update_sectors; - } - prev = prev_badblocks(bb, &bad, hint); /* start after all badblocks */ if ((prev + 1) >= bb->count && !overlap_front(bb, prev, &bad)) { len = sectors; - goto update_sectors; + goto out; } if (overlap_front(bb, prev, &bad)) { @@ -1339,7 +1339,7 @@ static int _badblocks_check(struct badblocks *bb, sector_t s, int sectors, } /* Not front overlap, but behind overlap */ - if ((prev + 1) < bb->count && overlap_behind(bb, &bad, prev + 1)) { + if (overlap_behind(bb, &bad, prev + 1)) { len = BB_OFFSET(p[prev + 1]) - bad.start; hint = prev + 1; goto update_sectors; -- 2.39.2