From patchwork Sat Feb 12 06:22:14 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Chuanxiao.Dong" X-Patchwork-Id: 551521 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter1.kernel.org (8.14.4/8.14.3) with ESMTP id p1C6TcNv011873 for ; Sat, 12 Feb 2011 06:29:38 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1758520Ab1BLG2u (ORCPT ); Sat, 12 Feb 2011 01:28:50 -0500 Received: from mga09.intel.com ([134.134.136.24]:38613 "EHLO mga09.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1758199Ab1BLG2r (ORCPT ); Sat, 12 Feb 2011 01:28:47 -0500 Received: from orsmga002.jf.intel.com ([10.7.209.21]) by orsmga102.jf.intel.com with ESMTP; 11 Feb 2011 22:28:46 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="4.60,460,1291622400"; d="scan'208";a="601972110" Received: from cdong3-fc.bj.intel.com (HELO intel.com) ([172.16.120.198]) by orsmga002.jf.intel.com with ESMTP; 11 Feb 2011 22:28:45 -0800 Date: Sat, 12 Feb 2011 14:22:14 +0800 From: Chuanxiao Dong To: linux-mmc@vger.kernel.org, cjb@laptop.org Cc: linux-kernel@vger.kernel.org, akpm@linux-foundation.org, adrian.hunter@nokia.com Subject: [PATCH v4 1/3]mmc: set max_discard_sectors value for mmc queue Message-ID: <20110212062214.GB25519@intel.com> Reply-To: Chuanxiao Dong MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.19 (2009-01-05) Sender: linux-mmc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-mmc@vger.kernel.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.6 (demeter1.kernel.org [140.211.167.41]); Sat, 12 Feb 2011 06:29:38 +0000 (UTC) diff --git a/drivers/mmc/card/queue.c b/drivers/mmc/card/queue.c index 4e42d03..6c13859 100644 --- a/drivers/mmc/card/queue.c +++ b/drivers/mmc/card/queue.c @@ -131,7 +131,8 @@ int mmc_init_queue(struct mmc_queue *mq, struct mmc_card *card, spinlock_t *lock queue_flag_set_unlocked(QUEUE_FLAG_NONROT, mq->queue); if (mmc_can_erase(card)) { queue_flag_set_unlocked(QUEUE_FLAG_DISCARD, mq->queue); - mq->queue->limits.max_discard_sectors = UINT_MAX; + mq->queue->limits.max_discard_sectors = + mmc_set_max_discard_sectors(card); if (card->erased_byte == 0) mq->queue->limits.discard_zeroes_data = 1; if (!mmc_can_trim(card) && is_power_of_2(card->erase_size)) { diff --git a/drivers/mmc/core/core.c b/drivers/mmc/core/core.c index 34a7e8c..0eb27aa 100644 --- a/drivers/mmc/core/core.c +++ b/drivers/mmc/core/core.c @@ -1470,6 +1470,26 @@ int mmc_erase_group_aligned(struct mmc_card *card, unsigned int from, } EXPORT_SYMBOL(mmc_erase_group_aligned); +/* + * Set max_discard_sectors for mmc queue. + * max_discard_sectors will determine how many sectors can be erased at one + * time. Sometimes user may want to erase a large area of SD or MMC card, it may + * take long time which delay some other important I/O requests. So we would + * better set some values for max_discard_sectors which can forbid block layer + * pass too many sectors at one time. + * + * 'pref_erase' is initialized for this purpose. We can use it to set a preferred + * value for it. + */ +int mmc_set_max_discard_sectors(struct mmc_card *card) +{ + if (card->pref_erase) + return card->pref_erase; + else + return UINT_MAX; +} +EXPORT_SYMBOL(mmc_set_max_discard_sectors); + int mmc_set_blocklen(struct mmc_card *card, unsigned int blocklen) { struct mmc_command cmd; diff --git a/include/linux/mmc/core.h b/include/linux/mmc/core.h index 64e013f..a218d57 100644 --- a/include/linux/mmc/core.h +++ b/include/linux/mmc/core.h @@ -152,6 +152,7 @@ extern int mmc_can_trim(struct mmc_card *card); extern int mmc_can_secure_erase_trim(struct mmc_card *card); extern int mmc_erase_group_aligned(struct mmc_card *card, unsigned int from, unsigned int nr); +extern int mmc_set_max_discard_sectors(struct mmc_card *card); extern int mmc_set_blocklen(struct mmc_card *card, unsigned int blocklen);