public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/4] cfq-iosched: algebraic simplification in cfq_prio_to_maxrq()
@ 2011-05-24  3:18 Namhyung Kim
  2011-05-24  3:18 ` [PATCH 2/4] cfq-iosched: reduce bit operations in cfq_choose_req() Namhyung Kim
                   ` (3 more replies)
  0 siblings, 4 replies; 8+ messages in thread
From: Namhyung Kim @ 2011-05-24  3:18 UTC (permalink / raw)
  To: Jens Axboe; +Cc: linux-kernel

Simplify the calculation in cfq_prio_to_maxrq(), plus replace CFQ_PRIO_LISTS to
IOPRIO_BE_NR since they are the same and IOPRIO_BE_NR looks more reasonable in
this context IMHO.

Signed-off-by: Namhyung Kim <namhyung@gmail.com>
---
 block/cfq-iosched.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/block/cfq-iosched.c b/block/cfq-iosched.c
index ab7a9e6a9b1c..151a050e692c 100644
--- a/block/cfq-iosched.c
+++ b/block/cfq-iosched.c
@@ -2029,7 +2029,7 @@ cfq_prio_to_maxrq(struct cfq_data *cfqd, struct cfq_queue *cfqq)
 
 	WARN_ON(cfqq->ioprio >= IOPRIO_BE_NR);
 
