Re: Deadlock possibly caused by too_many_isolated.

Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
From: Wu Fengguang
Date: Sunday, October 24, 2010 - 9:52 am

On Fri, Oct 22, 2010 at 04:09:21PM +0800, Jens Axboe wrote:

You are right. The below scratch patch adds minimal mempool code for raid1.
It passed simple stress test of resync + 3 dd writers. Although write
throughput is rather slow in my qemu, I don't observe any
temporary/permanent stuck ups.

 drivers/md/raid1.c  |   32 ++++++++++++++++++++++++++++----
 drivers/md/raid1.h  |    2 ++
 fs/bio.c            |   31 +++++++++++++++++++++----------
 include/linux/bio.h |    2 ++
 4 files changed, 53 insertions(+), 14 deletions(-)

--- linux-next.orig/drivers/md/raid1.c	2010-10-25 00:02:40.000000000 +0800
+++ linux-next/drivers/md/raid1.c	2010-10-25 00:28:16.000000000 +0800
@@ -76,6 +76,14 @@ static void r1bio_pool_free(void *r1_bio
 	kfree(r1_bio);
 }
 
+static void r1_bio_destructor(struct bio *bio)
+{
+	r1bio_t *r1_bio = bio->bi_private;
+	conf_t *conf = r1_bio->mddev->private;
+
+	bio_free(bio, conf->r1_bio_set);
+}
+
 #define RESYNC_BLOCK_SIZE (64*1024)
 //#define RESYNC_BLOCK_SIZE PAGE_SIZE
 #define RESYNC_SECTORS (RESYNC_BLOCK_SIZE >> 9)
@@ -85,6 +93,7 @@ static void r1bio_pool_free(void *r1_bio
 static void * r1buf_pool_alloc(gfp_t gfp_flags, void *data)
 {
 	struct pool_info *pi = data;
+	conf_t *conf = pi->mddev->private;
 	struct page *page;
 	r1bio_t *r1_bio;
 	struct bio *bio;
@@ -100,7 +109,8 @@ static void * r1buf_pool_alloc(gfp_t gfp
 	 * Allocate bios : 1 for reading, n-1 for writing
 	 */
 	for (j = pi->raid_disks ; j-- ; ) {
-		bio = bio_alloc(gfp_flags, RESYNC_PAGES);
+		bio = bio_alloc_bioset(gfp_flags, RESYNC_PAGES,
+				       conf->r1_bio_set);
 		if (!bio)
 			goto out_free_bio;
 		r1_bio->bios[j] = bio;
@@ -386,6 +396,10 @@ static void raid1_end_write_request(stru
 				!test_bit(R1BIO_Degraded, &r1_bio->state),
 				behind);
 		md_write_end(r1_bio->mddev);
+		if (to_put) {
+			bio_put(to_put);
+			to_put = NULL;
+		}
 		raid_end_bio_io(r1_bio);
 	}
 
@@ -851,7 +865,7 @@ static int make_request(mddev_t *mddev, 
 		}
 		r1_bio->read_disk = rdisk;
 
-		read_bio = bio_clone(bio, GFP_NOIO);
+		read_bio = bio_clone_bioset(bio, GFP_NOIO, conf->r1_bio_set);
 
 		r1_bio->bios[rdisk] = read_bio;
 
@@ -946,7 +960,7 @@ static int make_request(mddev_t *mddev, 
 		if (!r1_bio->bios[i])
 			continue;
 
-		mbio = bio_clone(bio, GFP_NOIO);
+		mbio = bio_clone_bioset(bio, GFP_NOIO, conf->r1_bio_set);
 		r1_bio->bios[i] = mbio;
 
 		mbio->bi_sector	= r1_bio->sector + conf->mirrors[i].rdev->data_offset;
@@ -1646,7 +1660,9 @@ static void raid1d(mddev_t *mddev)
 					mddev->ro ? IO_BLOCKED : NULL;
 				r1_bio->read_disk = disk;
 				bio_put(bio);
-				bio = bio_clone(r1_bio->master_bio, GFP_NOIO);
+				bio = bio_clone_bioset(r1_bio->master_bio,
+						       GFP_NOIO,
+						       conf->r1_bio_set);
 				r1_bio->bios[r1_bio->read_disk] = bio;
 				rdev = conf->mirrors[disk].rdev;
 				if (printk_ratelimit())
@@ -1948,6 +1964,10 @@ static conf_t *setup_conf(mddev_t *mddev
 					  conf->poolinfo);
 	if (!conf->r1bio_pool)
 		goto abort;
+	conf->r1_bio_set = bioset_create(mddev->raid_disks * 2, 0);
+	if (!conf->r1_bio_set)
+		goto abort;
+	conf->r1_bio_set->bio_destructor = r1_bio_destructor;
 
 	conf->poolinfo->mddev = mddev;
 
@@ -2012,6 +2032,8 @@ static conf_t *setup_conf(mddev_t *mddev
 	if (conf) {
 		if (conf->r1bio_pool)
 			mempool_destroy(conf->r1bio_pool);
+		if (conf->r1_bio_set)
+			bioset_free(conf->r1_bio_set);
 		kfree(conf->mirrors);
 		safe_put_page(conf->tmppage);
 		kfree(conf->poolinfo);
@@ -2121,6 +2143,8 @@ static int stop(mddev_t *mddev)
 	blk_sync_queue(mddev->queue); /* the unplug fn references 'conf'*/
 	if (conf->r1bio_pool)
 		mempool_destroy(conf->r1bio_pool);
+	if (conf->r1_bio_set)
+		bioset_free(conf->r1_bio_set);
 	kfree(conf->mirrors);
 	kfree(conf->poolinfo);
 	kfree(conf);
--- linux-next.orig/fs/bio.c	2010-10-25 00:02:39.000000000 +0800
+++ linux-next/fs/bio.c	2010-10-25 00:03:37.000000000 +0800
@@ -306,6 +306,7 @@ out_set:
 	bio->bi_flags |= idx << BIO_POOL_OFFSET;
 	bio->bi_max_vecs = nr_iovecs;
 	bio->bi_io_vec = bvl;
+	bio->bi_destructor = bs->bio_destructor;
 	return bio;
 
 err_free:
@@ -340,12 +341,7 @@ static void bio_fs_destructor(struct bio
  */
 struct bio *bio_alloc(gfp_t gfp_mask, int nr_iovecs)
 {
-	struct bio *bio = bio_alloc_bioset(gfp_mask, nr_iovecs, fs_bio_set);
-
-	if (bio)
-		bio->bi_destructor = bio_fs_destructor;
-
-	return bio;
+	return bio_alloc_bioset(gfp_mask, nr_iovecs, fs_bio_set);
 }
 EXPORT_SYMBOL(bio_alloc);
 
@@ -460,20 +456,21 @@ void __bio_clone(struct bio *bio, struct
 EXPORT_SYMBOL(__bio_clone);
 
 /**
- *	bio_clone	-	clone a bio
+ *	bio_clone_bioset	-	clone a bio
  *	@bio: bio to clone
  *	@gfp_mask: allocation priority
+ *	@bs: bio_set to allocate from
  *
  * 	Like __bio_clone, only also allocates the returned bio
  */
-struct bio *bio_clone(struct bio *bio, gfp_t gfp_mask)
+struct bio *
+bio_clone_bioset(struct bio *bio, gfp_t gfp_mask, struct bio_set *bs)
 {
-	struct bio *b = bio_alloc_bioset(gfp_mask, bio->bi_max_vecs, fs_bio_set);
+	struct bio *b = bio_alloc_bioset(gfp_mask, bio->bi_max_vecs, bs);
 
 	if (!b)
 		return NULL;
 
-	b->bi_destructor = bio_fs_destructor;
 	__bio_clone(b, bio);
 
 	if (bio_integrity(bio)) {
@@ -489,6 +486,19 @@ struct bio *bio_clone(struct bio *bio, g
 
 	return b;
 }
+EXPORT_SYMBOL(bio_clone_bioset);
+
+/**
+ *	bio_clone	-	clone a bio
+ *	@bio: bio to clone
+ *	@gfp_mask: allocation priority
+ *
+ *	Like __bio_clone, only also allocates the returned bio
+ */
+struct bio *bio_clone(struct bio *bio, gfp_t gfp_mask)
+{
+	return bio_clone_bioset(bio, gfp_mask, fs_bio_set);
+}
 EXPORT_SYMBOL(bio_clone);
 
 /**
@@ -1664,6 +1674,7 @@ static int __init init_bio(void)
 	fs_bio_set = bioset_create(BIO_POOL_SIZE, 0);
 	if (!fs_bio_set)
 		panic("bio: can't allocate bios\n");
+	fs_bio_set->bio_destructor = bio_fs_destructor;
 
 	bio_split_pool = mempool_create_kmalloc_pool(BIO_SPLIT_ENTRIES,
 						     sizeof(struct bio_pair));
--- linux-next.orig/include/linux/bio.h	2010-10-25 00:02:40.000000000 +0800
+++ linux-next/include/linux/bio.h	2010-10-25 00:03:37.000000000 +0800
@@ -227,6 +227,7 @@ extern int bio_phys_segments(struct requ
 
 extern void __bio_clone(struct bio *, struct bio *);
 extern struct bio *bio_clone(struct bio *, gfp_t);
+extern struct bio *bio_clone_bioset(struct bio *, gfp_t, struct bio_set *);
 
 extern void bio_init(struct bio *);
 
@@ -299,6 +300,7 @@ struct bio_set {
 	mempool_t *bio_integrity_pool;
 #endif
 	mempool_t *bvec_pool;
+	bio_destructor_t	*bio_destructor;
 };
 
 struct biovec_slab {
--- linux-next.orig/drivers/md/raid1.h	2010-10-25 00:02:40.000000000 +0800
+++ linux-next/drivers/md/raid1.h	2010-10-25 00:03:37.000000000 +0800
@@ -60,6 +60,8 @@ struct r1_private_data_s {
 	mempool_t *r1bio_pool;
 	mempool_t *r1buf_pool;
 
+	struct bio_set *r1_bio_set;
+
 	/* When taking over an array from a different personality, we store
 	 * the new thread here until we fully activate the array.
 	 */
--
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
Deadlock possibly caused by too_many_isolated., Neil Brown, (Tue Sep 14, 4:11 pm)
Re: Deadlock possibly caused by too_many_isolated., Rik van Riel, (Tue Sep 14, 5:30 pm)
Re: Deadlock possibly caused by too_many_isolated., Neil Brown, (Tue Sep 14, 7:23 pm)
Re: Deadlock possibly caused by too_many_isolated., Wu Fengguang, (Tue Sep 14, 7:37 pm)
Re: Deadlock possibly caused by too_many_isolated., Wu Fengguang, (Tue Sep 14, 7:54 pm)
Re: Deadlock possibly caused by too_many_isolated., Wu Fengguang, (Tue Sep 14, 8:06 pm)
Re: Deadlock possibly caused by too_many_isolated., Wu Fengguang, (Tue Sep 14, 8:13 pm)
Re: Deadlock possibly caused by too_many_isolated., Neil Brown, (Tue Sep 14, 8:17 pm)
Re: Deadlock possibly caused by too_many_isolated., Shaohua Li, (Tue Sep 14, 8:18 pm)
Re: Deadlock possibly caused by too_many_isolated., Wu Fengguang, (Tue Sep 14, 8:31 pm)
Re: Deadlock possibly caused by too_many_isolated., Wu Fengguang, (Tue Sep 14, 8:47 pm)
Re: Deadlock possibly caused by too_many_isolated., Wu Fengguang, (Wed Sep 15, 1:28 am)
Re: Deadlock possibly caused by too_many_isolated., Neil Brown, (Wed Sep 15, 1:44 am)
Re: Deadlock possibly caused by too_many_isolated., Neil Brown, (Sun Oct 17, 9:14 pm)
Re: Deadlock possibly caused by too_many_isolated., KOSAKI Motohiro, (Sun Oct 17, 10:04 pm)
Re: Deadlock possibly caused by too_many_isolated., Torsten Kaiser, (Mon Oct 18, 3:58 am)
Re: Deadlock possibly caused by too_many_isolated., Wu Fengguang, (Mon Oct 18, 9:15 am)
Re: Deadlock possibly caused by too_many_isolated., Andrew Morton, (Mon Oct 18, 2:58 pm)
Re: Deadlock possibly caused by too_many_isolated., Neil Brown, (Mon Oct 18, 3:31 pm)
Re: Deadlock possibly caused by too_many_isolated., Andrew Morton, (Mon Oct 18, 3:41 pm)
Re: Deadlock possibly caused by too_many_isolated., Neil Brown, (Mon Oct 18, 4:11 pm)
Re: Deadlock possibly caused by too_many_isolated., KOSAKI Motohiro, (Mon Oct 18, 5:57 pm)
Re: Deadlock possibly caused by too_many_isolated., Minchan Kim, (Mon Oct 18, 6:15 pm)
Re: Deadlock possibly caused by too_many_isolated., KOSAKI Motohiro, (Mon Oct 18, 6:21 pm)
Re: Deadlock possibly caused by too_many_isolated., Minchan Kim, (Mon Oct 18, 6:32 pm)
Re: Deadlock possibly caused by too_many_isolated., KOSAKI Motohiro, (Mon Oct 18, 7:03 pm)
Re: Deadlock possibly caused by too_many_isolated., Minchan Kim, (Mon Oct 18, 7:16 pm)
Re: Deadlock possibly caused by too_many_isolated., Wu Fengguang, (Mon Oct 18, 7:24 pm)
Re: Deadlock possibly caused by too_many_isolated., Wu Fengguang, (Mon Oct 18, 7:35 pm)
Re: Deadlock possibly caused by too_many_isolated., KOSAKI Motohiro, (Mon Oct 18, 7:37 pm)
Re: Deadlock possibly caused by too_many_isolated., Minchan Kim, (Mon Oct 18, 7:37 pm)
Re: Deadlock possibly caused by too_many_isolated., Minchan Kim, (Mon Oct 18, 7:52 pm)
Re: Deadlock possibly caused by too_many_isolated., KOSAKI Motohiro, (Mon Oct 18, 7:54 pm)
Re: Deadlock possibly caused by too_many_isolated., Wu Fengguang, (Mon Oct 18, 8:05 pm)
Re: Deadlock possibly caused by too_many_isolated., Minchan Kim, (Mon Oct 18, 8:09 pm)
Re: Deadlock possibly caused by too_many_isolated., KOSAKI Motohiro, (Mon Oct 18, 8:13 pm)
Re: Deadlock possibly caused by too_many_isolated., Shaohua Li, (Mon Oct 18, 8:21 pm)
Re: Deadlock possibly caused by too_many_isolated., Minchan Kim, (Mon Oct 18, 10:11 pm)
Re: Deadlock possibly caused by too_many_isolated., Shaohua Li, (Tue Oct 19, 12:15 am)
Re: Deadlock possibly caused by too_many_isolated., Minchan Kim, (Tue Oct 19, 12:34 am)
Re: Deadlock possibly caused by too_many_isolated., Torsten Kaiser, (Tue Oct 19, 1:43 am)
Re: Deadlock possibly caused by too_many_isolated., Torsten Kaiser, (Tue Oct 19, 3:06 am)
Re: Deadlock possibly caused by too_many_isolated., Wu Fengguang, (Tue Oct 19, 10:57 pm)
Re: Deadlock possibly caused by too_many_isolated., KOSAKI Motohiro, (Wed Oct 20, 12:05 am)
Re: Deadlock possibly caused by too_many_isolated., Torsten Kaiser, (Wed Oct 20, 12:25 am)
Re: Deadlock possibly caused by too_many_isolated., Wu Fengguang, (Wed Oct 20, 2:01 am)
Re: Deadlock possibly caused by too_many_isolated., Wu Fengguang, (Wed Oct 20, 2:27 am)
Re: Deadlock possibly caused by too_many_isolated., Torsten Kaiser, (Wed Oct 20, 3:07 am)
Re: Deadlock possibly caused by too_many_isolated., Jens Axboe, (Wed Oct 20, 6:03 am)
Re: Deadlock possibly caused by too_many_isolated., Minchan Kim, (Wed Oct 20, 7:23 am)
Re: Deadlock possibly caused by too_many_isolated., Torsten Kaiser, (Wed Oct 20, 8:35 am)
Re: Deadlock possibly caused by too_many_isolated., Minchan Kim, (Wed Oct 20, 4:31 pm)
Re: Deadlock possibly caused by too_many_isolated., Wu Fengguang, (Thu Oct 21, 10:37 pm)
Re: Deadlock possibly caused by too_many_isolated., Wu Fengguang, (Fri Oct 22, 1:07 am)
Re: Deadlock possibly caused by too_many_isolated., Jens Axboe, (Fri Oct 22, 1:09 am)
Re: Deadlock possibly caused by too_many_isolated., Wu Fengguang, (Sun Oct 24, 9:52 am)
Re: Deadlock possibly caused by too_many_isolated., Neil Brown, (Sun Oct 24, 11:40 pm)
Re: Deadlock possibly caused by too_many_isolated., Wu Fengguang, (Mon Oct 25, 12:26 am)