From patchwork Mon Jun 25 15:08:38 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Genoud X-Patchwork-Id: 167136 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from merlin.infradead.org (unknown [IPv6:2001:4978:20e::2]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 3C8A6B6FA1 for ; Tue, 26 Jun 2012 01:11:00 +1000 (EST) Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.76 #1 (Red Hat Linux)) id 1SjAuY-00067w-J2; Mon, 25 Jun 2012 15:09:06 +0000 Received: from mail-wi0-f177.google.com ([209.85.212.177]) by merlin.infradead.org with esmtps (Exim 4.76 #1 (Red Hat Linux)) id 1SjAuV-00067j-8s for linux-mtd@lists.infradead.org; Mon, 25 Jun 2012 15:09:04 +0000 Received: by wibhm11 with SMTP id hm11so2399237wib.0 for ; Mon, 25 Jun 2012 08:09:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:x-mailer; bh=IijQsR05hYxIF/cCiLNWTHsUzPKyXPeyV+mqH3pH5EY=; b=V3CNeAlkqu0a1fFO4GGTcAPO+cL9Wahg/Blg3Sfhv99UNmdPyeJgYRS4DuHPhOOn8Y C4+0ytUpsFl7pj1glFgH9hpf3SnUMz4HJonhkCR3J34zUHocXWUoXTG6ueBdZE6Ce/m6 RuE3SZFuh4seWrefeT5WaOj/ptkfN7mAF0j65CQ1yaSm3/EQ1THb+NSycza+VA0oBiQI 0FSUbfT091nbyGgrS47e24pirkpuwuQOiyOYlC0ymTryoV0gP375gLYNqkFj1z2euFir RIxDTyoC02heOy4xyiQvbSH1n1XRfRQgi1f6SlxhCQP+uUJRdNi3qw1gO4sA+dP1shX/ qj/w== Received: by 10.216.134.145 with SMTP id s17mr6277700wei.22.1340636941146; Mon, 25 Jun 2012 08:09:01 -0700 (PDT) Received: from localhost.localdomain (lyon.paratronic.fr. [213.41.177.106]) by mx.google.com with ESMTPS id gv7sm17248069wib.4.2012.06.25.08.09.00 (version=TLSv1/SSLv3 cipher=OTHER); Mon, 25 Jun 2012 08:09:00 -0700 (PDT) From: Richard Genoud To: Artem Bityutskiy Subject: [PATCH] UBI: add minimal amount of reserved erase blocks in Kconfig Date: Mon, 25 Jun 2012 17:08:38 +0200 Message-Id: <1340636918-7505-1-git-send-email-richard.genoud@gmail.com> X-Mailer: git-send-email 1.7.2.5 X-Spam-Note: CRM114 invocation failed X-Spam-Score: -2.7 (--) X-Spam-Report: SpamAssassin version 3.3.2 on merlin.infradead.org summary: Content analysis details: (-2.7 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.7 RCVD_IN_DNSWL_LOW RBL: Sender listed at http://www.dnswl.org/, low trust [209.85.212.177 listed in list.dnswl.org] 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider (richard.genoud[at]gmail.com) -0.0 SPF_PASS SPF: sender matches SPF record -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature Cc: Richard Genoud , linux-mtd@lists.infradead.org, David Woodhouse , linux-kernel@vger.kernel.org X-BeenThere: linux-mtd@lists.infradead.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: Linux MTD discussion mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: linux-mtd-bounces@lists.infradead.org Errors-To: linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org On NAND flash devices, UBI reserves some physical erase blocks (PEB) for bad block handling. Today, the number of reserved PEB can only be set as a percentage of the total number of PEB in each UBI volume. For example, for a NAND flash with 128KiB PEB, 2 MTD partition of 20MiB (mtd0) and 100MiB (mtd1) and 2% reserved PEB: - the UBI volume on mtd0 will have 2 PEB reserved - the UBI volume on mtd1 will have 16 PEB reserved The problem with this behaviour is that NAND flash manufacturers give a minimum number of valid block (NVB) during the endurance life of the device. E.G.: Parameter Symbol Min Max Unit Notes -------------------------------------------------------------- Valid block number NVB 1004 1024 Blocks 1 Note: 1. Invalid blocks are block that contain one or more bad bits beyond ECC. The device may contain bad blocks upon shipment. Additional bad blocks may develop over time; however, the total number of available blocks will not drop below NVB during the endurance life of the device. From this number we can deduce the maximum number of bad PEB that a device will contain during its endurance life : A 128MiB NAND flash (1024 PEB) will not have less than 20 bad blocks during the flash endurance life. BUT, the manufacturer doesn't tell where those bad block will appear. He doesn't say either if they will be equally disposed on the whole device (and I'm pretty sure they won't). So, according to the datasheets, we should reserve the maximum number of bad PEB for each UBI volume. (Worst case scenario: 20 bad blocks appears on the smallest UBI volume.) => The actual parameter MTD_UBI_BEB_RESERVE is not enough to cover this scenario. We need to set a minimal number of reserved PEB for a UBI volume. That's what this patch introduce. Signed-off-by: Richard Genoud --- drivers/mtd/ubi/Kconfig | 18 ++++++++++++++++++ drivers/mtd/ubi/misc.c | 5 +++-- drivers/mtd/ubi/ubi.h | 3 --- 3 files changed, 21 insertions(+), 5 deletions(-) diff --git a/drivers/mtd/ubi/Kconfig b/drivers/mtd/ubi/Kconfig index 738ee8d..6770b96 100644 --- a/drivers/mtd/ubi/Kconfig +++ b/drivers/mtd/ubi/Kconfig @@ -27,6 +27,24 @@ config MTD_UBI_WL_THRESHOLD life-cycle less than 10000, the threshold should be lessened (e.g., to 128 or 256, although it does not have to be power of 2). +config MTD_UBI_BEB_MIN_RESERVE + int "Minimal number of reserved eraseblocks for bad eraseblocks handling" + default 2 + range 0 2147483647 + depends on MTD_UBI + help + If the MTD device admits of bad eraseblocks (e.g. NAND flash), UBI + reserves some amount of physical eraseblocks to handle new bad + eraseblocks. For example, if a flash physical eraseblock becomes bad, + UBI uses these reserved physical eraseblocks to relocate the bad one. + This option specifies the minimal amount of eraseblocks that will be + reserved for bad eraseblock handling. + If the device has less or as many eraseblocks as this value, the + percentage value (MTD_UBI_BEB_RESERVE) is used. + If the underlying flash does not admit of bad eraseblocks (e.g. NOR + flash), this value is ignored and nothing is reserved. + Leave the default value if unsure. + config MTD_UBI_BEB_RESERVE int "Percentage of reserved eraseblocks for bad eraseblocks handling" default 1 diff --git a/drivers/mtd/ubi/misc.c b/drivers/mtd/ubi/misc.c index f6a7d7a..c2c6db0 100644 --- a/drivers/mtd/ubi/misc.c +++ b/drivers/mtd/ubi/misc.c @@ -100,8 +100,9 @@ void ubi_calculate_reserved(struct ubi_device *ubi) { ubi->beb_rsvd_level = ubi->good_peb_count/100; ubi->beb_rsvd_level *= CONFIG_MTD_UBI_BEB_RESERVE; - if (ubi->beb_rsvd_level < MIN_RESEVED_PEBS) - ubi->beb_rsvd_level = MIN_RESEVED_PEBS; + if ((ubi->beb_rsvd_level < CONFIG_MTD_UBI_BEB_MIN_RESERVE) && + (ubi->good_peb_count > CONFIG_MTD_UBI_BEB_MIN_RESERVE)) + ubi->beb_rsvd_level = CONFIG_MTD_UBI_BEB_MIN_RESERVE; } /** diff --git a/drivers/mtd/ubi/ubi.h b/drivers/mtd/ubi/ubi.h index a1a81c9..d321c74 100644 --- a/drivers/mtd/ubi/ubi.h +++ b/drivers/mtd/ubi/ubi.h @@ -59,9 +59,6 @@ #define ubi_err(fmt, ...) printk(KERN_ERR "UBI error: %s: " fmt "\n", \ __func__, ##__VA_ARGS__) -/* Lowest number PEBs reserved for bad PEB handling */ -#define MIN_RESEVED_PEBS 2 - /* Background thread name pattern */ #define UBI_BGT_NAME_PATTERN "ubi_bgt%dd"