public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
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 3/3] use kref for bio
Date: Wed, 26 Apr 2006 10:11:02 +0800	[thread overview]
Message-ID: <20060426021122.069267000@localhost.localdomain> (raw)
In-Reply-To: 20060426021059.235216000@localhost.localdomain

[-- Attachment #1: kref-bio.patch --]
[-- Type: text/plain, Size: 3275 bytes --]

Use kref for reference counter of bio.
This patch also removes BUG_ON() for freeing unreferenced bio.
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>

 Documentation/block/biodoc.txt |    2 +-
 fs/bio.c                       |   17 ++++++++++-------
 fs/xfs/linux-2.6/xfs_aops.c    |    1 -
 include/linux/bio.h            |    4 ++--
 4 files changed, 13 insertions(+), 11 deletions(-)

Index: 2.6-git/Documentation/block/biodoc.txt
===================================================================
--- 2.6-git.orig/Documentation/block/biodoc.txt
+++ 2.6-git/Documentation/block/biodoc.txt
@@ -462,7 +462,7 @@ struct bio {
                                         used as index into pool */
        struct bio_vec   *bi_io_vec;  /* the actual vec list */
        bio_end_io_t	*bi_end_io;  /* bi_end_io (bio) */
-       atomic_t		bi_cnt;	     /* pin count: free when it hits zero */
+       struct kref	bi_kref;     /* pin count */
        void             *bi_private;
        bio_destructor_t *bi_destructor; /* bi_destructor (bio) */
 };
Index: 2.6-git/fs/bio.c
===================================================================
--- 2.6-git.orig/fs/bio.c
+++ 2.6-git/fs/bio.c
@@ -139,7 +139,7 @@ void bio_init(struct bio *bio)
 	bio->bi_size = 0;
 	bio->bi_max_vecs = 0;
 	bio->bi_end_io = NULL;
-	atomic_set(&bio->bi_cnt, 1);
+	kref_init(&bio->bi_kref);
 	bio->bi_private = NULL;
 }
 
@@ -208,6 +208,14 @@ void zero_fill_bio(struct bio *bio)
 }
 EXPORT_SYMBOL(zero_fill_bio);
 
+static void release_bio(struct kref *kref)
+{
+	struct bio *bio = container_of(kref, struct bio, bi_kref);
+
+	bio->bi_next = NULL;
+	bio->bi_destructor(bio);
+}
+
 /**
  * bio_put - release a reference to a bio
  * @bio:   bio to release reference to
@@ -218,15 +226,10 @@ EXPORT_SYMBOL(zero_fill_bio);
  **/
 void bio_put(struct bio *bio)
 {
-	BIO_BUG_ON(!atomic_read(&bio->bi_cnt));
-
 	/*
 	 * last put frees it
 	 */
-	if (atomic_dec_and_test(&bio->bi_cnt)) {
-		bio->bi_next = NULL;
-		bio->bi_destructor(bio);
-	}
+	kref_put(&bio->bi_kref, release_bio);
 }
 
 inline int bio_phys_segments(request_queue_t *q, struct bio *bio)
Index: 2.6-git/fs/xfs/linux-2.6/xfs_aops.c
===================================================================
--- 2.6-git.orig/fs/xfs/linux-2.6/xfs_aops.c
+++ 2.6-git/fs/xfs/linux-2.6/xfs_aops.c
@@ -272,7 +272,6 @@ xfs_end_bio(
 		return 1;
 
 	ASSERT(ioend);
-	ASSERT(atomic_read(&bio->bi_cnt) >= 1);
 
 	/* Toss bio and pass work off to an xfsdatad thread */
 	if (!test_bit(BIO_UPTODATE, &bio->bi_flags))
Index: 2.6-git/include/linux/bio.h
===================================================================
--- 2.6-git.orig/include/linux/bio.h
+++ 2.6-git/include/linux/bio.h
@@ -106,7 +106,7 @@ struct bio {
 	struct bio_vec		*bi_io_vec;	/* the actual vec list */
 
 	bio_end_io_t		*bi_end_io;
-	atomic_t		bi_cnt;		/* pin count */
+	struct kref		bi_kref;	/* pin count */
 
 	void			*bi_private;
 
@@ -249,7 +249,7 @@ struct bio {
  * returns. and then bio would be freed memory when if (bio->bi_flags ...)
  * runs
  */
-#define bio_get(bio)	atomic_inc(&(bio)->bi_cnt)
+#define bio_get(bio)	kref_get(&(bio)->bi_kref)
 
 
 /*

--

  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 ` [patch 2/3] use kref for io_context Akinobu Mita
2006-04-26  2:11 ` Akinobu Mita [this message]
2006-04-26  2:26   ` [patch 3/3] use kref for bio 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=20060426021122.069267000@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox