diff mbox

[4/8,dm-bio-prison] Change the bio-prison interface so the memory for the cells is passed in.

Message ID 20130121233245.GF27093@agk-dp.fab.redhat.com (mailing list archive)
State Deferred, archived
Headers show

Commit Message

Alasdair G Kergon Jan. 21, 2013, 11:32 p.m. UTC
On Thu, Dec 13, 2012 at 08:19:12PM +0000, Joe Thornber wrote:
> @@ -87,6 +79,20 @@ void dm_bio_prison_destroy(struct dm_bio_prison *prison)
>  }
>  EXPORT_SYMBOL_GPL(dm_bio_prison_destroy);
>  
> +struct dm_bio_prison_cell *
> +dm_bio_prison_alloc_cell(struct dm_bio_prison *prison, gfp_t gfp)

Let's keep that on one line.

> +int dm_bio_detain(struct dm_bio_prison *prison,
> +		  struct dm_cell_key *key,
> +		  struct bio *inmate,
> +		  struct dm_bio_prison_cell *memory,

The caller has already allocated 'memory' specifically to hold that struct.
Call it 'new_cell' perhaps?   'cell_prealloc' ?

> +		  struct dm_bio_prison_cell **ref)

cell_ref ?

> @@ -226,6 +226,53 @@ struct thin_c {
>  
>  /*----------------------------------------------------------------*/
>  
> +static int bio_detain(struct pool *pool, struct dm_cell_key *key, struct bio *bio,
> +		      struct dm_bio_prison_cell **result)
> +{
> +	int r;
> +	struct dm_bio_prison_cell *cell;
> +
> +	cell = dm_bio_prison_alloc_cell(pool->prison, GFP_NOIO);
> +	if (!cell)
> +		return -ENOMEM;

Redundant test?  The mempool allocation always succeeds (or blocks).

> +	r = dm_bio_detain(pool->prison, key, bio, cell, result);
> +
> +	if (r)
> +		/*
> +		 * We reused an old cell, or errored; we can get rid of

Can't have errored that I can see.

> +		 * the new one.
> +		 */
> +		dm_bio_prison_free_cell(pool->prison, cell);
> +
> +	return r;
> +}

Alasdair





--
dm-devel mailing list
dm-devel@redhat.com
https://www.redhat.com/mailman/listinfo/dm-devel

Comments

Joe Thornber Jan. 22, 2013, 11:31 a.m. UTC | #1
Alasdair,

I've pushed changes to the thin-dev and all-caches branches of my
github tree:

https://github.com/jthornber/linux-2.6.git

https://github.com/jthornber/linux-2.6/commit/ed52136ac238af0958b89b29749e27f049e0cb0c
https://github.com/jthornber/linux-2.6/commit/cf5273fe5f4e77b3df3acdbfc6bb09ff76dafcbd
https://github.com/jthornber/linux-2.6/commit/6e77ba56b8bbd21f43f00c2551c01a2e7d10aaf9

Note the mempool alloc _can_ fail with GFP_NOIO/GFP_NOWAIT.

- Joe

--
dm-devel mailing list
dm-devel@redhat.com
https://www.redhat.com/mailman/listinfo/dm-devel
Alasdair G Kergon Jan. 22, 2013, 12:10 p.m. UTC | #2
On Tue, Jan 22, 2013 at 11:31:49AM +0000, Joe Thornber wrote:
> Note the mempool alloc _can_ fail with GFP_NOIO/GFP_NOWAIT.

Not with GFP_NOIO.

include/linux/gfp.h:
#define GFP_NOIO        (__GFP_WAIT)

mempool_alloc():
        might_sleep_if(gfp_mask & __GFP_WAIT);

Alasdair

--
dm-devel mailing list
dm-devel@redhat.com
https://www.redhat.com/mailman/listinfo/dm-devel
diff mbox

Patch

--- a/dm-bio-prison.c	2013-01-14 19:32:36.000000000 +0000
+++ b/dm-bio-prison.c	2013-01-21 23:09:49.000000000 +0000
@@ -79,8 +79,7 @@ 
 }
 EXPORT_SYMBOL_GPL(dm_bio_prison_destroy);
 
-struct dm_bio_prison_cell *
-dm_bio_prison_alloc_cell(struct dm_bio_prison *prison, gfp_t gfp)
+struct dm_bio_prison_cell *dm_bio_prison_alloc_cell(struct dm_bio_prison *prison, gfp_t gfp)
 {
 	return mempool_alloc(prison->cell_pool, gfp);
 }
--- a/dm-thin.c	2013-01-18 15:00:00.000000000 +0000
+++ b/dm-thin.c	2013-01-21 23:09:48.000000000 +0000
@@ -250,16 +250,16 @@ 
 	int r;
 	struct dm_bio_prison_cell *cell;
 
+	/*
+	 * Allocate a cell from the prison's mempool.
+	 * This might block but it can't fail.
+	 */
 	cell = dm_bio_prison_alloc_cell(pool->prison, GFP_NOIO);
-	if (!cell)
-		return -ENOMEM;
 
 	r = dm_bio_detain(pool->prison, key, bio, cell, result);
-
 	if (r)
 		/*
-		 * We reused an old cell, or errored; we can get rid of
-		 * the new one.
+		 * We reused an old cell: get rid of the new one.
 		 */
 		dm_bio_prison_free_cell(pool->prison, cell);