From patchwork Wed Feb 25 21:55:59 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alan Cooper X-Patchwork-Id: 5884721 Return-Path: X-Original-To: patchwork-linux-mmc@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 5173ABF440 for ; Wed, 25 Feb 2015 22:01:36 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 8131F20375 for ; Wed, 25 Feb 2015 22:01:34 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 84DC920304 for ; Wed, 25 Feb 2015 22:01:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753354AbbBYWBR (ORCPT ); Wed, 25 Feb 2015 17:01:17 -0500 Received: from mail-gw3-out.broadcom.com ([216.31.210.64]:3629 "EHLO mail-gw3-out.broadcom.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753683AbbBYWBO (ORCPT ); Wed, 25 Feb 2015 17:01:14 -0500 X-IronPort-AV: E=Sophos;i="5.09,647,1418112000"; d="scan'208";a="57887726" Received: from irvexchcas08.broadcom.com (HELO IRVEXCHCAS08.corp.ad.broadcom.com) ([10.9.208.57]) by mail-gw3-out.broadcom.com with ESMTP; 25 Feb 2015 14:23:04 -0800 Received: from IRVEXCHSMTP2.corp.ad.broadcom.com (10.9.207.52) by IRVEXCHCAS08.corp.ad.broadcom.com (10.9.208.57) with Microsoft SMTP Server (TLS) id 14.3.174.1; Wed, 25 Feb 2015 14:01:12 -0800 Received: from mail-irva-13.broadcom.com (10.10.10.20) by IRVEXCHSMTP2.corp.ad.broadcom.com (10.9.207.52) with Microsoft SMTP Server id 14.3.174.1; Wed, 25 Feb 2015 14:01:12 -0800 Received: from stbsrv-and-3.and.broadcom.com (stbsrv-and-3.and.broadcom.com [10.28.16.21]) by mail-irva-13.broadcom.com (Postfix) with ESMTP id 7BAB941054; Wed, 25 Feb 2015 13:59:19 -0800 (PST) From: Al Cooper To: , , CC: Al Cooper Subject: [PATCH] mmc: mkfs takes hours on some combinations of eMMC device and host controller Date: Wed, 25 Feb 2015 16:55:59 -0500 Message-ID: <1424901359-6309-1-git-send-email-alcooperx@gmail.com> X-Mailer: git-send-email 1.9.0.138.g2de3478 MIME-Version: 1.0 Sender: linux-mmc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-mmc@vger.kernel.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, FREEMAIL_FROM,RCVD_IN_DNSWL_HI,T_RP_MATCHES_RCVD,UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP mkfs.ext4 will erase the entire partition on the eMMC device before writing the actual filesystem. The number of blocks erased on each erase eMMC command is determined at run time based on the max erase or trim time specified by the EXT_CSD in the eMMC device and the max eMMC command timeout supported by the host controller. The routine in the kernel that calculates the max number of blocks specified per command returns 1 with some combinations of host controllers with a short max command timeout and eMMC devices with long max erase or trim time. This will end up requiring over 8 million erase sequences on a 4GB eMMC partition and will take many hours. For example, on a host controller with a 50MHz timeout clock specified in the Host CAPS register and an eMMC device with a TRIM Multiplier of 6 specified in the EXT_CSD we get 2^27/50000000=2.68 secs for a max command timeout and 6*.300=1.8 secs for a trim operation which only allows 1 per trim command. The problem seems to be in mmc_do_calc_max_discard() which does it's calculations based on erase blocks but converts to and returns write blocks (2MB blocks to 512 bytes blocks for a typical eMMC device) unless the value is 1 in which case it just returns the 1. The routine also subtracts 1 from the max calculation before converting from erase to write blocks which should not be needed. This change will convert all non-zero max calculations from erase to write blocks and will no longer subtract 1 from the erase block max before converting to write blocks. This allow mkfs.ext4 to run in 30 secs instead of >10 hours. Signed-off-by: Al Cooper --- drivers/mmc/core/core.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/drivers/mmc/core/core.c b/drivers/mmc/core/core.c index 23f10f7..1b61ac0 100644 --- a/drivers/mmc/core/core.c +++ b/drivers/mmc/core/core.c @@ -2231,16 +2231,13 @@ static unsigned int mmc_do_calc_max_discard(struct mmc_card *card, if (!qty) return 0; - if (qty == 1) - return 1; - /* Convert qty to sectors */ if (card->erase_shift) - max_discard = --qty << card->erase_shift; + max_discard = qty << card->erase_shift; else if (mmc_card_sd(card)) max_discard = qty; else - max_discard = --qty * card->erase_size; + max_discard = qty * card->erase_size; return max_discard; }