diff mbox

[v2] mmc: core: optimize mmc_calc_max_discard

Message ID 1518111705-11122-1-git-send-email-vlvrdv@gmail.com (mailing list archive)
State New, archived
Headers show

Commit Message

Sergio Valverde Feb. 8, 2018, 5:41 p.m. UTC
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.

Signed-off-by: Sergio Valverde <vlvrdv@gmail.com>
---
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(-)

Comments

Shawn Lin Feb. 9, 2018, 7:38 a.m. UTC | #1
On 2018/2/9 1:41, Sergio Valverde wrote:
> 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,

Reviewed-by: Shawn Lin <shawn.lin@rock-chip.com>

> Signed-off-by: Sergio Valverde <vlvrdv@gmail.com>
> ---
> 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(-)
> 
> diff --git a/drivers/mmc/core/core.c b/drivers/mmc/core/core.c
> index 1f0f44f..c32c0f4 100644
> --- a/drivers/mmc/core/core.c
> +++ b/drivers/mmc/core/core.c
> @@ -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;
> 

--
To unsubscribe from this list: send the line "unsubscribe linux-mmc" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Ulf Hansson Feb. 14, 2018, 10:38 a.m. UTC | #2
On 8 February 2018 at 18:41, Sergio Valverde <vlvrdv@gmail.com> wrote:
> 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.
>
> Signed-off-by: Sergio Valverde <vlvrdv@gmail.com>

Thanks, applied for next!

Kind regards
Uffe

> ---
> 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(-)
>
> diff --git a/drivers/mmc/core/core.c b/drivers/mmc/core/core.c
> index 1f0f44f..c32c0f4 100644
> --- a/drivers/mmc/core/core.c
> +++ b/drivers/mmc/core/core.c
> @@ -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
>
--
To unsubscribe from this list: send the line "unsubscribe linux-mmc" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

diff --git a/drivers/mmc/core/core.c b/drivers/mmc/core/core.c
index 1f0f44f..c32c0f4 100644
--- a/drivers/mmc/core/core.c
+++ b/drivers/mmc/core/core.c
@@ -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;