-	return 2 * (base_rq + base_rq * (CFQ_PRIO_LISTS - 1 - cfqq->ioprio));
+	return 2 * base_rq * (IOPRIO_BE_NR - cfqq->ioprio);
 }
 
 /*
-- 
1.7.5.2


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

* [PATCH 2/4] cfq-iosched: reduce bit operations in cfq_choose_req()
  2011-05-24  3:18 [PATCH 1/4] cfq-iosched: algebraic simplification in cfq_prio_to_maxrq() Namhyung Kim
@ 2011-05-24  3:18 ` Namhyung Kim
  2011-05-24 17:34   ` Justin TerAvest
  2011-05-24  3:18 ` [PATCH 3/4] cfq-iosched: remove unused 'group_changed' in cfq_service_tree_add() Namhyung Kim
                   ` (2 subsequent siblings)
  3 siblings, 1 reply; 8+ messages in thread
From: Namhyung Kim @ 2011-05-24  3:18 UTC (permalink / raw)
  To: Jens Axboe; +Cc: linux-kernel

Reduce the number of bit operations in cfq_choose_req() on average
(and worst) cases.

Signed-off-by: Namhyung Kim <namhyung@gmail.com>
---
 block/cfq-iosched.c |   14 +++++---------
 1 files changed, 5 insertions(+), 9 deletions(-)

diff --git a/block/cfq-iosched.c b/block/cfq-iosched.c
index 151a050e692c..a79e62063144 100644
--- a/block/cfq-iosched.c
+++ b/block/cfq-iosched.c
@@ -665,15 +665,11 @@ cfq_choose_req(struct cfq_data *cfqd, struct request *rq1, struct request *rq2,
 	if (rq2 == NULL)
 		return rq1;
 
-	if (rq_is_sync(rq1) && !rq_is_sync(rq2))
-		return rq1;
-	else if (rq_is_sync(rq2) && !rq_is_sync(rq1))
-		return rq2;
-	if ((rq1->cmd_flags & REQ_META) && !(rq2->cmd_flags & REQ_META))
-		return rq1;
-	else if ((rq2->cmd_flags & REQ_META) &&
-		 !(rq1->cmd_flags & REQ_META))
-		return rq2;
+	if (rq_is_sync(rq1) != rq_is_sync(rq2))
+		return rq_is_sync(rq1) ? rq1 : rq2;
+
+	if ((rq1->cmd_flags ^ rq2->cmd_flags) & REQ_META)
+		return rq1->cmd_flags & REQ_META ? rq1 : rq2;
 
 	s1 = blk_rq_pos(rq1);
 	s2 = blk_rq_pos(rq2);
-- 
1.7.5.2


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

* [PATCH 3/4] cfq-iosched: remove unused 'group_changed' in cfq_service_tree_add()
  2011-05-24  3:18 [PATCH 1/4] cfq-iosched: algebraic simplification in cfq_prio_to_maxrq() Namhyung Kim
  2011-05-24  3:18 ` [PATCH 2/4] cfq-iosched: reduce bit operations in cfq_choose_req() Namhyung Kim
@ 2011-05-24  3:18 ` Namhyung Kim
  2011-05-24 17:32   ` Justin TerAvest
  2011-05-24  3:18 ` [PATCH 4/4] cfq-iosched: free cic_index if cfqd allocation fails Namhyung Kim
  2011-05-24  8:13 ` [PATCH 1/4] cfq-iosched: algebraic simplification in cfq_prio_to_maxrq() Jens Axboe
  3 siblings, 1 reply; 8+ messages in thread
From: Namhyung Kim @ 2011-05-24  3:18 UTC (permalink / raw)
  To: Jens Axboe; +Cc: linux-kernel, Justin TerAvest

The 'group_changed' variable is initialized to 0 and never changed, so
checking the variable is meaningless.

It is a leftover from 0bbfeb832042 ("cfq-iosched: Always provide group
iosolation."). Let's get rid of it.

Signed-off-by: Namhyung Kim <namhyung@gmail.com>
Cc: Justin TerAvest <teravest@google.com>
---
 block/cfq-iosched.c |    3 +--
 1 files changed, 1 insertions(+), 2 deletions(-)

diff --git a/block/cfq-iosched.c b/block/cfq-iosched.c
index a79e62063144..4ceebd346710 100644
--- a/block/cfq-iosched.c
+++ b/block/cfq-iosched.c
@@ -1206,7 +1206,6 @@ static void cfq_service_tree_add(struct cfq_data *cfqd, struct cfq_queue *cfqq,
 	struct cfq_rb_root *service_tree;
 	int left;
 	int new_cfqq = 1;
-	int group_changed = 0;
 
 	service_tree = service_tree_for(cfqq->cfqg, cfqq_prio(cfqq),
 						cfqq_type(cfqq));
@@ -1277,7 +1276,7 @@ static void cfq_service_tree_add(struct cfq_data *cfqd, struct cfq_queue *cfqq,
 	rb_link_node(&cfqq->rb_node, parent, p);
 	rb_insert_color(&cfqq->rb_node, &service_tree->rb);
 	service_tree->count++;
-	if ((add_front || !new_cfqq) && !group_changed)
+	if (add_front || !new_cfqq)
 		return;
 	cfq_group_notify_queue_add(cfqd, cfqq->cfqg);
 }
-- 
1.7.5.2


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

* [PATCH 4/4] cfq-iosched: free cic_index if cfqd allocation fails
  2011-05-24  3:18 [PATCH 1/4] cfq-iosched: algebraic simplification in cfq_prio_to_maxrq() Namhyung Kim
  2011-05-24  3:18 ` [PATCH 2/4] cfq-iosched: reduce bit operations in cfq_choose_req() Namhyung Kim
  2011-05-24  3:18 ` [PATCH 3/4] cfq-iosched: remove unused 'group_changed' in cfq_service_tree_add() Namhyung Kim
@ 2011-05-24  3:18 ` Namhyung Kim
  2011-05-24  8:13 ` [PATCH 1/4] cfq-iosched: algebraic simplification in cfq_prio_to_maxrq() Jens Axboe
  3 siblings, 0 replies; 8+ messages in thread
From: Namhyung Kim @ 2011-05-24  3:18 UTC (permalink / raw)
  To: Jens Axboe; +Cc: linux-kernel

When struct cfq_data allocation fails, cic_index need to be freed.

Signed-off-by: Namhyung Kim <namhyung@gmail.com>
---
 block/cfq-iosched.c |    6 +++++-
 1 files changed, 5 insertions(+), 1 deletions(-)

diff --git a/block/cfq-iosched.c b/block/cfq-iosched.c
index 4ceebd346710..7fe732a274b2 100644
--- a/block/cfq-iosched.c
+++ b/block/cfq-iosched.c
@@ -3881,8 +3881,12 @@ static void *cfq_init_queue(struct request_queue *q)
 		return NULL;
 
 	cfqd = kmalloc_node(sizeof(*cfqd), GFP_KERNEL | __GFP_ZERO, q->node);
-	if (!cfqd)
+	if (!cfqd) {
+		spin_lock(&cic_index_lock);
+		ida_remove(&cic_index_ida, i);
+		spin_unlock(&cic_index_lock);
 		return NULL;
+	}
 
 	/*
 	 * Don't need take queue_lock in the routine, since we are
-- 
1.7.5.2


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

* Re: [PATCH 1/4] cfq-iosched: algebraic simplification in cfq_prio_to_maxrq()
  2011-05-24  3:18 [PATCH 1/4] cfq-iosched: algebraic simplification in cfq_prio_to_maxrq() Namhyung Kim
                   ` (2 preceding siblings ...)
  2011-05-24  3:18 ` [PATCH 4/4] cfq-iosched: free cic_index if cfqd allocation fails Namhyung Kim
@ 2011-05-24  8:13 ` Jens Axboe
  3 siblings, 0 replies; 8+ messages in thread
From: Jens Axboe @ 2011-05-24  8:13 UTC (permalink / raw)
  To: Namhyung Kim; +Cc: linux-kernel

On 2011-05-24 05:18, Namhyung Kim wrote:
> Simplify the calculation in cfq_prio_to_maxrq(), plus replace CFQ_PRIO_LISTS to
> IOPRIO_BE_NR since they are the same and IOPRIO_BE_NR looks more reasonable in
> this context IMHO.

Double checked your math, it is indeed identical to
2*base_rq*IOPRIO_BE_NR - 2*base_rq*cfqq->ioprio. Looks a lot cleaner,
thanks.

-- 
Jens Axboe


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

* Re: [PATCH 3/4] cfq-iosched: remove unused 'group_changed' in cfq_service_tree_add()
  2011-05-24  3:18 ` [PATCH 3/4] cfq-iosched: remove unused 'group_changed' in cfq_service_tree_add() Namhyung Kim
@ 2011-05-24 17:32   ` Justin TerAvest
  0 siblings, 0 replies; 8+ messages in thread
From: Justin TerAvest @ 2011-05-24 17:32 UTC (permalink / raw)
  To: Namhyung Kim; +Cc: Jens Axboe, lkml

Looks good to me.

Reviewed-by: Justin TerAvest <teravest@google.com>

On Mon, May 23, 2011 at 8:18 PM, Namhyung Kim <namhyung@gmail.com> wrote:
> The 'group_changed' variable is initialized to 0 and never changed, so
> checking the variable is meaningless.
>
> It is a leftover from 0bbfeb832042 ("cfq-iosched: Always provide group
> iosolation."). Let's get rid of it.
>
> Signed-off-by: Namhyung Kim <namhyung@gmail.com>
> Cc: Justin TerAvest <teravest@google.com>
> ---
>  block/cfq-iosched.c |    3 +--
>  1 files changed, 1 insertions(+), 2 deletions(-)
>
> diff --git a/block/cfq-iosched.c b/block/cfq-iosched.c
> index a79e62063144..4ceebd346710 100644
> --- a/block/cfq-iosched.c
> +++ b/block/cfq-iosched.c
> @@ -1206,7 +1206,6 @@ static void cfq_service_tree_add(struct cfq_data *cfqd, struct cfq_queue *cfqq,
>        struct cfq_rb_root *service_tree;
>        int left;
>        int new_cfqq = 1;
> -       int group_changed = 0;
>
>        service_tree = service_tree_for(cfqq->cfqg, cfqq_prio(cfqq),
>                                                cfqq_type(cfqq));
> @@ -1277,7 +1276,7 @@ static void cfq_service_tree_add(struct cfq_data *cfqd, struct cfq_queue *cfqq,
>        rb_link_node(&cfqq->rb_node, parent, p);
>        rb_insert_color(&cfqq->rb_node, &service_tree->rb);
>        service_tree->count++;
> -       if ((add_front || !new_cfqq) && !group_changed)
> +       if (add_front || !new_cfqq)
>                return;
>        cfq_group_notify_queue_add(cfqd, cfqq->cfqg);
>  }
> --
> 1.7.5.2
>
>

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

* Re: [PATCH 2/4] cfq-iosched: reduce bit operations in cfq_choose_req()
  2011-05-24  3:18 ` [PATCH 2/4] cfq-iosched: reduce bit operations in cfq_choose_req() Namhyung Kim
@ 2011-05-24 17:34   ` Justin TerAvest
  2011-05-25  2:34     ` Namhyung Kim
  0 siblings, 1 reply; 8+ messages in thread
From: Justin TerAvest @ 2011-05-24 17:34 UTC (permalink / raw)
  To: Namhyung Kim; +Cc: Jens Axboe, lkml

Why make this change? Are we that sensitive to the number of operations?

It makes the code a bit harder to read, I think.

On Mon, May 23, 2011 at 8:18 PM, Namhyung Kim <namhyung@gmail.com> wrote:
> Reduce the number of bit operations in cfq_choose_req() on average
> (and worst) cases.
>
> Signed-off-by: Namhyung Kim <namhyung@gmail.com>
> ---
>  block/cfq-iosched.c |   14 +++++---------
>  1 files changed, 5 insertions(+), 9 deletions(-)
>
> diff --git a/block/cfq-iosched.c b/block/cfq-iosched.c
> index 151a050e692c..a79e62063144 100644
> --- a/block/cfq-iosched.c
> +++ b/block/cfq-iosched.c
> @@ -665,15 +665,11 @@ cfq_choose_req(struct cfq_data *cfqd, struct request *rq1, struct request *rq2,
>        if (rq2 == NULL)
>                return rq1;
>
> -       if (rq_is_sync(rq1) && !rq_is_sync(rq2))
> -               return rq1;
> -       else if (rq_is_sync(rq2) && !rq_is_sync(rq1))
> -               return rq2;
> -       if ((rq1->cmd_flags & REQ_META) && !(rq2->cmd_flags & REQ_META))
> -               return rq1;
> -       else if ((rq2->cmd_flags & REQ_META) &&
> -                !(rq1->cmd_flags & REQ_META))
> -               return rq2;
> +       if (rq_is_sync(rq1) != rq_is_sync(rq2))
> +               return rq_is_sync(rq1) ? rq1 : rq2;
> +
> +       if ((rq1->cmd_flags ^ rq2->cmd_flags) & REQ_META)
> +               return rq1->cmd_flags & REQ_META ? rq1 : rq2;
>
>        s1 = blk_rq_pos(rq1);
>        s2 = blk_rq_pos(rq2);
> --
> 1.7.5.2
>
> --
> To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
> Please read the FAQ at  http://www.tux.org/lkml/
>

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

* Re: [PATCH 2/4] cfq-iosched: reduce bit operations in cfq_choose_req()
  2011-05-24 17:34   ` Justin TerAvest
@ 2011-05-25  2:34     ` Namhyung Kim
  0 siblings, 0 replies; 8+ messages in thread
From: Namhyung Kim @ 2011-05-25  2:34 UTC (permalink / raw)
  To: Justin TerAvest; +Cc: Jens Axboe, lkml

2011-05-24 (화), 10:34 -0700, Justin TerAvest:
> Why make this change? Are we that sensitive to the number of operations?
> 
> It makes the code a bit harder to read, I think.
> 

Hi Justin,

I thought that the function is a sort of hot path operation so it would
be better make it even a bit faster, no? And if you guys think this
patch makes the code harder we can add a comment, although I don't think
it's hard enough. :)

Thanks.


-- 
Regards,
Namhyung Kim



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

end of thread, other threads:[~2011-05-25  2:34 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-05-24  3:18 [PATCH 1/4] cfq-iosched: algebraic simplification in cfq_prio_to_maxrq() Namhyung Kim
2011-05-24  3:18 ` [PATCH 2/4] cfq-iosched: reduce bit operations in cfq_choose_req() Namhyung Kim
2011-05-24 17:34   ` Justin TerAvest
2011-05-25  2:34     ` Namhyung Kim
2011-05-24  3:18 ` [PATCH 3/4] cfq-iosched: remove unused 'group_changed' in cfq_service_tree_add() Namhyung Kim
2011-05-24 17:32   ` Justin TerAvest
2011-05-24  3:18 ` [PATCH 4/4] cfq-iosched: free cic_index if cfqd allocation fails Namhyung Kim
2011-05-24  8:13 ` [PATCH 1/4] cfq-iosched: algebraic simplification in cfq_prio_to_maxrq() Jens Axboe

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox