* [PATCH] CFQ: clarify cleverness regarding cic->key
@ 2011-08-03 18:54 Paul Bolle
2011-08-03 21:18 ` Vivek Goyal
0 siblings, 1 reply; 2+ messages in thread
From: Paul Bolle @ 2011-08-03 18:54 UTC (permalink / raw)
To: Jens Axboe; +Cc: linux-kernel
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 */
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
^ permalink raw reply related [flat|nested] 2+ messages in thread* Re: [PATCH] CFQ: clarify cleverness regarding cic->key
2011-08-03 18:54 [PATCH] CFQ: clarify cleverness regarding cic->key Paul Bolle
@ 2011-08-03 21:18 ` Vivek Goyal
0 siblings, 0 replies; 2+ messages in thread
From: Vivek Goyal @ 2011-08-03 21:18 UTC (permalink / raw)
To: Paul Bolle; +Cc: Jens Axboe, linux-kernel
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/
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2011-08-03 21:18 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-08-03 18:54 [PATCH] CFQ: clarify cleverness regarding cic->key Paul Bolle
2011-08-03 21:18 ` Vivek Goyal
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox