From patchwork Thu May 4 12:48:28 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Li Nan X-Patchwork-Id: 90079 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp302806vqo; Thu, 4 May 2023 06:09:13 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7sGRV7qfvaoLaotWfISTnYncp3+dZPhhG221SwtvlhkQhjP1ppbrAxDg2UBZOYsABxU95d X-Received: by 2002:a17:90b:3101:b0:23f:962e:825d with SMTP id gc1-20020a17090b310100b0023f962e825dmr2290808pjb.1.1683205753375; Thu, 04 May 2023 06:09:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1683205753; cv=none; d=google.com; s=arc-20160816; b=YOo/nHfLGG5FOppd72vJ2a+D2zPnSdhnzKKyXIzDFKGaK63Ucjfal0X2OogXCidYc9 ZSu9iMbTCoum0MYvxnjQKiHwAoS3Y6mYPgMPrFUc0ed6ZWmoKICqifrWLu8PeXT6M3PZ sHl0yK+H03LB7mnRht7EbXFMjG3V7w1DE0HNZXjipwhd6yNRCaRsLKutWuJYhA+cvlnG hgwnqJ4fesU1XQN94LiTqY81S2h9p1qKkM46oW9Fxls4psLIsju7lR3ANmvXXooPk1IV mR+NWEMooFwcS3gZXYoX7qV+JNDQ4UtZJItWthX+l1JVb5R0WiABv6IJyekk6GW2SQ0e CjNA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=9zvkkRlRCEPBWFsuvLW86XuxHZkHvw0XJ2i8FZZOiM4=; b=XDIAGS+eNIjZ88+sU9EEazRc9ZVdj/BlmyqDzApE2PCgPimeN/qqbiPYNq5KAfnXLz 70DiLFDWsCHZvjMLh1XNUqo6Ci6T2RP9LwokDMumcaYsLPoFmHn7pVRuPauYC3oZnvS0 sfQqb7vgOSx/IHqKE/+ftDovvxdSD1vFZC7Jsves7UoWPl+Zo5oxWrxyJC1FOmIdKQ6j mn4kmqC+DaCciTOEQwGpvzdDgbCYxqex2MjvvX6VrMNHIHWXvXqBFi1+6bRhZYb3edtK IH/u9tJLFjF6S1O5g7YeoGP+H6rAzbFhqERhMstS3Mp/9xEnqawx69r8vGeUnpjwzkxQ RYpQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id a13-20020a17090a740d00b0024dec84c2fcsi3882768pjg.122.2023.05.04.06.08.59; Thu, 04 May 2023 06:09:13 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231139AbjEDMua (ORCPT + 99 others); Thu, 4 May 2023 08:50:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36478 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230329AbjEDMtv (ORCPT ); Thu, 4 May 2023 08:49:51 -0400 Received: from dggsgout11.his.huawei.com (dggsgout11.his.huawei.com [45.249.212.51]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 23D116A7D; Thu, 4 May 2023 05:49:43 -0700 (PDT) Received: from mail02.huawei.com (unknown [172.30.67.143]) by dggsgout11.his.huawei.com (SkyGuard) with ESMTP id 4QBttq1GYTz4f3kkN; Thu, 4 May 2023 20:49:39 +0800 (CST) Received: from huaweicloud.com (unknown [10.175.127.227]) by APP4 (Coremail) with SMTP id gCh0CgBnHbHdqVNkzuf5Ig--.27873S15; Thu, 04 May 2023 20:49:40 +0800 (CST) From: linan666@huaweicloud.com To: axboe@kernel.dk, linan122@huawei.com, vishal.l.verma@intel.com, dan.j.williams@intel.com Cc: linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, yukuai3@huawei.com, yi.zhang@huawei.com, houtao1@huawei.com, yangerkun@huawei.com Subject: [PATCH v2 11/11] block/badblocks: try to merge badblocks as much as possible Date: Thu, 4 May 2023 20:48:28 +0800 Message-Id: <20230504124828.679770-12-linan666@huaweicloud.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20230504124828.679770-1-linan666@huaweicloud.com> References: <20230504124828.679770-1-linan666@huaweicloud.com> MIME-Version: 1.0 X-CM-TRANSID: gCh0CgBnHbHdqVNkzuf5Ig--.27873S15 X-Coremail-Antispam: 1UD129KBjvJXoW7Ww48tFW5WF4UKF43Cr1xZrb_yoW8Cry7pF n0y3WfKry2gr17W3W5X3W8Kr10g34fJF4UCF43Xw1jkFyxGwn3tF1kZw4FqFyjgF43Wrs0 v3Wruryjva4kCa7anT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUmab4IE77IF4wAFF20E14v26rWj6s0DM7CY07I20VC2zVCF04k2 6cxKx2IYs7xG6rWj6s0DM7CIcVAFz4kK6r1j6r18M28IrcIa0xkI8VA2jI8067AKxVWUAV Cq3wA2048vs2IY020Ec7CjxVAFwI0_Xr0E3s1l8cAvFVAK0II2c7xJM28CjxkF64kEwVA0 rcxSw2x7M28EF7xvwVC0I7IYx2IY67AKxVWDJVCq3wA2z4x0Y4vE2Ix0cI8IcVCY1x0267 AKxVW8Jr0_Cr1UM28EF7xvwVC2z280aVAFwI0_GcCE3s1l84ACjcxK6I8E87Iv6xkF7I0E 14v26rxl6s0DM2vYz4IE04k24VAvwVAKI4IrM2AIxVAIcxkEcVAq07x20xvEncxIr21l5I 8CrVACY4xI64kE6c02F40Ex7xfMcIj6xIIjxv20xvE14v26r1j6r18McIj6I8E87Iv67AK xVWUJVW8JwAm72CE4IkC6x0Yz7v_Jr0_Gr1lF7xvr2IYc2Ij64vIr41lFIxGxcIEc7CjxV A2Y2ka0xkIwI1lw4CEc2x0rVAKj4xxMxAIw28IcxkI7VAKI48JMxC20s026xCaFVCjc4AY 6r1j6r4UMI8I3I0E5I8CrVAFwI0_Jr0_Jr4lx2IqxVCjr7xvwVAFwI0_JrI_JrWlx4CE17 CEb7AF67AKxVWUtVW8ZwCIc40Y0x0EwIxGrwCI42IY6xIIjxv20xvE14v26r4j6ryUMIIF 0xvE2Ix0cI8IcVCY1x0267AKxVW8Jr0_Cr1UMIIF0xvE42xK8VAvwI8IcIk0rVWUJVWUCw CI42IY6I8E87Iv67AKxVW8JVWxJwCI42IY6I8E87Iv6xkF7I0E14v26r4UJVWxJrUvcSsG vfC2KfnxnUUI43ZEXa7IU1lksDUUUUU== X-CM-SenderInfo: polqt0awwwqx5xdzvxpfor3voofrz/ X-CFilter-Loop: Reflected X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,SPF_HELO_NONE, SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1764969156517483850?= X-GMAIL-MSGID: =?utf-8?q?1764969156517483850?= From: Li Nan If we set a new badblocks, we first merge it with existing region, then try to combine lo and hi. If there are still badblocks need to be set, create it. It is a bad way when setting a laget number of badblocks. for example, it will become chaotic if we set as below: # echo 1 1 > bad_blocks # echo 512 1 > bad_blocks # echo 0 513 > bad_blocks # cat bad_blocks 0 512 512 1 512 1 Fix it by trying to merge as much as possible. If we have merged any badblocks, retry to merge next sectors. Do not check sectors while combining, we should combine lo and hi each sycle. Fixes: 9e0e252a048b ("badblocks: Add core badblock management code") Signed-off-by: Li Nan --- block/badblocks.c | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/block/badblocks.c b/block/badblocks.c index bb0324b66f57..7e6fce10c82d 100644 --- a/block/badblocks.c +++ b/block/badblocks.c @@ -347,8 +347,6 @@ int badblocks_set(struct badblocks *bb, sector_t s, int sectors, lo = 0; hi = bb->count; if (bb->count) { - int merged_sectors; - /* Find the last range that starts at-or-before 's' */ while (hi - lo > 1) { int mid = (lo + hi) / 2; @@ -360,12 +358,19 @@ int badblocks_set(struct badblocks *bb, sector_t s, int sectors, hi = mid; } - merged_sectors = badblocks_merge(bb, s, sectors, acknowledged, - &lo, &hi, &changed); - s += merged_sectors; - sectors -= merged_sectors; - if (sectors == 0) + while (sectors) { + int merged_sectors; + + merged_sectors = badblocks_merge(bb, s, sectors, acknowledged, + &lo, &hi, &changed); + /* can't merge, break to create */ + if (!merged_sectors) + break; + + s += merged_sectors; + sectors -= merged_sectors; badblocks_combine(bb, lo); + } } rv = badblocks_create(bb, s, sectors, hi, acknowledged, &changed);