Skip to contentSkip to conversation

maximum discard size

PATCH In review Adrian Hunter 2 participants 5 messages Jun 28, 2011 – Jul 15, 2011

Subsystems (2)
lore
Share & tools
lore

Adrian Hunter

author maintainer
#0 lore raw

cover maximum discard size

Hi

Here is a patch that sets a maximum discard size for host controllers that cannot manage large timeouts. And another patch putting it into use for shdci.

Adrian Hunter (2):
mmc: queue: let host controllers specify maximum discard timeout
mmc: sdhci: specify maximum discard timeout

 drivers/mmc/card/queue.c |   33 ++++++++++++++------
 drivers/mmc/core/core.c  |   76 ++++++++++++++++++++++++++++++++++++++++++++++
 drivers/mmc/host/sdhci.c |    5 +++
 include/linux/mmc/core.h |    1 +
 include/linux/mmc/host.h |    1 +
 5 files changed, 106 insertions(+), 10 deletions(-)

Regards
Adrian Hunter

author maintainer
#1 lore raw

PATCH 1/2 mmc: queue: let host controllers specify maximum discard timeout

Some host controllers will not operate without a hardware timeout that is limited in value. However large discards require large timeouts, so there needs to be a way to specify the maximum discard size.

A host controller driver may now specify the maximum discard timeout possible so that max_discard_sectors can be calculated.

However, for eMMC when the High Capacity Erase Group Size is not in use, the timeout calculation depends on clock rate which may change. For that case Preferred Erase Size is used instead.

---
 drivers/mmc/card/queue.c |   33 ++++++++++++++------
 drivers/mmc/core/core.c  |   76 ++++++++++++++++++++++++++++++++++++++++++++++
 include/linux/mmc/core.h |    1 +
 include/linux/mmc/host.h |    1 +
 4 files changed, 101 insertions(+), 10 deletions(-)
drivers/mmc/card/queue.c +23 -10
index 6413afa..defc11b 100644
@@ -101,6 +101,27 @@ static void mmc_request(struct request_queue *q)
 		wake_up_process(mq->thread);
 }
 
+static void mmc_queue_setup_discard(struct request_queue *q,
+				    struct mmc_card *card)
+{
+	unsigned max_discard;
+
+	max_discard = mmc_calc_max_discard(card);
+	if (!max_discard)
+		return;
+
+	queue_flag_set_unlocked(QUEUE_FLAG_DISCARD, q);
+	q->limits.max_discard_sectors = max_discard;
+	if (card->erased_byte == 0)
+		q->limits.discard_zeroes_data = 1;
+	q->limits.discard_granularity = card->pref_erase << 9;
+	/* granularity must not be greater than max. discard */
+	if (card->pref_erase > max_discard)
+		q->limits.discard_granularity = 0;
+	if (mmc_can_secure_erase_trim(card))
+		queue_flag_set_unlocked(QUEUE_FLAG_SECDISCARD, q);
+}
+
 /**
  * mmc_init_queue - initialise a queue structure.
  * @mq: mmc queue
@@ -130,16 +151,8 @@ int mmc_init_queue(struct mmc_queue *mq, struct mmc_card *card,
 
 	blk_queue_prep_rq(mq->queue, mmc_prep_request);
 	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;
-		if (card->erased_byte == 0)
-			mq->queue->limits.discard_zeroes_data = 1;
-		mq->queue->limits.discard_granularity = card->pref_erase << 9;
-		if (mmc_can_secure_erase_trim(card))
-			queue_flag_set_unlocked(QUEUE_FLAG_SECDISCARD,
-						mq->queue);
-	}
+	if (mmc_can_erase(card))
+		mmc_queue_setup_discard(mq->queue, card);
 
 #ifdef CONFIG_MMC_BLOCK_BOUNCE
 	if (host->max_segs == 1) {
drivers/mmc/core/core.c +76 -0

82 lines not on this page · raw message

include/linux/mmc/core.h +1 -0
index 791f060..86d81cf 100644
@@ -155,6 +155,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 unsigned int mmc_calc_max_discard(struct mmc_card *card);
 
 extern int mmc_set_blocklen(struct mmc_card *card, unsigned int blocklen);
 
include/linux/mmc/host.h +1 -0
index ac3fbac..0adecb1 100644
@@ -230,6 +230,7 @@ struct mmc_host {
 	unsigned int		max_req_size;	/* maximum number of bytes in one req */
 	unsigned int		max_blk_size;	/* maximum size of one mmc block */
 	unsigned int		max_blk_count;	/* maximum number of blocks in one req */
+	unsigned int		max_discard_to;	/* max. discard timeout in ms */
 
 	/* private data */
 	spinlock_t		lock;		/* lock for claim and bus ops */
Signature · 1 line
1.7.4.4
author maintainer
#2 lore raw

PATCH 2/2 mmc: sdhci: specify maximum discard timeout

In reply to Adrian Hunter

In general, SDHC hardware timeout cannot be avoided. Accordingly, the maximum timeout is specified to limit the maximum discard size.

---
 drivers/mmc/host/sdhci.c |    5 +++++
 1 files changed, 5 insertions(+), 0 deletions(-)
drivers/mmc/host/sdhci.c +5 -0
index 91d9892..f7e0434 100644
@@ -2488,6 +2488,11 @@ int sdhci_add_host(struct sdhci_host *host)
 	} else
 		mmc->f_min = host->max_clk / SDHCI_MAX_DIV_SPEC_200;
 
+	if (host->quirks & SDHCI_QUIRK_DATA_TIMEOUT_USES_SDCLK)
+		mmc->max_discard_to = (1 << 27) / (mmc->f_max / 1000);
+	else
+		mmc->max_discard_to = (1 << 27) / host->timeout_clk;
+
 	mmc->caps |= MMC_CAP_SDIO_IRQ | MMC_CAP_ERASE | MMC_CAP_CMD23;
 
 	if (host->quirks & SDHCI_QUIRK_MULTIBLOCK_READ_ACMD12)
Signature · 1 line
1.7.4.4
author maintainer
#3 lore raw
In reply to Adrian Hunter
Quoted 5 lines · Adrian Hunter

Hi

Here is a patch that sets a maximum discard size for host controllers that cannot manage large timeouts. And another patch putting it into use for shdci.

Can this be applied?

Quoted 17 lines

Adrian Hunter (2):
mmc: queue: let host controllers specify maximum discard timeout
mmc: sdhci: specify maximum discard timeout

  drivers/mmc/card/queue.c |   33 ++++++++++++++------
  drivers/mmc/core/core.c  |   76 ++++++++++++++++++++++++++++++++++++++++++++++
  drivers/mmc/host/sdhci.c |    5 +++
  include/linux/mmc/core.h |    1 +
  include/linux/mmc/host.h |    1 +
  5 files changed, 106 insertions(+), 10 deletions(-)

Regards
Adrian Hunter
--
To unsubscribe from this list: send the line "unsubscribe linux-mmc" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

#4 lore raw

Hi Adrian,

Quoted 9 lines · Adrian Hunter
Quoted 3 lines

Here is a patch that sets a maximum discard size for host controllers that cannot manage large timeouts. And another patch putting it into use for shdci.

Can this be applied?

Quoted 3 lines

Adrian Hunter (2):
mmc: queue: let host controllers specify maximum discard timeout
mmc: sdhci: specify maximum discard timeout

These two are already in mmc-next for 3.1 -- looks like I forgot to send an e-mail letting you know I'd merged them, sorry.

Thanks,

- Chris.

Signature · 2 lines
Chris Ball   <[email protected]>   <http://printf.net/>
One Laptop Per Child