linux-mmc.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] mmc: core: optimize mmc_calc_max_discard
@ 2018-02-07 23:59 Sergio Valverde
  2018-02-08 17:41 ` [PATCH v2] " Sergio Valverde
  0 siblings, 1 reply; 4+ messages in thread
From: Sergio Valverde @ 2018-02-07 23:59 UTC (permalink / raw)
  Cc: Sergio Valverde, Ulf Hansson, Linus Walleij, Shawn Lin,
	Adrian Hunter, Bartlomiej Zolnierkiewicz, linux-mmc, linux-kernel

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>
---
 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..97856b1 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 (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;
-- 
2.7.4


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH v2] mmc: core: optimize mmc_calc_max_discard
  2018-02-07 23:59 [PATCH] mmc: core: optimize mmc_calc_max_discard Sergio Valverde
@ 2018-02-08 17:41 ` Sergio Valverde
  2018-02-09  7:38   ` Shawn Lin
  2018-02-14 10:38   ` Ulf Hansson
  0 siblings, 2 replies; 4+ messages in thread
From: Sergio Valverde @ 2018-02-08 17:41 UTC (permalink / raw)
  Cc: Sergio Valverde, Ulf Hansson, Linus Walleij, Shawn Lin,
	Adrian Hunter, Bartlomiej Zolnierkiewicz, linux-mmc, linux-kernel

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(-)

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


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH v2] mmc: core: optimize mmc_calc_max_discard
  2018-02-08 17:41 ` [PATCH v2] " Sergio Valverde
@ 2018-02-09  7:38   ` Shawn Lin
  2018-02-14 10:38   ` Ulf Hansson
  1 sibling, 0 replies; 4+ messages in thread
From: Shawn Lin @ 2018-02-09  7:38 UTC (permalink / raw)
  To: Sergio Valverde
  Cc: shawn.lin, Ulf Hansson, Linus Walleij, Adrian Hunter,
	Bartlomiej Zolnierkiewicz, linux-mmc


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;
> 


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH v2] mmc: core: optimize mmc_calc_max_discard
  2018-02-08 17:41 ` [PATCH v2] " Sergio Valverde
  2018-02-09  7:38   ` Shawn Lin
@ 2018-02-14 10:38   ` Ulf Hansson
  1 sibling, 0 replies; 4+ messages in thread
From: Ulf Hansson @ 2018-02-14 10:38 UTC (permalink / raw)
  To: Sergio Valverde
  Cc: Linus Walleij, Shawn Lin, Adrian Hunter,
	Bartlomiej Zolnierkiewicz, linux-mmc@vger.kernel.org,
	Linux Kernel Mailing List

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
>

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2018-02-14 10:38 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-02-07 23:59 [PATCH] mmc: core: optimize mmc_calc_max_discard Sergio Valverde
2018-02-08 17:41 ` [PATCH v2] " Sergio Valverde
2018-02-09  7:38   ` Shawn Lin
2018-02-14 10:38   ` Ulf Hansson

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).