public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Vivek Goyal <vgoyal@redhat.com>
To: Paul Bolle <pebolle@tiscali.nl>
Cc: Jens Axboe <axboe@kernel.dk>, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] CFQ: clarify cleverness regarding cic->key
Date: Wed, 3 Aug 2011 17:18:17 -0400	[thread overview]
Message-ID: <20110803211817.GG32385@redhat.com> (raw)
In-Reply-To: <1312397690.30457.10.camel@x61.thuisdomein>

On Wed, Aug 03, 2011 at 08:54:50PM +0200, Paul Bolle wrote:
> Add (and edit) a few comments to make the cleverness regarding cic->key
> more obvious.
> 
> Signed-off-by: Paul Bolle <pebolle@tiscali.nl>
> ---

> 0) Not even compile tested.
> 
> 1) It seems I ran into another CFQ corner case again. This forces me to
> study this code once more. I found the clever dual use of cic->key
> rather non-obvious. But perhaps this is a common idiom. Anyhow, are
> these comments too verbose? 
> 
>  block/cfq-iosched.c       |   11 +++++++++--
>  include/linux/iocontext.h |    2 ++
>  2 files changed, 11 insertions(+), 2 deletions(-)
> 
> diff --git a/block/cfq-iosched.c b/block/cfq-iosched.c
> index 1f96ad6..c1618dd 100644
> --- a/block/cfq-iosched.c
> +++ b/block/cfq-iosched.c
> @@ -480,6 +480,10 @@ static inline void cic_set_cfqq(struct cfq_io_context *cic,
>  #define CIC_DEAD_KEY	1ul
>  #define CIC_DEAD_INDEX_SHIFT	1
>  
> +/*
> + * We mangle cic_index so it will always be an odd number, and then cast it to
> + * a void pointer, so it can never be a valid pointer to a struct cfq_data.
> + */
>  static inline void *cfqd_dead_key(struct cfq_data *cfqd)
>  {
>  	return (void *)(cfqd->cic_index << CIC_DEAD_INDEX_SHIFT | CIC_DEAD_KEY);
> @@ -489,6 +493,8 @@ static inline struct cfq_data *cic_to_cfqd(struct cfq_io_context *cic)
>  {
>  	struct cfq_data *cfqd = cic->key;
>  
> +	/* if this is an odd number it can't be valid a pointer to a
> +	 * struct cfq_data, so this must be dead cic */

Use following format for comments.

	/*
	 * comment.
	 */


Apart from this minor nit, documentation looks fine to me.

Thanks
Vivek

>  	if (unlikely((unsigned long) cfqd & CIC_DEAD_KEY))
>  		return NULL;
>  
> @@ -2708,6 +2714,7 @@ static void cic_free_func(struct io_context *ioc, struct cfq_io_context *cic)
>  	BUG_ON(!(dead_key & CIC_DEAD_KEY));
>  
>  	spin_lock_irqsave(&ioc->lock, flags);
> +	/* we must demangle dead_key into a valid radix tree index again */
>  	radix_tree_delete(&ioc->radix_root, dead_key >> CIC_DEAD_INDEX_SHIFT);
>  	hlist_del_rcu(&cic->cic_list);
>  	spin_unlock_irqrestore(&ioc->lock, flags);
> @@ -3141,8 +3148,8 @@ cfq_cic_lookup(struct cfq_data *cfqd, struct io_context *ioc)
>  }
>  
>  /*
> - * Add cic into ioc, using cfqd as the search key. This enables us to lookup
> - * the process specific cfq io context when entered from the block layer.
> + * Add cic into ioc, using cic_index as the search key. This enables us to
> + * lookup the process specific cfq io context when entered from the block layer.
>   * Also adds the cic to a per-cfqd list, used when this queue is removed.
>   */
>  static int cfq_cic_link(struct cfq_data *cfqd, struct io_context *ioc,
> diff --git a/include/linux/iocontext.h b/include/linux/iocontext.h
> index 5037a0a..a7f2c83 100644
> --- a/include/linux/iocontext.h
> +++ b/include/linux/iocontext.h
> @@ -14,6 +14,8 @@ struct cfq_ttime {
>  };
>  
>  struct cfq_io_context {
> +	/* either a valid pointer to a struct cfq_data or a (mangled) index
> +	 * to io_context->radix_root */
>  	void *key;
>  
>  	struct cfq_queue *cfqq[2];
> -- 
> 1.7.4.4
> 
> --
> 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/

      reply	other threads:[~2011-08-03 21:18 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-08-03 18:54 [PATCH] CFQ: clarify cleverness regarding cic->key Paul Bolle
2011-08-03 21:18 ` Vivek Goyal [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20110803211817.GG32385@redhat.com \
    --to=vgoyal@redhat.com \
    --cc=axboe@kernel.dk \
    --cc=linux-kernel@vger.kernel.org \
    --cc=pebolle@tiscali.nl \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox