Skip to contentSkip to conversation

mmc: core: optimize mmc_calc_max_discard

PATCH Superseded Sergio Valverde 3 participants 4 messages Feb 8, 2018 – Feb 14, 2018 MMC, SD and SDIO

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 mmc: core: optimize mmc_calc_max_discard

If the max_discard value is zero, the conditional branch that checks the trim capabilities will never update this value with max_trim.

Change the condition statement to also check the max_discard value in order to avoid an unnecessary call to mmc_do_calc_max_discard.

---
 drivers/mmc/core/core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/mmc/core/core.c +1 -1
index 1f0f44f..97856b1 100644
@@ -2567,7 +2567,7 @@ unsigned int mmc_calc_max_discard(struct mmc_card *card)
 		return card->pref_erase;
 
 	max_discard = mmc_do_calc_max_discard(card, MMC_ERASE_ARG);
-	if (mmc_can_trim(card)) {
+	if (mmc_can_trim(card) && max_discard) {
 		max_trim = mmc_do_calc_max_discard(card, MMC_TRIM_ARG);
 		if (max_trim < max_discard)
 			max_discard = max_trim;
Signature · 1 line
2.7.4
#1 lore raw

PATCH v2 1/1 mmc: core: optimize mmc_calc_max_discard

If the max_discard value is zero, the conditional branch that checks the trim capabilities will never update this value with max_trim.

Change the condition statement to also check the max_discard value in order to avoid an unnecessary call to mmc_do_calc_max_discard.

---
Changes in v2:
- Evaluate max_discard to avoid unnecessary calls to mmc_can_trim.

 drivers/mmc/core/core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/mmc/core/core.c +1 -1
index 1f0f44f..c32c0f4 100644
@@ -2567,7 +2567,7 @@ unsigned int mmc_calc_max_discard(struct mmc_card *card)
 		return card->pref_erase;
 
 	max_discard = mmc_do_calc_max_discard(card, MMC_ERASE_ARG);
-	if (mmc_can_trim(card)) {
+	if (max_discard && mmc_can_trim(card)) {
 		max_trim = mmc_do_calc_max_discard(card, MMC_TRIM_ARG);
 		if (max_trim < max_discard)
 			max_discard = max_trim;
Signature · 1 line
2.7.4
Reviewed-by on v2 1/1
#2 lore raw
Quoted 6 lines · Sergio Valverde

If the max_discard value is zero, the conditional branch that checks the trim capabilities will never update this value with max_trim.

Change the condition statement to also check the max_discard value in order to avoid an unnecessary call to mmc_do_calc_max_discard.

Given it's not in the hot call patch and it's rare to return zero from mmc_do_calc_max_discard if you read the code instead of doing sanity check by tools. So I doubt there is no gain in practice. But FWIW,

Quoted 22 lines

---
Changes in v2:
- Evaluate max_discard to avoid unnecessary calls to mmc_can_trim.

  drivers/mmc/core/core.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
drivers/mmc/core/core.c +1 -1
index 1f0f44f..c32c0f4 100644
@@ -2567,7 +2567,7 @@ unsigned int mmc_calc_max_discard(struct mmc_card *card)
  		return card->pref_erase;
 
  	max_discard = mmc_do_calc_max_discard(card, MMC_ERASE_ARG);
-	if (mmc_can_trim(card)) {
+	if (max_discard && mmc_can_trim(card)) {
  		max_trim = mmc_do_calc_max_discard(card, MMC_TRIM_ARG);
  		if (max_trim < max_discard)
  			max_discard = max_trim;
Applied
#3 lore raw
In reply to Sergio Valverde
Quoted 7 lines · Sergio Valverde

If the max_discard value is zero, the conditional branch that checks the trim capabilities will never update this value with max_trim.

Change the condition statement to also check the max_discard value in order to avoid an unnecessary call to mmc_do_calc_max_discard.

Thanks, applied for next!

Kind regards
Uffe

Quoted 23 lines

---
Changes in v2:
- Evaluate max_discard to avoid unnecessary calls to mmc_can_trim.

 drivers/mmc/core/core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/mmc/core/core.c +1 -2
index 1f0f44f..c32c0f4 100644
@@ -2567,7 +2567,7 @@ unsigned int mmc_calc_max_discard(struct mmc_card *card)
                return card->pref_erase;
 
        max_discard = mmc_do_calc_max_discard(card, MMC_ERASE_ARG);
-       if (mmc_can_trim(card)) {
+       if (max_discard && mmc_can_trim(card)) {
                max_trim = mmc_do_calc_max_discard(card, MMC_TRIM_ARG);
                if (max_trim < max_discard)
                        max_discard = max_trim;
--

2.7.4