From: Akinobu Mita <mita@miraclelinux.com>
To: linux-kernel@vger.kernel.org
Cc: akpm@osdl.org, Akinobu Mita <mita@miraclelinux.com>,
Jens Axboe <axboe@suse.de>, Greg KH <greg@kroah.com>
Subject: [patch 2/3] use kref for io_context
Date: Wed, 26 Apr 2006 10:11:01 +0800 [thread overview]
Message-ID: <20060426021121.689604000@localhost.localdomain> (raw)
In-Reply-To: 20060426021059.235216000@localhost.localdomain
[-- Attachment #1: use-kref.patch --]
[-- Type: text/plain, Size: 3499 bytes --]
Use kref for reference counter of io_context.
This patch also removes BUG_ON() for freeing unreferenced io_context.
But kref can detect it if CONFIG_DEBUG_SLAB is enabled.
Signed-off-by: Akinobu Mita <mita@miraclelinux.com>
CC: Jens Axboe <axboe@suse.de>
CC: Greg KH <greg@kroah.com>
block/cfq-iosched.c | 2 +-
block/ll_rw_blk.c | 43 +++++++++++++++++++++----------------------
include/linux/blkdev.h | 2 +-
3 files changed, 23 insertions(+), 24 deletions(-)
Index: 2.6-git/block/ll_rw_blk.c
===================================================================
--- 2.6-git.orig/block/ll_rw_blk.c
+++ 2.6-git/block/ll_rw_blk.c
@@ -3536,29 +3536,29 @@ int __init blk_dev_init(void)
/*
* IO Context helper functions
*/
+static void release_io_context(struct kref *kref)
+{
+ struct io_context *ioc = container_of(kref, struct io_context, kref);
+ struct cfq_io_context *cic;
+
+ rcu_read_lock();
+ if (ioc->aic && ioc->aic->dtor)
+ ioc->aic->dtor(ioc->aic);
+ if (ioc->cic_root.rb_node != NULL) {
+ struct rb_node *n = rb_first(&ioc->cic_root);
+ cic = rb_entry(n, struct cfq_io_context, rb_node);
+ cic->dtor(ioc);
+ }
+ rcu_read_unlock();
+ kmem_cache_free(iocontext_cachep, ioc);
+}
+
void put_io_context(struct io_context *ioc)
{
if (ioc == NULL)
return;
- BUG_ON(atomic_read(&ioc->refcount) == 0);
-
- if (atomic_dec_and_test(&ioc->refcount)) {
- struct cfq_io_context *cic;
-
- rcu_read_lock();
- if (ioc->aic && ioc->aic->dtor)
- ioc->aic->dtor(ioc->aic);
- if (ioc->cic_root.rb_node != NULL) {
- struct rb_node *n = rb_first(&ioc->cic_root);
-
- cic = rb_entry(n, struct cfq_io_context, rb_node);
- cic->dtor(ioc);
- }
- rcu_read_unlock();
-
- kmem_cache_free(iocontext_cachep, ioc);
- }
+ kref_put(&ioc->kref, release_io_context);
}
EXPORT_SYMBOL(put_io_context);
@@ -3606,7 +3606,7 @@ struct io_context *current_io_context(gf
ret = kmem_cache_alloc(iocontext_cachep, gfp_flags);
if (ret) {
- atomic_set(&ret->refcount, 1);
+ kref_init(&ret->kref);
ret->task = current;
ret->set_ioprio = NULL;
ret->last_waited = jiffies; /* doesn't matter... */
@@ -3631,7 +3631,7 @@ struct io_context *get_io_context(gfp_t
struct io_context *ret;
ret = current_io_context(gfp_flags);
if (likely(ret))
- atomic_inc(&ret->refcount);
+ kref_get(&ret->kref);
return ret;
}
EXPORT_SYMBOL(get_io_context);
@@ -3642,8 +3642,7 @@ void copy_io_context(struct io_context *
struct io_context *dst = *pdst;
if (src) {
- BUG_ON(atomic_read(&src->refcount) == 0);
- atomic_inc(&src->refcount);
+ kref_get(&src->kref);
put_io_context(dst);
*pdst = src;
}
Index: 2.6-git/include/linux/blkdev.h
===================================================================
--- 2.6-git.orig/include/linux/blkdev.h
+++ 2.6-git/include/linux/blkdev.h
@@ -88,7 +88,7 @@ struct cfq_io_context {
* (apart from the atomic refcount), so require no locking.
*/
struct io_context {
- atomic_t refcount;
+ struct kref kref;
struct task_struct *task;
int (*set_ioprio)(struct io_context *, unsigned int);
Index: 2.6-git/block/cfq-iosched.c
===================================================================
--- 2.6-git.orig/block/cfq-iosched.c
+++ 2.6-git/block/cfq-iosched.c
@@ -1068,7 +1068,7 @@ __cfq_dispatch_requests(struct cfq_data
dispatched++;
if (!cfqd->active_cic) {
- atomic_inc(&crq->io_context->ioc->refcount);
+ kref_get(&crq->io_context->ioc->kref);
cfqd->active_cic = crq->io_context;
}
--
next prev parent reply other threads:[~2006-04-26 2:11 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2006-04-26 2:10 [patch 0/3] use kref Akinobu Mita
2006-04-26 2:11 ` [patch 1/3] use kref for blk_queue_tag Akinobu Mita
2006-04-26 2:42 ` Nick Piggin
2006-04-26 5:17 ` Greg KH
2006-04-26 2:11 ` Akinobu Mita [this message]
2006-04-26 2:11 ` [patch 3/3] use kref for bio Akinobu Mita
2006-04-26 2:26 ` Al Viro
2006-04-26 5:13 ` Jens Axboe
2006-04-26 5:18 ` Greg KH
2006-04-26 7:20 ` Akinobu Mita
2006-04-26 7:39 ` Al Viro
2006-04-26 9:29 ` Nick Piggin
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=20060426021121.689604000@localhost.localdomain \
--to=mita@miraclelinux.com \
--cc=akpm@osdl.org \
--cc=axboe@suse.de \
--cc=greg@kroah.com \
--cc=linux-kernel@vger.kernel.org \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.