Another cache target
Subsystems (3)
Here's a cache target that Heinz Mauelshagen, Mike Snitzer and I have been working on.
It's also available in the thin-dev branch of my git tree:
[email protected]:jthornber/linux-2.6.git
The main features are a plug-in architecture for policies which decide what data gets cached, and reuse of the metadata library from the thin provisioning target.
These patches apply on top of the dm patches that agk has got queued for 3.8.
If anyone has the time to try it out I'd love to hear how you get on.
PATCH 1/8 Fix a bug in btree_del, and another bug that was compensating for it.
When deleting nested btrees the inner most btree wasn't being deleted.
The thin-metadata code was serendipitously compensating for this by claiming there was one extra layer in the tree.
--- drivers/md/dm-thin-metadata.c | 2 +- drivers/md/persistent-data/dm-btree.c | 9 +++++++-- 2 files changed, 8 insertions(+), 3 deletions(-)
drivers/md/dm-thin-metadata.c +1 -1
@@ -408,7 +408,7 @@ static void __setup_btree_details(struct dm_pool_metadata *pmd) pmd->tl_info.tm = pmd->tm; pmd->tl_info.levels =1 ; - pmd->tl_info.value_type.context = &pmd->info; + pmd->tl_info.value_type.context = &pmd->bl_info; pmd->tl_info.value_type.size =sizeof (__le64); pmd->tl_info.value_type.inc = subtree_inc; pmd->tl_info.value_type.dec = subtree_dec;
drivers/md/persistent-data/dm-btree.c +7 -2
@@ -230,6 +230,11 @@ static void pop_frame(struct del_stack *s)dm_tm_unlock (s->tm, f->b); } +static bool is_internal_level (struct dm_btree_info *info,struct frame *f) +{ +return f->level < (info->levels -1 ); +} +int dm_btree_del (struct dm_btree_info *info,dm_block_t root) {int r;
@@ -241,7 +246,7 @@ int dm_btree_del(struct dm_btree_info *info, dm_block_t root) s->tm = info->tm; s->top =-1 ; - r =push_frame (s, root,1 ); + r =push_frame (s, root,0 );if (r) goto out;
@@ -267,7 +272,7 @@ int dm_btree_del(struct dm_btree_info *info, dm_block_t root)if (r) goto out; - }else if (f->level != (info->levels -1 )) { + }else if (is_internal_level (info, f)) { b =value64 (f->n, f->current_child); f->current_child++; r =push_frame (s, b, f->level +1 );
Signature · 1 line
1.7.10.4
PATCH 2/8 dm_btree_walk
In reply to Joe ThornberIterates the contents of a btree.
--- drivers/md/persistent-data/dm-btree-internal.h | 1 + drivers/md/persistent-data/dm-btree-spine.c | 7 ++++ drivers/md/persistent-data/dm-btree.c | 52 ++++++++++++++++++++++++ drivers/md/persistent-data/dm-btree.h | 3 ++ 4 files changed, 63 insertions(+)
drivers/md/persistent-data/dm-btree-internal.h +1 -0
@@ -64,6 +64,7 @@ struct ro_spine {void init_ro_spine (struct ro_spine *s,struct dm_btree_info *info);int exit_ro_spine (struct ro_spine *s);int ro_step (struct ro_spine *s,dm_block_t new_child); +void ro_pop (struct ro_spine *s);struct btree_node *ro_node (struct ro_spine *s);struct shadow_spine {
drivers/md/persistent-data/dm-btree-spine.c +7 -0
@@ -164,6 +164,13 @@ int ro_step(struct ro_spine *s, dm_block_t new_child)return r; } +void ro_pop (struct ro_spine *s) +{ +BUG_ON (!s->count); + --s->count; +unlock_block (s->info, s->nodes[s->count]); +} +struct btree_node *ro_node (struct ro_spine *s) {struct dm_block *block;
drivers/md/persistent-data/dm-btree.c +52 -0
55 lines not on this page · raw message
drivers/md/persistent-data/dm-btree.h +3 -0
@@ -142,4 +142,7 @@ int dm_btree_remove(struct dm_btree_info *info, dm_block_t root,int dm_btree_find_highest_key (struct dm_btree_info *info,dm_block_t root,uint64_t *result_keys); +int dm_btree_walk (struct dm_btree_info *info,dm_block_t root, +int (*fn)(void *,uint64_t *keys,void *leaf),void *context); +#endif /* _LINUX_DM_BTREE_H */
Signature · 1 line
1.7.10.4
PATCH 3/8 tweak an error message
In reply to Joe Thornber--- drivers/md/persistent-data/dm-space-map-metadata.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/md/persistent-data/dm-space-map-metadata.c +1 -1
@@ -337,7 +337,7 @@ static int sm_metadata_new_block(struct dm_space_map *sm, dm_block_t *b) {int r =sm_metadata_new_block_ (sm, b);if (r) -DMERR ("out of metadata space" ); +DMERR ("unable to allocate new metadata block" );return r; }
Signature · 1 line
1.7.10.4
PATCH 4/8 Change the bio-prison interface so the memory for the cells is passed in.
In reply to Joe Thornber--- drivers/md/dm-bio-prison.c | 156 +++++++++++++++++++++++--------------------- drivers/md/dm-bio-prison.h | 51 ++++++++++++--- drivers/md/dm-thin.c | 102 +++++++++++++++++++++-------- 3 files changed, 200 insertions(+), 109 deletions(-)
drivers/md/dm-bio-prison.c +82 -74
@@ -14,14 +14,6 @@/*----------------------------------------------------------------*/ -struct dm_bio_prison_cell { -struct hlist_node list; -struct dm_bio_prison *prison; -struct dm_cell_key key; -struct bio *holder; -struct bio_list bios; -}; -struct dm_bio_prison {spinlock_t lock;mempool_t *cell_pool;
@@ -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) +{ +return mempool_alloc (prison->cell_pool, gfp); +} +EXPORT_SYMBOL_GPL (dm_bio_prison_alloc_cell); + +void dm_bio_prison_free_cell (struct dm_bio_prison *prison, +struct dm_bio_prison_cell *cell) +{ +mempool_free (cell, prison->cell_pool); +} +EXPORT_SYMBOL_GPL (dm_bio_prison_free_cell); +static uint32_t hash_key (struct dm_bio_prison *prison,struct dm_cell_key *key) {const unsigned long BIG_PRIME =4294967291UL ;
@@ -115,91 +121,95 @@ static struct dm_bio_prison_cell *__search_bucket(struct hlist_head *bucket,return NULL ; } -/* -* This may block if a new cell needs allocating. You must ensure that -* cells will be unlocked even if the calling thread is blocked. -* -* Returns 1 if the cell was already held, 0 if @inmate is the new holder. -*/ -int dm_bio_detain (struct dm_bio_prison *prison,struct dm_cell_key *key, -struct bio *inmate,struct dm_bio_prison_cell **ref) +static void __setup_new_cell (struct dm_bio_prison *prison, +struct dm_cell_key *key, +struct bio *holder, +uint32_t hash, +struct dm_bio_prison_cell *cell) { -int r =1 ; -unsigned long flags; -uint32_t hash =hash_key (prison, key); -struct dm_bio_prison_cell *cell, *cell2; - -BUG_ON (hash > prison->nr_buckets); - -spin_lock_irqsave (&prison->lock, flags); - - cell =__search_bucket (prison->cells + hash, key); -if (cell) { -bio_list_add (&cell->bios, inmate); - goto out; - } +memcpy (&cell->key, key,sizeof (cell->key)); + cell->holder = holder; +bio_list_init (&cell->bios); +hlist_add_head (&cell->list, prison->cells + hash); +} -/* -* Allocate a new cell -*/ -spin_unlock_irqrestore (&prison->lock, flags); - cell2 =mempool_alloc (prison->cell_pool,GFP_NOIO ); -spin_lock_irqsave (&prison->lock, flags); +static int __bio_detain (struct dm_bio_prison *prison, +struct dm_cell_key *key, +struct bio *inmate, +struct dm_bio_prison_cell *memory, +struct dm_bio_prison_cell **ref) +{ +uint32_t hash =hash_key (prison, key); +struct dm_bio_prison_cell *cell; -/* -* We've been unlocked, so we have to double check that -* nobody else has inserted this cell in the meantime. -*/ cell =__search_bucket (prison->cells + hash, key);if (cell) { -mempool_free (cell2, prison->cell_pool); -bio_list_add (&cell->bios, inmate); - goto out; +if (inmate) +bio_list_add (&cell->bios, inmate); + *ref = cell; +return 1 ; } -/* -* Use new cell. -*/ - cell = cell2; - - cell->prison = prison; -memcpy (&cell->key, key,sizeof (cell->key)); - cell->holder = inmate; -bio_list_init (&cell->bios); -hlist_add_head (&cell->list, prison->cells + hash); +__setup_new_cell (prison, key, inmate, hash, memory); + *ref = memory; +return 0 ; +} - r =0 ; +static int bio_detain (struct dm_bio_prison *prison, +struct dm_cell_key *key, +struct bio *inmate, +struct dm_bio_prison_cell *memory, +struct dm_bio_prison_cell **ref) +{ +int r; +unsigned long flags; -out: +spin_lock_irqsave (&prison->lock, flags); + r =__bio_detain (prison, key, inmate, memory, ref);spin_unlock_irqrestore (&prison->lock, flags); - *ref = cell; -return r; } + +int dm_bio_detain (struct dm_bio_prison *prison, +struct dm_cell_key *key, +struct bio *inmate, +struct dm_bio_prison_cell *memory, +struct dm_bio_prison_cell **ref) +{ +return bio_detain (prison, key, inmate, memory, ref); +}EXPORT_SYMBOL_GPL (dm_bio_detain); +int dm_get_cell (struct dm_bio_prison *prison, +struct dm_cell_key *key, +struct dm_bio_prison_cell *memory, +struct dm_bio_prison_cell **ref) +{ +return bio_detain (prison, key,NULL , memory, ref); +} +EXPORT_SYMBOL_GPL (dm_get_cell); +/* * @inmates must have been initialised prior to this call */ -static void __cell_release (struct dm_bio_prison_cell *cell,struct bio_list *inmates) +static void __cell_release (struct dm_bio_prison_cell *cell, +struct bio_list *inmates) { -struct dm_bio_prison *prison = cell->prison; -hlist_del (&cell->list);if (inmates) { -bio_list_add (inmates, cell->holder); +if (cell->holder) +bio_list_add (inmates, cell->holder);bio_list_merge (inmates, &cell->bios); } - -mempool_free (cell, prison->cell_pool); } -void dm_cell_release (struct dm_bio_prison_cell *cell,struct bio_list *bios) +void dm_cell_release (struct dm_bio_prison *prison, +struct dm_bio_prison_cell *cell, +struct bio_list *bios) {unsigned long flags; -struct dm_bio_prison *prison = cell->prison;spin_lock_irqsave (&prison->lock, flags);__cell_release (cell, bios);
@@ -210,20 +220,18 @@ EXPORT_SYMBOL_GPL(dm_cell_release);/* * Sometimes we don't want the holder, just the additional bios. */ -static void __cell_release_no_holder (struct dm_bio_prison_cell *cell,struct bio_list *inmates) +static void __cell_release_no_holder (struct dm_bio_prison_cell *cell, +struct bio_list *inmates) { -struct dm_bio_prison *prison = cell->prison; -hlist_del (&cell->list);bio_list_merge (inmates, &cell->bios); - -mempool_free (cell, prison->cell_pool); } -void dm_cell_release_no_holder (struct dm_bio_prison_cell *cell,struct bio_list *inmates) +void dm_cell_release_no_holder (struct dm_bio_prison *prison, +struct dm_bio_prison_cell *cell, +struct bio_list *inmates) {unsigned long flags; -struct dm_bio_prison *prison = cell->prison;spin_lock_irqsave (&prison->lock, flags);__cell_release_no_holder (cell, inmates);
@@ -231,9 +239,9 @@ void dm_cell_release_no_holder(struct dm_bio_prison_cell *cell, struct bio_list }EXPORT_SYMBOL_GPL (dm_cell_release_no_holder); -void dm_cell_error (struct dm_bio_prison_cell *cell) +void dm_cell_error (struct dm_bio_prison *prison, +struct dm_bio_prison_cell *cell) { -struct dm_bio_prison *prison = cell->prison;struct bio_list bios;struct bio *bio;unsigned long flags;
drivers/md/dm-bio-prison.h +42 -9
70 lines not on this page · raw message
drivers/md/dm-thin.c +76 -26
264 lines not on this page · raw message
Signature · 1 line
1.7.10.4
Alasdair G Kergon
maintainerRe: [PATCH 4/8] [dm-bio-prison] Change the bio-prison interface so the memory for the cells is passed in.
Quoted 1 line · Joe Thornber
---
What is the motivation for changing this?
Alasdair
Re: [PATCH 4/8] [dm-bio-prison] Change the bio-prison interface so the memory for the cells is passed in.
Quoted 4 lines · Alasdair G Kergon
Quoted 1 line · Joe Thornber
---
What is the motivation for changing this?
Avoiding allocating memory on the main map path for dm-cache.
Alasdair G Kergon
maintainerRe: [PATCH 4/8] [dm-bio-prison] Change the bio-prison interface so the memory for the cells is passed in.
Quoted 3 lines · Joe Thornber
Quoted 1 line · Alasdair G Kergon
What is the motivation for changing this?
Avoiding allocating memory on the main map path for dm-cache.
What is the different about dm-cache that makes this a problem where it is not a problem for dm-thin?
Alasdair
Alasdair G Kergon
maintainerRe: [PATCH 4/8] [dm-bio-prison] Change the bio-prison interface so the memory for the cells is passed in.
In reply to Joe ThornberReview void dm_bio_prison_destroy(struct dm_bio_prison *prison) · line 83
Quoted 6 lines · Joe Thornber
(quoted diff) +2
-0@@ -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.
Review void dm_bio_prison_destroy(struct dm_bio_prison *prison) · line 87
Quoted 4 lines
(quoted diff) +4
-0+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' ?
Review void dm_bio_prison_destroy(struct dm_bio_prison *prison) · line 88
Quoted 1 line
(quoted diff) +1
-0+ struct dm_bio_prison_cell **ref)
cell_ref ?
Review struct thin_c { · line 237
Quoted 13 lines
(quoted diff) +9
-0@@ -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).
Review struct thin_c { · line 242
Quoted 5 lines
(quoted diff) +5
-0+ 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.
Review struct thin_c { · line 248
Quoted 6 lines
(quoted diff) +6
-0+ * the new one. + */ + dm_bio_prison_free_cell(pool->prison, cell); + + return r; +}
Alasdair
dm-bio-prison.c +1 -2
@@ -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); }
dm-thin.c +5 -5
@@ -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);
Re: [PATCH 4/8] [dm-bio-prison] Change the bio-prison interface so the memory for the cells is passed in.
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
Alasdair G Kergon
maintainerRe: [PATCH 4/8] [dm-bio-prison] Change the bio-prison interface so the memory for the cells is passed in.
Quoted 1 line · Joe Thornber
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
PATCH 5/8 Fix a race condition between discard bios and ordinary bios.
In reply to Joe ThornberThe deferred_set entries should not be incremented until the bio prison cells are held. Otherwise quiescing a block for discard may end up waiting for a bio that's held in the discard bios cell.
--- drivers/md/dm-thin.c | 59 +++++++++++++++++++++++++++++++++++++------------- 1 file changed, 44 insertions(+), 15 deletions(-)
drivers/md/dm-thin.c +44 -15
@@ -222,10 +222,28 @@ struct thin_c {struct pool *pool;struct dm_thin_device *td; + +/* +* The cell structures are too big to put on the stack, so we have +* a couple here for use by the main mapping function. +*/ +spinlock_t lock; +struct dm_bio_prison_cell cell1, cell2; };/*----------------------------------------------------------------*/ +/* +* wake_worker() is used when new work is queued and when pool_resume is +* ready to continue deferred IO processing. +*/ +static void wake_worker (struct pool *pool) +{ +queue_work (pool->wq, &pool->worker); +} + +/*----------------------------------------------------------------*/ +static int bio_detain (struct pool *pool,struct dm_cell_key *key,struct bio *bio,struct dm_bio_prison_cell **result) {
@@ -264,6 +282,19 @@ static void cell_release_no_holder(struct pool *pool,dm_bio_prison_free_cell (pool->prison, cell); } +static void cell_defer_no_holder_no_free (struct thin_c *tc, +struct dm_bio_prison_cell *cell) +{ +struct pool *pool = tc->pool; +unsigned long flags; + +spin_lock_irqsave (&pool->lock, flags); +dm_cell_release_no_holder (pool->prison, cell, &pool->deferred_bios); +spin_unlock_irqrestore (&pool->lock, flags); + +wake_worker (pool); +} +static void cell_error (struct pool *pool,struct dm_bio_prison_cell *cell) {
@@ -467,15 +498,6 @@ static void remap_and_issue(struct thin_c *tc, struct bio *bio,issue (tc, bio); } -/* -* wake_worker() is used when new work is queued and when pool_resume is -* ready to continue deferred IO processing. -*/ -static void wake_worker (struct pool *pool) -{ -queue_work (pool->wq, &pool->worker); -} -/*----------------------------------------------------------------*/ /*
@@ -1429,8 +1451,8 @@ static int thin_bio_map(struct dm_target *ti, struct bio *bio)dm_block_t block =get_bio_block (tc, bio);struct dm_thin_device *td = tc->td;struct dm_thin_lookup_result result; -struct dm_bio_prison_cell *cell1, *cell2;struct dm_cell_key key; +struct dm_bio_prison_cell *cell_result;thin_hook_bio (tc, bio);
@@ -1470,19 +1492,24 @@ static int thin_bio_map(struct dm_target *ti, struct bio *bio)return DM_MAPIO_SUBMITTED ; } +spin_lock (&tc->lock);build_virtual_key (tc->td, block, &key); -if (bio_detain (tc->pool, &key, bio, &cell1)) +if (dm_bio_detain (tc->pool->prison, &key, bio, &tc->cell1, &cell_result)) { +spin_unlock (&tc->lock);return DM_MAPIO_SUBMITTED ; + }build_data_key (tc->td, result.block, &key); -if (bio_detain (tc->pool, &key, bio, &cell2)) { -cell_defer_no_holder (tc, cell1); +if (dm_bio_detain (tc->pool->prison, &key, bio, &tc->cell2, &cell_result)) { +cell_defer_no_holder_no_free (tc, &tc->cell1); +spin_unlock (&tc->lock);return DM_MAPIO_SUBMITTED ; }inc_all_io_entry (tc->pool, bio); -cell_defer_no_holder (tc, cell2); -cell_defer_no_holder (tc, cell1); +cell_defer_no_holder_no_free (tc, &tc->cell2); +cell_defer_no_holder_no_free (tc, &tc->cell1); +spin_unlock (&tc->lock);remap (tc, bio, result.block);return DM_MAPIO_REMAPPED ;
@@ -2638,6 +2665,8 @@ static int thin_ctr(struct dm_target *ti, unsigned argc, char **argv)if (r) goto bad_thin_open; +spin_lock_init (&tc->lock); + ti->num_flush_requests =1 ; ti->flush_supported = true; ti->per_bio_data_size =sizeof (struct dm_thin_endio_hook );
Signature · 1 line
1.7.10.4
Re: [PATCH 5/8] [dm-thin] Fix a race condition between discard bios and ordinary bios.
Quoted 3 lines · Joe Thornber
The
deferred_setentries should not be incremented until the bio prison cells are held. Otherwise quiescing a block for discard may end up waiting for a bio that's held in the discard bios cell.
This patch's subject and header needs help. We've already fixed the race with discards and normal bios in an earlier patch:
https://www.redhat.com/archives/dm-devel/2012-December/msg00010.html
This patch is purely about adapting dm-thin to use the new bio-prison interface where the memory is now passed in rather than using a mempool in bio-prison. Two preallocated cells are now included in struct thin_c; this allows the map function to not block performing allocations (we want to avoid the cell allocation that is done in bio_detain).
The thin_c is allocated once in the constructor (thin_ctr). Because the thin_c is a shared resource, access to its cells must be serialized using a new spinlock.
(NOTE: elevating the dm_bio_prison_cell structure from dm-bio-prison.c to dm-bio-prison.h really should be part of this patch -- rather than the previous patch).
Alasdair G Kergon
maintainerRe: [PATCH 5/8] [dm-thin] Fix a race condition between discard bios and ordinary bios.
In reply to Joe Thornberdrivers/md/dm-thin.c static int thin_bio_map(struct dm_target *ti, struct bio *bio) · line 1497
Quoted 13 lines · Joe Thornber
drivers/md/dm-thin.c +2
-1@@ -1470,19 +1492,24 @@ static int thin_bio_map(struct dm_target *ti, struct bio *bio)return DM_MAPIO_SUBMITTED ; } +spin_lock (&tc->lock);build_virtual_key (tc->td, block, &key); -if (bio_detain (tc->pool, &key, bio, &cell1)) +if (dm_bio_detain (tc->pool->prison, &key, bio, &tc->cell1, &cell_result)) {
Use same variable name cell_result down in the depths of the function itself and all its callers?
Alasdair
Alasdair G Kergon
maintainerRe: [PATCH 5/8] [dm-thin] Fix a race condition between discard bios and ordinary bios.
In reply to Joe ThornberQuoted 5 lines · Joe Thornber
drivers/md/dm-thin.c +0
-0
drivers/md/dm-thin.c struct thin_c { · line 231
Quoted 10 lines
drivers/md/dm-thin.c +7
-0@@ -222,10 +222,28 @@ struct thin_c {struct pool *pool;struct dm_thin_device *td; + +/* +* The cell structures are too big to put on the stack, so we have +* a couple here for use by the main mapping function. +*/ +spinlock_t lock; +struct dm_bio_prison_cell cell1, cell2;
We're also trying to cut down on locking on these code paths. (High i/o load, many many cores?)
Have you hit any problems while testing due to the stack size? The cells don't seem ridiculously big - could we perhaps just put them on the stack for now? If we do hit stack size problems in real world configurations, then we can try to compare the locking approach with an approach that uses a separate (local) mempool for each cell (or a mempool with double-sized elements).
drivers/md/dm-thin.c static int thin_bio_map(struct dm_target *ti, struct bio *bio) · line 1497
Quoted 2 lines
drivers/md/dm-thin.c +1
-1-if (bio_detain (tc->pool, &key, bio, &cell1)) +if (dm_bio_detain (tc->pool->prison, &key, bio, &tc->cell1, &cell_result)) {
This deals with the existing upstream mempool deadlock, but there are still some other calls to bio_detain() remaining in the file in other functions that take one cell from a mempool and, before returning it, may require a second cell from the same mempool, which could lead to a deadlock.
Can they be fixed too? (Multiple mempools/larger mempool elements where there isn't such an easy on-stack fix? In the worst case we might later end up unable to avoid having to use the bio front_pad.)
Alasdair
Re: [PATCH 5/8] [dm-thin] Fix a race condition between discard bios and ordinary bios.
Quoted 20 lines · Alasdair G Kergon
Quoted 5 lines · Joe Thornber
drivers/md/dm-thin.c +0
-0drivers/md/dm-thin.c struct thin_c { · line 231
Quoted 10 lines
drivers/md/dm-thin.c +7
-0@@ -222,10 +222,28 @@ struct thin_c {struct pool *pool;struct dm_thin_device *td; + +/* +* The cell structures are too big to put on the stack, so we have +* a couple here for use by the main mapping function. +*/ +spinlock_t lock; +struct dm_bio_prison_cell cell1, cell2;We're also trying to cut down on locking on these code paths. (High i/o load, many many cores?)
Quoted 6 lines
Have you hit any problems while testing due to the stack size? The cells don't seem ridiculously big - could we perhaps just put them on the stack for now? If we do hit stack size problems in real world configurations, then we can try to compare the locking approach with an approach that uses a separate (local) mempool for each cell (or a mempool with double-sized elements).
I haven't hit any stack size issues. But the cell structures are 60 bytes each and putting two of them on the stack seems wasteful. I don't have enough knowledge to say this will be ok for all architectures and so took the safe option.
As for the spinlock; I agree that we need to be getting rid of locks on the fast path. There are two separate concerns here.
i) lock contention. We hold spin locks for short periods so hopefully this isn't happening much. I admit this has been my main focus when reasoning about the cost of locks.
ii) cpu cache invalidation caused by memory barriers. Harder to reason about. We just have to test well. Removing locks will be a compromise in other ways and we need to be careful to show we're improving performance. I think this is what the community is concerned about now?
The map function in dm-thin calls dm_thin_find_block() which hides a multitude of locking:
i) All functions in dm-thin-metadata.c grab a top level rw semaphore. In the map function's case we use a try_read_lock so it wont block, if it would block the bio is deferred to the worker thread.
ii) Whenever we get a metadata block from the block manager's cache, for instance as part of a btree lookup for the mapping, a rwsem is grabbed for the block. Again the fast path uses non-blocking variants to exit early.
We don't need both (i) and (ii). The original intention was to just have block level locking. The btree code is written carefully to allow concurrent updates and lookups using a rolling lock scheme. To get this working we need to put some form of quiescing into the commit code; we must ensure no read operations are in flight on a btree from the prior transaction before committing the current one. This commit barrier shouldn't be hard to put in.
Alternatively we could accept that the top level rwsem is there and just ditch the block level locking. I'd still want to keep it as a debug option, since it's great for catching errors in the metadata handling. In fact I did have this as an option in Kconfig originally but you asked me to turn it on always.
Summarising our options:
a) top level spin lock to protect the 'root block' field in thin_metadata, and implement the commit barrier. And a spin lock on every metadata block aquisition. More locks but the concurrent lookup/update for the btrees will mean fewer bios get deferred by the map function to another thread.
b) Top level rwsem. Drop block locking except as a debug option. More bios handed over to a separate thread for processing.
(b) is certainly simpler; if you'd like to go back to this say and I'll get a patch to you. (a) is better if you're just considering lock contention, but it clearly will trigger more memory barriers.
Either way I think you should merge the patch as given. You've just focussed on the spin lock because you can see it being called from that map function. If we're serious about reducing locks then the above piece of work is where we should start.
Quoted 9 lines
drivers/md/dm-thin.c static int thin_bio_map(struct dm_target *ti, struct bio *bio) · line 1497
Quoted 2 lines
drivers/md/dm-thin.c +1
-1-if (bio_detain (tc->pool, &key, bio, &cell1)) +if (dm_bio_detain (tc->pool->prison, &key, bio, &tc->cell1, &cell_result)) {This deals with the existing upstream mempool deadlock, but there are still some other calls to
bio_detain()remaining in the file in other functions that take one cell from a mempool and, before returning it, may require a second cell from the same mempool, which could lead to a deadlock.
Quoted 3 lines
Can they be fixed too? (Multiple mempools/larger mempool elements where there isn't such an easy on-stack fix? In the worst case we might later end up unable to avoid having to use the bio
front_pad.)
Yes, I've been unable to trigger this though so it dropped down in priority. We can use a similar approach to what I've done in dm-cache and have a little 'prealloced_structs' object that we fill in at an apposite moment. I'll get a patch to you, this is additional work and shouldn't hold up the current patch.
- Joe
Mikulas Patocka
maintainerRe: [PATCH 5/8] [dm-thin] Fix a race condition between discard bios and ordinary bios.
Quoted 28 lines · On Thu, 24 Jan 2013, [email protected] wrote:
Quoted 20 lines · Alasdair G Kergon
Quoted 5 lines · Joe Thornber
drivers/md/dm-thin.c +0
-0drivers/md/dm-thin.c struct thin_c { · line 231
Quoted 10 lines
drivers/md/dm-thin.c +7
-0@@ -222,10 +222,28 @@ struct thin_c {struct pool *pool;struct dm_thin_device *td; + +/* +* The cell structures are too big to put on the stack, so we have +* a couple here for use by the main mapping function. +*/ +spinlock_t lock; +struct dm_bio_prison_cell cell1, cell2;We're also trying to cut down on locking on these code paths. (High i/o load, many many cores?)
Quoted 6 lines
Have you hit any problems while testing due to the stack size? The cells don't seem ridiculously big - could we perhaps just put them on the stack for now? If we do hit stack size problems in real world configurations, then we can try to compare the locking approach with an approach that uses a separate (local) mempool for each cell (or a mempool with double-sized elements).
Quoted 4 lines
I haven't hit any stack size issues. But the cell structures are 60 bytes each and putting two of them on the stack seems wasteful. I don't have enough knowledge to say this will be ok for all architectures and so took the safe option.
I think it's better to put the structures on the stack (it is not that much, the stack has 8k, so 120 bytes is 1/68 of the stack) and remove the spinlock.
Mikulas
Re: [PATCH 5/8] [dm-thin] Fix a race condition between discard bios and ordinary bios.
Quoted 9 lines · Mikulas Patocka
Quoted 4 lines · On Thu, 24 Jan 2013, [email protected] wrote:
I haven't hit any stack size issues. But the cell structures are 60 bytes each and putting two of them on the stack seems wasteful. I don't have enough knowledge to say this will be ok for all architectures and so took the safe option.
I think it's better to put the structures on the stack (it is not that much, the stack has 8k, so 120 bytes is 1/68 of the stack) and remove the spinlock.
ok, will change. Thanks for looking at this Mikulas.
- Joe
PATCH 6/8 Add a transactional array.
In reply to Joe Thornber--- drivers/md/persistent-data/Makefile | 1 + drivers/md/persistent-data/dm-array.c | 818 +++++++++++++++++++++++++++++++++ drivers/md/persistent-data/dm-array.h | 128 ++++++ 3 files changed, 947 insertions(+) create mode 100644 drivers/md/persistent-data/dm-array.c create mode 100644 drivers/md/persistent-data/dm-array.h
drivers/md/persistent-data/Makefile +1 -0
@@ -1,5 +1,6 @@ obj-$(CONFIG_DM_PERSISTENT_DATA) += dm-persistent-data.o dm-persistent-data-objs := \ + dm-array.o \ dm-block-manager.o \ dm-space-map-common.o \ dm-space-map-disk.o \
drivers/md/persistent-data/dm-array.c new file +818 -0
818 lines not on this page · raw message
drivers/md/persistent-data/dm-array.h new file +128 -0
128 lines not on this page · raw message
Signature · 1 line
1.7.10.4
Alasdair G Kergon
maintainerRe: [PATCH 6/8] [persistent-data] Add a transactional array.
Reading first only the interface file (all-caches version), I'm left with the following questions about how to use the interface: please would you try to update the comments so they answer the questions?
Thanks,
Alasdair
drivers/md/persistent-data/dm-array.h new file +14 -0
@@ -0,0 +1,128 @@ +/* +* Copyright (C) 2012 Red Hat, Inc. +* +* This file is released under the GPL. +*/ +#ifndef _LINUX_DM_ARRAY_H +#define _LINUX_DM_ARRAY_H + +#include "dm-btree.h" + +/*----------------------------------------------------------------*/ + +/* +* The dm-array is a persistent version of an array. It packs the data
What sort of array?
+ * more efficiently than a btree which will result in less disk space use,
+ * and a performance boost. The get and set operations are still O(ln(n)),
+ * but with a much smaller constant.
+ *
+ * The value type structure is reused from the btree type to support proper
+ * reference counting of values.
+ *
+ * The arrays implicitly know their length, and bounds are checked for
+ * lookups and updates. It doesn't store this in an accessible place
+ * because it would waste a whole metadata block. Make sure you store the
+ * size along with the array root in your encompassing data.
+ */
How are array entries indexed?
Consecutive integers? Starting from 0 or 1?
Or can arrays be sparse, with the 'size' being the number of populated entries?
+/*
+ * Describes an array. Don't initialise this structure yourself, use the
+ * setup function below.
+ */
+struct dm_array_info {
+ struct dm_transaction_manager *tm;
+ struct dm_btree_value_type value_type;
+ struct dm_btree_info btree_info;
+};
What is the normal way to initialise an array of a specific size (that it says the caller must track)?
What error do I get if I try to add an element that would take it beyond the size the array is defined to have?
+/*
+ * Sets up a dm_array_info structure.
+ *
+ * info - the structure being filled in.
+ * tm - the transaction manager that should supervise this structure.
+ * vt - describes the leaf values.
+ */
+void dm_setup_array_info(struct dm_array_info *info,
+ struct dm_transaction_manager *tm,
+ struct dm_btree_value_type *vt);
+
+/*
+ * Initialise an empty array, zero length array.
+ *
+ * info - describes the array
Must this be populated first by calling dm_array_info() ?
+ * root - on success this will be filled out with the root block
And must this root block then be passed into all the functions that manipulate the array?
The description of dm_btree_empty() in dm-btree.h is that that function does 'Set up' and it's clearly paired with dm_btree_del().
Is there a counterpart to dm_setup_array_info if I want to destroy it or isn't one needed?
Is this similar to what dm_bitset_info_init() is doing and would an _init suffix instead of 'setup' be clearer here too?
+ */
+int dm_array_empty(struct dm_array_info *info, dm_block_t *root);
Is it compulsory to call this function after calling dm_setup_array_info()? [Otherwise I wouldn't have a 'root' I can use?]
But if so, how do I set the actual length of the array I want to use (which it says I must keep track myself)?
Am I required also to call dm_array_resize() afterwards with an old_size of 0 because an array with a size of 0 would otherwise be useless to me?
If I call this on an existing populated array will it 'empty' it correctly like the name suggests or shouldn't that be done?
+/*
+ * Resizes the array.
+ *
+ * info - describes the array
+ * root - the root block of the array on disk
+ * old_size - yes, the caller is responsible for remembering the size of the array
+ * new_size - can be bigger or smaller than old_size
+ * value - if we're growing the array the new entries will have this value
+ * new_root - on success, points to the new root block
+ *
+ * If growing the inc function for value will be called the appropriate
+ * number of times. So if the caller is holding a reference they may want
+ * to drop it.
+ */
+int dm_array_resize(struct dm_array_info *info, dm_block_t root,
+ uint32_t old_size, uint32_t new_size,
+ const void *value, dm_block_t *new_root)
+ __dm_written_to_disk(value);
If it gives me 'new_root' does that mean I must replace my copy of 'root' with it and does the old 'root' remain valid in any way or not?
+/*
+ * Frees a whole array. The value_type's decrement operation will be called
+ * for all values in the array
+ */
+int dm_array_del(struct dm_array_info *info, dm_block_t root);
Does anything remain valid after calling this?
- Is root no longer valid?
- Without touching 'info', can I call dm_array_empty() again at this point?
+/*
+ * Lookup a value in the array
+ *
+ * info - describes the array
+ * root - root block of the array
+ * index - array index
+ * value - the value to be read. Will be in on disk format of course.
+ *
+ * -ENODATA will be returned if the index is out of bounds.
+ */
+int dm_array_get(struct dm_array_info *info, dm_block_t root,
+ uint32_t index, void *value);
Is this like dm_get() ?
In what sense does dm_array_get get a dm_array?
- get_value? lookup?
+/*
+ * Set an entry in the array.
+ *
+ * info - describes the array
+ * root - root block of the array
+ * index - array index
+ * value - value to be written to disk. Make sure you bless this before
+ * calling.
How do I 'bless this'?
Must 'value' conform to the definition in info->value_type?
+ * new_root - the new root block
+ *
+ * The old value being overwritten will be decremented, the new value
+ * incremented.
+ *
+ * -ENODATA will be returned if the index is out of bounds.
+ */
+int dm_array_set(struct dm_array_info *info, dm_block_t root,
+ uint32_t index, const void *value, dm_block_t *new_root)
+ __dm_written_to_disk(value);
Define dm_array_set before dm_array_get in this file, perhaps?
set_value? store? rather then implying it's setting the whole array?
What am I supposed to do with 'new_root'? Does 'root' become invalid? Perhaps a general comment at the top about root and new_root would be a good way to explain.
+/*
+ * Walk through all the entries in an array.
+ *
+ * info - describes the array
+ * root - root block of the array
+ * fn - called back for every element
+ * context - passed to the callback
+ */
+int dm_array_walk(struct dm_array_info *info, dm_block_t root,
+ int (*fn)(void *, uint64_t key, void *leaf),
Make that 'void *context' so it's more obvious where it comes from?
+ void *context);
+ +/*----------------------------------------------------------------*/ +
+#endif
Re: [PATCH 6/8] [persistent-data] Add a transactional array.
Quoted 6 lines · Alasdair G Kergon
Reading first only the interface file (all-caches version), I'm left with the following questions about how to use the interface: please would you try to update the comments so they answer the questions?
Thanks,
Alasdair
Pushed thin-dev and all-caches with the following:
https://github.com/jthornber/linux-2.6/commit/b34914e9b7c85d4a3665746b2f617c7488e6805f
Alasdair G Kergon
maintainerRe: [PATCH 6/8] [persistent-data] Add a transactional array.
In reply to Joe Thornberdrivers/md/persistent-data/dm-array.c line 54
Quoted 10 lines · Joe Thornber
drivers/md/persistent-data/dm-array.c new file +3
-0@@ -0,0 +1,818 @@ +static int array_block_check (struct dm_block_validator *v, +struct dm_block *b, +size_t block_size)
Please rename block_size throughout to avoid any possible confusion with the inline function of the same name.
drivers/md/persistent-data/dm-array.c line 61
Quoted 7 lines
drivers/md/persistent-data/dm-array.c new file +7
-0+{ +struct array_block *bh_le =dm_block_data (b); +__le32 csum_disk; + +if (dm_block_location (b) !=le64_to_cpu (bh_le->blocknr)) { +DMERR_LIMIT ("array_block_check failed: blocknr %llu != wanted %llu" , +le64_to_cpu (bh_le->blocknr),dm_block_location (b));
We generally use an explicit cast to (unsigned long long) to avoid warnings on some archs. (Check the other places with format strings too.)
drivers/md/persistent-data/dm-array.c line 143
Quoted 4 lines
drivers/md/persistent-data/dm-array.c new file +4
-0+static uint32_t calc_max_entries (size_t value_size,size_t block_size) +{ +return (block_size -sizeof (struct array_block )) / value_size; +}
: warning: conversion to ‘uint32_t’ from ‘long unsigned int’ may alter its value
Perhaps some of the implict casting could be tidied a bit, but I haven't spotted any places where it causes real problems.
drivers/md/persistent-data/dm-array.c line 331
Quoted 10 lines
drivers/md/persistent-data/dm-array.c new file +10
-0+static int insert_full_ablocks (struct dm_array_info *info,size_t block_size, +unsigned begin_block,unsigned end_block, +unsigned max_entries,const void *value, +dm_block_t *root) +{ +int r; +struct dm_block *block; +struct array_block *ab; + +
Extra blank line.
drivers/md/persistent-data/dm-array.c line 337
Quoted 6 lines
drivers/md/persistent-data/dm-array.c new file +6
-0+while (begin_block != end_block) { + r =alloc_ablock (info, block_size, &block, &ab); +if (r) +return r; + +fill_ablock (info, ab, value,le32_to_cpu (ab->max_entries));
max_entries function parameter is unused - which should it be?
Quoted 29 lines
drivers/md/persistent-data/dm-array.c new file +29
-0+static int grow (struct resize *resize) +{ +int r; +struct dm_block *block; +struct array_block *ab; + +if (resize->new_nr_full_blocks > resize->old_nr_full_blocks) { +/* +* Pad the end of the old block? +*/ +if (resize->old_nr_entries_in_last_block >0 ) { + r =shadow_ablock (resize->info, &resize->root, + resize->old_nr_full_blocks, &block, &ab); +if (r) +return r; + +fill_ablock (resize->info, ab, resize->value, resize->max_entries); +unlock_ablock (resize->info, block); + } + +/* +* Add the full blocks. +*/ + r =insert_full_ablocks (resize->info, resize->block_size, + resize->old_nr_full_blocks, + resize->new_nr_full_blocks, + resize->max_entries, resize->value, + &resize->root); +if (r)
drivers/md/persistent-data/dm-array.c line 536
Quoted 10 lines
drivers/md/persistent-data/dm-array.c new file +10
-0+return r; + +/* +* Add new tail block? +*/ +if (resize->new_nr_entries_in_last_block) + r =insert_partial_ablock (resize->info, resize->block_size, + resize->new_nr_full_blocks, + resize->new_nr_entries_in_last_block, + resize->value, &resize->root);
return directly here and drop the else (maybe inverting the if test) and reducing the indentation?
drivers/md/persistent-data/dm-array.c line 539
Quoted 3 lines
drivers/md/persistent-data/dm-array.c new file +3
-0+ }else { +if (!resize->old_nr_entries_in_last_block) { + r = insert_partial_ablock(resize->info, resize->block_size,
Redundant {}
Quoted 4 lines
drivers/md/persistent-data/dm-array.c new file +4
-0+ resize->new_nr_full_blocks, + resize->new_nr_entries_in_last_block, + resize->value, &resize->root); + }else {
...
Quoted 6 lines
drivers/md/persistent-data/dm-array.c new file +6
-0+ r =dm_tm_ref (info->btree_info.tm, b, &ref_count); +if (r) { +DMERR_LIMIT ("couldn't get reference count" ); +return ; + } +
drivers/md/persistent-data/dm-array.c line 600
Quoted 10 lines
drivers/md/persistent-data/dm-array.c new file +10
-0+if (ref_count ==1 ) { +/* +* We're about to drop the last reference to this ablock. +* So we need to decrement the ref count of the contents. +*/ + r =get_ablock (info, b, &block, &ab); +if (r) { +DMERR_LIMIT ("couldn't get array block" ); +return ; + }
Can we add more context to these error messages - e.g. the block number?
Alasdair
--
dm-devel mailing list
[email protected]
https://www.redhat.com/mailman/listinfo/dm-devel
Re: [PATCH 6/8] [persistent-data] Add a transactional array.
Quoted 7 lines · Alasdair G Kergon
drivers/md/persistent-data/dm-array.c line 143
Quoted 4 lines · Joe Thornber
drivers/md/persistent-data/dm-array.c new file +4
-0+static uint32_t calc_max_entries (size_t value_size,size_t block_size) +{ +return (block_size -sizeof (struct array_block )) / value_size; +}: warning: conversion to ‘uint32_t’ from ‘long unsigned int’ may alter its value
Which tool are you using to get these warnings? I'm not seeing any with sparse or gcc, or perhaps you're building on a 32bit machine?
--
dm-devel mailing list
[email protected]
https://www.redhat.com/mailman/listinfo/dm-devel
Alasdair G Kergon
maintainerRe: [PATCH 6/8] [persistent-data] Add a transactional array.
Quoted 2 lines · Joe Thornber
Which tool are you using to get these warnings? I'm not seeing any with sparse or gcc, or perhaps you're building on a 32bit machine?
make EXTRA_CFLAGS=-Wconversion
Off by default as it's very noisy and most implicit conversions don't matter.
Alasdair
Re: [PATCH 6/8] [persistent-data] Add a transactional array.
In reply to Alasdair G KergonAlasdair,
I've just pushed a series of patches to thin-dev, and all-caches that address these.
I've refactored the grow() function, breaking it up to reduce indentation. However, I've left in 'else' clauses. I find the following says 'there are three options' ...
if (resize->new_nr_full_blocks > resize->old_nr_full_blocks)
return grow_needs_more_blocks(resize);
else if (resize->old_nr_entries_in_last_block)
return grow_extend_tail_block(resize, resize->new_nr_entries_in_last_block);
else
return grow_add_tail_block(resize);... more clearly than ...
if (resize->new_nr_full_blocks > resize->old_nr_full_blocks)
return grow_needs_more_blocks(resize);
else if (resize->old_nr_entries_in_last_block)
return grow_extend_tail_block(resize, resize->new_nr_entries_in_last_block);
return grow_add_tail_block(resize);Will change if you're still having trouble with it though.
- Joe
Quoted 133 lines · Alasdair G Kergon
drivers/md/persistent-data/dm-array.c line 54
Quoted 10 lines · Joe Thornber
drivers/md/persistent-data/dm-array.c new file +3
-0@@ -0,0 +1,818 @@ +static int array_block_check (struct dm_block_validator *v, +struct dm_block *b, +size_t block_size)Please rename
block_sizethroughout to avoid any possible confusion with the inline function of the same name.drivers/md/persistent-data/dm-array.c line 61
Quoted 7 lines
drivers/md/persistent-data/dm-array.c new file +7
-0+{ +struct array_block *bh_le =dm_block_data (b); +__le32 csum_disk; + +if (dm_block_location (b) !=le64_to_cpu (bh_le->blocknr)) { +DMERR_LIMIT ("array_block_check failed: blocknr %llu != wanted %llu" , +le64_to_cpu (bh_le->blocknr),dm_block_location (b));We generally use an explicit cast to (unsigned long long) to avoid warnings on some archs. (Check the other places with format strings too.)
drivers/md/persistent-data/dm-array.c line 143
Quoted 4 lines
drivers/md/persistent-data/dm-array.c new file +4
-0+static uint32_t calc_max_entries (size_t value_size,size_t block_size) +{ +return (block_size -sizeof (struct array_block )) / value_size; +}: warning: conversion to ‘uint32_t’ from ‘long unsigned int’ may alter its value
Perhaps some of the implict casting could be tidied a bit, but I haven't spotted any places where it causes real problems.
drivers/md/persistent-data/dm-array.c line 331
Quoted 10 lines
drivers/md/persistent-data/dm-array.c new file +10
-0+static int insert_full_ablocks (struct dm_array_info *info,size_t block_size, +unsigned begin_block,unsigned end_block, +unsigned max_entries,const void *value, +dm_block_t *root) +{ +int r; +struct dm_block *block; +struct array_block *ab; + +Extra blank line.
drivers/md/persistent-data/dm-array.c line 337
Quoted 6 lines
drivers/md/persistent-data/dm-array.c new file +6
-0+while (begin_block != end_block) { + r =alloc_ablock (info, block_size, &block, &ab); +if (r) +return r; + +fill_ablock (info, ab, value,le32_to_cpu (ab->max_entries));
max_entriesfunction parameter is unused - which should it be?Quoted 29 lines
drivers/md/persistent-data/dm-array.c new file +29
-0+static int grow (struct resize *resize) +{ +int r; +struct dm_block *block; +struct array_block *ab; + +if (resize->new_nr_full_blocks > resize->old_nr_full_blocks) { +/* +* Pad the end of the old block? +*/ +if (resize->old_nr_entries_in_last_block >0 ) { + r =shadow_ablock (resize->info, &resize->root, + resize->old_nr_full_blocks, &block, &ab); +if (r) +return r; + +fill_ablock (resize->info, ab, resize->value, resize->max_entries); +unlock_ablock (resize->info, block); + } + +/* +* Add the full blocks. +*/ + r =insert_full_ablocks (resize->info, resize->block_size, + resize->old_nr_full_blocks, + resize->new_nr_full_blocks, + resize->max_entries, resize->value, + &resize->root); +if (r)drivers/md/persistent-data/dm-array.c line 536
Quoted 10 lines
drivers/md/persistent-data/dm-array.c new file +10
-0+return r; + +/* +* Add new tail block? +*/ +if (resize->new_nr_entries_in_last_block) + r =insert_partial_ablock (resize->info, resize->block_size, + resize->new_nr_full_blocks, + resize->new_nr_entries_in_last_block, + resize->value, &resize->root);return directly here and drop the else (maybe inverting the if test) and reducing the indentation?
drivers/md/persistent-data/dm-array.c line 539
Quoted 3 lines
drivers/md/persistent-data/dm-array.c new file +3
-0+ }else { +if (!resize->old_nr_entries_in_last_block) { + r = insert_partial_ablock(resize->info, resize->block_size,Redundant {}
Quoted 4 lines
drivers/md/persistent-data/dm-array.c new file +4
-0+ resize->new_nr_full_blocks, + resize->new_nr_entries_in_last_block, + resize->value, &resize->root); + }else {...
Quoted 6 lines
drivers/md/persistent-data/dm-array.c new file +6
-0+ r =dm_tm_ref (info->btree_info.tm, b, &ref_count); +if (r) { +DMERR_LIMIT ("couldn't get reference count" ); +return ; + } +drivers/md/persistent-data/dm-array.c line 600
Quoted 10 lines
drivers/md/persistent-data/dm-array.c new file +10
-0+if (ref_count ==1 ) { +/* +* We're about to drop the last reference to this ablock. +* So we need to decrement the ref count of the contents. +*/ + r =get_ablock (info, b, &block, &ab); +if (r) { +DMERR_LIMIT ("couldn't get array block" ); +return ; + }Can we add more context to these error messages - e.g. the block number?
Quoted 2 lines
Alasdair
--
dm-devel mailing list
[email protected]
https://www.redhat.com/mailman/listinfo/dm-devel
Alasdair G Kergon
maintainerRe: [PATCH 6/8] [persistent-data] Add a transactional array.
Quoted 3 lines · Joe Thornber
I've refactored the
grow()function, breaking it up to reduce indentation. However, I've left in 'else' clauses. I find the following says 'there are three options' ...
Indeed, breaking it up like that has improved the readability and the final else makes little difference now.
Alasdair
PATCH 7/8 transactional bitset
In reply to Joe ThornberA wrapper around dm-array.
--- drivers/md/persistent-data/Makefile | 1 + drivers/md/persistent-data/dm-bitset.c | 163 ++++++++++++++++++++++++++++++++ drivers/md/persistent-data/dm-bitset.h | 59 ++++++++++++ 3 files changed, 223 insertions(+) create mode 100644 drivers/md/persistent-data/dm-bitset.c create mode 100644 drivers/md/persistent-data/dm-bitset.h
drivers/md/persistent-data/Makefile +1 -0
@@ -1,6 +1,7 @@ obj-$(CONFIG_DM_PERSISTENT_DATA) += dm-persistent-data.o dm-persistent-data-objs := \ dm-array.o \ + dm-bitset.o \ dm-block-manager.o \ dm-space-map-common.o \ dm-space-map-disk.o \
drivers/md/persistent-data/dm-bitset.c new file +163 -0
163 lines not on this page · raw message
drivers/md/persistent-data/dm-bitset.h new file +59 -0
59 lines not on this page · raw message
Signature · 1 line
1.7.10.4
Alasdair G Kergon
maintainerRe: [PATCH 7/8] [persistent-data] transactional bitset
Please add more comments to the functions in dm-bitset.h to confirm what they do and how to use them. (I've not repeated comments about dm-array.h that apply here too.)
drivers/md/persistent-data/dm-bitset.h line 23
Quoted 7 lines · Joe Thornber
drivers/md/persistent-data/dm-bitset.h new file +5
-0+struct dm_bitset_info { +struct dm_array_info array_info; + +uint32_t current_index; +uint64_t current_bits;
Put the uint64_t before the uint32_t perhaps? (Better packing?)
drivers/md/persistent-data/dm-bitset.h line 29
Quoted 6 lines
drivers/md/persistent-data/dm-bitset.h new file +6
-0+ + bool current_index_set:1; +}; + +void dm_bitset_info_init (struct dm_transaction_manager *tm, +struct dm_bitset_info *info);
Does this function populate info->array_info and track the array size so the caller doesn't need to do it in the way described in dm-array.h?
drivers/md/persistent-data/dm-bitset.h line 36
Quoted 6 lines
drivers/md/persistent-data/dm-bitset.h new file +6
-0+int dm_bitset_empty (struct dm_bitset_info *info,dm_block_t *root); + +int dm_bitset_resize (struct dm_bitset_info *info,dm_block_t root, +uint32_t old_nr_entries,uint32_t new_nr_entries, +bool default_value,dm_block_t *new_root); +
But does the caller need to track old/new nr_entries?
drivers/md/persistent-data/dm-bitset.h line 43
Quoted 6 lines
drivers/md/persistent-data/dm-bitset.h new file +6
-0+ +/* +* May flush and thus update the root. +*/ +int dm_bitset_set_bit (struct dm_bitset_info *info,dm_block_t root, +uint32_t index,dm_block_t *new_root);
What are the constraints on index?
Can index be too big and require a resize first? If so, what error is returned?
drivers/md/persistent-data/dm-bitset.h line 46
Quoted 2 lines
drivers/md/persistent-data/dm-bitset.h new file +2
-0+int dm_bitset_clear_bit (struct dm_bitset_info *info,dm_block_t root, +uint32_t index,dm_block_t *new_root);
Error if out of defined range?
drivers/md/persistent-data/dm-bitset.h line 50
Quoted 3 lines
drivers/md/persistent-data/dm-bitset.h new file +3
-0+int dm_bitset_test_bit (struct dm_bitset_info *info,dm_block_t root, +uint32_t index,dm_block_t *new_root,bool *result); +
Error if out of defined range?
drivers/md/persistent-data/dm-bitset.h line 55
Quoted 5 lines
drivers/md/persistent-data/dm-bitset.h new file +5
-0+/* +* You must call this to flush recent changes to disk. +*/ +int dm_bitset_flush (struct dm_bitset_info *info,dm_block_t root, +dm_block_t *new_root);
If there's a disk error, does flush fail and then could it be retried? Or does the bitset become unusable or read-only after a disk error?
drivers/md/persistent-data/dm-bitset.h line 59
Quoted 4 lines
drivers/md/persistent-data/dm-bitset.h new file +4
-0+ +/*----------------------------------------------------------------*/ + +#endif
Conventionally, add /* _LINUX_DM_BITSET_H */ after the #endif. (Helps when reading files with nested includes.)
- dm-array.h similarly.
Alasdair
PATCH 8/8 cache target
In reply to Joe Thornber--- Documentation/device-mapper/dm-cache.txt | 209 +++ drivers/md/Kconfig | 22 + drivers/md/Makefile | 6 + drivers/md/dm-cache-metadata.c | 1135 ++++++++++++ drivers/md/dm-cache-metadata.h | 170 ++ drivers/md/dm-cache-policy-cleaner.c | 482 +++++ drivers/md/dm-cache-policy-internal.h | 120 ++ drivers/md/dm-cache-policy-mq.c | 1254 +++++++++++++ drivers/md/dm-cache-policy.c | 147 ++ drivers/md/dm-cache-policy.h | 220 +++ drivers/md/dm-cache-target.c | 2443 +++++++++++++++++++++++++ drivers/md/persistent-data/dm-block-manager.c | 1 + 12 files changed, 6209 insertions(+) create mode 100644 Documentation/device-mapper/dm-cache.txt create mode 100644 drivers/md/dm-cache-metadata.c create mode 100644 drivers/md/dm-cache-metadata.h create mode 100644 drivers/md/dm-cache-policy-cleaner.c create mode 100644 drivers/md/dm-cache-policy-internal.h create mode 100644 drivers/md/dm-cache-policy-mq.c create mode 100644 drivers/md/dm-cache-policy.c create mode 100644 drivers/md/dm-cache-policy.h create mode 100644 drivers/md/dm-cache-target.c
Documentation/device-mapper/dm-cache.txt new file +209 -0
@@ -0,0 +1,209 @@ +* Introduction + +dm-cache is a device mapper target written by Joe Thornber, Heinz +Maueslhagen, and Mike Snitzer. + +It aims to improve performance of a block device (eg, a spindle) by +dynamically migrating some of its data to a faster, smaller device +(eg, an SSD). + +There are various caching solutions out there, for example bcache, we +feel there is a need for a purely device-mapper solution that allows +us to insert this caching at different levels of the dm stack. For +instance above the data device for a thin-provisioning pool. Caching +solutions that are integrated more closely with the virtual memory +system should give better performance. + +The target reuses the metadata library used in the thin-provisioning +library. + +The decision of what and when to migrate data is left to a plug-in +policy module. Several of these have been written as we experiment, +and we hope other people will contribute others for specific io +scenarios (eg. a vm image server). + +* Glossary + +- Migration - Movement of a logical block from one device to the other. +- Promotion - Migration from slow device to fast device. +- Demotion - Migration from fast device to slow device. + +* Design + +** Sub devices + +The target is constructed by passing three devices to it (along with +other params detailed later): + +- An origin device (the big, slow one). + +- A cache device (the small, fast one). + +- A small metadata device. + + Device that records which blocks are in the cache. Which are dirty, + and extra hints for use by the policy object. + + This information could be put on the cache device, but having it + separate allows the volume manager to configure it differently. eg, + as a mirror for extra robustness. + + +** Fixed block size + +The origin is divided up into blocks of a fixed size. This block size +is configurable when you first create the cache. Typically we've been +using block sizes of 256k - 1024k. + +Having a fixed block size simplifies the target a lot. But it is +something of a compromise. For instance a small part of a block may +be getting hit a lot (eg, /etc/passwd), yet the whole block will be +promoted to the cache. So large block sizes are bad, because they +waste cache space. And small block sizes are bad because they +increase the amount of metadata (both in core and on disk). + +** Writeback/writethrough + +The cache has these two modes. + +If writeback is selected then writes to blocks that are cached will +only go to the cache, and the block will be marked dirty in the +metadata. + +If writethrough mode is selected then a write to a cached block will +not complete until has hit both the origin and cache device. Clean +blocks should remain clean. + +A simple cleaner policy is provided, which will clean all dirty blocks +in a cache. Useful for decommissioning a cache. + +** Migration throttling + +Migrating data between the origin and cache device uses bandwidth. +The user can set a throttle to prevent more than a certain amount of +migrations occuring at any one time. Currently we're not taking any +account of normal io traffic going to the devs. More work needs to be +done here to avoid migrating during those peak io moments. + +** Updating on disk metadata + +On disk metadata is committed everytime a REQ_SYNC or REQ_FUA bio is +written. If no such requests are made then commits will occur every +second. This means the cache behaves like a physical disk that has a +write cache (the same is true of the thin-provisioning target). If +power is lost you may lose some recent writes. The metadata should +always be consistent in spite of a crash. + +The 'dirty' state for a cache block changes far too frequently for us +to keep updating it on the fly. So we treat it as a hint. In normal +operation it will be written when the dm device is suspended. If the +system crashes all cache blocks will be assumed dirty when restarted. + +** per block policy hints + +Policy plug-ins can store a chunk of data per cache block. It's up to +the policy how big this chunk is (please keep it small). Like the +dirty flags this data is lost if there's a crash so a safe fallback +value should always be possible. + +For instance the 'mq' policy, which is currently the default policy, +uses this facility to store the hit count of the cache blocks. If +there's a crash this information will be lost, which means the cache +may be less efficient until those hit counts are regenerated. + +Policy hints effect performance, not correctness. + +** Policy messaging + +Policies will have different tunables, specific to each one. So we +need a generic way of getting and setting these. One way would be +through a sysfs interface; much as we do with a block device's queue +parameters. Another is to use the device-mapper message facility. +We're using that latter method currently, though don't feel strongly +one way or the other. + +** discard bitset resolution + +We can avoid copying data during migration if we know the block has +been discarded. A prime example of this is when mkfs discards the +whole block device. We store a bitset tracking the discard state of +blocks. However, we allow this bitset to have a different block size +from the cache blocks. This is because we need to track the discard +state for all of the origin device (compare with the dirty bitset +which is just for the smaller cache device). + +** Target interface + + cache <metadata dev> + <cache dev> + <origin dev> + <block size> + <#feature args> [<feature arg>]* + <policy> + <#policy args> + [policy args]* + + metadata dev : fast device holding the persistent metadata + cache dev : fast device holding cached data blocks + origin dev : slow device holding original data blocks + block size : cache unit size in sectors + policy : the replacement policy to use + + #feature args : number of feature arguments passed + feature args : 'writeback' or 'writethrough' (one or the other). + + #policy args : an even number of arguments corresponding to + key/value pairs passed to the policy. + policy args : key/value pairs (eg, 'migration_threshold 1024000') + +A policy called 'default' is always registered. This is an alias for +the policy we currently think is giving best all round performance. + +* Example usage + +The test suite can be found here: + +https://github.com/jthornber/thinp-test-suite + +0 41943040 cache /dev/mapper/metadata /dev/mapper/ssd /dev/mapper/origin 512 1 writeback default 0 + +* Policy interface + +- Try to keep transactionality out of it. The core is careful to + avoid asking about anything that is migrating. This is a pain, but + makes it easier to write the policies. + +- Mappings are loaded into the policy at construction time. + +- Every bio that is mapped by the target is referred to the policy, it + can give a simple HIT or MISS or issue a migration. + +- Currently there's no way for the policy to issue background work, + eg, start writing back dirty blocks that are soon going to be evicted. + +- Because we map bios, rather than requests it's easy for the policy + to get fooled by many small bios. For this reason the core target + issues periodic ticks to the policy. It's suggested that the policy + doesn't update states (eg, hit counts) for a block more than once + for each tick. [The core ticks by watching bios complete, and so + trying to see when the io scheduler has let the ios run] + + + void (*destroy)(struct dm_cache_policy *p); + void (*map)(struct dm_cache_policy *p, dm_block_t origin_block, int data_dir, + bool can_migrate, bool cheap_copy, struct bio *bio, + struct policy_result *result); + + int (*load_mapping)(struct dm_cache_policy *p, dm_block_t oblock, dm_block_t cblock); + + /* must succeed */ + void (*remove_mapping)(struct dm_cache_policy *p, dm_block_t oblock); + void (*force_mapping)(struct dm_cache_policy *p, dm_block_t current_oblock, + dm_block_t new_oblock); + + dm_block_t (*residency)(struct dm_cache_policy *p); + void (*set_seq_io_threshold)(struct dm_cache_policy *p, + unsigned int seq_io_thresh); + + void (*tick)(struct dm_cache_policy *p); +
drivers/md/Kconfig +22 -0
@@ -268,6 +268,28 @@ config DM_DEBUG_BLOCK_STACK_TRACING If unsure, say N. +config DM_CACHE + tristate "Cache target (EXPERIMENTAL)" + depends on BLK_DEV_DM && EXPERIMENTAL + select DM_PERSISTENT_DATA + select DM_PRISON + ---help--- + Use an SSD to speed up a slower device. + +config DM_CACHE_MQ + tristate "MQ Cache Policy (EXPERIMENTAL)" + depends on DM_CACHE + default y + ---help--- + Under development + +config DM_CACHE_CLEANER + tristate "Cleaner Cache Policy (EXPERIMENTAL)" + depends on DM_CACHE + default y + ---help--- + Under development + config DM_MIRROR tristate "Mirror target" depends on BLK_DEV_DM
drivers/md/Makefile +6 -0
@@ -11,6 +11,9 @@ dm-mirror-y += dm-raid1.o dm-log-userspace-y \ += dm-log-userspace-base.o dm-log-userspace-transfer.o dm-thin-pool-y += dm-thin.o dm-thin-metadata.o +dm-cache-y += dm-cache-target.o dm-cache-metadata.o dm-cache-policy.o +dm-cache-mq-y += dm-cache-policy-mq.o +dm-cache-cleaner-y += dm-cache-policy-cleaner.o md-mod-y += md.o bitmap.o raid456-y += raid5.o
@@ -43,6 +46,9 @@ obj-$(CONFIG_DM_LOG_USERSPACE) += dm-log-userspace.o obj-$(CONFIG_DM_ZERO) += dm-zero.o obj-$(CONFIG_DM_RAID) += dm-raid.o obj-$(CONFIG_DM_THIN_PROVISIONING) += dm-thin-pool.o +obj-$(CONFIG_DM_CACHE) += dm-cache.o +obj-$(CONFIG_DM_CACHE_MQ) += dm-cache-mq.o +obj-$(CONFIG_DM_CACHE_CLEANER) += dm-cache-cleaner.o obj-$(CONFIG_DM_VERITY) += dm-verity.o ifeq ($(CONFIG_DM_UEVENT),y)
drivers/md/dm-cache-metadata.c new file +1135 -0
1,135 lines not on this page · raw message
drivers/md/dm-cache-metadata.h new file +170 -0
170 lines not on this page · raw message
drivers/md/dm-cache-policy-cleaner.c new file +482 -0
482 lines not on this page · raw message
drivers/md/dm-cache-policy-internal.h new file +120 -0
120 lines not on this page · raw message
drivers/md/dm-cache-policy-mq.c new file +1254 -0
838 lines not on this page · raw message
drivers/md/dm-cache-policy.c new file +147 -0
147 lines not on this page · raw message
drivers/md/dm-cache-policy.h new file +220 -0
220 lines not on this page · raw message
drivers/md/dm-cache-target.c new file +2443 -0
2,443 lines not on this page · raw message
drivers/md/persistent-data/dm-block-manager.c +1 -0
Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
Signature · 1 line
1.7.10.4
Part of the diff is not shown here. View the raw message.
Re: [PATCH 8/8] [dm-cache] cache target
Mmmm, another one! I've been looking forward to this.... :)
I've really only looked at the documentation; I'm currently playing with the built code and will look at the source later.
Quoted 30 lines · Joe Thornber
--- Documentation/device-mapper/dm-cache.txt | 209 +++ drivers/md/Kconfig | 22 + drivers/md/Makefile | 6 + drivers/md/dm-cache-metadata.c | 1135 ++++++++++++ drivers/md/dm-cache-metadata.h | 170 ++ drivers/md/dm-cache-policy-cleaner.c | 482 +++++ drivers/md/dm-cache-policy-internal.h | 120 ++ drivers/md/dm-cache-policy-mq.c | 1254 +++++++++++++ drivers/md/dm-cache-policy.c | 147 ++ drivers/md/dm-cache-policy.h | 220 +++ drivers/md/dm-cache-target.c | 2443 +++++++++++++++++++++++++ drivers/md/persistent-data/dm-block-manager.c | 1 + 12 files changed, 6209 insertions(+) create mode 100644 Documentation/device-mapper/dm-cache.txt create mode 100644 drivers/md/dm-cache-metadata.c create mode 100644 drivers/md/dm-cache-metadata.h create mode 100644 drivers/md/dm-cache-policy-cleaner.c create mode 100644 drivers/md/dm-cache-policy-internal.h create mode 100644 drivers/md/dm-cache-policy-mq.c create mode 100644 drivers/md/dm-cache-policy.c create mode 100644 drivers/md/dm-cache-policy.h create mode 100644 drivers/md/dm-cache-target.cDocumentation/device-mapper/dm-cache.txt new file +0
-0
Documentation/device-mapper/dm-cache.txt line 4
Quoted 4 lines
Documentation/device-mapper/dm-cache.txt new file +4
-0@@ -0,0 +1,209 @@ +* Introduction + +dm-cache is a device mapper target written by Joe Thornber, Heinz +Maueslhagen, and Mike Snitzer.
Is this "Mauelshagen"?
Quoted 14 lines
Documentation/device-mapper/dm-cache.txt new file +14
-0+It aims to improve performance of a block device (eg, a spindle) by +dynamically migrating some of its data to a faster, smaller device +(eg, an SSD). + +There are various caching solutions out there, for example bcache, we +feel there is a need for a purely device-mapper solution that allows +us to insert this caching at different levels of the dm stack. For +instance above the data device for a thin-provisioning pool. Caching +solutions that are integrated more closely with the virtual memory +system should give better performance. + +The target reuses the metadata library used in the thin-provisioning +library. +
Documentation/device-mapper/dm-cache.txt line 29
Quoted 10 lines
Documentation/device-mapper/dm-cache.txt new file +10
-0+The decision of what and when to migrate data is left to a plug-in +policy module. Several of these have been written as we experiment, +and we hope other people will contribute others for specific io +scenarios (eg. a vm image server). + +* Glossary + +- Migration - Movement of a logical block from one device to the other. +- Promotion - Migration from slow device to fast device. +- Demotion - Migration from fast device to slow device.
If a block is promoted to the fast device, is it always the case that the block still resides on the slow device? The existence of WT mode implies this, but on the other hand you do say "move" here.
Or is this more like tiered storage where promoting a block moves it to the fast device and it's no longer on the slow device?
Put another way -- if I use my SSD as a writethrough cache for a disk and one day the SSD loses its brains, can I expect to still have a reasonably up to date copy on the disk?
Documentation/device-mapper/dm-cache.txt line 42
Quoted 12 lines
Documentation/device-mapper/dm-cache.txt new file +12
-0+* Design + +** Sub devices + +The target is constructed by passing three devices to it (along with +other params detailed later): + +- An origin device (the big, slow one). + +- A cache device (the small, fast one). + +- A small metadata device.
How do I calculate how big the metadata device has to be?
Quoted 70 lines
Documentation/device-mapper/dm-cache.txt new file +70
-0+ Device that records which blocks are in the cache. Which are dirty, + and extra hints for use by the policy object. + + This information could be put on the cache device, but having it + separate allows the volume manager to configure it differently. eg, + as a mirror for extra robustness. + + +** Fixed block size + +The origin is divided up into blocks of a fixed size. This block size +is configurable when you first create the cache. Typically we've been +using block sizes of 256k - 1024k. + +Having a fixed block size simplifies the target a lot. But it is +something of a compromise. For instance a small part of a block may +be getting hit a lot (eg, /etc/passwd), yet the whole block will be +promoted to the cache. So large block sizes are bad, because they +waste cache space. And small block sizes are bad because they +increase the amount of metadata (both in core and on disk). + +** Writeback/writethrough + +The cache has these two modes. + +If writeback is selected then writes to blocks that are cached will +only go to the cache, and the block will be marked dirty in the +metadata. + +If writethrough mode is selected then a write to a cached block will +not complete until has hit both the origin and cache device. Clean +blocks should remain clean. + +A simple cleaner policy is provided, which will clean all dirty blocks +in a cache. Useful for decommissioning a cache. + +** Migration throttling + +Migrating data between the origin and cache device uses bandwidth. +The user can set a throttle to prevent more than a certain amount of +migrations occuring at any one time. Currently we're not taking any +account of normal io traffic going to the devs. More work needs to be +done here to avoid migrating during those peak io moments. + +** Updating on disk metadata + +On disk metadata is committed everytime a REQ_SYNC or REQ_FUA bio is +written. If no such requests are made then commits will occur every +second. This means the cache behaves like a physical disk that has a +write cache (the same is true of the thin-provisioning target). If +power is lost you may lose some recent writes. The metadata should +always be consistent in spite of a crash. + +The 'dirty' state for a cache block changes far too frequently for us +to keep updating it on the fly. So we treat it as a hint. In normal +operation it will be written when the dm device is suspended. If the +system crashes all cache blocks will be assumed dirty when restarted. + +** per block policy hints + +Policy plug-ins can store a chunk of data per cache block. It's up to +the policy how big this chunk is (please keep it small). Like the +dirty flags this data is lost if there's a crash so a safe fallback +value should always be possible. + +For instance the 'mq' policy, which is currently the default policy, +uses this facility to store the hit count of the cache blocks. If +there's a crash this information will be lost, which means the cache +may be less efficient until those hit counts are regenerated. +
Documentation/device-mapper/dm-cache.txt line 123
Quoted 10 lines
Documentation/device-mapper/dm-cache.txt new file +10
-0+Policy hints effect performance, not correctness. + +** Policy messaging + +Policies will have different tunables, specific to each one. So we +need a generic way of getting and setting these. One way would be +through a sysfs interface; much as we do with a block device's queue +parameters. Another is to use the device-mapper message facility. +We're using that latter method currently, though don't feel strongly +one way or the other.
Is there any documentation for the message formats?
Or the policy parameters?
--D
Quoted 69 lines
Documentation/device-mapper/dm-cache.txt new file +69
-0+ +** discard bitset resolution + +We can avoid copying data during migration if we know the block has +been discarded. A prime example of this is when mkfs discards the +whole block device. We store a bitset tracking the discard state of +blocks. However, we allow this bitset to have a different block size +from the cache blocks. This is because we need to track the discard +state for all of the origin device (compare with the dirty bitset +which is just for the smaller cache device). + +** Target interface + + cache <metadata dev> + <cache dev> + <origin dev> + <block size> + <#feature args> [<feature arg>]* + <policy> + <#policy args> + [policy args]* + + metadata dev : fast device holding the persistent metadata + cache dev : fast device holding cached data blocks + origin dev : slow device holding original data blocks + block size : cache unit size in sectors + policy : the replacement policy to use + + #feature args : number of feature arguments passed + feature args : 'writeback' or 'writethrough' (one or the other). + + #policy args : an even number of arguments corresponding to + key/value pairs passed to the policy. + policy args : key/value pairs (eg, 'migration_threshold 1024000') + +A policy called 'default' is always registered. This is an alias for +the policy we currently think is giving best all round performance. + +* Example usage + +The test suite can be found here: + +https://github.com/jthornber/thinp-test-suite + +0 41943040 cache /dev/mapper/metadata /dev/mapper/ssd /dev/mapper/origin 512 1 writeback default 0 + +* Policy interface + +- Try to keep transactionality out of it. The core is careful to + avoid asking about anything that is migrating. This is a pain, but + makes it easier to write the policies. + +- Mappings are loaded into the policy at construction time. + +- Every bio that is mapped by the target is referred to the policy, it + can give a simple HIT or MISS or issue a migration. + +- Currently there's no way for the policy to issue background work, + eg, start writing back dirty blocks that are soon going to be evicted. + +- Because we map bios, rather than requests it's easy for the policy + to get fooled by many small bios. For this reason the core target + issues periodic ticks to the policy. It's suggested that the policy + doesn't update states (eg, hit counts) for a block more than once + for each tick. [The core ticks by watching bios complete, and so + trying to see when the io scheduler has let the ios run] + + + void (*destroy)(struct dm_cache_policy *p);
Documentation/device-mapper/dm-cache.txt line 202
Quoted 10 lines
Documentation/device-mapper/dm-cache.txt new file +10
-0+ void (*map)(struct dm_cache_policy *p, dm_block_t origin_block, int data_dir, + bool can_migrate, bool cheap_copy, struct bio *bio, + struct policy_result *result); + + int (*load_mapping)(struct dm_cache_policy *p, dm_block_t oblock, dm_block_t cblock); + + /* must succeed */ + void (*remove_mapping)(struct dm_cache_policy *p, dm_block_t oblock); + void (*force_mapping)(struct dm_cache_policy *p, dm_block_t current_oblock, + dm_block_t new_oblock);
q> +
Quoted 6,101 lines
Documentation/device-mapper/dm-cache.txt new file +6
-0+ dm_block_t (*residency)(struct dm_cache_policy *p); + void (*set_seq_io_threshold)(struct dm_cache_policy *p, + unsigned int seq_io_thresh); + + void (*tick)(struct dm_cache_policy *p); +drivers/md/Kconfig +22
-0@@ -268,6 +268,28 @@ config DM_DEBUG_BLOCK_STACK_TRACING If unsure, say N. +config DM_CACHE + tristate "Cache target (EXPERIMENTAL)" + depends on BLK_DEV_DM && EXPERIMENTAL + select DM_PERSISTENT_DATA + select DM_PRISON + ---help--- + Use an SSD to speed up a slower device. + +config DM_CACHE_MQ + tristate "MQ Cache Policy (EXPERIMENTAL)" + depends on DM_CACHE + default y + ---help--- + Under development + +config DM_CACHE_CLEANER + tristate "Cleaner Cache Policy (EXPERIMENTAL)" + depends on DM_CACHE + default y + ---help--- + Under development + config DM_MIRROR tristate "Mirror target" depends on BLK_DEV_DMdrivers/md/Makefile +6
-0@@ -11,6 +11,9 @@ dm-mirror-y += dm-raid1.o dm-log-userspace-y \ += dm-log-userspace-base.o dm-log-userspace-transfer.o dm-thin-pool-y += dm-thin.o dm-thin-metadata.o +dm-cache-y += dm-cache-target.o dm-cache-metadata.o dm-cache-policy.o +dm-cache-mq-y += dm-cache-policy-mq.o +dm-cache-cleaner-y += dm-cache-policy-cleaner.o md-mod-y += md.o bitmap.o raid456-y += raid5.o@@ -43,6 +46,9 @@ obj-$(CONFIG_DM_LOG_USERSPACE) += dm-log-userspace.o obj-$(CONFIG_DM_ZERO) += dm-zero.o obj-$(CONFIG_DM_RAID) += dm-raid.o obj-$(CONFIG_DM_THIN_PROVISIONING) += dm-thin-pool.o +obj-$(CONFIG_DM_CACHE) += dm-cache.o +obj-$(CONFIG_DM_CACHE_MQ) += dm-cache-mq.o +obj-$(CONFIG_DM_CACHE_CLEANER) += dm-cache-cleaner.o obj-$(CONFIG_DM_VERITY) += dm-verity.o ifeq ($(CONFIG_DM_UEVENT),y)drivers/md/dm-cache-metadata.c new file +1135
-0@@ -0,0 +1,1135 @@ +/* +* Copyright (C) 2012 Red Hat, Inc. +* +* This file is released under the GPL. +*/ + +#include "dm-cache-metadata.h" + +#include "persistent-data/dm-array.h" +#include "persistent-data/dm-bitset.h" +#include "persistent-data/dm-space-map.h" +#include "persistent-data/dm-space-map-disk.h" +#include "persistent-data/dm-transaction-manager.h" + +#include <linux/device-mapper.h> + +/*----------------------------------------------------------------*/ + +//#define debug(x...) pr_alert(x) +#define debug(x...) ; + +#define DM_MSG_PREFIX "cache metadata" + +#define CACHE_SUPERBLOCK_MAGIC 06142003 +#define CACHE_SUPERBLOCK_LOCATION 0 +#define CACHE_VERSION 1 +#define CACHE_METADATA_CACHE_SIZE 64 + +/* +* 3 for btree insert + +* 2 for btree lookup used within space map +*/ +#define CACHE_MAX_CONCURRENT_LOCKS 5 +#define SPACE_MAP_ROOT_SIZE 128 + +enum superblock_flag_bits { +/* for spotting crashes that would invalidate the dirty bitset */ +CLEAN_SHUTDOWN , +}; + +/* +* Each mapping from cache block -> origin block carries a set of flags. +*/ +enum mapping_bits { +/* +* A valid mapping. Because we're using an array we clear this +* flag for an non existant mapping. +*/ +M_VALID =1 , + +/* +* The data on the cache is different from that on the origin. +*/ +M_DIRTY =2 +}; + +struct cache_disk_superblock { +__le32 csum; +__le32 flags; +__le64 blocknr; + +__u8 uuid[16 ]; +__le64 magic; +__le32 version; + +__u8 policy_name[CACHE_POLICY_NAME_SIZE ]; + +__u8 metadata_space_map_root[SPACE_MAP_ROOT_SIZE ]; +__le64 mapping_root; +__le64 hint_root; + +__le64 discard_root; +__le64 discard_block_size; +__le64 discard_nr_blocks; + +__le32 data_block_size; +__le32 metadata_block_size; +__le32 cache_blocks; + +__le32 compat_flags; +__le32 compat_ro_flags; +__le32 incompat_flags; + +__le32 read_hits; +__le32 read_misses; +__le32 write_hits; +__le32 write_misses; +} __packed; + +struct dm_cache_metadata { +struct block_device *bdev; +struct dm_block_manager *bm; +struct dm_space_map *metadata_sm; +struct dm_transaction_manager *tm; + +struct dm_array_info info; +struct dm_array_info hint_info; +struct dm_bitset_info discard_info; + +struct rw_semaphore root_lock; +dm_block_t root; +dm_block_t hint_root; +dm_block_t discard_root; + +sector_t discard_block_size; +dm_dblock_t discard_nr_blocks; + +sector_t data_block_size; +dm_cblock_t cache_blocks; +bool changed:1 ; +bool clean_when_opened:1 ; + +char policy_name[CACHE_POLICY_NAME_SIZE ]; +struct dm_cache_statistics stats; +}; + +/*------------------------------------------------------------------- +* superblock validator +*-----------------------------------------------------------------*/ + +#define SUPERBLOCK_CSUM_XOR 9031977 + +static void sb_prepare_for_write (struct dm_block_validator *v, +struct dm_block *b, +size_t block_size) +{ +struct cache_disk_superblock *disk_super =dm_block_data (b); + + disk_super->blocknr =cpu_to_le64 (dm_block_location (b)); + disk_super->csum =cpu_to_le32 (dm_bm_checksum (&disk_super->flags, + block_size -sizeof (__le32), +SUPERBLOCK_CSUM_XOR )); +} + +static int sb_check (struct dm_block_validator *v, +struct dm_block *b, +size_t block_size) +{ +struct cache_disk_superblock *disk_super =dm_block_data (b); +__le32 csum_le; + +if (dm_block_location (b) !=le64_to_cpu (disk_super->blocknr)) { +DMERR ("sb_check failed: blocknr %llu: " +"wanted %llu" ,le64_to_cpu (disk_super->blocknr), + (unsigned long long )dm_block_location (b)); +return -ENOTBLK ; + } + +if (le64_to_cpu (disk_super->magic) !=CACHE_SUPERBLOCK_MAGIC ) { +DMERR ("sb_check failed: magic %llu: " +"wanted %llu" ,le64_to_cpu (disk_super->magic), + (unsigned long long )CACHE_SUPERBLOCK_MAGIC ); +return -EILSEQ ; + } + + csum_le =cpu_to_le32 (dm_bm_checksum (&disk_super->flags, + block_size -sizeof (__le32), +SUPERBLOCK_CSUM_XOR )); +if (csum_le != disk_super->csum) { +DMERR ("sb_check failed: csum %u: wanted %u" , +le32_to_cpu (csum_le),le32_to_cpu (disk_super->csum)); +return -EILSEQ ; + } + +return 0 ; +} + +static struct dm_block_validator sb_validator = { + .name ="superblock" , + .prepare_for_write = sb_prepare_for_write, + .check = sb_check +}; + +/*----------------------------------------------------------------*/ + +static int superblock_read_lock (struct dm_cache_metadata *cmd, +struct dm_block **sblock) +{ +return dm_bm_read_lock (cmd->bm,CACHE_SUPERBLOCK_LOCATION , + &sb_validator, sblock); +} + +static int superblock_lock_zero (struct dm_cache_metadata *cmd, +struct dm_block **sblock) +{ +return dm_bm_write_lock_zero (cmd->bm,CACHE_SUPERBLOCK_LOCATION , + &sb_validator, sblock); +} + +static int superblock_lock (struct dm_cache_metadata *cmd, +struct dm_block **sblock) +{ +return dm_bm_write_lock (cmd->bm,CACHE_SUPERBLOCK_LOCATION , + &sb_validator, sblock); +} + +/*----------------------------------------------------------------*/ + +static int __superblock_all_zeroes (struct dm_block_manager *bm,int *result) +{ +int r; +unsigned i; +struct dm_block *b; +__le64 *data_le, zero =cpu_to_le64 (0 ); +unsigned block_size =dm_bm_block_size (bm) /sizeof (__le64); + +/* +* We can't use a validator here - it may be all zeroes. +*/ + r =dm_bm_read_lock (bm,CACHE_SUPERBLOCK_LOCATION ,NULL , &b); +if (r) +return r; + + data_le =dm_block_data (b); + *result =1 ; +for (i =0 ; i < block_size; i++) { +if (data_le[i] != zero) { + *result =0 ; +break ; + } + } + +return dm_bm_unlock (b); +} + +static void __setup_mapping_info (struct dm_cache_metadata *cmd) +{ +struct dm_btree_value_type vt; + + vt.context =NULL ; + vt.size =sizeof (__le64); + vt.inc =NULL ; + vt.dec =NULL ; + vt.equal =NULL ; +dm_setup_array_info (&cmd->info, cmd->tm, &vt); + + vt.size =sizeof (__le32); +dm_setup_array_info (&cmd->hint_info, cmd->tm, &vt); +} + +static int __write_initial_superblock (struct dm_cache_metadata *cmd) +{ +int r; +struct dm_block *sblock; +size_t metadata_len; +struct cache_disk_superblock *disk_super; +sector_t bdev_size =i_size_read (cmd->bdev->bd_inode) >>SECTOR_SHIFT ; + +/* FIXME: see if we can lose the max sectors limit */ +if (bdev_size >CACHE_METADATA_MAX_SECTORS ) + bdev_size =CACHE_METADATA_MAX_SECTORS ; + + r =dm_sm_root_size (cmd->metadata_sm, &metadata_len); +if (r <0 ) +return r; + + r =dm_tm_pre_commit (cmd->tm); +if (r <0 ) +return r; + + r =superblock_lock_zero (cmd, &sblock); +if (r) +return r; + + disk_super =dm_block_data (sblock); + disk_super->flags =0 ; +memset (disk_super->uuid,0 ,sizeof (disk_super->uuid)); + disk_super->magic =cpu_to_le64 (CACHE_SUPERBLOCK_MAGIC ); + disk_super->version =cpu_to_le32 (CACHE_VERSION ); +memset (disk_super->policy_name,0 ,CACHE_POLICY_NAME_SIZE ); + + r =dm_sm_copy_root (cmd->metadata_sm, &disk_super->metadata_space_map_root, + metadata_len); +if (r <0 ) + goto bad_locked; + + disk_super->mapping_root =cpu_to_le64 (cmd->root); + disk_super->hint_root =cpu_to_le64 (cmd->hint_root); + disk_super->discard_root =cpu_to_le64 (cmd->discard_root); + disk_super->discard_block_size =cpu_to_le64 (cmd->discard_block_size); + disk_super->discard_nr_blocks =cpu_to_le64 (from_dblock (cmd->discard_nr_blocks)); + disk_super->metadata_block_size =cpu_to_le32 (CACHE_METADATA_BLOCK_SIZE >>SECTOR_SHIFT ); + disk_super->data_block_size =cpu_to_le32 (cmd->data_block_size); + disk_super->cache_blocks =cpu_to_le32 (0 ); +memset (disk_super->policy_name,0 ,sizeof (disk_super->policy_name)); + + disk_super->read_hits =cpu_to_le32 (0 ); + disk_super->read_misses =cpu_to_le32 (0 ); + disk_super->write_hits =cpu_to_le32 (0 ); + disk_super->write_misses =cpu_to_le32 (0 ); + +return dm_tm_commit (cmd->tm, sblock); + +bad_locked: +dm_bm_unlock (sblock); +return r; +} + +static int __format_metadata (struct dm_cache_metadata *cmd) +{ +int r; + +debug ("formatting metadata dev" ); + r =dm_tm_create_with_sm (cmd->bm,CACHE_SUPERBLOCK_LOCATION , + &cmd->tm, &cmd->metadata_sm); +if (r <0 ) { +DMERR ("tm_create_with_sm failed" ); +return r; + } + +__setup_mapping_info (cmd); + + r =dm_array_empty (&cmd->info, &cmd->root); +if (r <0 ) + goto bad; + +dm_bitset_info_init (cmd->tm, &cmd->discard_info); + + r =dm_bitset_empty (&cmd->discard_info, &cmd->discard_root); +if (r <0 ) + goto bad; + + cmd->discard_block_size =0 ; + cmd->discard_nr_blocks =0 ; + + r =__write_initial_superblock (cmd); +if (r) + goto bad; + + cmd->clean_when_opened = true; +return 0 ; + +bad: +dm_tm_destroy (cmd->tm); +dm_sm_destroy (cmd->metadata_sm); + +return r; +} + +static int __check_incompat_features (struct cache_disk_superblock *disk_super, +struct dm_cache_metadata *cmd) +{ +uint32_t features; + + features =le32_to_cpu (disk_super->incompat_flags) & ~CACHE_FEATURE_INCOMPAT_SUPP ; +if (features) { +DMERR ("could not access metadata due to unsupported optional features (%lx)." , + (unsigned long )features); +return -EINVAL ; + } + +/* +* Check for read-only metadata to skip the following RDWR checks. +*/ +if (get_disk_ro (cmd->bdev->bd_disk)) +return 0 ; + + features =le32_to_cpu (disk_super->compat_ro_flags) & ~CACHE_FEATURE_COMPAT_RO_SUPP ; +if (features) { +DMERR ("could not access metadata RDWR due to unsupported optional features (%lx)." , + (unsigned long )features); +return -EINVAL ; + } + +return 0 ; +} + +static int __open_metadata (struct dm_cache_metadata *cmd) +{ +int r; +struct dm_block *sblock; +struct cache_disk_superblock *disk_super; +unsigned long sb_flags; + + r =superblock_read_lock (cmd, &sblock); +if (r <0 ) { +DMERR ("couldn't read lock superblock" ); +return r; + } + + disk_super =dm_block_data (sblock); + + r =__check_incompat_features (disk_super, cmd); +if (r <0 ) + goto bad; + + r =dm_tm_open_with_sm (cmd->bm,CACHE_SUPERBLOCK_LOCATION , + disk_super->metadata_space_map_root, +sizeof (disk_super->metadata_space_map_root), + &cmd->tm, &cmd->metadata_sm); +if (r <0 ) { +DMERR ("tm_open_with_sm failed" ); + goto bad; + } + +__setup_mapping_info (cmd); +dm_bitset_info_init (cmd->tm, &cmd->discard_info); + sb_flags =le32_to_cpu (disk_super->flags); + cmd->clean_when_opened =test_bit (CLEAN_SHUTDOWN , &sb_flags); +return dm_bm_unlock (sblock); + +bad: +dm_bm_unlock (sblock); +return r; +} + +static int __open_or_format_metadata (struct dm_cache_metadata *cmd, +bool format_device) +{ +int r, unformatted; + + r =__superblock_all_zeroes (cmd->bm, &unformatted); +if (r) +return r; + +if (unformatted) +return format_device ?__format_metadata (cmd) : -EPERM ; + +return __open_metadata (cmd); +} + +static int __create_persistent_data_objects (struct dm_cache_metadata *cmd, +bool may_format_device) +{ +int r; + cmd->bm =dm_block_manager_create (cmd->bdev,CACHE_METADATA_BLOCK_SIZE , +CACHE_METADATA_CACHE_SIZE , +CACHE_MAX_CONCURRENT_LOCKS ); +if (IS_ERR (cmd->bm)) { +DMERR ("could not create block manager" ); +return PTR_ERR (cmd->bm); + } + + r =__open_or_format_metadata (cmd, may_format_device); +if (r) +dm_block_manager_destroy (cmd->bm); + +return r; +} + +static void __destroy_persistent_data_objects (struct dm_cache_metadata *cmd) +{ +dm_sm_destroy (cmd->metadata_sm); +dm_tm_destroy (cmd->tm); +dm_block_manager_destroy (cmd->bm); +} + +typedef unsigned long (*flags_mutator )(unsigned long ); + +static void update_flags (struct cache_disk_superblock *disk_super, +flags_mutator mutator) +{ +uint32_t sb_flags =mutator (le32_to_cpu (disk_super->flags)); + disk_super->flags =cpu_to_le32 (sb_flags); +} + +static unsigned long set_clean_shutdown (unsigned long flags) +{ +set_bit (CLEAN_SHUTDOWN , &flags); +return flags; +} + +static unsigned long clear_clean_shutdown (unsigned long flags) +{ +clear_bit (CLEAN_SHUTDOWN , &flags); +return flags; +} + +static void read_superblock_fields (struct dm_cache_metadata *cmd, +struct cache_disk_superblock *disk_super) +{ + cmd->root =le64_to_cpu (disk_super->mapping_root); + cmd->hint_root =le64_to_cpu (disk_super->hint_root); + cmd->discard_root =le64_to_cpu (disk_super->discard_root); + cmd->discard_block_size =le64_to_cpu (disk_super->discard_block_size); + cmd->discard_nr_blocks =to_dblock (le64_to_cpu (disk_super->discard_nr_blocks)); + cmd->data_block_size =le32_to_cpu (disk_super->data_block_size); + cmd->cache_blocks =to_cblock (le32_to_cpu (disk_super->cache_blocks)); +strncpy (cmd->policy_name, disk_super->policy_name,sizeof (cmd->policy_name)); + + cmd->stats.read_hits =le32_to_cpu (disk_super->read_hits); + cmd->stats.read_misses =le32_to_cpu (disk_super->read_misses); + cmd->stats.write_hits =le32_to_cpu (disk_super->write_hits); + cmd->stats.write_misses =le32_to_cpu (disk_super->write_misses); + + cmd->changed = false; +} + +/* +* The mutator updates the superblock flags. +*/ +static int __begin_transaction_flags (struct dm_cache_metadata *cmd, +flags_mutator mutator) +{ +int r; +struct cache_disk_superblock *disk_super; +struct dm_block *sblock; + + r =superblock_lock (cmd, &sblock); +if (r) +return r; + + disk_super =dm_block_data (sblock); +update_flags (disk_super, mutator); +read_superblock_fields (cmd, disk_super); + +return dm_bm_flush_and_unlock (cmd->bm, sblock); +} + +static int __begin_transaction (struct dm_cache_metadata *cmd) +{ +int r; +struct cache_disk_superblock *disk_super; +struct dm_block *sblock; + +/* +* We re-read the superblock every time. Shouldn't need to do this +* really. +*/ + r =superblock_read_lock (cmd, &sblock); +if (r) +return r; + + disk_super =dm_block_data (sblock); +read_superblock_fields (cmd, disk_super); +dm_bm_unlock (sblock); + +return 0 ; +} + +static int __commit_transaction (struct dm_cache_metadata *cmd, +flags_mutator mutator) +{ +int r; +size_t metadata_len; +struct cache_disk_superblock *disk_super; +struct dm_block *sblock; + +/* +* We need to know if the cache_disk_superblock exceeds a 512-byte sector. +*/ +BUILD_BUG_ON (sizeof (struct cache_disk_superblock ) >512 ); + + r =dm_bitset_flush (&cmd->discard_info, cmd->discard_root, + &cmd->discard_root); +if (r) +return r; + + r =dm_tm_pre_commit (cmd->tm); +if (r <0 ) +return r; + + r =dm_sm_root_size (cmd->metadata_sm, &metadata_len); +if (r <0 ) +return r; + + r =superblock_lock (cmd, &sblock); +if (r) +return r; + + disk_super =dm_block_data (sblock); + +if (mutator) +update_flags (disk_super, mutator); + +debug ("root = %lu\n" , (unsigned long ) cmd->root); + disk_super->mapping_root =cpu_to_le64 (cmd->root); + disk_super->hint_root =cpu_to_le64 (cmd->hint_root); + disk_super->discard_root =cpu_to_le64 (cmd->discard_root); + disk_super->discard_block_size =cpu_to_le64 (cmd->discard_block_size); + disk_super->discard_nr_blocks =cpu_to_le64 (from_dblock (cmd->discard_nr_blocks)); + disk_super->cache_blocks =cpu_to_le32 (from_cblock (cmd->cache_blocks)); +strncpy (disk_super->policy_name, cmd->policy_name,sizeof (disk_super->policy_name)); + + disk_super->read_hits =cpu_to_le32 (cmd->stats.read_hits); + disk_super->read_misses =cpu_to_le32 (cmd->stats.read_misses); + disk_super->write_hits =cpu_to_le32 (cmd->stats.write_hits); + disk_super->write_misses =cpu_to_le32 (cmd->stats.write_misses); + + r =dm_sm_copy_root (cmd->metadata_sm, &disk_super->metadata_space_map_root, + metadata_len); +if (r <0 ) { +dm_bm_unlock (sblock); +return r; + } + +return dm_tm_commit (cmd->tm, sblock); +} + +/*----------------------------------------------------------------*/ + +/* +* The mappings are held in a dm-array that has 64-bit values stored in +* little-endian format. The index is the cblock, the high 48bits of the +* value are the oblock and the low 16 bit the flags. +*/ +#define FLAGS_MASK ((1 << 16) - 1) + +static __le64 pack_value (dm_oblock_t block,unsigned flags) +{ +uint64_t value =from_oblock (block); + value <<=16 ; + value = value | (flags &FLAGS_MASK ); +return cpu_to_le64 (value); +} + +static void unpack_value (__le64 value_le,dm_oblock_t *block,unsigned *flags) +{ +uint64_t value =le64_to_cpu (value_le); +uint64_t b = value >>16 ; + *block =to_oblock (b); + *flags = value &FLAGS_MASK ; +} + +/*----------------------------------------------------------------*/ + +struct dm_cache_metadata *dm_cache_metadata_open (struct block_device *bdev, +sector_t data_block_size, +bool may_format_device) +{ +int r; +struct dm_cache_metadata *cmd; + + cmd =kzalloc (sizeof (*cmd),GFP_KERNEL ); +if (!cmd) { +DMERR ("could not allocate metadata struct" ); +return NULL ; + } + +init_rwsem (&cmd->root_lock); + cmd->bdev = bdev; + cmd->data_block_size = data_block_size; + cmd->cache_blocks =0 ; + cmd->changed = true; + + r =__create_persistent_data_objects (cmd, may_format_device); +if (r) { +kfree (cmd); +return ERR_PTR (r); + } + + r =__begin_transaction_flags (cmd, clear_clean_shutdown); +if (r <0 ) { +dm_cache_metadata_close (cmd); +return ERR_PTR (r); + } + +return cmd; +} + +void dm_cache_metadata_close (struct dm_cache_metadata *cmd) +{ +__destroy_persistent_data_objects (cmd); +kfree (cmd); +} + +int dm_cache_resize (struct dm_cache_metadata *cmd,dm_cblock_t new_cache_size) +{ +int r; +__le64 null_mapping =pack_value (0 ,0 ); + +down_write (&cmd->root_lock); +__dm_bless_for_disk (&null_mapping); + r =dm_array_resize (&cmd->info, cmd->root,from_cblock (cmd->cache_blocks), +from_cblock (new_cache_size), + &null_mapping, &cmd->root); +if (!r) + cmd->cache_blocks = new_cache_size; + cmd->changed = true; +up_write (&cmd->root_lock); + +return r; +} + +int dm_cache_discard_bitset_resize (struct dm_cache_metadata *cmd, +sector_t discard_block_size, +dm_dblock_t new_nr_entries) +{ +int r; + +down_write (&cmd->root_lock); + r =dm_bitset_resize (&cmd->discard_info, + cmd->discard_root, +from_dblock (cmd->discard_nr_blocks), +from_dblock (new_nr_entries), + false, &cmd->discard_root); +if (!r) { + cmd->discard_block_size = discard_block_size; + cmd->discard_nr_blocks = new_nr_entries; + } + + cmd->changed = true; +up_write (&cmd->root_lock); + +return r; +} + +static int __set_discard (struct dm_cache_metadata *cmd,dm_dblock_t b) +{ +return dm_bitset_set_bit (&cmd->discard_info, cmd->discard_root, +from_dblock (b), &cmd->discard_root); +} + +static int __clear_discard (struct dm_cache_metadata *cmd,dm_dblock_t b) +{ +return dm_bitset_clear_bit (&cmd->discard_info, cmd->discard_root, +from_dblock (b), &cmd->discard_root); +} + +static int __is_discarded (struct dm_cache_metadata *cmd,dm_dblock_t b, +bool *is_discarded) +{ +return dm_bitset_test_bit (&cmd->discard_info, cmd->discard_root, +from_dblock (b), &cmd->discard_root, + is_discarded); +} + +static int __discard (struct dm_cache_metadata *cmd, +dm_dblock_t dblock,bool discard) +{ +int r; + + r = (discard ? __set_discard : __clear_discard)(cmd, dblock); +if (r) +return r; + + cmd->changed = true; +return 0 ; +} + +int dm_cache_set_discard (struct dm_cache_metadata *cmd, +dm_dblock_t dblock,bool discard) +{ +int r; + +down_write (&cmd->root_lock); + r =__discard (cmd, dblock, discard); +up_write (&cmd->root_lock); + +return r; +} + +static int __load_discards (struct dm_cache_metadata *cmd, +load_discard_fn fn,void *context) +{ +int r =0 ; +dm_block_t b; +bool discard; + +for (b =0 ; b <from_dblock (cmd->discard_nr_blocks); b++) { +dm_dblock_t dblock =to_dblock (b); + +if (cmd->clean_when_opened) { + r =__is_discarded (cmd, dblock, &discard); +if (r) +return r; + }else + discard = false; + + r =fn (context, cmd->discard_block_size, dblock, discard); +if (r) +break ; + } + +return r; +} + +int dm_cache_load_discards (struct dm_cache_metadata *cmd, +load_discard_fn fn,void *context) +{ +int r; + +down_read (&cmd->root_lock); + r =__load_discards (cmd, fn, context); +up_read (&cmd->root_lock); + +return r; +} + +dm_cblock_t dm_cache_size (struct dm_cache_metadata *cmd) +{ +dm_cblock_t r; + +down_read (&cmd->root_lock); + r = cmd->cache_blocks; +up_read (&cmd->root_lock); + +return r; +} + +static int __remove (struct dm_cache_metadata *cmd,dm_cblock_t cblock) +{ +int r; +__le64 value =pack_value (0 ,0 ); + +debug ("__remove %lu\n" , (unsigned long ) oblock); +__dm_bless_for_disk (&value); + r =dm_array_set (&cmd->info, cmd->root,from_cblock (cblock), + &value, &cmd->root); +if (r) +return r; + + cmd->changed = true; +return 0 ; +} + +int dm_cache_remove_mapping (struct dm_cache_metadata *cmd,dm_cblock_t cblock) +{ +int r; + +down_write (&cmd->root_lock); + r =__remove (cmd, cblock); +up_write (&cmd->root_lock); + +return r; +} + +static int __insert (struct dm_cache_metadata *cmd, +dm_cblock_t cblock,dm_oblock_t oblock) +{ +int r; +__le64 value =pack_value (oblock,M_VALID ); +__dm_bless_for_disk (&value); + + r =dm_array_set (&cmd->info, cmd->root,from_cblock (cblock), + &value, &cmd->root); +if (r) +return r; + + cmd->changed = true; +return 0 ; +} + +int dm_cache_insert_mapping (struct dm_cache_metadata *cmd, +dm_cblock_t cblock,dm_oblock_t oblock) +{ +int r; + +down_write (&cmd->root_lock); + r =__insert (cmd, cblock, oblock); +up_write (&cmd->root_lock); + +return r; +} + +struct thunk { +load_mapping_fn fn; +void *context; + +struct dm_cache_metadata *cmd; +bool respect_dirty_flags; +bool hints_valid; +}; + +static bool hints_array_available (struct dm_cache_metadata *cmd, +const char *policy_name) +{ +bool policy_names_match = !strncmp (cmd->policy_name, policy_name, +sizeof (cmd->policy_name)); + +return cmd->clean_when_opened && policy_names_match && cmd->hint_root; +} + +static int __load_mapping (void *context,uint64_t cblock,void *leaf) +{ +int r =0 ; +bool dirty; +__le64 value; +__le32 hint_value =0 ; +dm_oblock_t oblock; +unsigned flags; +struct thunk *thunk = context; +struct dm_cache_metadata *cmd = thunk->cmd; + +memcpy (&value, leaf,sizeof (value)); +unpack_value (value, &oblock, &flags); + +if (flags &M_VALID ) { +if (thunk->hints_valid) { + r =dm_array_get (&cmd->hint_info, cmd->hint_root, + cblock, &hint_value); +if (r && r != -ENODATA ) +return r; + } + + dirty = thunk->respect_dirty_flags ? (flags &M_DIRTY ) : true; + r = thunk->fn (thunk->context, oblock,to_cblock (cblock), + dirty,le32_to_cpu (hint_value), thunk->hints_valid); + } + +return r; +} + +static int __load_mappings (struct dm_cache_metadata *cmd,const char *policy_name, +load_mapping_fn fn,void *context) +{ +struct thunk thunk; + + thunk.fn = fn; + thunk.context = context; + + thunk.cmd = cmd; + thunk.respect_dirty_flags = cmd->clean_when_opened; + thunk.hints_valid =hints_array_available (cmd, policy_name); + +return dm_array_walk (&cmd->info, cmd->root, __load_mapping, &thunk); +} + +int dm_cache_load_mappings (struct dm_cache_metadata *cmd,const char *policy_name, +load_mapping_fn fn,void *context) +{ +int r; + +debug ("> dm_cache_load_mappings\n" ); +down_read (&cmd->root_lock); + r =__load_mappings (cmd, policy_name, fn, context); +up_read (&cmd->root_lock); +debug ("< dm_cache_load_mappings\n" ); + +return r; +} + +static int __dump_mapping (void *context,uint64_t cblock,void *leaf) +{ +int r =0 ; +__le64 value; +dm_oblock_t oblock; +unsigned flags; + +memcpy (&value, leaf,sizeof (value)); +unpack_value (value, &oblock, &flags); + +if (flags &M_VALID ) +pr_alert ("%p o(%u) -> c(%u)\n" , leaf, + (unsigned )from_oblock (oblock), + (unsigned ) cblock); + +return r; +} + +static int __dump_mappings (struct dm_cache_metadata *cmd) +{ +return dm_array_walk (&cmd->info, cmd->root, __dump_mapping,NULL ); +} + +void dm_cache_dump (struct dm_cache_metadata *cmd) +{ +down_read (&cmd->root_lock); +__dump_mappings (cmd); +up_read (&cmd->root_lock); +} + +int dm_cache_changed_this_transaction (struct dm_cache_metadata *cmd) +{ +int r; + +down_read (&cmd->root_lock); + r = cmd->changed; +up_read (&cmd->root_lock); + +return r; +} + +static int __dirty (struct dm_cache_metadata *cmd,dm_cblock_t cblock,bool dirty) +{ +int r; +unsigned flags; +dm_oblock_t oblock; +__le64 value; + + r =dm_array_get (&cmd->info, cmd->root,from_cblock (cblock), &value); +if (r) +return r; + +unpack_value (value, &oblock, &flags); + +if (((flags &M_DIRTY ) && dirty) || (!(flags &M_DIRTY ) && !dirty)) +/* nothing to be done */ +return 0 ; + + value =pack_value (oblock, flags | (dirty ?M_DIRTY :0 )); +__dm_bless_for_disk (&value); + + r =dm_array_set (&cmd->info, cmd->root,from_cblock (cblock), + &value, &cmd->root); +if (r) +return r; + + cmd->changed = true; +return 0 ; + +} + +int dm_cache_set_dirty (struct dm_cache_metadata *cmd, +dm_cblock_t cblock,bool dirty) +{ +int r; + +down_write (&cmd->root_lock); + r =__dirty (cmd, cblock, dirty); +up_write (&cmd->root_lock); + +return r; +} + +void dm_cache_get_stats (struct dm_cache_metadata *cmd, +struct dm_cache_statistics *stats) +{ +down_read (&cmd->root_lock); +memcpy (stats, &cmd->stats,sizeof (*stats)); +up_read (&cmd->root_lock); +} + +void dm_cache_set_stats (struct dm_cache_metadata *cmd, +struct dm_cache_statistics *stats) +{ +down_write (&cmd->root_lock); +memcpy (&cmd->stats, stats,sizeof (*stats)); +up_write (&cmd->root_lock); +} + +int dm_cache_commit (struct dm_cache_metadata *cmd,bool clean_shutdown) +{ +int r; +flags_mutator mutator = (clean_shutdown ? set_clean_shutdown : + clear_clean_shutdown); + +down_write (&cmd->root_lock); + r =__commit_transaction (cmd, mutator); +if (r) + goto out; + + r =__begin_transaction (cmd); + +out: +up_write (&cmd->root_lock); +return r; +} + +int dm_cache_get_free_metadata_block_count (struct dm_cache_metadata *cmd, +dm_block_t *result) +{ +int r = -EINVAL ; + +down_read (&cmd->root_lock); + r =dm_sm_get_nr_free (cmd->metadata_sm, result); +up_read (&cmd->root_lock); + +return r; +} + +int dm_cache_get_metadata_dev_size (struct dm_cache_metadata *cmd, +dm_block_t *result) +{ +int r = -EINVAL ; + +down_read (&cmd->root_lock); + r =dm_sm_get_nr_blocks (cmd->metadata_sm, result); +up_read (&cmd->root_lock); + +return r; +} + +/*----------------------------------------------------------------*/ + +static int begin_hints (struct dm_cache_metadata *cmd,const char *policy_name) +{ +int r; +__le32 value; + +if (!policy_name[0 ] || + (strlen (policy_name) >sizeof (cmd->policy_name) -1 )) +return -EINVAL ; + +if (strcmp (cmd->policy_name, policy_name)) { +strncpy (cmd->policy_name, policy_name,sizeof (cmd->policy_name)); + +if (cmd->hint_root) { + r =dm_array_del (&cmd->hint_info, cmd->hint_root); +if (r) +return r; + } + + r =dm_array_empty (&cmd->hint_info, &cmd->hint_root); +if (r) +return r; + + value =cpu_to_le32 (0 ); +__dm_bless_for_disk (&value); + r =dm_array_resize (&cmd->hint_info, cmd->hint_root,0 , +from_cblock (cmd->cache_blocks), + &value, &cmd->hint_root); +if (r) +return r; + } + +return 0 ; +} + +int dm_cache_begin_hints (struct dm_cache_metadata *cmd,const char *policy_name) +{ +int r; + +down_write (&cmd->root_lock); + r =begin_hints (cmd, policy_name); +up_write (&cmd->root_lock); + +return r; +} + +static int save_hint (struct dm_cache_metadata *cmd,dm_cblock_t cblock, +uint32_t hint) +{ +int r; +__le32 value =cpu_to_le32 (hint); +__dm_bless_for_disk (&value); + + r =dm_array_set (&cmd->hint_info, cmd->hint_root, +from_cblock (cblock), &value, &cmd->hint_root); + cmd->changed = true; + +return r; +} + +int dm_cache_save_hint (struct dm_cache_metadata *cmd,dm_cblock_t cblock, +uint32_t hint) +{ +int r; + +down_write (&cmd->root_lock); + r =save_hint (cmd, cblock, hint); +up_write (&cmd->root_lock); + +return r; +}drivers/md/dm-cache-metadata.h new file +170
-0@@ -0,0 +1,170 @@ +/* +* Copyright (C) 2012 Red Hat, Inc. +* +* This file is released under the GPL. +*/ + +#ifndef DM_CACHE_METADATA_H +#define DM_CACHE_METADATA_H + +#include "persistent-data/dm-block-manager.h" + +/*----------------------------------------------------------------*/ + +/* +* It's helpful to get sparse to differentiate between indexes into the +* origin device, indexes into the cache device, and indexes into the +* discard bitset. +*/ + +typedef dm_block_t __bitwise__ dm_oblock_t; +typedef uint32_t __bitwise__ dm_cblock_t; +typedef dm_block_t __bitwise__ dm_dblock_t; + +static inline dm_oblock_t to_oblock (dm_block_t b) +{ +return (__force dm_oblock_t ) b; +} + +static inline dm_block_t from_oblock (dm_oblock_t b) +{ +return (__force dm_block_t ) b; +} + +static inline dm_cblock_t to_cblock (uint32_t b) +{ +return (__force dm_cblock_t ) b; +} + +static inline uint32_t from_cblock (dm_cblock_t b) +{ +return (__force uint32_t ) b; +} + +static inline dm_dblock_t to_dblock (dm_block_t b) +{ +return (__force dm_dblock_t ) b; +} + +static inline dm_block_t from_dblock (dm_dblock_t b) +{ +return (__force dm_block_t ) b; +} + +/*----------------------------------------------------------------*/ + +#define CACHE_POLICY_NAME_SIZE 16 +#define CACHE_METADATA_BLOCK_SIZE 4096 + +/* FIXME: remove this restriction */ +/* +* The metadata device is currently limited in size. +* +* We have one block of index, which can hold 255 index entries. Each +* index entry contains allocation info about 16k metadata blocks. +*/ +#define CACHE_METADATA_MAX_SECTORS (255 * (1 << 14) * (CACHE_METADATA_BLOCK_SIZE / (1 << SECTOR_SHIFT))) + +/* +* A metadata device larger than 16GB triggers a warning. +*/ +#define CACHE_METADATA_MAX_SECTORS_WARNING (16 * (1024 * 1024 * 1024 >> SECTOR_SHIFT)) + +/*----------------------------------------------------------------*/ + +/* +* Compat feature flags. Any incompat flags beyond the ones +* specified below will prevent use of the thin metadata. +*/ +#define CACHE_FEATURE_COMPAT_SUPP 0UL +#define CACHE_FEATURE_COMPAT_RO_SUPP 0UL +#define CACHE_FEATURE_INCOMPAT_SUPP 0UL + +/* +* Reopens or creates a new, empty metadata volume. +* Returns an ERR_PTR on failure. +*/ +struct dm_cache_metadata *dm_cache_metadata_open (struct block_device *bdev, +sector_t data_block_size, +bool may_format_device); + +void dm_cache_metadata_close (struct dm_cache_metadata *cmd); + +/* +* The metadata needs to know how many cache blocks there are. We're dont +* care about the origin, assuming the core target is giving us valid +* origin blocks to map to. +*/ +int dm_cache_resize (struct dm_cache_metadata *cmd,dm_cblock_t new_cache_size); +dm_cblock_t dm_cache_size (struct dm_cache_metadata *cmd); + +int dm_cache_discard_bitset_resize (struct dm_cache_metadata *cmd, +sector_t discard_block_size, +dm_dblock_t new_nr_entries); + +typedef int (*load_discard_fn )(void *context,sector_t discard_block_size, +dm_dblock_t dblock,bool discarded); +int dm_cache_load_discards (struct dm_cache_metadata *cmd, +load_discard_fn fn,void *context); + +int dm_cache_set_discard (struct dm_cache_metadata *cmd,dm_dblock_t dblock,bool discard); + +int dm_cache_remove_mapping (struct dm_cache_metadata *cmd,dm_cblock_t cblock); +int dm_cache_insert_mapping (struct dm_cache_metadata *cmd,dm_cblock_t cblock,dm_oblock_t oblock); +int dm_cache_changed_this_transaction (struct dm_cache_metadata *cmd); + +typedef int (*load_mapping_fn )(void *context,dm_oblock_t oblock, +dm_cblock_t cblock,bool dirty, +uint32_t hint,bool hint_valid); +int dm_cache_load_mappings (struct dm_cache_metadata *cmd, +const char *policy_name, +load_mapping_fn fn, +void *context); + +int dm_cache_set_dirty (struct dm_cache_metadata *cmd,dm_cblock_t cblock,bool dirty); + +struct dm_cache_statistics { +uint32_t read_hits; +uint32_t read_misses; +uint32_t write_hits; +uint32_t write_misses; +}; + +void dm_cache_get_stats (struct dm_cache_metadata *cmd, +struct dm_cache_statistics *stats); +void dm_cache_set_stats (struct dm_cache_metadata *cmd, +struct dm_cache_statistics *stats); + +int dm_cache_commit (struct dm_cache_metadata *cmd,bool clean_shutdown); + +int dm_cache_get_free_metadata_block_count (struct dm_cache_metadata *cmd, +dm_block_t *result); + +int dm_cache_get_metadata_dev_size (struct dm_cache_metadata *cmd, +dm_block_t *result); + +void dm_cache_dump (struct dm_cache_metadata *cmd); + +/* +* The policy is invited to save a 32bit hint value for every cblock (eg, +* for a hit count). These are stored against the policy name. If +* policies are changed, then hints will be lost. If the machine crashes, +* hints will be lost. +* +* The hints are indexed by the cblock, but many policies will not +* neccessarily have a fast way of accessing efficiently via cblock. So +* rather than querying the policy for each cblock, we let it walk its data +* structures and fill in the hints in whatever order it wishes. +*/ + +int dm_cache_begin_hints (struct dm_cache_metadata *cmd,const char *policy_name); + +/* +* requests hints for every cblock and stores in the metadata device. +*/ +int dm_cache_save_hint (struct dm_cache_metadata *cmd, +dm_cblock_t cblock,uint32_t hint); + +/*----------------------------------------------------------------*/ + +#endif drivers/md/dm-cache-policy-cleaner.c new file +482
-0@@ -0,0 +1,482 @@ +/* +* Copyright (C) 2012 Red Hat. All rights reserved. +* +* writeback cache policy supporting flushing out dirty cache blocks. +* +* This file is released under the GPL. +*/ + +#include "dm-cache-policy.h" +#include "dm.h" + +#include <linux/hash.h> +#include <linux/list.h> +#include <linux/module.h> +#include <linux/slab.h> + +/*----------------------------------------------------------------*/ + +/* Cache entry struct. */ +struct wb_cache_entry { +struct list_head list; +struct hlist_node hlist; + +dm_oblock_t oblock; +dm_cblock_t cblock; +bool dirty:1 ; +bool pending:1 ; +}; + +struct hash { +struct hlist_head *table; +dm_block_t hash_bits; +unsigned nr_buckets; +}; + +struct policy { +struct dm_cache_policy policy; +spinlock_t lock; + +struct list_head free; +struct list_head clean; +struct list_head clean_pending; +struct list_head dirty; + +/* +* We know exactly how many cblocks will be needed, +* so we can allocate them up front. +*/ +dm_cblock_t cache_size, nr_cblocks_allocated; +struct wb_cache_entry *cblocks; +struct hash chash; +}; + +/*----------------------------------------------------------------------------*/ + +/* +* Low-level functions. +*/ +static unsigned next_power (unsigned n,unsigned min) +{ +return roundup_pow_of_two (max (n, min)); +} + +static struct policy *to_policy (struct dm_cache_policy *p) +{ + return container_of(p, struct policy, policy); +} + +static struct list_head *list_pop (struct list_head *q) +{ +struct list_head *r = q->next; +list_del (r); +return r; +} + +/*----------------------------------------------------------------------------*/ + +/* Allocate/free various resources. */ +static int alloc_hash (struct hash *hash,unsigned elts) +{ + hash->nr_buckets =next_power (elts >>4 ,16 ); + hash->hash_bits =ffs (hash->nr_buckets) -1 ; + hash->table =vzalloc (sizeof (*hash->table) * hash->nr_buckets); + +return hash->table ?0 : -ENOMEM ; +} + +static void free_hash (struct hash *hash) +{ +vfree (hash->table); +} + +static int alloc_cache_blocks_with_hash (struct policy *p,dm_cblock_t cache_size) +{ +int r; + + p->cblocks =vzalloc (sizeof (*p->cblocks) *from_cblock (cache_size)); +if (p->cblocks) { +unsigned u =from_cblock (cache_size); + +while (u--) +list_add (&p->cblocks[u].list, &p->free); + + p->nr_cblocks_allocated =0 ; + +/* Cache entries hash. */ + r =alloc_hash (&p->chash,from_cblock (cache_size)); +if (r) +vfree (p->cblocks); + + }else + r = -ENOMEM ; + +return r; +} + +static void free_cache_blocks_and_hash (struct policy *p) +{ +free_hash (&p->chash); +vfree (p->cblocks); +} + +static struct wb_cache_entry *alloc_cache_entry (struct policy *p) +{ +struct wb_cache_entry *e; + +BUG_ON (from_cblock (p->nr_cblocks_allocated) >=from_cblock (p->cache_size)); + + e = list_entry(list_pop(&p->free), struct wb_cache_entry, list); + p->nr_cblocks_allocated =to_cblock (from_cblock (p->nr_cblocks_allocated) +1 ); + +return e; +} + +/*----------------------------------------------------------------------------*/ + +/* Hash functions (lookup, insert, remove). */ +static struct wb_cache_entry *lookup_cache_entry (struct policy *p,dm_oblock_t oblock) +{ +struct hash *hash = &p->chash; +unsigned h =hash_64 (from_oblock (oblock), hash->hash_bits); +struct wb_cache_entry *cur; +struct hlist_node *tmp; +struct hlist_head *bucket = &hash->table[h]; + +hlist_for_each_entry (cur, tmp, bucket, hlist) { +if (cur->oblock == oblock) { +/* Move upfront bucket for faster access. */ +hlist_del (&cur->hlist); +hlist_add_head (&cur->hlist, bucket); +return cur; + } + } + +return NULL ; +} + +static void insert_cache_hash_entry (struct policy *p,struct wb_cache_entry *e) +{ +unsigned h =hash_64 (from_oblock (e->oblock), p->chash.hash_bits); + +hlist_add_head (&e->hlist, &p->chash.table[h]); +} + +static void remove_cache_hash_entry (struct wb_cache_entry *e) +{ +hlist_del (&e->hlist); +} + +/* Public interface (see dm-cache-policy.h */ +static int wb_map (struct dm_cache_policy *pe,dm_oblock_t oblock, +bool can_block,bool can_migrate,bool discarded_oblock, +struct bio *bio,struct policy_result *result) +{ +struct policy *p =to_policy (pe); +struct wb_cache_entry *e; +unsigned long flags; + + result->op =POLICY_MISS ; + +if (can_block) +spin_lock_irqsave (&p->lock, flags); + +else if (!spin_trylock_irqsave (&p->lock, flags)) +return -EWOULDBLOCK ; + + e =lookup_cache_entry (p, oblock); +if (e) { + result->op =POLICY_HIT ; + result->cblock = e->cblock; + + } + +spin_unlock_irqrestore (&p->lock, flags); + +return 0 ; +} + +static int wb_lookup (struct dm_cache_policy *pe,dm_oblock_t oblock,dm_cblock_t *cblock) +{ +int r; +struct policy *p =to_policy (pe); +struct wb_cache_entry *e; +unsigned long flags; + +if (!spin_trylock_irqsave (&p->lock, flags)) +return -EWOULDBLOCK ; + + e =lookup_cache_entry (p, oblock); +if (e) { + *cblock = e->cblock; + r =0 ; + + }else + r = -ENOENT ; + +spin_unlock_irqrestore (&p->lock, flags); + +return r; +} + + +static void __set_clear_dirty (struct dm_cache_policy *pe,dm_oblock_t oblock,bool set) +{ +struct policy *p =to_policy (pe); +struct wb_cache_entry *e; + + e =lookup_cache_entry (p, oblock); +BUG_ON (!e); + +if (set) { +if (!e->dirty) { + e->dirty = true; +list_move (&e->list, &p->dirty); + } + + }else { +if (e->dirty) { + e->pending = false; + e->dirty = false; +list_move (&e->list, &p->clean); + } + } +} + +static void wb_set_dirty (struct dm_cache_policy *pe,dm_oblock_t oblock) +{ +struct policy *p =to_policy (pe); +unsigned long flags; + +spin_lock_irqsave (&p->lock, flags); +__set_clear_dirty (pe, oblock, true); +spin_unlock_irqrestore (&p->lock, flags); +} + +static void wb_clear_dirty (struct dm_cache_policy *pe,dm_oblock_t oblock) +{ +struct policy *p =to_policy (pe); +unsigned long flags; + +spin_lock_irqsave (&p->lock, flags); +__set_clear_dirty (pe, oblock, false); +spin_unlock_irqrestore (&p->lock, flags); +} + +static void add_cache_entry (struct policy *p,struct wb_cache_entry *e) +{ +insert_cache_hash_entry (p, e); +if (e->dirty) +list_add (&e->list, &p->dirty); +else +list_add (&e->list, &p->clean); +} + +static int wb_load_mapping (struct dm_cache_policy *pe, +dm_oblock_t oblock,dm_cblock_t cblock, +uint32_t hint,bool hint_valid) +{ +int r; +struct policy *p =to_policy (pe); +struct wb_cache_entry *e =alloc_cache_entry (p); + +if (e) { + e->cblock = cblock; + e->oblock = oblock; + e->dirty = false;/* blocks default to clean */ +add_cache_entry (p, e); + r =0 ; + + }else + r = -ENOMEM ; + +return r; +} + +static void wb_destroy (struct dm_cache_policy *pe) +{ +struct policy *p =to_policy (pe); + +free_cache_blocks_and_hash (p); +kfree (p); +} + +static struct wb_cache_entry *__wb_force_remove_mapping (struct policy *p,dm_oblock_t oblock) +{ +struct wb_cache_entry *r =lookup_cache_entry (p, oblock); + +BUG_ON (!r); + +remove_cache_hash_entry (r); +list_del (&r->list); + +return r; +} + +static void wb_remove_mapping (struct dm_cache_policy *pe,dm_oblock_t oblock) +{ +struct policy *p =to_policy (pe); +struct wb_cache_entry *e; +unsigned long flags; + +spin_lock_irqsave (&p->lock, flags); + e =__wb_force_remove_mapping (p, oblock); +list_add_tail (&e->list, &p->free); +BUG_ON (!from_cblock (p->nr_cblocks_allocated)); + p->nr_cblocks_allocated =to_cblock (from_cblock (p->nr_cblocks_allocated) -1 ); +spin_unlock_irqrestore (&p->lock, flags); +} + +static void wb_force_mapping (struct dm_cache_policy *pe, +dm_oblock_t current_oblock,dm_oblock_t oblock) +{ +struct policy *p =to_policy (pe); +struct wb_cache_entry *e; +unsigned long flags; + +spin_lock_irqsave (&p->lock, flags); + e =__wb_force_remove_mapping (p, current_oblock); + e->oblock = oblock; +add_cache_entry (p, e); +spin_unlock_irqrestore (&p->lock, flags); +} + +static struct wb_cache_entry *get_next_dirty_entry (struct policy *p) +{ +struct list_head *l; +struct wb_cache_entry *r; + +if (list_empty (&p->dirty)) +return NULL ; + + l =list_pop (&p->dirty); + r = container_of(l, struct wb_cache_entry, list); +list_add (l, &p->clean_pending); + +return r; +} + +static int wb_writeback_work (struct dm_cache_policy *pe, +dm_oblock_t *oblock, +dm_cblock_t *cblock) +{ +int r = -ENOENT ; +struct policy *p =to_policy (pe); +struct wb_cache_entry *e; +unsigned long flags; + +spin_lock_irqsave (&p->lock, flags); + + e =get_next_dirty_entry (p); +if (e) { + *oblock = e->oblock; + *cblock = e->cblock; + r =0 ; + } + +spin_unlock_irqrestore (&p->lock, flags); + +return r; +} + +static dm_cblock_t wb_residency (struct dm_cache_policy *pe) +{ +return to_policy (pe)->nr_cblocks_allocated; +} + +#if 0 +static int wb_status (struct dm_cache_policy *pe,status_type_t type,unsigned status_flags,char *result,unsigned maxlen) +{ +ssize_t sz =0 ; +struct policy *p =to_policy (pe); + +switch (type) { +case STATUSTYPE_INFO : +DMEMIT ("%u" ,from_cblock (p->nr_dirty)); +break ; + +case STATUSTYPE_TABLE : +break ; + } + +return 0 ; +} +#endif + +/* Init the policy plugin interface function pointers. */ +static void init_policy_functions (struct policy *p) +{ + p->policy.destroy = wb_destroy; + p->policy.map = wb_map; + p->policy.lookup = wb_lookup; + p->policy.set_dirty = wb_set_dirty; + p->policy.clear_dirty = wb_clear_dirty; + p->policy.load_mapping = wb_load_mapping; + p->policy.walk_mappings =NULL ; + p->policy.remove_mapping = wb_remove_mapping; + p->policy.writeback_work = wb_writeback_work; + p->policy.force_mapping = wb_force_mapping; + p->policy.residency = wb_residency; + p->policy.tick =NULL ; +#if 0 + p->policy.status = wb_status; + p->policy.message =NULL ; +#endif +} + +static struct dm_cache_policy *wb_create (dm_cblock_t cache_size, +sector_t origin_size, +sector_t block_size, +int argc,char **argv) +{ +int r; +struct policy *p =kzalloc (sizeof (*p),GFP_KERNEL ); + +if (!p) +return NULL ; + +init_policy_functions (p); +INIT_LIST_HEAD (&p->free); +INIT_LIST_HEAD (&p->clean); +INIT_LIST_HEAD (&p->clean_pending); +INIT_LIST_HEAD (&p->dirty); + + p->cache_size = cache_size; +spin_lock_init (&p->lock); + +/* Allocate cache entry structs and add them to free list. */ + r =alloc_cache_blocks_with_hash (p, cache_size); +if (!r) +return &p->policy; + +kfree (p); + +return NULL ; +} +/*----------------------------------------------------------------------------*/ + +static struct dm_cache_policy_type wb_policy_type = { + .name ="cleaner" , + .hint_size =0 , + .owner =THIS_MODULE , + .create = wb_create +}; + +static int __init wb_init (void ) +{ +return dm_cache_policy_register (&wb_policy_type); +} + +static void __exit wb_exit(void) +{ +dm_cache_policy_unregister (&wb_policy_type); +} + +module_init (wb_init); +module_exit (wb_exit); + +MODULE_AUTHOR ("Heinz Mauelshagen" ); +MODULE_LICENSE ("GPL" ); +MODULE_DESCRIPTION ("cleaner cache policy" ); + +/*----------------------------------------------------------------------------*/ drivers/md/dm-cache-policy-internal.h new file +120
-0@@ -0,0 +1,120 @@ +/* +* Copyright (C) 2012 Red Hat. All rights reserved. +* +* This file is released under the GPL. +*/ + +#ifndef DM_CACHE_POLICY_INTERNAL_H +#define DM_CACHE_POLICY_INTERNAL_H + +#include "dm-cache-policy.h" + +/*----------------------------------------------------------------*/ + +/* +* Little inline functions that simplify calling the policy methods. +*/ +static inline int policy_map (struct dm_cache_policy *p,dm_oblock_t oblock, +bool can_block,bool can_migrate,bool discarded_oblock, +struct bio *bio,struct policy_result *result) +{ +return p->map (p, oblock, can_block, can_migrate, discarded_oblock, bio, result); +} + +static inline int policy_lookup (struct dm_cache_policy *p,dm_oblock_t oblock,dm_cblock_t *cblock) +{ +BUG_ON (!p->lookup); +return p->lookup (p, oblock, cblock); +} + +static inline void policy_set_dirty (struct dm_cache_policy *p,dm_oblock_t oblock) +{ +if (p->set_dirty) + p->set_dirty (p, oblock); +} + +static inline void policy_clear_dirty (struct dm_cache_policy *p,dm_oblock_t oblock) +{ +if (p->clear_dirty) + p->clear_dirty (p, oblock); +} + +static inline int policy_load_mapping (struct dm_cache_policy *p, +dm_oblock_t oblock,dm_cblock_t cblock, +uint32_t hint,bool hint_valid) +{ +return p->load_mapping (p, oblock, cblock, hint, hint_valid); +} + +static inline int policy_walk_mappings (struct dm_cache_policy *p, +policy_walk_fn fn,void *context) +{ +return p->walk_mappings ? p->walk_mappings (p, fn, context) :0 ; +} + +static inline int policy_writeback_work (struct dm_cache_policy *p, +dm_oblock_t *oblock, +dm_cblock_t *cblock) +{ +return p->writeback_work ? p->writeback_work (p, oblock, cblock) : -ENOENT ; +} + +static inline void policy_remove_mapping (struct dm_cache_policy *p,dm_oblock_t oblock) +{ +return p->remove_mapping (p, oblock); +} + +static inline void policy_force_mapping (struct dm_cache_policy *p, +dm_oblock_t current_oblock,dm_oblock_t new_oblock) +{ +return p->force_mapping (p, current_oblock, new_oblock); +} + +static inline dm_cblock_t policy_residency (struct dm_cache_policy *p) +{ +return p->residency (p); +} + +static inline void policy_tick (struct dm_cache_policy *p) +{ +if (p->tick) +return p->tick (p); +} + +static inline int policy_status (struct dm_cache_policy *p,status_type_t type, +unsigned status_flags,char *result,unsigned maxlen) +{ +return p->status ? p->status (p, type, status_flags, result, maxlen) :0 ; +} + +static inline int policy_message (struct dm_cache_policy *p,unsigned argc,char **argv) +{ +return p->message ? p->message (p, argc, argv) :0 ; +} + +/*----------------------------------------------------------------*/ + +/* +* Creates a new cache policy given a policy name, a cache size, an origin size and the block size. +*/ +struct dm_cache_policy *dm_cache_policy_create (const char *name,dm_cblock_t cache_size, +sector_t origin_size,sector_t block_size, +int argc,char **argv); + +/* +* Destroys the policy. This drops references to the policy module as well +* as calling it's destroy method. So always use this rather than calling +* the policy->destroy method directly. +*/ +void dm_cache_policy_destroy (struct dm_cache_policy *p); + +/* +* In case we've forgotten. +*/ +const char *dm_cache_policy_get_name (struct dm_cache_policy *p); + +size_t dm_cache_policy_get_hint_size (struct dm_cache_policy *p); + +/*----------------------------------------------------------------*/ + +#endif drivers/md/dm-cache-policy-mq.c new file +1254
-0@@ -0,0 +1,1254 @@ +/* +* Copyright (C) 2012 Red Hat. All rights reserved. +* +* This file is released under the GPL. +*/ + +#include "dm-cache-policy.h" +#include "dm.h" + +#include <linux/hash.h> +#include <linux/list.h> +#include <linux/module.h> +#include <linux/mutex.h> +#include <linux/slab.h> + +#define DM_MSG_PREFIX "cache-policy-mq" + +static struct kmem_cache *mq_entry_cache; + +/*----------------------------------------------------------------*/ + +static unsigned next_power (unsigned n,unsigned min) +{ +return roundup_pow_of_two (max (n, min)); +} + +/*----------------------------------------------------------------*/ + +static unsigned long *alloc_bitset (unsigned nr_entries) +{ +size_t s =sizeof (unsigned long ) *dm_div_up (nr_entries,BITS_PER_LONG ); +return vzalloc (s); +} + +static void free_bitset (unsigned long *bits) +{ +vfree (bits); +} + +/*----------------------------------------------------------------*/ + +/* +* Large, sequential ios are probably better left on the origin device since +* spindles tend to have good bandwidth. +* +* The io_tracker tries to spot when the io is in one of these sequential +* modes. +* +* The two thresholds are hard coded for now. I'd like them to be +* accessible through a sysfs interface, rather than via the target line. +*/ +#define RANDOM_THRESHOLD_DEFAULT 4 +#define SEQUENTIAL_THRESHOLD_DEFAULT 512 + +enum io_pattern { +PATTERN_SEQUENTIAL , +PATTERN_RANDOM +}; + +struct io_tracker { +enum io_pattern pattern; + +unsigned nr_seq_samples; +unsigned nr_rand_samples; +int thresholds[2 ]; + +dm_oblock_t last_end_oblock; +}; + +static void iot_init (struct io_tracker *t, +int sequential_threshold,int random_threshold) +{ + t->pattern =PATTERN_RANDOM ; + t->nr_seq_samples =0 ; + t->nr_rand_samples =0 ; + t->thresholds[PATTERN_SEQUENTIAL ] = sequential_threshold >-1 ? sequential_threshold :SEQUENTIAL_THRESHOLD_DEFAULT ; + t->thresholds[PATTERN_RANDOM ] = random_threshold >-1 ? random_threshold :RANDOM_THRESHOLD_DEFAULT ; + t->last_end_oblock =0 ; +} + +static enum io_pattern iot_pattern (struct io_tracker *t) +{ +return t->pattern; +} + +static void iot_update_stats (struct io_tracker *t,struct bio *bio) +{ +if (bio->bi_sector ==from_oblock (t->last_end_oblock) +1 ) { + t->nr_seq_samples++; + + }else { +/* +* Just one non-sequential IO is enough to reset the +* counters. +*/ +if (t->nr_seq_samples) { + t->nr_seq_samples =0 ; + t->nr_rand_samples =0 ; + } + + t->nr_rand_samples++; + } + + t->last_end_oblock =to_oblock (bio->bi_sector +bio_sectors (bio) -1 ); +} + +static void iot_check_for_pattern_switch (struct io_tracker *t) +{ +switch (t->pattern) { +case PATTERN_SEQUENTIAL : +if (t->nr_rand_samples >= t->thresholds[PATTERN_RANDOM ]) { + t->pattern =PATTERN_RANDOM ; + t->nr_seq_samples = t->nr_rand_samples =0 ; + } +break ; + +case PATTERN_RANDOM : +if (t->nr_seq_samples >= t->thresholds[PATTERN_SEQUENTIAL ]) { + t->pattern =PATTERN_SEQUENTIAL ; + t->nr_seq_samples = t->nr_rand_samples =0 ; + } +break ; + } +} + +static void iot_examine_bio (struct io_tracker *t,struct bio *bio) +{ +iot_update_stats (t, bio); +iot_check_for_pattern_switch (t); +} + +/*----------------------------------------------------------------*/ + + +/* +* This queue is divided up into different levels. Allowing us to push +* entries to the back of any of the levels. Think of it as a partially +* sorted queue. +*/ +#define NR_QUEUE_LEVELS 16u + +struct queue { +struct list_head qs[NR_QUEUE_LEVELS ]; +}; + +static void queue_init (struct queue *q) +{ +unsigned i; + +for (i =0 ; i <NR_QUEUE_LEVELS ; i++) +INIT_LIST_HEAD (q->qs + i); +} + +/* +* Insert an entry to the back of the given level. +*/ +static void queue_push (struct queue *q,unsigned level,struct list_head *elt) +{ +list_add_tail (elt, q->qs + level); +} + +static void queue_remove (struct list_head *elt) +{ +list_del (elt); +} + +/* +* Shifts all regions down one level. This has no effect on the order of +* the queue. +*/ +static void queue_shift_down (struct queue *q) +{ +unsigned level; + +for (level =1 ; level <NR_QUEUE_LEVELS ; level++) +list_splice_init (q->qs + level, q->qs + level -1 ); +} + +/* +* Gives us the oldest entry of the lowest popoulated level. If the first +* level is emptied then we shift down one level. +*/ +static struct list_head *queue_pop (struct queue *q) +{ +unsigned level; +struct list_head *r; + +for (level =0 ; level <NR_QUEUE_LEVELS ; level++) +if (!list_empty (q->qs + level)) { + r = q->qs[level].next; +list_del (r); + +/* have we just emptied the bottom level? */ +if (level ==0 &&list_empty (q->qs)) +queue_shift_down (q); + +return r; + } + +return NULL ; +} + +static struct list_head *list_pop (struct list_head *lh) +{ +struct list_head *r = lh->next; + +BUG_ON (!r); +list_del_init (r); + +return r; +} + +/*----------------------------------------------------------------*/ + +/* +* Describes a cache entry. Used in both the cache and the pre_cache. +*/ +struct entry { +struct hlist_node hlist; +struct list_head list; +dm_oblock_t oblock; +dm_cblock_t cblock;/* valid iff in_cache */ + +// FIXME: pack these better +bool in_cache:1 ; +unsigned hit_count; +unsigned generation; +unsigned tick; +}; + +struct mq_policy { +struct dm_cache_policy policy; + +/* protects everything */ +struct mutex lock; +dm_cblock_t cache_size; +struct io_tracker tracker; + +/* +* We maintain two queues of entries. The cache proper contains +* the currently active mappings. Whereas the pre_cache tracks +* blocks that are being hit frequently and potential candidates +* for promotion to the cache. +*/ +struct queue pre_cache; +struct queue cache; + +/* +* Keeps track of time, incremented by the core. We use this to +* avoid attributing multiple hits within the same tick. +* +* Access to tick_protected should be done with the spin lock held. +* It's copied to tick at the start of the map function (within the +* mutex). +*/ +spinlock_t tick_lock; +unsigned tick_protected; +unsigned tick; + +/* +* A count of the number of times the map function has been called +* and found an entry in the pre_cache or cache. Currently used to +* calculate the generation. +*/ +unsigned hit_count; + +/* +* A generation is a longish period that is used to trigger some +* book keeping effects. eg, decrementing hit counts on entries. +* This is needed to allow the cache to evolve as io patterns +* change. +*/ +unsigned generation; +unsigned generation_period;/* in lookups (will probably change) */ + +/* +* Entries in the pre_cache whose hit count passes the promotion +* threshold move to the cache proper. Working out the correct +* value for the promotion_threshold is crucial to this policy. +*/ +unsigned promote_threshold; + +/* +* We need cache_size entries for the cache, and choose to have +* cache_size entries for the pre_cache too. One motivation for +* using the same size is to make the hit counts directly +* comparable between pre_cache and cache. +*/ +unsigned nr_entries; +unsigned nr_entries_allocated; +struct list_head free; + +/* +* Cache blocks may be unallocated. We store this info in a +* bitset. +*/ +unsigned long *allocation_bitset; +unsigned nr_cblocks_allocated; +unsigned find_free_nr_words; +unsigned find_free_last_word; + +/* +* The hash table allows us to quickly find an entry by origin +* block. Both pre_cache and cache entries are in here. +*/ +unsigned nr_buckets; +dm_block_t hash_bits; +struct hlist_head *table; + +int threshold_args[2 ]; +}; + +/*----------------------------------------------------------------*/ +/* Free/alloc mq cache entry structures. */ +static void takeout_queue (struct list_head *lh,struct queue *q) +{ +unsigned level; + +for (level =0 ; level <NR_QUEUE_LEVELS ; level++) +list_splice (q->qs + level, lh); +} + +static void free_entries (struct mq_policy *mq) +{ +struct entry *e, *tmp; + +takeout_queue (&mq->free, &mq->pre_cache); +takeout_queue (&mq->free, &mq->cache); + +list_for_each_entry_safe (e, tmp, &mq->free, list) +kmem_cache_free (mq_entry_cache, e); +} + +static int alloc_entries (struct mq_policy *mq,unsigned elts) +{ +unsigned u = mq->nr_entries; + +INIT_LIST_HEAD (&mq->free); + mq->nr_entries_allocated =0 ; + +while (u--) { +struct entry *e =kmem_cache_zalloc (mq_entry_cache,GFP_KERNEL ); + +if (!e) { +free_entries (mq); +return -ENOMEM ; + } + + +list_add (&e->list, &mq->free); + } + +return 0 ; +} + +/*----------------------------------------------------------------*/ + +/* +* Simple hash table implementation. Should replace with the standard hash +* table that's making its way upstream. +*/ +static void hash_insert (struct mq_policy *mq,struct entry *e) +{ +unsigned h =hash_64 (from_oblock (e->oblock), mq->hash_bits); +hlist_add_head (&e->hlist, mq->table + h); +} + +static struct entry *hash_lookup (struct mq_policy *mq,dm_oblock_t oblock) +{ +unsigned h =hash_64 (from_oblock (oblock), mq->hash_bits); +struct hlist_head *bucket = mq->table + h; +struct hlist_node *tmp; +struct entry *e; + +hlist_for_each_entry (e, tmp, bucket, hlist) +if (e->oblock == oblock) { +hlist_del (&e->hlist); +hlist_add_head (&e->hlist, bucket); +return e; + } + +return NULL ; +} + +static void hash_remove (struct entry *e) +{ +hlist_del (&e->hlist); +} + +/*----------------------------------------------------------------*/ + +/* +* Allocates a new entry structure. The memory is allocated in one lump, +* so we just handing it out here. Returns NULL if all entries have +* already been allocated. Cannot fail otherwise. +*/ +static struct entry *alloc_entry (struct mq_policy *mq) +{ +struct entry *e; + +if (mq->nr_entries_allocated >= mq->nr_entries) { +BUG_ON (!list_empty (&mq->free)); +return NULL ; + } + + e = list_entry(list_pop(&mq->free), struct entry, list); +INIT_LIST_HEAD (&e->list); +INIT_HLIST_NODE (&e->hlist); + + mq->nr_entries_allocated++; +return e; +} + +/*----------------------------------------------------------------*/ + +/* +* Mark cache blocks allocated or not in the bitset. +*/ +static void alloc_cblock (struct mq_policy *mq,dm_cblock_t cblock) +{ +BUG_ON (from_cblock (cblock) >from_cblock (mq->cache_size)); +BUG_ON (test_bit (from_cblock (cblock), mq->allocation_bitset)); +set_bit (from_cblock (cblock), mq->allocation_bitset); + mq->nr_cblocks_allocated++; +} + +static void free_cblock (struct mq_policy *mq,dm_cblock_t cblock) +{ +BUG_ON (from_cblock (cblock) >from_cblock (mq->cache_size)); +BUG_ON (!test_bit (from_cblock (cblock), mq->allocation_bitset)); +clear_bit (from_cblock (cblock), mq->allocation_bitset); + mq->nr_cblocks_allocated--; +} + +static bool any_free_cblocks (struct mq_policy *mq) +{ +return mq->nr_cblocks_allocated <from_cblock (mq->cache_size); +} + +/* +* Fills result out with a cache block that isn't in use, or return +* -ENOSPC. This does _not_ mark the cblock as allocated, the caller is +* reponsible for that. +*/ +static int __find_free_cblock (struct mq_policy *mq,unsigned begin,unsigned end, +dm_cblock_t *result,unsigned *last_word) +{ +int r = -ENOSPC ; +unsigned w; + +for (w = begin; w < end; w++) { +/* +* ffz is undefined if no zero exists +*/ +if (mq->allocation_bitset[w] != ~0UL ) { + *last_word = w; + *result =to_cblock ((w *BITS_PER_LONG ) +ffz (mq->allocation_bitset[w])); +if (from_cblock (*result) <from_cblock (mq->cache_size)) + r =0 ; + +break ; + } + } + +return r; +} + +static int find_free_cblock (struct mq_policy *mq,dm_cblock_t *result) +{ +int r; + +if (!any_free_cblocks (mq)) +return -ENOSPC ; + + r =__find_free_cblock (mq, mq->find_free_last_word, mq->find_free_nr_words, result, &mq->find_free_last_word); +if (r == -ENOSPC && mq->find_free_last_word) + r =__find_free_cblock (mq,0 , mq->find_free_last_word, result, &mq->find_free_last_word); + +return r; +} + +/*----------------------------------------------------------------*/ + +/* +* Now we get to the meat of the policy. This section deals with deciding +* when to to add entries to the pre_cache and cache, and move between +* them. +*/ + +/* +* The queue level is based on the log2 of the hit count. +*/ +static unsigned queue_level (struct entry *e) +{ +return min ((unsigned )ilog2 (e->hit_count),NR_QUEUE_LEVELS -1u ); +} + +/* +* Inserts the entry into the pre_cache or the cache. Ensures the cache +* block is marked as allocated if necc. Inserts into the hash table. Sets the +* tick which records when the entry was last moved about. +*/ +static void push (struct mq_policy *mq,struct entry *e) +{ + e->tick = mq->tick; +hash_insert (mq, e); + +if (e->in_cache) { +alloc_cblock (mq, e->cblock); +queue_push (&mq->cache,queue_level (e), &e->list); + }else +queue_push (&mq->pre_cache,queue_level (e), &e->list); +} + +/* +* Removes an entry from pre_cache or cache. Removes from the hash table. +* Frees off the cache block if necc. +*/ +static void del (struct mq_policy *mq,struct entry *e) +{ +queue_remove (&e->list); +hash_remove (e); +if (e->in_cache) +free_cblock (mq, e->cblock); +} + +/* +* Like del, except it removes the first entry in the queue (ie. the least +* recently used). +*/ +static struct entry *pop (struct mq_policy *mq,struct queue *q) +{ + struct entry *e = container_of(queue_pop(q), struct entry, list); + +if (e) { +hash_remove (e); + +if (e->in_cache) +free_cblock (mq, e->cblock); + } + +return e; +} + +/* +* Has this entry already been updated? +*/ +static bool updated_this_tick (struct mq_policy *mq,struct entry *e) +{ +return mq->tick == e->tick; +} + +/* +* The promotion threshold is adjusted every generation. As are the counts +* of the entries. +* +* At the moment the threshold is taken by averaging the hit counts of some +* of the entries in the cache (the first 20 entries of the first level). +* +* We can be much cleverer than this though. For example, each promotion +* could bump up the threshold helping to prevent churn. Much more to do +* here. +*/ + +#define MAX_TO_AVERAGE 20 + +static void check_generation (struct mq_policy *mq) +{ +unsigned total =0 , nr =0 , count =0 , level; +struct list_head *head; +struct entry *e; + +if ((mq->hit_count >= mq->generation_period) && + (mq->nr_cblocks_allocated ==from_cblock (mq->cache_size))) { + + mq->hit_count =0 ; + mq->generation++; + +for (level =0 ; level <NR_QUEUE_LEVELS && count <MAX_TO_AVERAGE ; level++) { + head = mq->cache.qs + level; + list_for_each_entry (e, head, list) { + nr++; + total += e->hit_count; + +if (++count >=MAX_TO_AVERAGE ) +break ; + } + } + + mq->promote_threshold = nr ? total / nr :1 ; +if (mq->promote_threshold * nr < total) + mq->promote_threshold++; + +pr_alert ("promote threshold = %u, nr = %u\n" , mq->promote_threshold, nr); + } +} + +/* +* Whenever we use an entry we bump up it's hit counter, and push it to the +* back to it's current level. +*/ +static void requeue_and_update_tick (struct mq_policy *mq,struct entry *e) +{ +if (updated_this_tick (mq, e)) +return ; + + e->hit_count++; + mq->hit_count++; +check_generation (mq); + +/* generation adjustment, to stop the counts increasing forever. */ +/* FIXME: divide? */ +//e->hit_count -= min(e->hit_count - 1, mq->generation - e->generation); + e->generation = mq->generation; + +del (mq, e); +push (mq, e); +} + +/* +* Demote the least recently used entry from the cache to the pre_cache. +* Returns the new cache entry to use, and the old origin block it was +* mapped to. +* +* We drop the hit count on the demoted entry back to 1 to stop it bouncing +* straight back into the cache if it's subsequently hit. There are +* various options here, and more experimentation would be good: +* +* - just forget about the demoted entry completely (ie. don't insert it +into the pre_cache). +* - divide the hit count rather that setting to some hard coded value. +* - set the hit count to a hard coded value other than 1, eg, is it better +* if it goes in at level 2? +*/ +static dm_cblock_t demote_cblock (struct mq_policy *mq,dm_oblock_t *oblock) +{ +dm_cblock_t result; +struct entry *demoted =pop (mq, &mq->cache); + +BUG_ON (!demoted); + result = demoted->cblock; + *oblock = demoted->oblock; + demoted->in_cache = false; + demoted->hit_count =1 ; +push (mq, demoted); + +return result; +} + +/* +* We modify the basic promotion_threshold depending on the specific io. +* +* If the origin block has been discarded then there's no cost to copy it +* to the cache. +* +* We bias towards reads, since they can be demoted at no cost if they +* haven't been dirtied. +*/ +#define DISCARDED_PROMOTE_THRESHOLD 1 +#define READ_PROMOTE_THRESHOLD 4 +#define WRITE_PROMOTE_THRESHOLD 8 + +static unsigned adjusted_promote_threshold (struct mq_policy *mq, +bool discarded_oblock,int data_dir) +{ +if (discarded_oblock &&any_free_cblocks (mq) && data_dir ==WRITE ) +/* +* We don't need to do any copying at all, so give this a +* very low threshold. In practice this only triggers +* during initial population after a format. +*/ +return DISCARDED_PROMOTE_THRESHOLD ; + +return data_dir ==READ ? + (mq->promote_threshold +READ_PROMOTE_THRESHOLD ) : + (mq->promote_threshold +WRITE_PROMOTE_THRESHOLD ); +} + +static bool should_promote (struct mq_policy *mq,struct entry *e, +bool discarded_oblock,int data_dir) +{ +return e->hit_count >= +adjusted_promote_threshold (mq, discarded_oblock, data_dir); +} + +static int cache_entry_found (struct mq_policy *mq, +struct entry *e, +struct policy_result *result) +{ +requeue_and_update_tick (mq, e); + +if (e->in_cache) { + result->op =POLICY_HIT ; + result->cblock = e->cblock; +return 0 ; + } + +return 0 ; +} + +/* +* Moves and entry from the pre_cache to the cache. The main work is +* finding which cache block to use. +*/ +static int pre_cache_to_cache (struct mq_policy *mq,struct entry *e, +struct policy_result *result) +{ +dm_cblock_t cblock; + +if (find_free_cblock (mq, &cblock) == -ENOSPC ) { + result->op =POLICY_REPLACE ; + cblock =demote_cblock (mq, &result->old_oblock); + }else + result->op =POLICY_NEW ; + + result->cblock = e->cblock = cblock; + +del (mq, e); + e->in_cache = true; +push (mq, e); + +return 0 ; +} + +static int pre_cache_entry_found (struct mq_policy *mq,struct entry *e, +bool can_migrate,bool discarded_oblock, +int data_dir,struct policy_result *result) +{ +int r =0 ; +bool updated =updated_this_tick (mq, e); + +requeue_and_update_tick (mq, e); + +if ((!discarded_oblock && updated) || + !should_promote (mq, e, discarded_oblock, data_dir)) + result->op =POLICY_MISS ; + +else if (!can_migrate) + r = -EWOULDBLOCK ; + +else + r =pre_cache_to_cache (mq, e, result); + +return r; +} + +static void insert_in_pre_cache (struct mq_policy *mq, +dm_oblock_t oblock) +{ +struct entry *e =alloc_entry (mq); + +if (!e) +/* +* There's no spare entry structure, so we grab the least +* used one from the pre_cache. +*/ + e =pop (mq, &mq->pre_cache); + +if (unlikely (!e)) { +DMWARN ("couldn't pop from pre cache" ); +return ; + } + + e->in_cache = false; + e->oblock = oblock; + e->hit_count =1 ; + e->generation = mq->generation; +push (mq, e); +} + +static void insert_in_cache (struct mq_policy *mq,dm_oblock_t oblock, +struct policy_result *result) +{ +struct entry *e; +dm_cblock_t cblock; + +if (find_free_cblock (mq, &cblock) == -ENOSPC ) { + result->op =POLICY_MISS ; +insert_in_pre_cache (mq, oblock); +return ; + } + + e =alloc_entry (mq); +if (unlikely (!e)) { + result->op =POLICY_MISS ; +return ; + } + + e->oblock = oblock; + e->cblock = cblock; + e->in_cache = true; + e->hit_count =1 ; + e->generation = mq->generation; +push (mq, e); + + result->op =POLICY_NEW ; + result->cblock = e->cblock; +} + +static int no_entry_found (struct mq_policy *mq,dm_oblock_t oblock, +bool can_migrate,bool discarded_oblock, +int data_dir,struct policy_result *result) +{ +if (adjusted_promote_threshold (mq, discarded_oblock, data_dir) ==1 ) { +if (can_migrate) { +insert_in_cache (mq, oblock, result); +return 0 ; + }else +return -EWOULDBLOCK ; + + }else { +insert_in_pre_cache (mq, oblock); + result->op =POLICY_MISS ; +return 0 ; + } +} + +/* +* Looks the oblock up in the hash table, then decides whether to put in +* pre_cache, or cache etc. +*/ +static int map (struct mq_policy *mq,dm_oblock_t oblock, +bool can_migrate,bool discarded_oblock, +int data_dir,struct policy_result *result) +{ +int r =0 ; +struct entry *e =hash_lookup (mq, oblock); + +if (e && e->in_cache) + r =cache_entry_found (mq, e, result); + +else if (iot_pattern (&mq->tracker) ==PATTERN_SEQUENTIAL ) + result->op =POLICY_MISS ; + +else if (e) + r =pre_cache_entry_found (mq, e, can_migrate, discarded_oblock, + data_dir, result); +else + r =no_entry_found (mq, oblock, can_migrate, discarded_oblock, + data_dir, result); + +if (r == -EWOULDBLOCK )Lines of this file are not shown. View the raw message.
drivers/md/dm-cache-policy.c new file +147
-0Lines of this file are not shown. View the raw message.
drivers/md/dm-cache-policy.h new file +220
-0Lines of this file are not shown. View the raw message.
drivers/md/dm-cache-target.c new file +2443
-0Lines of this file are not shown. View the raw message.
drivers/md/persistent-data/dm-block-manager.c +1
-0Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
Signature · 6 lines
1.7.10.4 -- dm-devel mailing list [email protected] https://www.redhat.com/mailman/listinfo/dm-devel
Part of the diff is not shown here. View the raw message.
Re: [PATCH 8/8] [dm-cache] cache target
Quoted 5 lines · Darrick J. Wong
Mmmm, another one! I've been looking forward to this.... :)
Documentation/device-mapper/dm-cache.txt line 4
Quoted 2 lines
Documentation/device-mapper/dm-cache.txt new file +2
-0+dm-cache is a device mapper target written by Joe Thornber, Heinz +Maueslhagen, and Mike Snitzer.Is this "Mauelshagen"?
y
Quoted 9 lines
Quoted 4 lines
+- Migration - Movement of a logical block from one device to the other. +- Promotion - Migration from slow device to fast device. +- Demotion - Migration from fast device to slow device.If a block is promoted to the fast device, is it always the case that the block still resides on the slow device? The existence of WT mode implies this, but on the other hand you do say "move" here.
Quoted 6 lines
Or is this more like tiered storage where promoting a block moves it to the fast device and it's no longer on the slow device?
Put another way -- if I use my SSD as a writethrough cache for a disk and one day the SSD loses its brains, can I expect to still have a reasonably up to date copy on the disk?
The cached device is the same size as the origin (not origin + ssd). If writethrough mode is selected then writes will not complete until they've hit both the origin and the cache. This makes it a relatively safe way to try the cache out.
Here's the little test I use to demonstrate this:
def test_writethrough
size = gig(2)
# wipe the origin to ensure we don't accidentally have the same # data on it.
with_standard_linear(:data_size => size) do |origin|
wipe_device(origin)
end
# format and set up a git repo on the cache with_standard_cache(:format => true,
:io_mode => :writethrough, :data_size => size) do |cache|
git_prepare(cache, :ext4)
end
# origin should have all data with_standard_linear(:data_size => size) do |origin|
git_extract(origin, :ext4, TAGS[0..1])
end
end
Quoted 1 line
How do I calculate how big the metadata device has to be?
Metadata size will be proportional to the number of blocks in your cache (ssd_size / block_size). For each block we store:
- The mapping and some flags (64bits)
- Policy hint data (size determined by policy, 64bit for mq)
In addition we store a small bitset that records the discard state of the origin.
A good rule of thumb would be: 4mb + (16bytes * nr_blocks)
Quoted 3 lines
Is there any documentation for the message formats?
Or the policy parameters?
Not yet, I'll let Heinz handle this, he put the messaging stuff in.
- Joe
Alasdair G Kergon
maintainerRe: [PATCH 8/8] [dm-cache] cache target
In reply to Joe Thornber[Although I'm replying to this old email, I'm looking at updated code taken from the all-caches branch ofgit://github.com/jthornber/linux-2.6 ]
Quoted 7 lines · Joe Thornber
drivers/md/Kconfig | 22 +drivers/md/dm-cache-policy-cleaner.c | 482 +++++ drivers/md/dm-cache-policy-mq.c | 1254 +++++++++++++
drivers/md/Kconfig config DM_DEBUG_BLOCK_STACK_TRACING · line 277
Quoted 9 lines
drivers/md/Kconfig +8
-0+config DM_CACHE + tristate "Cache target (EXPERIMENTAL)" + depends on BLK_DEV_DM + default n + select DM_PERSISTENT_DATA + select DM_PRISON + ---help--- + Use an SSD to speed up a slower device.
Can we allow for other non-SSD uses too?
"Use a faster device like an SSD to speed up a slower device." perhaps?
Quoted 9 lines
drivers/md/Kconfig +6
-0+ dm-cache attempts to improve performance of a block device by + moving frequently used data to a smaller, higher performance + device. Different 'policy' plugins can be used to change the + algorithms used to select which blocks are promoted, demoted, + cleaned etc. It supports writeback and writethrough modes. +++ b/drivers/md/dm-cache-policy-cleaner.c
drivers/md/Kconfig
Quoted 6 lines
drivers/md/Kconfig +5
-0@@ -0,0 +1,482 @@ +#include "dm-cache-policy.h" +#include "dm.h" + +#include <linux/hash.h> +#include <linux/list.h>
list.h already included by dm.h
drivers/md/Kconfig
Quoted 5 lines
drivers/md/Kconfig +5
-0+#include <linux/module.h> +#include <linux/slab.h> + +/*----------------------------------------------------------------*/ +
#define DM_MSG_PREFIX "cache cleaner"
#define CLEANER_VERSION "1.0.0"
drivers/md/Kconfig
Quoted 3 lines
drivers/md/Kconfig +3
-0+static int alloc_cache_blocks_with_hash(struct policy *p, dm_cblock_t cache_size) +{ + int r;
int r = -ENOMEM ?
Quoted 7 lines
drivers/md/Kconfig +7
-0+ + p->cblocks = vzalloc(sizeof(*p->cblocks) * from_cblock(cache_size)); + if (p->cblocks) { + unsigned u = from_cblock(cache_size); + + while (u--) + list_add(&p->cblocks[u].list, &p->free);
drivers/md/Kconfig
Quoted 10 lines
drivers/md/Kconfig +10
-0+ + p->nr_cblocks_allocated = 0; + + /* Cache entries hash. */ + r = alloc_hash(&p->chash, from_cblock(cache_size)); + if (r) + vfree(p->cblocks); + + } else + r = -ENOMEM;
Initialise instead.
drivers/md/Kconfig
Quoted 4 lines
drivers/md/Kconfig +4
-0+} + + +static void __set_clear_dirty(struct dm_cache_policy *pe, dm_oblock_t oblock, bool set)
Extra blank line
Quoted 8 lines
drivers/md/Kconfig +8
-0+#if 0 +static int wb_status(struct dm_cache_policy *pe, status_type_t type, unsigned status_flags, char *result, unsigned maxlen) +{ + ssize_t sz = 0; + struct policy *p = to_policy(pe); + + switch (type) { + case STATUSTYPE_INFO:
drivers/md/Kconfig
Quoted 10 lines
drivers/md/Kconfig +10
-0+ DMEMIT("%u", from_cblock(p->nr_dirty)); + break; + + case STATUSTYPE_TABLE: + break; + } + + return 0; +} +#endif
Provide a documented stable status or drop this for now?
drivers/md/Kconfig
Quoted 9 lines
drivers/md/Kconfig +8
-0+#if 0 + p->policy.status = wb_status; + p->policy.message = NULL; +#endif +static int __init wb_init(void) +{ + return dm_cache_policy_register(&wb_policy_type); +}
Log like other modules (e.g. dm-queue-length.c):
DMINFO("version " CLEANER_VERSION " loaded");Similar DMINFO changes in dm-cache-policy-mq.c.
Alasdair
Alasdair G Kergon
maintainerRe: [PATCH 8/8] [dm-cache] cache target
Quoted 2 lines · Alasdair G Kergon
updated code taken from the all-caches branch of
git://github.com/jthornber/linux-2.6
File: dm-cache-policy.c
Quoted 3 lines
#include "
dm.h"#include <
linux/list.h>
Already pulled in via dm.h
Quoted 5 lines
static struct
dm_cache_policy_type*__get_policy(const char *name){ struct dm_cache_policy_type *t = __find_policy(name); if (!t) {
Could we move this up a level and avoid the inverted unlock/lock (which only seems to confuse automated lock analysis)?
__find_policy(); if not found, request_module and __find_policy again ?
Quoted 6 lines
spin_unlock(®ister_lock);
request_module("dm-cache-%s", name);
spin_lock(®ister_lock);
t = __find_policy(name);
}Quoted 6 lines
int
dm_cache_policy_register(struct dm_cache_policy_type *type){ int r; /* One size fits all for now */ if (type->hint_size != 0 && type->hint_size != 4)
This should never happen unless coding error or corruption => DMWARN?
Quoted 8 lines
return -EINVAL;void
dm_cache_policy_destroy(struct dm_cache_policy *p){ struct dm_cache_policy_type *t = p->private; put_policy(t);
module_put should be AFTER destroy or the code could get unloaded while destroy is still running?
[Still to check the ref counting is sufficient: to understand why this is a bit simpler than dm-path-selector which also handles modules plugging into modules and went through a few iterations fixing ref problems]
Quoted 2 lines
p->destroy(p); }
Alasdair
Alasdair G Kergon
maintainerRe: [PATCH 8/8] [dm-cache] cache target
Quoted 2 lines · Alasdair G Kergon
updated code taken from the all-caches branch of
git://github.com/jthornber/linux-2.6
File: dm-cache-target.c
Quoted 1 line
#include <
asm/div64.h>
Is this needed anywhere? We should be using sector_div for sector_t.
Quoted 1 line
#include <
linux/blkdev.h>
Already in dm.h
Quoted 1 line
#include <
linux/list.h>
Already in dm.h
Quoted 4 lines
struct cache_features {
enum cache_mode mode;
bool write_through:1;
};We should probably support 'ignore_discard' like thin, so it's possible to skip internal target discard processing if the user thinks it gives them no net benefit.
Quoted 1 line
struct cache {
Rather large - some parts could be moved out into sub structures (stats), but never mind for now.
Quoted 13 lines
static struct
dm_bio_prison_cell*prealloc_get_cell(struct prealloc *p){ struct dm_bio_prison_cell *r = NULL; if (p->cell1) { r = p->cell1; p->cell1 = NULL; } else if (p->cell2) { r = p->cell2; p->cell2 = NULL; } else BUG();
Brief comment explaining the assumption here (or at top of fn) to help people if this BUG() is hit?
Quoted 11 lines
static void
prealloc_put_cell(struct prealloc *p, struct dm_bio_prison_cell *cell){ if (!p->cell2) p->cell2 = cell; else if (!p->cell1) p->cell1 = cell; else BUG(); }
Same.
Quoted 6 lines
static
dm_dblock_toblock_to_dblock(struct cache *cache, dm_oblock_t oblock){ sector_t tmp = cache->discard_block_size; dm_block_t b = from_oblock(oblock); do_div(tmp, cache->sectors_per_block);
sector_div? (and elsewhere)
Quoted 10 lines
do_div(b, tmp); return to_dblock(b); }static void
load_stats(struct cache *cache){ struct dm_cache_statistics stats; dm_cache_get_stats(cache->cmd, &stats);
Make it clearer from the fn name where the stats are "got" from? e.g. dm_cache_metadata_* or _get_stats_from_*
Quoted 7 lines
static void
migration_success_post_commit(struct dm_cache_migration *mg){ unsigned long flags; struct cache *cache = mg->cache; if (mg->writeback) { DMWARN("shouldn't get here");
Explain why. BUG? or corruption?
Quoted 14 lines
return;/*
* People generally discard large parts of a device, eg, the whole device
* when formatting. Splitting these large discards up into cache block
* sized ios and then quiescing (always neccessary for discard) takes too
* long.
*
* We keep it simple, and allow any size of discard to come in, and just
* mark off blocks on the discard bitset. No passdown occurs! *
* To implement passdown we need to change thebio_prisonsuch that a cell
* can have a key that spans many blocks. This change is planned for
* thin-provisioning.
Re-word the last bit of this slightly so it doesn't become incorrect if thin provisioning implements this? (Would we remember to update this comment otherwise?)
Quoted 8 lines
*/
static voidprocess_discard_bio(struct cache *cache, struct bio *bio)static void
cache_dtr(struct dm_target *ti){ struct cache *cache = ti->private; pr_alert("dm-cache statistics:\n");
alert?! Just debugging code that you'll be removing, I trust:)
Quoted 19 lines
static int ensure_args__(struct
dm_arg_set*as,
unsigned count, char **error){ if (as->argc < count) { *error = "Insufficient args"; return -EINVAL; } return 0; }#define ensure_args(n) \ do { \ r = ensure_args__(as, n, error); \ if (r) \ return r; \ } while (0)
Quoted 8 lines
static int parse_metadata_dev(struct
cache_args*ca, structdm_arg_set*as,
char **error){ int r; sector_t metadata_dev_size; char b[BDEVNAME_SIZE]; ensure_args(1);
I'm afraid I don't see any benefit of this: it slows down understanding of the code and has a hidden 'return' that isn't hinted at in the macro name to trip people up.
Can we not do something like:
if (!at_least_one_arg(as, error)) return -EINVAL;
Quoted 13 lines
#define parse(name) \
do { \
r = parse_ ## name(ca, &as, error); \
if (r) \
return r; \
} while (0)
parse(metadata_dev);
parse(cache_dev);
parse(origin_dev);
parse(block_size);
parse(features);
parse(policy);Quoted 1 line
#undef parse
Please just write this out longhand: I don't see the gain from making the reader deal with a new macro.
Quoted 1 line
static struct
kmem_cache*_migration_cache;
Remove _ prefix I think.
Quoted 1 line
static int
cache_create(struct cache_args *ca, struct cache **result)
Use PTR_ERR maybe? Maybe not.
Quoted 5 lines
ti->num_discard_bios = 1; ti->discards_supported = true; ti->discard_zeroes_data_unsupported = true; if (cache->features.write_through)
Fix: if (ca->features.write_through)
Quoted 6 lines
ti->num_write_bios = cache_num_write_bios;static int cache_status(struct
dm_target*ti,status_type_ttype,
unsignedstatus_flags, char *result, unsigned maxlen)
Add provision for policy status here too?
Quoted 1 line
static int
process_config_option(struct cache *cache, char **argv)
Document non-standard return value up-front?
Quoted 8 lines
{
if (!strcasecmp(argv[1], "migration_threshold")) {
unsigned long tmp;
if (kstrtoul(argv[2], 10, &tmp))
return -EINVAL;
cache->migration_threshold = tmp;Does this need any validation or is any value OK/sensible?
Quoted 3 lines
} else return 1; /* Inform caller it's not our option. */
Invert if and return 1 immediately, dropping need for else + indentation?
Document current message(s) supported by this file inline ahead of function here
Quoted 13 lines
static int
cache_message(struct dm_target *ti, unsigned argc, char **argv){ int r = 0; struct cache *cache = ti->private; if (argc != 3) return -EINVAL; r = !strcasecmp(argv[0], "set_config") ? process_config_option(cache, argv) : 1; if (r == 1) /* Message is for the target -> hand over to policy plugin. */ r = policy_message(cache->policy, argc, argv);
What's responsible for logging that the message wasn't recognised?
or is EINVAL enough perhaps as we don't really add any info to that?
Drop 'set_config'?
=> "set" or why not just use the variable name directly as the message?
Quoted 3 lines
static int cache_bvec_merge(struct
dm_target*ti,
structbvec_merge_data*bvm, structbio_vec*biovec, intmax_size)
Needs a comment to explain the reasoning here I think. We act as if the cache dev wasn't present?
Then take the hit and split later if cached?
Have we seen any impact in tests or tried alternatives here?
Quoted 1 line
static void
cache_io_hints(struct dm_target *ti, struct queue_limits *limits)
Check carefully. The thin version of this had to be fixed.
Quoted 1 line
static void
dm_cache_exit(void)
Missing __exit (not used anywhere else)
Alasdair
Re: [PATCH 8/8] [dm-cache] cache target
In reply to Alasdair G KergonQuoted 3 lines · Alasdair G Kergon
[Still to check the ref counting is sufficient: to understand why this is a bit simpler than dm-path-selector which also handles modules plugging into modules and went through a few iterations fixing ref problems]
dm-path-selector is more complicated because you have two 'type' structures. A public one and an internal (keyed on the ->name field of the public one).
Re: [PATCH 8/8] [dm-cache] cache target
In reply to Alasdair G KergonQuoted 4 lines · Alasdair G Kergon
Log like other modules (e.g.
dm-queue-length.c):DMINFO("version " CLEANER_VERSION " loaded");Similar DMINFO changes in
dm-cache-policy-mq.c.
When we've discussed this sort of thing before we've always decided not to version sub modules and instead just rely on the overall kernel version. Who are you intending should consume this DMINFO?
Alasdair G Kergon
maintainerRe: [PATCH 8/8] [dm-cache] cache target
Quoted 3 lines · Joe Thornber
When we've discussed this sort of thing before we've always decided not to version sub modules and instead just rely on the overall kernel version. Who are you intending should consume this DMINFO?
People who have reason to look at their system logs when something they can't explain has happened (and then us, when they send snippets of the logs).
All the optional dm sub-modules that plug into other modules report when they are loaded/unloaded. Then given that they are writing a line to the log, they might as well supply a version number in it, particularly if we're anticipating that once the core has settled down, future change will be concentrated around tuning these modules so we can't necessarily deduce which version of sub-module code is running from the module code version.
Relying on the core kernel version just turns this into a lookup table maintenance problem to find out what patch was applied to what distro when. dm versioning gives us a quick distro-independent way to guess which version of our code was likely to have been running from information often included in the intial report of the problem.
Alasdair
Quoted 6 lines · Joe Thornber
Here's a cache target that Heinz Mauelshagen, Mike Snitzer and I have been working on.
It's also available in the thin-dev branch of my git tree:
[email protected]:jthornber/linux-2.6.git
This url is best for others to clone from:git://github.com/jthornber/linux-2.6.git
Quoted 3 lines
The main features are a plug-in architecture for policies which decide what data gets cached, and reuse of the metadata library from the thin provisioning target.
It should be noted that there are more cache replacement policies available in Joe's thin-dev branch via the "basic" policy, see:drivers/md/dm-cache-policy-basic.c
(these basic policies include fifo, lru, lfu, and many more)
Quoted 2 lines
These patches apply on top of the dm patches that agk has got queued for 3.8.
agk's patches are here:
http://people.redhat.com/agk/patches/linux/editing/series.html
But agk hasn't staged all the required patches yet. I've imported agk's editing tree (and a couple other required patches that I previously posted to dm-devel, which aren't yet in agk's tree) into the 'dm-for-3.8' branch on my github tree here:git://github.com/snitm/linux.git
This 8 patch patchset from Joe should apply cleanly ontop of my 'dm-for-3.8' branch.
But if all you care about is a tree with all the changes then please just use Joe's github 'thin-dev' branch.
Quoted 35 lines · Mike Snitzer
Quoted 6 lines · Joe Thornber
Here's a cache target that Heinz Mauelshagen, Mike Snitzer and I have been working on.
It's also available in the thin-dev branch of my git tree:
[email protected]:jthornber/linux-2.6.git
This url is best for others to clone from:
git://github.com/jthornber/linux-2.6.gitQuoted 3 lines
The main features are a plug-in architecture for policies which decide what data gets cached, and reuse of the metadata library from the thin provisioning target.
It should be noted that there are more cache replacement policies available in Joe's thin-dev branch via the "basic" policy, see:
drivers/md/dm-cache-policy-basic.c(these basic policies include fifo, lru, lfu, and many more)
Quoted 2 lines
These patches apply on top of the dm patches that agk has got queued for 3.8.
agk's patches are here:
http://people.redhat.com/agk/patches/linux/editing/series.htmlBut agk hasn't staged all the required patches yet. I've imported agk's editing tree (and a couple other required patches that I previously posted to dm-devel, which aren't yet in agk's tree) into the 'dm-for-3.8' branch on my github tree here:
git://github.com/snitm/linux.git
Quoted 5 lines
This 8 patch patchset from Joe should apply cleanly ontop of my 'dm-for-3.8' branch.
But if all you care about is a tree with all the changes then please just use Joe's github 'thin-dev' branch.
A full list of broken-out patches would've been nice, but oh well, I ate this git tree. :)
Curiously, the Documentation/device-mapper/dm-cache.txt says to specify devices in the order: metadata, origin, and cache, but the code (and Joe's mail) seeem to want metadata, cache, origin. This sort of makes me wonder what's going on?
Also, I found a bug when using the mru policy. If I do this:
<set up a scsi_debug "ssd" with a 448M /dev/sda1 for cache and the rest for
metadata on /dev/sda2>
# echo 0 67108864 cache /dev/sda2 /dev/sda1 /dev/vda 512 0 mru 0 | dmsetup create fubar ...<use fubar, fill up the cache>... # dmsetup remove fubar # echo 0 67108864 cache /dev/sda2 /dev/sda1 /dev/vda 512 0 mru 0 | dmsetup create fubar
I see the following crash in dmesg:
[ 426.661458] scsi1 : scsi_debug, version 1.82 [20100324], dev_size_mb=512, opts=0x0 [ 426.663955] scsi 1:0:0:0: Direct-Access Linux scsi_debug 0004 PQ: 0 ANSI: 5 [ 426.667005] sd 1:0:0:0: Attached scsi generic sg0 type 0 [ 426.667020] sd 1:0:0:0: [sda] 1048576 512-byte logical blocks: (536 MB/512 MiB) [ 426.667046] sd 1:0:0:0: [sda] Write Protect is off [ 426.667057] sd 1:0:0:0: [sda] Write cache: enabled, read cache: enabled, supports DPO and FUA [ 426.667203] sda: unknown partition table [ 426.667311] sd 1:0:0:0: [sda] Attached SCSI disk [ 426.694055] sda: sda1 sda2 [ 448.155368] bio: create slab <bio-1> at 1 [ 460.762930] promote thresholds = 65/4 queue stats = 1/0 [ 468.121084] promote thresholds = 65/4 queue stats = 1/1 [ 471.970865] dm-cache statistics: [ 471.974809] read hits: 887895 [ 471.976948] read misses: 499 [ 471.978195] write hits: 0 [ 471.979380] write misses: 0 [ 471.980716] demotions: 7 [ 471.982391] promotions: 1799 [ 471.983798] copies avoided: 7 [ 471.985137] cache cell clashs: 0 [ 471.986886] commits: 1653 [ 471.988410] discards: 0 [ 474.177476] bio: create slab <bio-1> at 1 [ 474.206000] BUG: unable to handle kernel NULL pointer dereference at 0000000000000008 [ 474.209037] IP: [<ffffffffa01b1aad>] queue_evict_default+0x1d/0x50 [dm_cache_basic] [ 474.209969] PGD 0 [ 474.209969] Oops: 0002 [#1] PREEMPT SMP [ 474.209969] Modules linked in: scsi_debug dm_cache_basic dm_cache_mq dm_cache dm_bio_prison dm_persistent_data dm_bufio crc_t10dif nfsv4 sch_fq_codel eeprom nfsd auth_rpcgss exportfs af_packet btrfs zlib_deflate libcrc32c [last unloaded: scsi_debug] [ 474.209969] CPU 0 [ 474.209969] Pid: 1285, comm: kworker/u:2 Not tainted 3.7.0-dmcache #1 Bochs Bochs [ 474.209969] RIP: 0010:[<ffffffffa01b1aad>] [<ffffffffa01b1aad>] queue_evict_default+0x1d/0x50 [dm_cache_basic] [ 474.209969] RSP: 0018:ffff880055641be8 EFLAGS: 00010282 [ 474.209969] RAX: ffff880073a85eb0 RBX: ffff880037ca5c00 RCX: 0000000000000000 [ 474.209969] RDX: 0000000000000000 RSI: 0007fff80005ffff RDI: ffff880073a85eb0 [ 474.209969] RBP: ffff880055641be8 R08: e000000000000000 R09: ffff880072d619a0 [ 474.209969] R10: 0000000000000034 R11: fffffff80005ffff R12: ffff880037f33d30 [ 474.209969] R13: ffff880037ca5c78 R14: ffff880055641c98 R15: 000000000001ffff [ 474.209969] FS: 0000000000000000(0000) GS:ffff88007fc00000(0000) knlGS:0000000000000000 [ 474.209969] CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 [ 474.209969] CR2: 0000000000000008 CR3: 0000000001a0c000 CR4: 00000000000407f0 [ 474.209969] DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000 [ 474.209969] DR3: 0000000000000000 DR6: 00000000ffff0ff0 DR7: 0000000000000400 [ 474.209969] Process kworker/u:2 (pid: 1285, threadinfo ffff880055640000, task ffff88007cb62de0) [ 474.209969] Stack: [ 474.209969] ffff880055641c58 ffffffffa01b28a4 0000000000000040 0000000000000286 [ 474.209969] ffff880000000000 ffffffffa017658c 0000000000000000 ffff880155641cd0 [ 474.209969] ffff880055641c58 ffff88007cac7400 ffff880055641d50 ffff880037f33d30 [ 474.209969] Call Trace: [ 474.209969] [<ffffffffa01b28a4>] basic_map+0x484/0x708 [dm_cache_basic] [ 474.209969] [<ffffffffa017658c>] ? dm_bio_detain+0x5c/0x80 [dm_bio_prison] [ 474.209969] [<ffffffffa019c221>] process_bio+0x101/0x4c0 [dm_cache] [ 474.209969] [<ffffffffa019cb4f>] do_worker+0x56f/0x630 [dm_cache] [ 474.209969] [<ffffffff81081ab6>] ? finish_task_switch+0x56/0xb0 [ 474.209969] [<ffffffff8106fa31>] process_one_work+0x121/0x490 [ 474.209969] [<ffffffffa019c5e0>] ? process_bio+0x4c0/0x4c0 [dm_cache] [ 474.209969] [<ffffffff81070be5>] worker_thread+0x165/0x3f0 [ 474.209969] [<ffffffff81070a80>] ? manage_workers+0x2a0/0x2a0 [ 474.209969] [<ffffffff81076010>] kthread+0xc0/0xd0 [ 474.209969] [<ffffffff81075f50>] ? flush_kthread_worker+0xb0/0xb0 [ 474.209969] [<ffffffff815680ac>] ret_from_fork+0x7c/0xb0 [ 474.209969] [<ffffffff81075f50>] ? flush_kthread_worker+0xb0/0xb0 [ 474.209969] Code: de 48 89 47 08 48 89 f8 5d c3 0f 0b 66 90 66 66 66 66 90 55 48 8b bf f8 01 00 00 48 89 e5 e8 ab ff ff ff 48 8b 48 28 48 8b 50 30 <48> 89 51 08 48 89 0a 48 ba 00 01 10 00 00 00 ad de 48 b9 00 02 [ 474.209969] RIP [<ffffffffa01b1aad>] queue_evict_default+0x1d/0x50 [dm_cache_basic] [ 474.209969] RSP <ffff880055641be8> [ 474.209969] CR2: 0000000000000008 [ 474.333040] ---[ end trace 20dda5f362594054 ]--- [ 474.336010] BUG: unable to handle kernel paging request at ffffffffffffffd8 [ 474.336680] IP: [<ffffffff810761f0>] kthread_data+0x10/0x20 [ 474.336680] PGD 1a0e067 PUD 1a0f067 PMD 0 [ 474.336680] Oops: 0000 [#2] PREEMPT SMP [ 474.336680] Modules linked in: scsi_debug dm_cache_basic dm_cache_mq dm_cache dm_bio_prison dm_persistent_data dm_bufio crc_t10dif nfsv4 sch_fq_codel eeprom nfsd auth_rpcgss exportfs af_packet btrfs zlib_deflate libcrc32c [last unloaded: scsi_debug] [ 474.336680] CPU 0 [ 474.336680] Pid: 1285, comm: kworker/u:2 Tainted: G D 3.7.0-dmcache #1 Bochs Bochs [ 474.336680] RIP: 0010:[<ffffffff810761f0>] [<ffffffff810761f0>] kthread_data+0x10/0x20 [ 474.336680] RSP: 0018:ffff8800556417a8 EFLAGS: 00010096 [ 474.336680] RAX: 0000000000000000 RBX: 0000000000000000 RCX: ffffffff81bb2f80 [ 474.336680] RDX: 0000000000000000 RSI: 0000000000000000 RDI: ffff88007cb62de0 [ 474.336680] RBP: ffff8800556417a8 R08: 0000000000000001 R09: 0000000000000083 [ 474.336680] R10: 0000000000000000 R11: 0000000000000001 R12: 0000000000000000 [ 474.336680] R13: ffff88007cb631d0 R14: 0000000000000000 R15: 0000000000000001 [ 474.336680] FS: 0000000000000000(0000) GS:ffff88007fc00000(0000) knlGS:0000000000000000 [ 474.336680] CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 [ 474.336680] CR2: ffffffffffffffd8 CR3: 0000000001a0c000 CR4: 00000000000407f0 [ 474.336680] DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000 [ 474.336680] DR3: 0000000000000000 DR6: 00000000ffff0ff0 DR7: 0000000000000400 [ 474.336680] Process kworker/u:2 (pid: 1285, threadinfo ffff880055640000, task ffff88007cb62de0) [ 474.336680] Stack: [ 474.336680] ffff8800556417c8 ffffffff81071445 ffff8800556417c8 ffff88007fc12880 [ 474.336680] ffff880055641848 ffffffff81565a58 ffff8800556417f8 ffff880037daeba0 [ 474.336680] ffff88007cb62de0 ffff880055641fd8 ffff880055641fd8 ffff880055641fd8 [ 474.336680] Call Trace: [ 474.336680] [<ffffffff81071445>] wq_worker_sleeping+0x15/0xc0 [ 474.336680] [<ffffffff81565a58>] __schedule+0x5f8/0x7c0 [ 474.336680] [<ffffffff81565d39>] schedule+0x29/0x70 [ 474.336680] [<ffffffff81057748>] do_exit+0x678/0x9e0 [ 474.336680] [<ffffffff8155fe50>] ? printk+0x4d/0x4f [ 474.336680] [<ffffffff8100662b>] oops_end+0xab/0xf0 [ 474.336680] [<ffffffff8155f7a6>] no_context+0x201/0x210 [ 474.336680] [<ffffffff8155f986>] __bad_area_nosemaphore+0x1d1/0x1f0 [ 474.336680] [<ffffffff8110ba75>] ? mempool_kmalloc+0x15/0x20 [ 474.336680] [<ffffffff8155f9b8>] bad_area_nosemaphore+0x13/0x15 [ 474.336680] [<ffffffff810311a2>] __do_page_fault+0x322/0x4d0 [ 474.336680] [<ffffffff8111109f>] ? get_page_from_freelist+0x1bf/0x460 [ 474.336680] [<ffffffff81335eca>] ? virtblk_request+0x44a/0x460 [ 474.336680] [<ffffffff81232d56>] ? cpumask_next_and+0x36/0x50 [ 474.336680] [<ffffffff81232d56>] ? cpumask_next_and+0x36/0x50 [ 474.336680] [<ffffffff8108fa53>] ? update_sd_lb_stats+0x123/0x610 [ 474.336680] [<ffffffff8103138e>] do_page_fault+0xe/0x10 [ 474.336680] [<ffffffff8102e425>] do_async_page_fault+0x35/0xa0 [ 474.336680] [<ffffffff81567925>] async_page_fault+0x25/0x30 [ 474.336680] [<ffffffffa01b1aad>] ? queue_evict_default+0x1d/0x50 [dm_cache_basic] [ 474.336680] [<ffffffffa01b1aa5>] ? queue_evict_default+0x15/0x50 [dm_cache_basic] [ 474.336680] [<ffffffffa01b28a4>] basic_map+0x484/0x708 [dm_cache_basic] [ 474.336680] [<ffffffffa017658c>] ? dm_bio_detain+0x5c/0x80 [dm_bio_prison] [ 474.336680] [<ffffffffa019c221>] process_bio+0x101/0x4c0 [dm_cache] [ 474.336680] [<ffffffffa019cb4f>] do_worker+0x56f/0x630 [dm_cache] [ 474.336680] [<ffffffff81081ab6>] ? finish_task_switch+0x56/0xb0 [ 474.336680] [<ffffffff8106fa31>] process_one_work+0x121/0x490 [ 474.336680] [<ffffffffa019c5e0>] ? process_bio+0x4c0/0x4c0 [dm_cache] [ 474.336680] [<ffffffff81070be5>] worker_thread+0x165/0x3f0 [ 474.336680] [<ffffffff81070a80>] ? manage_workers+0x2a0/0x2a0 [ 474.336680] [<ffffffff81076010>] kthread+0xc0/0xd0 [ 474.336680] [<ffffffff81075f50>] ? flush_kthread_worker+0xb0/0xb0 [ 474.336680] [<ffffffff815680ac>] ret_from_fork+0x7c/0xb0 [ 474.336680] [<ffffffff81075f50>] ? flush_kthread_worker+0xb0/0xb0 [ 474.336680] Code: 00 48 89 e5 5d 48 8b 40 c8 48 c1 e8 02 83 e0 01 c3 66 2e 0f 1f 84 00 00 00 00 00 66 66 66 66 90 48 8b 87 98 03 00 00 55 48 89 e5 <48> 8b 40 d8 5d c3 66 2e 0f 1f 84 00 00 00 00 00 66 66 66 66 90 [ 474.336680] RIP [<ffffffff810761f0>] kthread_data+0x10/0x20 [ 474.336680] RSP <ffff8800556417a8> [ 474.336680] CR2: ffffffffffffffd8 [ 474.336680] ---[ end trace 20dda5f362594055 ]--- [ 474.336680] Fixing recursive fault but reboot is needed! [ 477.004016] Kernel panic - not syncing: Watchdog detected hard LOCKUP on cpu 1 [ 477.004016] Shutting down cpus with NMI [ 477.004016] panic occurred, switching back to text console
*Before* it crashes, though, I can run my iops exerciser and watch the numbers climb from ~300 to ~100000. Nice work! :)
(The default policy engine doesn't seem to have this problem, but I haven't figured out how to make it cache blocks yet...)
--D
Quoted 5 lines
--
dm-devel mailing list
[email protected]
https://www.redhat.com/mailman/listinfo/dm-devel
Quoted 42 lines · Darrick J. Wong
Quoted 35 lines · Mike Snitzer
Quoted 6 lines · Joe Thornber
Here's a cache target that Heinz Mauelshagen, Mike Snitzer and I have been working on.
It's also available in the thin-dev branch of my git tree:
[email protected]:jthornber/linux-2.6.git
This url is best for others to clone from:
git://github.com/jthornber/linux-2.6.gitQuoted 3 lines
The main features are a plug-in architecture for policies which decide what data gets cached, and reuse of the metadata library from the thin provisioning target.
It should be noted that there are more cache replacement policies available in Joe's thin-dev branch via the "basic" policy, see:
drivers/md/dm-cache-policy-basic.c(these basic policies include fifo, lru, lfu, and many more)
Quoted 2 lines
These patches apply on top of the dm patches that agk has got queued for 3.8.
agk's patches are here:
http://people.redhat.com/agk/patches/linux/editing/series.htmlBut agk hasn't staged all the required patches yet. I've imported agk's editing tree (and a couple other required patches that I previously posted to dm-devel, which aren't yet in agk's tree) into the 'dm-for-3.8' branch on my github tree here:
git://github.com/snitm/linux.gitQuoted 5 lines
This 8 patch patchset from Joe should apply cleanly ontop of my 'dm-for-3.8' branch.
But if all you care about is a tree with all the changes then please just use Joe's github 'thin-dev' branch.
Quoted 6 lines
A full list of broken-out patches would've been nice, but oh well, I ate this git tree. :)
Curiously, the
Documentation/device-mapper/dm-cache.txtsays to specify devices in the order: metadata, origin, and cache, but the code (and Joe's mail) seeem to want metadata, cache, origin. This sort of makes me wonder what's going on?
The patch Joe posted has the proper order (metadata, cache, origin -- I fixed the ordering in dm-cache,txt and Joe pulled it in before posting the patches). Seems Joe forgot to push his last few tweaks to his thin-dev branch.
Quoted 1 line
Also, I found a bug when using the mru policy. If I do this:
Pretty sure you'd be best served to focus on the code Joe posted. Maybe best to clone my github tree and start with my 'dm-for-3.8' branch. And then apply all the patches Joe posted.
I'd stick to the "default" policy -- aka "mq".
Joe purposely didn't post the "basic" policies because they are less well tested.
Quoted 145 lines
<set up a
scsi_debug"ssd" with a 448M/dev/sda1for cache and the rest for
metadata on/dev/sda2># echo 0 67108864 cache /dev/sda2 /dev/sda1 /dev/vda 512 0 mru 0 | dmsetup create fubar ...<use fubar, fill up the cache>... # dmsetup remove fubar # echo 0 67108864 cache /dev/sda2 /dev/sda1 /dev/vda 512 0 mru 0 | dmsetup create fubarI see the following crash in dmesg:
[ 426.661458] scsi1 : scsi_debug, version 1.82 [20100324], dev_size_mb=512, opts=0x0 [ 426.663955] scsi 1:0:0:0: Direct-Access Linux scsi_debug 0004 PQ: 0 ANSI: 5 [ 426.667005] sd 1:0:0:0: Attached scsi generic sg0 type 0 [ 426.667020] sd 1:0:0:0: [sda] 1048576 512-byte logical blocks: (536 MB/512 MiB) [ 426.667046] sd 1:0:0:0: [sda] Write Protect is off [ 426.667057] sd 1:0:0:0: [sda] Write cache: enabled, read cache: enabled, supports DPO and FUA [ 426.667203] sda: unknown partition table [ 426.667311] sd 1:0:0:0: [sda] Attached SCSI disk [ 426.694055] sda: sda1 sda2 [ 448.155368] bio: create slab <bio-1> at 1 [ 460.762930] promote thresholds = 65/4 queue stats = 1/0 [ 468.121084] promote thresholds = 65/4 queue stats = 1/1 [ 471.970865] dm-cache statistics: [ 471.974809] read hits: 887895 [ 471.976948] read misses: 499 [ 471.978195] write hits: 0 [ 471.979380] write misses: 0 [ 471.980716] demotions: 7 [ 471.982391] promotions: 1799 [ 471.983798] copies avoided: 7 [ 471.985137] cache cell clashs: 0 [ 471.986886] commits: 1653 [ 471.988410] discards: 0 [ 474.177476] bio: create slab <bio-1> at 1 [ 474.206000] BUG: unable to handle kernel NULL pointer dereference at 0000000000000008 [ 474.209037] IP: [<ffffffffa01b1aad>] queue_evict_default+0x1d/0x50 [dm_cache_basic] [ 474.209969] PGD 0 [ 474.209969] Oops: 0002 [#1] PREEMPT SMP [ 474.209969] Modules linked in: scsi_debug dm_cache_basic dm_cache_mq dm_cache dm_bio_prison dm_persistent_data dm_bufio crc_t10dif nfsv4 sch_fq_codel eeprom nfsd auth_rpcgss exportfs af_packet btrfs zlib_deflate libcrc32c [last unloaded: scsi_debug] [ 474.209969] CPU 0 [ 474.209969] Pid: 1285, comm: kworker/u:2 Not tainted 3.7.0-dmcache #1 Bochs Bochs [ 474.209969] RIP: 0010:[<ffffffffa01b1aad>] [<ffffffffa01b1aad>] queue_evict_default+0x1d/0x50 [dm_cache_basic] [ 474.209969] RSP: 0018:ffff880055641be8 EFLAGS: 00010282 [ 474.209969] RAX: ffff880073a85eb0 RBX: ffff880037ca5c00 RCX: 0000000000000000 [ 474.209969] RDX: 0000000000000000 RSI: 0007fff80005ffff RDI: ffff880073a85eb0 [ 474.209969] RBP: ffff880055641be8 R08: e000000000000000 R09: ffff880072d619a0 [ 474.209969] R10: 0000000000000034 R11: fffffff80005ffff R12: ffff880037f33d30 [ 474.209969] R13: ffff880037ca5c78 R14: ffff880055641c98 R15: 000000000001ffff [ 474.209969] FS: 0000000000000000(0000) GS:ffff88007fc00000(0000) knlGS:0000000000000000 [ 474.209969] CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 [ 474.209969] CR2: 0000000000000008 CR3: 0000000001a0c000 CR4: 00000000000407f0 [ 474.209969] DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000 [ 474.209969] DR3: 0000000000000000 DR6: 00000000ffff0ff0 DR7: 0000000000000400 [ 474.209969] Process kworker/u:2 (pid: 1285, threadinfo ffff880055640000, task ffff88007cb62de0) [ 474.209969] Stack: [ 474.209969] ffff880055641c58 ffffffffa01b28a4 0000000000000040 0000000000000286 [ 474.209969] ffff880000000000 ffffffffa017658c 0000000000000000 ffff880155641cd0 [ 474.209969] ffff880055641c58 ffff88007cac7400 ffff880055641d50 ffff880037f33d30 [ 474.209969] Call Trace: [ 474.209969] [<ffffffffa01b28a4>] basic_map+0x484/0x708 [dm_cache_basic] [ 474.209969] [<ffffffffa017658c>] ? dm_bio_detain+0x5c/0x80 [dm_bio_prison] [ 474.209969] [<ffffffffa019c221>] process_bio+0x101/0x4c0 [dm_cache] [ 474.209969] [<ffffffffa019cb4f>] do_worker+0x56f/0x630 [dm_cache] [ 474.209969] [<ffffffff81081ab6>] ? finish_task_switch+0x56/0xb0 [ 474.209969] [<ffffffff8106fa31>] process_one_work+0x121/0x490 [ 474.209969] [<ffffffffa019c5e0>] ? process_bio+0x4c0/0x4c0 [dm_cache] [ 474.209969] [<ffffffff81070be5>] worker_thread+0x165/0x3f0 [ 474.209969] [<ffffffff81070a80>] ? manage_workers+0x2a0/0x2a0 [ 474.209969] [<ffffffff81076010>] kthread+0xc0/0xd0 [ 474.209969] [<ffffffff81075f50>] ? flush_kthread_worker+0xb0/0xb0 [ 474.209969] [<ffffffff815680ac>] ret_from_fork+0x7c/0xb0 [ 474.209969] [<ffffffff81075f50>] ? flush_kthread_worker+0xb0/0xb0 [ 474.209969] Code: de 48 89 47 08 48 89 f8 5d c3 0f 0b 66 90 66 66 66 66 90 55 48 8b bf f8 01 00 00 48 89 e5 e8 ab ff ff ff 48 8b 48 28 48 8b 50 30 <48> 89 51 08 48 89 0a 48 ba 00 01 10 00 00 00 ad de 48 b9 00 02 [ 474.209969] RIP [<ffffffffa01b1aad>] queue_evict_default+0x1d/0x50 [dm_cache_basic] [ 474.209969] RSP <ffff880055641be8> [ 474.209969] CR2: 0000000000000008 [ 474.333040] ---[ end trace 20dda5f362594054 ]--- [ 474.336010] BUG: unable to handle kernel paging request at ffffffffffffffd8 [ 474.336680] IP: [<ffffffff810761f0>] kthread_data+0x10/0x20 [ 474.336680] PGD 1a0e067 PUD 1a0f067 PMD 0 [ 474.336680] Oops: 0000 [#2] PREEMPT SMP [ 474.336680] Modules linked in: scsi_debug dm_cache_basic dm_cache_mq dm_cache dm_bio_prison dm_persistent_data dm_bufio crc_t10dif nfsv4 sch_fq_codel eeprom nfsd auth_rpcgss exportfs af_packet btrfs zlib_deflate libcrc32c [last unloaded: scsi_debug] [ 474.336680] CPU 0 [ 474.336680] Pid: 1285, comm: kworker/u:2 Tainted: G D 3.7.0-dmcache #1 Bochs Bochs [ 474.336680] RIP: 0010:[<ffffffff810761f0>] [<ffffffff810761f0>] kthread_data+0x10/0x20 [ 474.336680] RSP: 0018:ffff8800556417a8 EFLAGS: 00010096 [ 474.336680] RAX: 0000000000000000 RBX: 0000000000000000 RCX: ffffffff81bb2f80 [ 474.336680] RDX: 0000000000000000 RSI: 0000000000000000 RDI: ffff88007cb62de0 [ 474.336680] RBP: ffff8800556417a8 R08: 0000000000000001 R09: 0000000000000083 [ 474.336680] R10: 0000000000000000 R11: 0000000000000001 R12: 0000000000000000 [ 474.336680] R13: ffff88007cb631d0 R14: 0000000000000000 R15: 0000000000000001 [ 474.336680] FS: 0000000000000000(0000) GS:ffff88007fc00000(0000) knlGS:0000000000000000 [ 474.336680] CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 [ 474.336680] CR2: ffffffffffffffd8 CR3: 0000000001a0c000 CR4: 00000000000407f0 [ 474.336680] DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000 [ 474.336680] DR3: 0000000000000000 DR6: 00000000ffff0ff0 DR7: 0000000000000400 [ 474.336680] Process kworker/u:2 (pid: 1285, threadinfo ffff880055640000, task ffff88007cb62de0) [ 474.336680] Stack: [ 474.336680] ffff8800556417c8 ffffffff81071445 ffff8800556417c8 ffff88007fc12880 [ 474.336680] ffff880055641848 ffffffff81565a58 ffff8800556417f8 ffff880037daeba0 [ 474.336680] ffff88007cb62de0 ffff880055641fd8 ffff880055641fd8 ffff880055641fd8 [ 474.336680] Call Trace: [ 474.336680] [<ffffffff81071445>] wq_worker_sleeping+0x15/0xc0 [ 474.336680] [<ffffffff81565a58>] __schedule+0x5f8/0x7c0 [ 474.336680] [<ffffffff81565d39>] schedule+0x29/0x70 [ 474.336680] [<ffffffff81057748>] do_exit+0x678/0x9e0 [ 474.336680] [<ffffffff8155fe50>] ? printk+0x4d/0x4f [ 474.336680] [<ffffffff8100662b>] oops_end+0xab/0xf0 [ 474.336680] [<ffffffff8155f7a6>] no_context+0x201/0x210 [ 474.336680] [<ffffffff8155f986>] __bad_area_nosemaphore+0x1d1/0x1f0 [ 474.336680] [<ffffffff8110ba75>] ? mempool_kmalloc+0x15/0x20 [ 474.336680] [<ffffffff8155f9b8>] bad_area_nosemaphore+0x13/0x15 [ 474.336680] [<ffffffff810311a2>] __do_page_fault+0x322/0x4d0 [ 474.336680] [<ffffffff8111109f>] ? get_page_from_freelist+0x1bf/0x460 [ 474.336680] [<ffffffff81335eca>] ? virtblk_request+0x44a/0x460 [ 474.336680] [<ffffffff81232d56>] ? cpumask_next_and+0x36/0x50 [ 474.336680] [<ffffffff81232d56>] ? cpumask_next_and+0x36/0x50 [ 474.336680] [<ffffffff8108fa53>] ? update_sd_lb_stats+0x123/0x610 [ 474.336680] [<ffffffff8103138e>] do_page_fault+0xe/0x10 [ 474.336680] [<ffffffff8102e425>] do_async_page_fault+0x35/0xa0 [ 474.336680] [<ffffffff81567925>] async_page_fault+0x25/0x30 [ 474.336680] [<ffffffffa01b1aad>] ? queue_evict_default+0x1d/0x50 [dm_cache_basic] [ 474.336680] [<ffffffffa01b1aa5>] ? queue_evict_default+0x15/0x50 [dm_cache_basic] [ 474.336680] [<ffffffffa01b28a4>] basic_map+0x484/0x708 [dm_cache_basic] [ 474.336680] [<ffffffffa017658c>] ? dm_bio_detain+0x5c/0x80 [dm_bio_prison] [ 474.336680] [<ffffffffa019c221>] process_bio+0x101/0x4c0 [dm_cache] [ 474.336680] [<ffffffffa019cb4f>] do_worker+0x56f/0x630 [dm_cache] [ 474.336680] [<ffffffff81081ab6>] ? finish_task_switch+0x56/0xb0 [ 474.336680] [<ffffffff8106fa31>] process_one_work+0x121/0x490 [ 474.336680] [<ffffffffa019c5e0>] ? process_bio+0x4c0/0x4c0 [dm_cache] [ 474.336680] [<ffffffff81070be5>] worker_thread+0x165/0x3f0 [ 474.336680] [<ffffffff81070a80>] ? manage_workers+0x2a0/0x2a0 [ 474.336680] [<ffffffff81076010>] kthread+0xc0/0xd0 [ 474.336680] [<ffffffff81075f50>] ? flush_kthread_worker+0xb0/0xb0 [ 474.336680] [<ffffffff815680ac>] ret_from_fork+0x7c/0xb0 [ 474.336680] [<ffffffff81075f50>] ? flush_kthread_worker+0xb0/0xb0 [ 474.336680] Code: 00 48 89 e5 5d 48 8b 40 c8 48 c1 e8 02 83 e0 01 c3 66 2e 0f 1f 84 00 00 00 00 00 66 66 66 66 90 48 8b 87 98 03 00 00 55 48 89 e5 <48> 8b 40 d8 5d c3 66 2e 0f 1f 84 00 00 00 00 00 66 66 66 66 90 [ 474.336680] RIP [<ffffffff810761f0>] kthread_data+0x10/0x20 [ 474.336680] RSP <ffff8800556417a8> [ 474.336680] CR2: ffffffffffffffd8 [ 474.336680] ---[ end trace 20dda5f362594055 ]--- [ 474.336680] Fixing recursive fault but reboot is needed! [ 477.004016] Kernel panic - not syncing: Watchdog detected hard LOCKUP on cpu 1 [ 477.004016] Shutting down cpus with NMI [ 477.004016] panic occurred, switching back to text console
Quoted 5 lines
*Before* it crashes, though, I can run my iops exerciser and watch the numbers climb from ~300 to ~100000. Nice work! :)
(The default policy engine doesn't seem to have this problem, but I haven't figured out how to make it cache blocks yet...)
What is your iops exerciser? Do you have a pointer? You're running the same workload against "default" and not seeing what you'd expect?
Mike
Quoted 32 lines · Mike Snitzer
Quoted 17 lines · Darrick J. Wong
Quoted 10 lines · Mike Snitzer
agk's patches are here:
http://people.redhat.com/agk/patches/linux/editing/series.htmlBut agk hasn't staged all the required patches yet. I've imported agk's editing tree (and a couple other required patches that I previously posted to dm-devel, which aren't yet in agk's tree) into the 'dm-for-3.8' branch on my github tree here:
git://github.com/snitm/linux.gitQuoted 5 lines
This 8 patch patchset from Joe should apply cleanly ontop of my 'dm-for-3.8' branch.
But if all you care about is a tree with all the changes then please just use Joe's github 'thin-dev' branch.
Quoted 6 lines
A full list of broken-out patches would've been nice, but oh well, I ate this git tree. :)
Curiously, the
Documentation/device-mapper/dm-cache.txtsays to specify devices in the order: metadata, origin, and cache, but the code (and Joe's mail) seeem to want metadata, cache, origin. This sort of makes me wonder what's going on?The patch Joe posted has the proper order (metadata, cache, origin -- I fixed the ordering in dm-cache,txt and Joe pulled it in before posting the patches). Seems Joe forgot to push his last few tweaks to his thin-dev branch.
Quoted 5 lines
Quoted 1 line
Also, I found a bug when using the mru policy. If I do this:
Pretty sure you'd be best served to focus on the code Joe posted. Maybe best to clone my github tree and start with my 'dm-for-3.8' branch. And then apply all the patches Joe posted.
Also, AFAIK Joe pulled Linus latest tree from this afternoon into his thin-dev; which included a bunch of bleeding v3.8 merge changes. That makes his thin-dev inappropriate for stable testing. You could eaisly be hitting some early v3.8 issue.
My "dm-for-3.8" is v3.7 + the bulk of the DM patches destined for v3.8.
Quoted 41 lines · Mike Snitzer
Quoted 32 lines · Mike Snitzer
Quoted 17 lines · Darrick J. Wong
Quoted 10 lines · Mike Snitzer
agk's patches are here:
http://people.redhat.com/agk/patches/linux/editing/series.htmlBut agk hasn't staged all the required patches yet. I've imported agk's editing tree (and a couple other required patches that I previously posted to dm-devel, which aren't yet in agk's tree) into the 'dm-for-3.8' branch on my github tree here:
git://github.com/snitm/linux.gitQuoted 5 lines
This 8 patch patchset from Joe should apply cleanly ontop of my 'dm-for-3.8' branch.
But if all you care about is a tree with all the changes then please just use Joe's github 'thin-dev' branch.
Quoted 6 lines
A full list of broken-out patches would've been nice, but oh well, I ate this git tree. :)
Curiously, the
Documentation/device-mapper/dm-cache.txtsays to specify devices in the order: metadata, origin, and cache, but the code (and Joe's mail) seeem to want metadata, cache, origin. This sort of makes me wonder what's going on?The patch Joe posted has the proper order (metadata, cache, origin -- I fixed the ordering in dm-cache,txt and Joe pulled it in before posting the patches). Seems Joe forgot to push his last few tweaks to his thin-dev branch.
Quoted 5 lines
Quoted 1 line
Also, I found a bug when using the mru policy. If I do this:
Pretty sure you'd be best served to focus on the code Joe posted. Maybe best to clone my github tree and start with my 'dm-for-3.8' branch. And then apply all the patches Joe posted.
Quoted 6 lines
Also, AFAIK Joe pulled Linus latest tree from this afternoon into his thin-dev; which included a bunch of bleeding v3.8 merge changes. That makes his thin-dev inappropriate for stable testing. You could eaisly be hitting some early v3.8 issue.
My "dm-for-3.8" is v3.7 + the bulk of the DM patches destined for v3.8.
Ok, I'll go grab that. :)
--D
Quoted 42 lines · Darrick J. Wong
Quoted 41 lines · Mike Snitzer
Quoted 37 lines · Mike Snitzer
Quoted 17 lines · Darrick J. Wong
Quoted 10 lines · Mike Snitzer
agk's patches are here:
http://people.redhat.com/agk/patches/linux/editing/series.htmlBut agk hasn't staged all the required patches yet. I've imported agk's editing tree (and a couple other required patches that I previously posted to dm-devel, which aren't yet in agk's tree) into the 'dm-for-3.8' branch on my github tree here:
git://github.com/snitm/linux.gitQuoted 5 lines
This 8 patch patchset from Joe should apply cleanly ontop of my 'dm-for-3.8' branch.
But if all you care about is a tree with all the changes then please just use Joe's github 'thin-dev' branch.
Quoted 6 lines
A full list of broken-out patches would've been nice, but oh well, I ate this git tree. :)
Curiously, the
Documentation/device-mapper/dm-cache.txtsays to specify devices in the order: metadata, origin, and cache, but the code (and Joe's mail) seeem to want metadata, cache, origin. This sort of makes me wonder what's going on?The patch Joe posted has the proper order (metadata, cache, origin -- I fixed the ordering in dm-cache,txt and Joe pulled it in before posting the patches). Seems Joe forgot to push his last few tweaks to his thin-dev branch.
Quoted 1 line
Also, I found a bug when using the mru policy. If I do this:
Pretty sure you'd be best served to focus on the code Joe posted. Maybe best to clone my github tree and start with my 'dm-for-3.8' branch. And then apply all the patches Joe posted.
Quoted 8 lines
Quoted 6 lines
Also, AFAIK Joe pulled Linus latest tree from this afternoon into his thin-dev; which included a bunch of bleeding v3.8 merge changes. That makes his thin-dev inappropriate for stable testing. You could eaisly be hitting some early v3.8 issue.
My "dm-for-3.8" is v3.7 + the bulk of the DM patches destined for v3.8.
Ok, I'll go grab that. :)
To make life easier for you, and others, I've created a new 'dm-devel-cache' branch on my github tree (It is a branched from my 'dm-for-3.8').
I applied the 8 patches Joe posted to dm-devel and one extra compiler warning fix.
Again my github tree is git://github.com/snitm/linux.git
Mike
Quoted 48 lines · Mike Snitzer
Quoted 45 lines · Darrick J. Wong
Quoted 35 lines · Mike Snitzer
Quoted 6 lines · Joe Thornber
Here's a cache target that Heinz Mauelshagen, Mike Snitzer and I have been working on.
It's also available in the thin-dev branch of my git tree:
[email protected]:jthornber/linux-2.6.git
This url is best for others to clone from:
git://github.com/jthornber/linux-2.6.gitQuoted 3 lines
The main features are a plug-in architecture for policies which decide what data gets cached, and reuse of the metadata library from the thin provisioning target.
It should be noted that there are more cache replacement policies available in Joe's thin-dev branch via the "basic" policy, see:
drivers/md/dm-cache-policy-basic.c(these basic policies include fifo, lru, lfu, and many more)
Quoted 2 lines
These patches apply on top of the dm patches that agk has got queued for 3.8.
agk's patches are here:
http://people.redhat.com/agk/patches/linux/editing/series.htmlBut agk hasn't staged all the required patches yet. I've imported agk's editing tree (and a couple other required patches that I previously posted to dm-devel, which aren't yet in agk's tree) into the 'dm-for-3.8' branch on my github tree here:
git://github.com/snitm/linux.gitQuoted 5 lines
This 8 patch patchset from Joe should apply cleanly ontop of my 'dm-for-3.8' branch.
But if all you care about is a tree with all the changes then please just use Joe's github 'thin-dev' branch.
A full list of broken-out patches would've been nice, but oh well, I ate this git tree. :)
Quoted 8 lines
Quoted 3 lines
Curiously, the
Documentation/device-mapper/dm-cache.txtsays to specify devices in the order: metadata, origin, and cache, but the code (and Joe's mail) seeem to want metadata, cache, origin. This sort of makes me wonder what's going on?The patch Joe posted has the proper order (metadata, cache, origin -- I fixed the ordering in dm-cache,txt and Joe pulled it in before posting the patches). Seems Joe forgot to push his last few tweaks to his thin-dev branch.
Ahh. :)
Quoted 10 lines
Quoted 1 line
Also, I found a bug when using the mru policy. If I do this:
Pretty sure you'd be best served to focus on the code Joe posted. Maybe best to clone my github tree and start with my 'dm-for-3.8' branch. And then apply all the patches Joe posted.
I'd stick to the "default" policy -- aka "mq".
Joe purposely didn't post the "basic" policies because they are less well tested.
Ok, I'll stick to mq for now then. I'll try to figure out what it does exactly.
Quoted 145 lines
Quoted 145 lines
<set up a
scsi_debug"ssd" with a 448M/dev/sda1for cache and the rest for
metadata on/dev/sda2># echo 0 67108864 cache /dev/sda2 /dev/sda1 /dev/vda 512 0 mru 0 | dmsetup create fubar ...<use fubar, fill up the cache>... # dmsetup remove fubar # echo 0 67108864 cache /dev/sda2 /dev/sda1 /dev/vda 512 0 mru 0 | dmsetup create fubarI see the following crash in dmesg:
[ 426.661458] scsi1 : scsi_debug, version 1.82 [20100324], dev_size_mb=512, opts=0x0 [ 426.663955] scsi 1:0:0:0: Direct-Access Linux scsi_debug 0004 PQ: 0 ANSI: 5 [ 426.667005] sd 1:0:0:0: Attached scsi generic sg0 type 0 [ 426.667020] sd 1:0:0:0: [sda] 1048576 512-byte logical blocks: (536 MB/512 MiB) [ 426.667046] sd 1:0:0:0: [sda] Write Protect is off [ 426.667057] sd 1:0:0:0: [sda] Write cache: enabled, read cache: enabled, supports DPO and FUA [ 426.667203] sda: unknown partition table [ 426.667311] sd 1:0:0:0: [sda] Attached SCSI disk [ 426.694055] sda: sda1 sda2 [ 448.155368] bio: create slab <bio-1> at 1 [ 460.762930] promote thresholds = 65/4 queue stats = 1/0 [ 468.121084] promote thresholds = 65/4 queue stats = 1/1 [ 471.970865] dm-cache statistics: [ 471.974809] read hits: 887895 [ 471.976948] read misses: 499 [ 471.978195] write hits: 0 [ 471.979380] write misses: 0 [ 471.980716] demotions: 7 [ 471.982391] promotions: 1799 [ 471.983798] copies avoided: 7 [ 471.985137] cache cell clashs: 0 [ 471.986886] commits: 1653 [ 471.988410] discards: 0 [ 474.177476] bio: create slab <bio-1> at 1 [ 474.206000] BUG: unable to handle kernel NULL pointer dereference at 0000000000000008 [ 474.209037] IP: [<ffffffffa01b1aad>] queue_evict_default+0x1d/0x50 [dm_cache_basic] [ 474.209969] PGD 0 [ 474.209969] Oops: 0002 [#1] PREEMPT SMP [ 474.209969] Modules linked in: scsi_debug dm_cache_basic dm_cache_mq dm_cache dm_bio_prison dm_persistent_data dm_bufio crc_t10dif nfsv4 sch_fq_codel eeprom nfsd auth_rpcgss exportfs af_packet btrfs zlib_deflate libcrc32c [last unloaded: scsi_debug] [ 474.209969] CPU 0 [ 474.209969] Pid: 1285, comm: kworker/u:2 Not tainted 3.7.0-dmcache #1 Bochs Bochs [ 474.209969] RIP: 0010:[<ffffffffa01b1aad>] [<ffffffffa01b1aad>] queue_evict_default+0x1d/0x50 [dm_cache_basic] [ 474.209969] RSP: 0018:ffff880055641be8 EFLAGS: 00010282 [ 474.209969] RAX: ffff880073a85eb0 RBX: ffff880037ca5c00 RCX: 0000000000000000 [ 474.209969] RDX: 0000000000000000 RSI: 0007fff80005ffff RDI: ffff880073a85eb0 [ 474.209969] RBP: ffff880055641be8 R08: e000000000000000 R09: ffff880072d619a0 [ 474.209969] R10: 0000000000000034 R11: fffffff80005ffff R12: ffff880037f33d30 [ 474.209969] R13: ffff880037ca5c78 R14: ffff880055641c98 R15: 000000000001ffff [ 474.209969] FS: 0000000000000000(0000) GS:ffff88007fc00000(0000) knlGS:0000000000000000 [ 474.209969] CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 [ 474.209969] CR2: 0000000000000008 CR3: 0000000001a0c000 CR4: 00000000000407f0 [ 474.209969] DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000 [ 474.209969] DR3: 0000000000000000 DR6: 00000000ffff0ff0 DR7: 0000000000000400 [ 474.209969] Process kworker/u:2 (pid: 1285, threadinfo ffff880055640000, task ffff88007cb62de0) [ 474.209969] Stack: [ 474.209969] ffff880055641c58 ffffffffa01b28a4 0000000000000040 0000000000000286 [ 474.209969] ffff880000000000 ffffffffa017658c 0000000000000000 ffff880155641cd0 [ 474.209969] ffff880055641c58 ffff88007cac7400 ffff880055641d50 ffff880037f33d30 [ 474.209969] Call Trace: [ 474.209969] [<ffffffffa01b28a4>] basic_map+0x484/0x708 [dm_cache_basic] [ 474.209969] [<ffffffffa017658c>] ? dm_bio_detain+0x5c/0x80 [dm_bio_prison] [ 474.209969] [<ffffffffa019c221>] process_bio+0x101/0x4c0 [dm_cache] [ 474.209969] [<ffffffffa019cb4f>] do_worker+0x56f/0x630 [dm_cache] [ 474.209969] [<ffffffff81081ab6>] ? finish_task_switch+0x56/0xb0 [ 474.209969] [<ffffffff8106fa31>] process_one_work+0x121/0x490 [ 474.209969] [<ffffffffa019c5e0>] ? process_bio+0x4c0/0x4c0 [dm_cache] [ 474.209969] [<ffffffff81070be5>] worker_thread+0x165/0x3f0 [ 474.209969] [<ffffffff81070a80>] ? manage_workers+0x2a0/0x2a0 [ 474.209969] [<ffffffff81076010>] kthread+0xc0/0xd0 [ 474.209969] [<ffffffff81075f50>] ? flush_kthread_worker+0xb0/0xb0 [ 474.209969] [<ffffffff815680ac>] ret_from_fork+0x7c/0xb0 [ 474.209969] [<ffffffff81075f50>] ? flush_kthread_worker+0xb0/0xb0 [ 474.209969] Code: de 48 89 47 08 48 89 f8 5d c3 0f 0b 66 90 66 66 66 66 90 55 48 8b bf f8 01 00 00 48 89 e5 e8 ab ff ff ff 48 8b 48 28 48 8b 50 30 <48> 89 51 08 48 89 0a 48 ba 00 01 10 00 00 00 ad de 48 b9 00 02 [ 474.209969] RIP [<ffffffffa01b1aad>] queue_evict_default+0x1d/0x50 [dm_cache_basic] [ 474.209969] RSP <ffff880055641be8> [ 474.209969] CR2: 0000000000000008 [ 474.333040] ---[ end trace 20dda5f362594054 ]--- [ 474.336010] BUG: unable to handle kernel paging request at ffffffffffffffd8 [ 474.336680] IP: [<ffffffff810761f0>] kthread_data+0x10/0x20 [ 474.336680] PGD 1a0e067 PUD 1a0f067 PMD 0 [ 474.336680] Oops: 0000 [#2] PREEMPT SMP [ 474.336680] Modules linked in: scsi_debug dm_cache_basic dm_cache_mq dm_cache dm_bio_prison dm_persistent_data dm_bufio crc_t10dif nfsv4 sch_fq_codel eeprom nfsd auth_rpcgss exportfs af_packet btrfs zlib_deflate libcrc32c [last unloaded: scsi_debug] [ 474.336680] CPU 0 [ 474.336680] Pid: 1285, comm: kworker/u:2 Tainted: G D 3.7.0-dmcache #1 Bochs Bochs [ 474.336680] RIP: 0010:[<ffffffff810761f0>] [<ffffffff810761f0>] kthread_data+0x10/0x20 [ 474.336680] RSP: 0018:ffff8800556417a8 EFLAGS: 00010096 [ 474.336680] RAX: 0000000000000000 RBX: 0000000000000000 RCX: ffffffff81bb2f80 [ 474.336680] RDX: 0000000000000000 RSI: 0000000000000000 RDI: ffff88007cb62de0 [ 474.336680] RBP: ffff8800556417a8 R08: 0000000000000001 R09: 0000000000000083 [ 474.336680] R10: 0000000000000000 R11: 0000000000000001 R12: 0000000000000000 [ 474.336680] R13: ffff88007cb631d0 R14: 0000000000000000 R15: 0000000000000001 [ 474.336680] FS: 0000000000000000(0000) GS:ffff88007fc00000(0000) knlGS:0000000000000000 [ 474.336680] CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 [ 474.336680] CR2: ffffffffffffffd8 CR3: 0000000001a0c000 CR4: 00000000000407f0 [ 474.336680] DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000 [ 474.336680] DR3: 0000000000000000 DR6: 00000000ffff0ff0 DR7: 0000000000000400 [ 474.336680] Process kworker/u:2 (pid: 1285, threadinfo ffff880055640000, task ffff88007cb62de0) [ 474.336680] Stack: [ 474.336680] ffff8800556417c8 ffffffff81071445 ffff8800556417c8 ffff88007fc12880 [ 474.336680] ffff880055641848 ffffffff81565a58 ffff8800556417f8 ffff880037daeba0 [ 474.336680] ffff88007cb62de0 ffff880055641fd8 ffff880055641fd8 ffff880055641fd8 [ 474.336680] Call Trace: [ 474.336680] [<ffffffff81071445>] wq_worker_sleeping+0x15/0xc0 [ 474.336680] [<ffffffff81565a58>] __schedule+0x5f8/0x7c0 [ 474.336680] [<ffffffff81565d39>] schedule+0x29/0x70 [ 474.336680] [<ffffffff81057748>] do_exit+0x678/0x9e0 [ 474.336680] [<ffffffff8155fe50>] ? printk+0x4d/0x4f [ 474.336680] [<ffffffff8100662b>] oops_end+0xab/0xf0 [ 474.336680] [<ffffffff8155f7a6>] no_context+0x201/0x210 [ 474.336680] [<ffffffff8155f986>] __bad_area_nosemaphore+0x1d1/0x1f0 [ 474.336680] [<ffffffff8110ba75>] ? mempool_kmalloc+0x15/0x20 [ 474.336680] [<ffffffff8155f9b8>] bad_area_nosemaphore+0x13/0x15 [ 474.336680] [<ffffffff810311a2>] __do_page_fault+0x322/0x4d0 [ 474.336680] [<ffffffff8111109f>] ? get_page_from_freelist+0x1bf/0x460 [ 474.336680] [<ffffffff81335eca>] ? virtblk_request+0x44a/0x460 [ 474.336680] [<ffffffff81232d56>] ? cpumask_next_and+0x36/0x50 [ 474.336680] [<ffffffff81232d56>] ? cpumask_next_and+0x36/0x50 [ 474.336680] [<ffffffff8108fa53>] ? update_sd_lb_stats+0x123/0x610 [ 474.336680] [<ffffffff8103138e>] do_page_fault+0xe/0x10 [ 474.336680] [<ffffffff8102e425>] do_async_page_fault+0x35/0xa0 [ 474.336680] [<ffffffff81567925>] async_page_fault+0x25/0x30 [ 474.336680] [<ffffffffa01b1aad>] ? queue_evict_default+0x1d/0x50 [dm_cache_basic] [ 474.336680] [<ffffffffa01b1aa5>] ? queue_evict_default+0x15/0x50 [dm_cache_basic] [ 474.336680] [<ffffffffa01b28a4>] basic_map+0x484/0x708 [dm_cache_basic] [ 474.336680] [<ffffffffa017658c>] ? dm_bio_detain+0x5c/0x80 [dm_bio_prison] [ 474.336680] [<ffffffffa019c221>] process_bio+0x101/0x4c0 [dm_cache] [ 474.336680] [<ffffffffa019cb4f>] do_worker+0x56f/0x630 [dm_cache] [ 474.336680] [<ffffffff81081ab6>] ? finish_task_switch+0x56/0xb0 [ 474.336680] [<ffffffff8106fa31>] process_one_work+0x121/0x490 [ 474.336680] [<ffffffffa019c5e0>] ? process_bio+0x4c0/0x4c0 [dm_cache] [ 474.336680] [<ffffffff81070be5>] worker_thread+0x165/0x3f0 [ 474.336680] [<ffffffff81070a80>] ? manage_workers+0x2a0/0x2a0 [ 474.336680] [<ffffffff81076010>] kthread+0xc0/0xd0 [ 474.336680] [<ffffffff81075f50>] ? flush_kthread_worker+0xb0/0xb0 [ 474.336680] [<ffffffff815680ac>] ret_from_fork+0x7c/0xb0 [ 474.336680] [<ffffffff81075f50>] ? flush_kthread_worker+0xb0/0xb0 [ 474.336680] Code: 00 48 89 e5 5d 48 8b 40 c8 48 c1 e8 02 83 e0 01 c3 66 2e 0f 1f 84 00 00 00 00 00 66 66 66 66 90 48 8b 87 98 03 00 00 55 48 89 e5 <48> 8b 40 d8 5d c3 66 2e 0f 1f 84 00 00 00 00 00 66 66 66 66 90 [ 474.336680] RIP [<ffffffff810761f0>] kthread_data+0x10/0x20 [ 474.336680] RSP <ffff8800556417a8> [ 474.336680] CR2: ffffffffffffffd8 [ 474.336680] ---[ end trace 20dda5f362594055 ]--- [ 474.336680] Fixing recursive fault but reboot is needed! [ 477.004016] Kernel panic - not syncing: Watchdog detected hard LOCKUP on cpu 1 [ 477.004016] Shutting down cpus with NMI [ 477.004016] panic occurred, switching back to text console
Quoted 8 lines
Quoted 5 lines
*Before* it crashes, though, I can run my iops exerciser and watch the numbers climb from ~300 to ~100000. Nice work! :)
(The default policy engine doesn't seem to have this problem, but I haven't figured out how to make it cache blocks yet...)
What is your iops exerciser? Do you have a pointer? You're running the same workload against "default" and not seeing what you'd expect?
Actually, I decided to try out "mru" and see what it would do (or not do). My current theory is that mq doesn't seem to like putting blocks in the cache until after you write 'em(?) There's no way to spit out the cache stats while it's running, so it's difficult to make observations.
The "exerciser" is called maxiops, from:
http://djwong.org/programs/bogodisk/bogoseek-0.6.2.tar.gz
untar, make, ./maxiops /dev/somethingorother -b 4096
The third column of output is a rough estimate of iops. maxiops is really just an aio port of bogoseek -n, which is in the same package. If you want to do a destructive write test with them, pass -w.
--D
Quoted 2 lines
Mike
Quoted 5 lines · Darrick J. Wong
Actually, I decided to try out "mru" and see what it would do (or not do). My current theory is that mq doesn't seem to like putting blocks in the cache until after you write 'em(?) There's no way to spit out the cache stats while it's running, so it's difficult to make observations.
Quoted 8 lines
The "exerciser" is called maxiops, from:
http://djwong.org/programs/bogodisk/bogoseek-0.6.2.tar.gzuntar, make, ./maxiops
/dev/somethingorother-b 4096The third column of output is a rough estimate of iops. maxiops is really just an aio port of bogoseek -n, which is in the same package. If you want to do a destructive write test with them, pass -w.
The mq policy is very conservative, designed to slowly move frequently accessed blocks into the cache. I'm going to provide another policy that's simpler, but much more aggressive about caching writes and constantly cleaning blocks in the background.
There are a couple of reasons why mq may have decided not to cache your blocks:
i) They just aren't being hit very frequently.
ii) It's decided that you're doing a big linear read/write, and so is not updating it's hit stats. Vivek Goyal put this code in for us and it's been a big win in the testing I've done. The rationale being that spindles are often very good at doing v. large contiguous io.
The threshold for deciding what is linear/random io is configurable.
You may also want to experiment with discarding all data at the start of your test (eg, as mkfs does). In this case mq is aware that promoting a block to the cache is very cheap because no copying is needed, and as such will promote much sooner.
I'll add some tests to my test suite that use your maxiops program and see if I can work out what's going on.
- Joe
Quoted 2 lines · On Fri, Dec 14, 2012 at 10:24:43AM +0000, [email protected] wrote:
I'll add some tests to my test suite that use your maxiops program and see if I can work out what's going on.
I've played with your maxiops program, and added these tests to the suite:
def maxiops(dev, nr_seeks = 10000)
ProcessControl.run("maxiops -s #{nr_seeks} #{dev} -wb 4096")end
def discard_dev(dev)
dev.discard(0, dev_size(dev))
end
def test_maxiops_cache_no_discard
with_standard_cache(:format => true,
:data_size => gig(1)) do |cache|
maxiops(cache, 10000)
endend
def test_maxiops_cache_with_discard
size = 512
with_standard_cache(:format => true,
:data_size => gig(1), :cache_size => meg(size)) do |cache|
discard_dev(cache)
report_time("maxiops with cache size #{size}m", STDERR) do
maxiops(cache, 10000)
end
end
end
def test_maxiops_linear
with_standard_linear(:data_size => gig(1)) do |linear|
maxiops(linear, 10000)
end
end
The maxiops program appears to be doing random writes over the device (at least the way I'm calling it). So I'm not surprised the mq policy can't be bothered to cache anything.
Even an agressive write policy wouldn't do much good here, as maxiops is continuously writing. Such a strategy needs bursty io, so the cache has time to clean itself.
Discarding the device before running maxiops, as discussed, does indeed persuade mq to cache blocks as soon as they're hit (see test_maxiops_cache_with_discard).
As a sanity check I set up the cache device with various amounts of SSD allocated and timed a short run of maxiops. For a small amount of SSD, performance is similar to that of my spindle, for as much SSD as spindle, performance is the same as my SSD.
SSD size | Elapsed time (seconds) 128m | 32 256m | 23 512m | 13.5 1024m | 3.4
Now the bad news is I'm regularly seeing runs that have terrible performance; not a hang since the io stall oops isn't triggering. So there's obviously a race in there somewhere that's getting things into a bad state. Will investigate more, it could easily be an issue in the test suite.
- Joe
Quoted 43 lines · On Fri, Dec 14, 2012 at 12:11:44PM +0000, [email protected] wrote:
Quoted 2 lines · On Fri, Dec 14, 2012 at 10:24:43AM +0000, [email protected] wrote:
I'll add some tests to my test suite that use your maxiops program and see if I can work out what's going on.
I've played with your maxiops program, and added these tests to the suite:
def
maxiops(dev, nr_seeks = 10000)ProcessControl.run("maxiops -s #{nr_seeks} #{dev} -wb 4096")end
def
discard_dev(dev)dev.discard(0, dev_size(dev))end
def
test_maxiops_cache_no_discardwith_standard_cache(:format => true, :data_size => gig(1)) do |cache| maxiops(cache, 10000) endend
def
test_maxiops_cache_with_discard
size = 512with_standard_cache(:format => true,
:data_size => gig(1), :cache_size => meg(size)) do |cache|
discard_dev(cache)
report_time("maxiops with cache size #{size}m", STDERR)do
maxiops(cache, 10000)
end
end
enddef
test_maxiops_linear
with_standard_linear(:data_size => gig(1))do |linear|
maxiops(linear, 10000)
end
end
Quoted 7 lines
The maxiops program appears to be doing random writes over the device (at least the way I'm calling it). So I'm not surprised the mq policy can't be bothered to cache anything.
Even an agressive write policy wouldn't do much good here, as maxiops is continuously writing. Such a strategy needs bursty io, so the cache has time to clean itself.
<nod> I'll keep that in mind. Does cleaning trigger as soon as the disk quiets down?
Quoted 3 lines
Discarding the device before running maxiops, as discussed, does indeed persuade mq to cache blocks as soon as they're hit (see
test_maxiops_cache_with_discard).
Noted.
Quoted 11 lines
As a sanity check I set up the cache device with various amounts of SSD allocated and timed a short run of maxiops. For a small amount of SSD, performance is similar to that of my spindle, for as much SSD as spindle, performance is the same as my SSD.
SSD size | Elapsed time (seconds) 128m | 32 256m | 23 512m | 13.5 1024m | 3.4
Quoted 5 lines
Now the bad news is I'm regularly seeing runs that have terrible performance; not a hang since the io stall oops isn't triggering. So there's obviously a race in there somewhere that's getting things into a bad state. Will investigate more, it could easily be an issue in the test suite.
Yeah, I think I've seen some odd behavior too - on one of my runs, blkid reported that the cache device had the same superblock as the aggregate device. My guess is that block 0 on the exported device got mapped to block 0 of the cache. I'll see if I can make it happen again, but that brings me to another set of questions.
First, is there a plan to have userspace tools to set up the cache, provide protective superblocks, etc.? As far as I can tell, the slow disk and the fast disk don't have headers to declare the existence of the cache, so blkid and friends can end up seeing things they shouldn't. How were you planning to keep users from mounting the slow device before the cache comes up?
Second, if the cache is in WB mode, is there a way to force it to flush the cache contents to disk? Or does it do that at dmsetup create time?
--D
Quoted 5 lines · Darrick J. Wong
Yeah, I think I've seen some odd behavior too - on one of my runs, blkid reported that the cache device had the same superblock as the aggregate device. My guess is that block 0 on the exported device got mapped to block 0 of the cache. I'll see if I can make it happen again, but that brings me to another set of questions.
This is normal.
Quoted 2 lines
First, is there a plan to have userspace tools to set up the cache, provide protective superblocks, etc.?
Yes, lvm2 will support it soon (hopefully). Tools like cache_check, cache_dump, cache_restore that manipulate the metadata device are nearly ready.
Quoted 4 lines
As far as I can tell, the slow disk and the fast
disk don't have headers to declare the existence of the cache, so blkid and friends can end up seeing things they shouldn't. How were you planning to keep users from mounting the slow device before the cache comes up?
We don't label the origin device or ssd in anyway.
Quoted 2 lines
Second, if the cache is in WB mode, is there a way to force it to flush the cache contents to disk? Or does it do that at dmsetup create time?
Reload the cache target with the cleaner policy. Once it's finished writing everything back it'll trigger a dm event that you can catch
with 'dmsetup wait'. Then check the status to double check there are no dirty blocks. At this point you can ditch the cache and use the origin directly. See test below.
def wait_for_all_clean(cache)
cache.event_tracker.wait(cache) do |cache|
status = CacheStatus.new(cache)
status.nr_dirty == 0
end
end
def test_cleaner_policy
with_standard_cache(:format => true) do |cache|
git_prepare(cache, :ext4)
cache.pause do
table = cache.active_table
table.targets[0].args[6] = 'cleaner'
cache.load(table)
end
wait_for_all_clean(cache)
end
# We should be able to use the origin directly now with_standard_linear do |origin|
fs = FS::file_system(:ext4, origin) fs.with_mount('./kernel_builds', :discard => true) do
# triggers fsck
end
end
end
- Joe
Quoted 8 lines · Joe Thornber
Quoted 5 lines · Darrick J. Wong
Yeah, I think I've seen some odd behavior too - on one of my runs, blkid reported that the cache device had the same superblock as the aggregate device. My guess is that block 0 on the exported device got mapped to block 0 of the cache. I'll see if I can make it happen again, but that brings me to another set of questions.
This is normal.
Okay, but this is a little scary too:
# blkid /dev/sda1: UUID="3cec6984-7db1-4b51-988c-19a574d444b3" TYPE="ext4" /dev/mapper/cache: UUID="3cec6984-7db1-4b51-988c-19a574d444b3" TYPE="ext4" /dev/vda: UUID="0bf9cc39-9ca1-4b4a-b543-774efe5b51cb" TYPE="ext4"
sda1 is the ssd, vda is the origin. I haven't used the cleaner yet; this is merely the result of beating on the cache long enough that the superblock gets flushed out to the origin.
It's not a problem /while/ the cache is mounted because opening sda1 or vda with O_EXCL (such as when you try to mount) return -EBUSY. When the cache isn't mounted, however, there's more of a problem -- any sane filesystem will notice that sda1 is smaller than the filesystem and refuse to mount, but there's not a lot preventing erroneous mounts of vda, which will possibly end in disaster.
I guess I'm simply afraid of accidentally mounting the origin device when it's dirty, whether it's through overeager boot scripts, or plain old stupidity on my part. :)
Quoted 7 lines
Quoted 2 lines
First, is there a plan to have userspace tools to set up the cache, provide protective superblocks, etc.?
Yes, lvm2 will support it soon (hopefully). Tools like
cache_check,cache_dump,cache_restorethat manipulate the metadata device are nearly ready.
Quoted 6 lines
Quoted 4 lines
As far as I can tell, the slow disk and the fast
disk don't have headers to declare the existence of the cache, so blkid and friends can end up seeing things they shouldn't. How were you planning to keep users from mounting the slow device before the cache comes up?We don't label the origin device or ssd in anyway.
<nod> I was rather hoping there'd be a label to avoid all that above blkid drama. :/
Quoted 30 lines
Quoted 2 lines
Second, if the cache is in WB mode, is there a way to force it to flush the cache contents to disk? Or does it do that at dmsetup create time?
Reload the cache target with the cleaner policy. Once it's finished writing everything back it'll trigger a dm event that you can catch
with 'dmsetup wait'. Then check the status to double check there are no dirty blocks. At this point you can ditch the cache and use the origin directly. See test below.def
wait_for_all_clean(cache)
cache.event_tracker.wait(cache)do |cache|
status =CacheStatus.new(cache)
status.nr_dirty == 0
end
enddef
test_cleaner_policy
with_standard_cache(:format => true)do |cache|
git_prepare(cache, :ext4)cache.pause do
table = cache.active_table
table.targets[0].args[6] = 'cleaner'
cache.load(table)
end
wait_for_all_clean(cache)
end
Quoted 8 lines
# We should be able to use the origin directly now
with_standard_lineardo |origin|
fs =FS::file_system(:ext4, origin)fs.with_mount('./kernel_builds', :discard => true)do
# triggers fsck
end
end
end
Ahh, nifty. But how does it work from the command line?
# dmsetup table cache: 0 67108864 cache 8:2 8:1 254:0 512 1 writeback default 0 # echo '0 67108864 cache /dev/sda2 /dev/sda1 /dev/vda 512 0 cleaner 0' | dmsetup reload cache # dmsetup table cache: 0 67108864 cache 8:2 8:1 254:0 512 1 writeback default 0
Is there some trickery to dmsetup that I'm missing here?
--D
Alasdair G Kergon
maintainerQuoted 2 lines · Darrick J. Wong
<nod> I was rather hoping there'd be a label to avoid all that above blkid drama. :/
We had debates about that.
When managed by LVM we hope the problems will be avoided. (E.g. Raw devices will have LVM identifiers; dm devices will have dm UUIDs in /sys identifying them as private.)
But we might yet revisit this.
Alasdair
Quoted 7 lines · Joe Thornber
Quoted 5 lines · Darrick J. Wong
Yeah, I think I've seen some odd behavior too - on one of my runs, blkid reported that the cache device had the same superblock as the aggregate device. My guess is that block 0 on the exported device got mapped to block 0 of the cache. I'll see if I can make it happen again, but that brings me to another set of questions.
Quoted 8 lines
This is normal.
Quoted 2 lines
First, is there a plan to have userspace tools to set up the cache, provide protective superblocks, etc.?
Yes, lvm2 will support it soon (hopefully). Tools like
cache_check,cache_dump,cache_restorethat manipulate the metadata device are nearly ready.
Are these tools available anywhere for testing?
--D
Quoted 49 lines
Quoted 5 lines
As far as I can tell, the slow disk and the fast
disk don't have headers to declare the existence of the cache, so blkid and friends can end up seeing things they shouldn't. How were you planning to keep users from mounting the slow device before the cache comes up?We don't label the origin device or ssd in anyway.
Quoted 2 lines
Second, if the cache is in WB mode, is there a way to force it to flush the cache contents to disk? Or does it do that at dmsetup create time?
Reload the cache target with the cleaner policy. Once it's finished writing everything back it'll trigger a dm event that you can catch
with 'dmsetup wait'. Then check the status to double check there are no dirty blocks. At this point you can ditch the cache and use the origin directly. See test below.def
wait_for_all_clean(cache)
cache.event_tracker.wait(cache)do |cache|
status =CacheStatus.new(cache)
status.nr_dirty == 0
end
enddef
test_cleaner_policy
with_standard_cache(:format => true)do |cache|
git_prepare(cache, :ext4)cache.pause do
table = cache.active_table
table.targets[0].args[6] = 'cleaner'
cache.load(table)
end
wait_for_all_clean(cache)
end# We should be able to use the origin directly now
with_standard_lineardo |origin|
fs =FS::file_system(:ext4, origin)fs.with_mount('./kernel_builds', :discard => true)do
# triggers fsck
end
end
end- Joe
Quoted 1 line · Darrick J. Wong
Are these tools available anywhere for testing?
Not yet. Give it a couple of weeks.
- Joe
Quoted 13 lines · Mike Snitzer
Quoted 10 lines · Darrick J. Wong
Quoted 9 lines · Mike Snitzer
Quoted 6 lines · Joe Thornber
Here's a cache target that Heinz Mauelshagen, Mike Snitzer and I have been working on.
It's also available in the thin-dev branch of my git tree:
[email protected]:jthornber/linux-2.6.git
[...]
Quoted 5 lines
Quoted 1 line
Also, I found a bug when using the mru policy. If I do this:
Pretty sure you'd be best served to focus on the code Joe posted. Maybe best to clone my github tree and start with my 'dm-for-3.8' branch. And then apply all the patches Joe posted.
I also tried the other policies before reading the comment above. I wanted to see data more agressively copied to the cache device to see what happened.
Specifically, I tested lru and had an interesting problem. One which suggests it is not specific to the policy, but possibly to trigger quickly with it.
When mounting an ext4 filesystem with lru:
attempt to access beyond end of device
sdc1: rw=0, want=625140480, limit=625140400
(though an fsck completed fine)
Possibly the outcome of lru trying to cache the final block of the filesystem? Where, I presume, mq would not try and do this unless this block became a hot-spot.
The table used was:
0 625140400 cache /dev/sdb1 /dev/sdb2 /dev/sdc1 256 1 writethrough lru 0
I tried both with a cache prepared using mq, and a clean cache -- where sdb1 and sdb2 have the first 4k blanked.
The code is the current dm-devel-cache (b910ac06) fromgit://github.com/snitm/linux.git
Quoted 1 line
I'd stick to the "default" policy -- aka "mq".
I tested mq, and had no problems whatsoever with stability (except where I modified the backing device and forgot to clear the cache.) I didn't yet do any performance test yet.
I look forward to being able to use this for general workstation use, and as storage for a simple (but large) hash-table database for an application.
Great stuff, thanks!
Signature · 1 line
Mark
Darrick,
please try attached patch, which is on my [email protected]:lvmguy/linux-2.6, branch thin-dev_Work as well. Does that fix the issue for you?
Thanks,
Heinz
Quoted 199 lines · Darrick J. Wong
Quoted 32 lines · Mike Snitzer
Quoted 6 lines · Joe Thornber
Here's a cache target that Heinz Mauelshagen, Mike Snitzer and I have been working on.
It's also available in the thin-dev branch of my git tree:
[email protected]:jthornber/linux-2.6.git
This url is best for others to clone from:
git://github.com/jthornber/linux-2.6.gitQuoted 3 lines
The main features are a plug-in architecture for policies which decide what data gets cached, and reuse of the metadata library from the thin provisioning target.
It should be noted that there are more cache replacement policies available in Joe's thin-dev branch via the "basic" policy, see:
drivers/md/dm-cache-policy-basic.c(these basic policies include fifo, lru, lfu, and many more)
Quoted 2 lines
These patches apply on top of the dm patches that agk has got queued for 3.8.
agk's patches are here:
http://people.redhat.com/agk/patches/linux/editing/series.htmlBut agk hasn't staged all the required patches yet. I've imported agk's editing tree (and a couple other required patches that I previously posted to dm-devel, which aren't yet in agk's tree) into the 'dm-for-3.8' branch on my github tree here:
git://github.com/snitm/linux.gitQuoted 5 lines
This 8 patch patchset from Joe should apply cleanly ontop of my 'dm-for-3.8' branch.
But if all you care about is a tree with all the changes then please just use Joe's github 'thin-dev' branch.
A full list of broken-out patches would've been nice, but oh well, I ate this git tree. :)
Curiously, the
Documentation/device-mapper/dm-cache.txtsays to specify devices in the order: metadata, origin, and cache, but the code (and Joe's mail) seeem to want metadata, cache, origin. This sort of makes me wonder what's going on?Also, I found a bug when using the mru policy. If I do this:
<set up a
scsi_debug"ssd" with a 448M/dev/sda1for cache and the rest for
metadata on/dev/sda2># echo 0 67108864 cache /dev/sda2 /dev/sda1 /dev/vda 512 0 mru 0 | dmsetup create fubar ...<use fubar, fill up the cache>... # dmsetup remove fubar # echo 0 67108864 cache /dev/sda2 /dev/sda1 /dev/vda 512 0 mru 0 | dmsetup create fubarI see the following crash in dmesg:
[ 426.661458] scsi1 : scsi_debug, version 1.82 [20100324], dev_size_mb=512, opts=0x0 [ 426.663955] scsi 1:0:0:0: Direct-Access Linux scsi_debug 0004 PQ: 0 ANSI: 5 [ 426.667005] sd 1:0:0:0: Attached scsi generic sg0 type 0 [ 426.667020] sd 1:0:0:0: [sda] 1048576 512-byte logical blocks: (536 MB/512 MiB) [ 426.667046] sd 1:0:0:0: [sda] Write Protect is off [ 426.667057] sd 1:0:0:0: [sda] Write cache: enabled, read cache: enabled, supports DPO and FUA [ 426.667203] sda: unknown partition table [ 426.667311] sd 1:0:0:0: [sda] Attached SCSI disk [ 426.694055] sda: sda1 sda2 [ 448.155368] bio: create slab <bio-1> at 1 [ 460.762930] promote thresholds = 65/4 queue stats = 1/0 [ 468.121084] promote thresholds = 65/4 queue stats = 1/1 [ 471.970865] dm-cache statistics: [ 471.974809] read hits: 887895 [ 471.976948] read misses: 499 [ 471.978195] write hits: 0 [ 471.979380] write misses: 0 [ 471.980716] demotions: 7 [ 471.982391] promotions: 1799 [ 471.983798] copies avoided: 7 [ 471.985137] cache cell clashs: 0 [ 471.986886] commits: 1653 [ 471.988410] discards: 0 [ 474.177476] bio: create slab <bio-1> at 1 [ 474.206000] BUG: unable to handle kernel NULL pointer dereference at 0000000000000008 [ 474.209037] IP: [<ffffffffa01b1aad>] queue_evict_default+0x1d/0x50 [dm_cache_basic] [ 474.209969] PGD 0 [ 474.209969] Oops: 0002 [#1] PREEMPT SMP [ 474.209969] Modules linked in: scsi_debug dm_cache_basic dm_cache_mq dm_cache dm_bio_prison dm_persistent_data dm_bufio crc_t10dif nfsv4 sch_fq_codel eeprom nfsd auth_rpcgss exportfs af_packet btrfs zlib_deflate libcrc32c [last unloaded: scsi_debug] [ 474.209969] CPU 0 [ 474.209969] Pid: 1285, comm: kworker/u:2 Not tainted 3.7.0-dmcache #1 Bochs Bochs [ 474.209969] RIP: 0010:[<ffffffffa01b1aad>] [<ffffffffa01b1aad>] queue_evict_default+0x1d/0x50 [dm_cache_basic] [ 474.209969] RSP: 0018:ffff880055641be8 EFLAGS: 00010282 [ 474.209969] RAX: ffff880073a85eb0 RBX: ffff880037ca5c00 RCX: 0000000000000000 [ 474.209969] RDX: 0000000000000000 RSI: 0007fff80005ffff RDI: ffff880073a85eb0 [ 474.209969] RBP: ffff880055641be8 R08: e000000000000000 R09: ffff880072d619a0 [ 474.209969] R10: 0000000000000034 R11: fffffff80005ffff R12: ffff880037f33d30 [ 474.209969] R13: ffff880037ca5c78 R14: ffff880055641c98 R15: 000000000001ffff [ 474.209969] FS: 0000000000000000(0000) GS:ffff88007fc00000(0000) knlGS:0000000000000000 [ 474.209969] CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 [ 474.209969] CR2: 0000000000000008 CR3: 0000000001a0c000 CR4: 00000000000407f0 [ 474.209969] DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000 [ 474.209969] DR3: 0000000000000000 DR6: 00000000ffff0ff0 DR7: 0000000000000400 [ 474.209969] Process kworker/u:2 (pid: 1285, threadinfo ffff880055640000, task ffff88007cb62de0) [ 474.209969] Stack: [ 474.209969] ffff880055641c58 ffffffffa01b28a4 0000000000000040 0000000000000286 [ 474.209969] ffff880000000000 ffffffffa017658c 0000000000000000 ffff880155641cd0 [ 474.209969] ffff880055641c58 ffff88007cac7400 ffff880055641d50 ffff880037f33d30 [ 474.209969] Call Trace: [ 474.209969] [<ffffffffa01b28a4>] basic_map+0x484/0x708 [dm_cache_basic] [ 474.209969] [<ffffffffa017658c>] ? dm_bio_detain+0x5c/0x80 [dm_bio_prison] [ 474.209969] [<ffffffffa019c221>] process_bio+0x101/0x4c0 [dm_cache] [ 474.209969] [<ffffffffa019cb4f>] do_worker+0x56f/0x630 [dm_cache] [ 474.209969] [<ffffffff81081ab6>] ? finish_task_switch+0x56/0xb0 [ 474.209969] [<ffffffff8106fa31>] process_one_work+0x121/0x490 [ 474.209969] [<ffffffffa019c5e0>] ? process_bio+0x4c0/0x4c0 [dm_cache] [ 474.209969] [<ffffffff81070be5>] worker_thread+0x165/0x3f0 [ 474.209969] [<ffffffff81070a80>] ? manage_workers+0x2a0/0x2a0 [ 474.209969] [<ffffffff81076010>] kthread+0xc0/0xd0 [ 474.209969] [<ffffffff81075f50>] ? flush_kthread_worker+0xb0/0xb0 [ 474.209969] [<ffffffff815680ac>] ret_from_fork+0x7c/0xb0 [ 474.209969] [<ffffffff81075f50>] ? flush_kthread_worker+0xb0/0xb0 [ 474.209969] Code: de 48 89 47 08 48 89 f8 5d c3 0f 0b 66 90 66 66 66 66 90 55 48 8b bf f8 01 00 00 48 89 e5 e8 ab ff ff ff 48 8b 48 28 48 8b 50 30 <48> 89 51 08 48 89 0a 48 ba 00 01 10 00 00 00 ad de 48 b9 00 02 [ 474.209969] RIP [<ffffffffa01b1aad>] queue_evict_default+0x1d/0x50 [dm_cache_basic] [ 474.209969] RSP <ffff880055641be8> [ 474.209969] CR2: 0000000000000008 [ 474.333040] ---[ end trace 20dda5f362594054 ]--- [ 474.336010] BUG: unable to handle kernel paging request at ffffffffffffffd8 [ 474.336680] IP: [<ffffffff810761f0>] kthread_data+0x10/0x20 [ 474.336680] PGD 1a0e067 PUD 1a0f067 PMD 0 [ 474.336680] Oops: 0000 [#2] PREEMPT SMP [ 474.336680] Modules linked in: scsi_debug dm_cache_basic dm_cache_mq dm_cache dm_bio_prison dm_persistent_data dm_bufio crc_t10dif nfsv4 sch_fq_codel eeprom nfsd auth_rpcgss exportfs af_packet btrfs zlib_deflate libcrc32c [last unloaded: scsi_debug] [ 474.336680] CPU 0 [ 474.336680] Pid: 1285, comm: kworker/u:2 Tainted: G D 3.7.0-dmcache #1 Bochs Bochs [ 474.336680] RIP: 0010:[<ffffffff810761f0>] [<ffffffff810761f0>] kthread_data+0x10/0x20 [ 474.336680] RSP: 0018:ffff8800556417a8 EFLAGS: 00010096 [ 474.336680] RAX: 0000000000000000 RBX: 0000000000000000 RCX: ffffffff81bb2f80 [ 474.336680] RDX: 0000000000000000 RSI: 0000000000000000 RDI: ffff88007cb62de0 [ 474.336680] RBP: ffff8800556417a8 R08: 0000000000000001 R09: 0000000000000083 [ 474.336680] R10: 0000000000000000 R11: 0000000000000001 R12: 0000000000000000 [ 474.336680] R13: ffff88007cb631d0 R14: 0000000000000000 R15: 0000000000000001 [ 474.336680] FS: 0000000000000000(0000) GS:ffff88007fc00000(0000) knlGS:0000000000000000 [ 474.336680] CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 [ 474.336680] CR2: ffffffffffffffd8 CR3: 0000000001a0c000 CR4: 00000000000407f0 [ 474.336680] DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000 [ 474.336680] DR3: 0000000000000000 DR6: 00000000ffff0ff0 DR7: 0000000000000400 [ 474.336680] Process kworker/u:2 (pid: 1285, threadinfo ffff880055640000, task ffff88007cb62de0) [ 474.336680] Stack: [ 474.336680] ffff8800556417c8 ffffffff81071445 ffff8800556417c8 ffff88007fc12880 [ 474.336680] ffff880055641848 ffffffff81565a58 ffff8800556417f8 ffff880037daeba0 [ 474.336680] ffff88007cb62de0 ffff880055641fd8 ffff880055641fd8 ffff880055641fd8 [ 474.336680] Call Trace: [ 474.336680] [<ffffffff81071445>] wq_worker_sleeping+0x15/0xc0 [ 474.336680] [<ffffffff81565a58>] __schedule+0x5f8/0x7c0 [ 474.336680] [<ffffffff81565d39>] schedule+0x29/0x70 [ 474.336680] [<ffffffff81057748>] do_exit+0x678/0x9e0 [ 474.336680] [<ffffffff8155fe50>] ? printk+0x4d/0x4f [ 474.336680] [<ffffffff8100662b>] oops_end+0xab/0xf0 [ 474.336680] [<ffffffff8155f7a6>] no_context+0x201/0x210 [ 474.336680] [<ffffffff8155f986>] __bad_area_nosemaphore+0x1d1/0x1f0 [ 474.336680] [<ffffffff8110ba75>] ? mempool_kmalloc+0x15/0x20 [ 474.336680] [<ffffffff8155f9b8>] bad_area_nosemaphore+0x13/0x15 [ 474.336680] [<ffffffff810311a2>] __do_page_fault+0x322/0x4d0 [ 474.336680] [<ffffffff8111109f>] ? get_page_from_freelist+0x1bf/0x460 [ 474.336680] [<ffffffff81335eca>] ? virtblk_request+0x44a/0x460 [ 474.336680] [<ffffffff81232d56>] ? cpumask_next_and+0x36/0x50 [ 474.336680] [<ffffffff81232d56>] ? cpumask_next_and+0x36/0x50 [ 474.336680] [<ffffffff8108fa53>] ? update_sd_lb_stats+0x123/0x610 [ 474.336680] [<ffffffff8103138e>] do_page_fault+0xe/0x10 [ 474.336680] [<ffffffff8102e425>] do_async_page_fault+0x35/0xa0 [ 474.336680] [<ffffffff81567925>] async_page_fault+0x25/0x30 [ 474.336680] [<ffffffffa01b1aad>] ? queue_evict_default+0x1d/0x50 [dm_cache_basic] [ 474.336680] [<ffffffffa01b1aa5>] ? queue_evict_default+0x15/0x50 [dm_cache_basic] [ 474.336680] [<ffffffffa01b28a4>] basic_map+0x484/0x708 [dm_cache_basic] [ 474.336680] [<ffffffffa017658c>] ? dm_bio_detain+0x5c/0x80 [dm_bio_prison] [ 474.336680] [<ffffffffa019c221>] process_bio+0x101/0x4c0 [dm_cache] [ 474.336680] [<ffffffffa019cb4f>] do_worker+0x56f/0x630 [dm_cache] [ 474.336680] [<ffffffff81081ab6>] ? finish_task_switch+0x56/0xb0 [ 474.336680] [<ffffffff8106fa31>] process_one_work+0x121/0x490 [ 474.336680] [<ffffffffa019c5e0>] ? process_bio+0x4c0/0x4c0 [dm_cache] [ 474.336680] [<ffffffff81070be5>] worker_thread+0x165/0x3f0 [ 474.336680] [<ffffffff81070a80>] ? manage_workers+0x2a0/0x2a0 [ 474.336680] [<ffffffff81076010>] kthread+0xc0/0xd0 [ 474.336680] [<ffffffff81075f50>] ? flush_kthread_worker+0xb0/0xb0 [ 474.336680] [<ffffffff815680ac>] ret_from_fork+0x7c/0xb0 [ 474.336680] [<ffffffff81075f50>] ? flush_kthread_worker+0xb0/0xb0 [ 474.336680] Code: 00 48 89 e5 5d 48 8b 40 c8 48 c1 e8 02 83 e0 01 c3 66 2e 0f 1f 84 00 00 00 00 00 66 66 66 66 90 48 8b 87 98 03 00 00 55 48 89 e5 <48> 8b 40 d8 5d c3 66 2e 0f 1f 84 00 00 00 00 00 66 66 66 66 90 [ 474.336680] RIP [<ffffffff810761f0>] kthread_data+0x10/0x20 [ 474.336680] RSP <ffff8800556417a8> [ 474.336680] CR2: ffffffffffffffd8 [ 474.336680] ---[ end trace 20dda5f362594055 ]--- [ 474.336680] Fixing recursive fault but reboot is needed! [ 477.004016] Kernel panic - not syncing: Watchdog detected hard LOCKUP on cpu 1 [ 477.004016] Shutting down cpus with NMI [ 477.004016] panic occurred, switching back to text console*Before* it crashes, though, I can run my iops exerciser and watch the numbers climb from ~300 to ~100000. Nice work! :)
(The default policy engine doesn't seem to have this problem, but I haven't figured out how to make it cache blocks yet...)
--D
Quoted 8 lines
Quoted 4 lines
--
dm-devel mailing list
[email protected]
https://www.redhat.com/mailman/listinfo/dm-devel--
dm-devel mailing list
[email protected]
https://www.redhat.com/mailman/listinfo/dm-devel
drivers/md/dm-cache-policy-basic.c +20 -8
@@ -1088,11 +1088,10 @@ static int find_free_cblock(struct policy *p, dm_cblock_t *result)return r; } -static void add_cache_entry (struct policy *p,struct basic_cache_entry *e) +static void alloc_cblock_insert_cache_and_count_entry (struct policy *p,struct basic_cache_entry *e) {unsigned t, u, end =ARRAY_SIZE (e->ce.count[T_HITS ]); - p->queues.fns->add (p, &e->ce.list);alloc_cblock (p, e->cblock);insert_cache_hash_entry (p, e);
@@ -1104,6 +1103,12 @@ static void add_cache_entry(struct policy *p, struct basic_cache_entry *e) p->cache_count[t][u] += e->ce.count[t][u]; } +static void add_cache_entry (struct policy *p,struct basic_cache_entry *e) +{ + p->queues.fns->add (p, &e->ce.list); +alloc_cblock_insert_cache_and_count_entry (p, e); +} +static void remove_cache_entry (struct policy *p,struct basic_cache_entry *e) {unsigned t, u, end =ARRAY_SIZE (e->ce.count[T_HITS ]);
@@ -1406,6 +1411,8 @@ static void sort_in_cache_entry(struct policy *p, struct basic_cache_entry *e)list_add_tail (&e->ce.list, elt); else list_add(&e->ce.list, elt); + +queue_add_tail (&p->queues.walk, &e->walk); } static int basic_load_mapping(struct dm_cache_policy *pe,
@@ -1426,20 +1433,25 @@ static int basic_load_mapping(struct dm_cache_policy *pe,unsigned reads, writes;hint_to_counts (hint, &reads, &writes); + e->ce.count[T_HITS ][0 ] = reads; + e->ce.count[T_HITS ][1 ] = writes;if (IS_MULTIQUEUE (p) ||IS_TWOQUEUE (p) ||IS_LFU_MFU_WS (p)) {/* FIXME: store also in larger hints rather than making up. */ - e->ce.count[T_HITS ][0 ] = reads; - e->ce.count[T_HITS ][1 ] = writes; e->ce.count[T_SECTORS ][0 ] = reads << p->block_shift; e->ce.count[T_SECTORS ][1 ] = writes << p->block_shift; -add_cache_entry (p, e); - p->nr_cblocks_allocated =to_cblock (from_cblock (p->nr_cblocks_allocated) +1 ); + } + } - }else -sort_in_cache_entry (p, e); +if (IS_MULTIQUEUE (p) ||IS_TWOQUEUE (p) ||IS_LFU_MFU_WS (p)) +add_cache_entry (p, e); +else { +sort_in_cache_entry (p, e); +alloc_cblock_insert_cache_and_count_entry (p, e); } + p->nr_cblocks_allocated =to_cblock (from_cblock (p->nr_cblocks_allocated) +1 ); +return 0 ; }
basic cache policy module fix [was: Re: Another cache target]
Quoted 6 lines · Heinz Mauelshagen
Darrick,
please try attached patch, which is on my [email protected]:lvmguy/linux-2.6, branch thin-dev_Work as well. Does that fix the issue for you?
FYI, I've pushed this fix to the previously mentioned 'dm-devel-cache' branch of my github: git://github.com/snitm/linux.git
Re: basic cache policy module fix [was: Re: Another cache target]
Quoted 4 lines · Mike Snitzer
Quoted 1 line · Heinz Mauelshagen
Quoted 8 lines
Quoted 5 lines
Darrick,
please try attached patch, which is on my [email protected]:lvmguy/linux-2.6, branch thin-dev_Work as well. Does that fix the issue for you?
FYI, I've pushed this fix to the previously mentioned 'dm-devel-cache' branch of my github:
git://github.com/snitm/linux.git
Hmm... now I see this:
[ 194.012775] ------------[ cut here ]------------ [ 194.014595] kernel BUG at /storage/home/djwong/cdev/work/linux-dmcache/drivers/md/dm-cache-policy-basic.c:447! [ 194.016018] invalid opcode: 0000 [#1] PREEMPT SMP [ 194.016018] Modules linked in: ext4 mbcache jbd2 dm_cache_basic dm_cache dm_bio_prison dm_persistent_data dm_bufio scsi_debug crc_t10dif sch_fq_codel eeprom nfsv4 nfsd auth_rpcgss exportfs af_packet btrfs zlib_deflate libcrc32c [last unloaded: dm_cache] [ 194.016018] CPU 1 [ 194.016018] Pid: 1572, comm: dmsetup Not tainted 3.7.0-dmcache #7 Bochs Bochs [ 194.016018] RIP: 0010:[<ffffffffa019a00d>] [<ffffffffa019a00d>] basic_load_mapping+0x1bd/0x1c0 [dm_cache_basic] [ 194.016018] RSP: 0018:ffff88007610fb18 EFLAGS: 00010246 [ 194.016018] RAX: 0000000000000700 RBX: ffff88007bedf000 RCX: 0000000000000000 [ 194.016018] RDX: 0000000000000380 RSI: 000000000000c075 RDI: ffff88007bedf000 [ 194.016018] RBP: ffff88007610fb48 R08: 0000000000000001 R09: 0000000000000001 [ 194.016018] R10: 0000000000000000 R11: 0000000000000000 R12: 000000000000c075 [ 194.016018] R13: 0000000000000380 R14: 0000000000000000 R15: 0000000000000001 [ 194.016018] FS: 00007f79095bb7c0(0000) GS:ffff88007fd00000(0000) knlGS:0000000000000000 [ 194.016018] CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 [ 194.016018] CR2: 00007fff3f33a6dc CR3: 0000000029ac4000 CR4: 00000000000407e0 [ 194.016018] DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000 [ 194.016018] DR3: 0000000000000000 DR6: 00000000ffff0ff0 DR7: 0000000000000400 [ 194.016018] Process dmsetup (pid: 1572, threadinfo ffff88007610e000, task ffff880076e3c470) [ 194.016018] Stack: [ 194.016018] ffff88007b715088 ffff880076c9ec00 0000000000000380 000000000000c075 [ 194.016018] 0000000000000001 00000000000001fd ffff88007610fb88 ffffffffa01a47e2 [ 194.016018] 0000000000000000 0000000000000017 ffff88007610fd28 0000000000000380 [ 194.016018] Call Trace: [ 194.016018] [<ffffffffa01a47e2>] load_mapping+0x42/0x90 [dm_cache] [ 194.016018] [<ffffffffa01a6835>] __load_mapping+0x75/0xd0 [dm_cache] [ 194.016018] [<ffffffffa018885e>] walk_ablock+0x8e/0xc0 [dm_persistent_data] [ 194.016018] [<ffffffffa01887d0>] ? get_ablock.isra.1+0x60/0x60 [dm_persistent_data] [ 194.016018] [<ffffffffa018cd64>] walk_node+0xa4/0xe0 [dm_persistent_data] [ 194.016018] [<ffffffffa01887d0>] ? get_ablock.isra.1+0x60/0x60 [dm_persistent_data] [ 194.016018] [<ffffffffa018cf16>] dm_btree_walk+0x46/0x70 [dm_persistent_data] [ 194.016018] [<ffffffffa018802d>] dm_array_walk+0x2d/0x30 [dm_persistent_data] [ 194.016018] [<ffffffffa01a67c0>] ? __dump_mapping+0x40/0x40 [dm_cache] [ 194.016018] [<ffffffffa01a7483>] dm_cache_load_mappings+0xa3/0xd0 [dm_cache] [ 194.016018] [<ffffffffa01a47a0>] ? complete_migration+0x30/0x30 [dm_cache] [ 194.016018] [<ffffffff813d6190>] ? dev_wait+0xc0/0xc0 [ 194.016018] [<ffffffffa01a3733>] cache_preresume+0xa3/0x130 [dm_cache] [ 194.016018] [<ffffffff813d2fa2>] dm_table_resume_targets+0x42/0xa0 [ 194.016018] [<ffffffff813d0b42>] dm_resume+0x62/0xd0 [ 194.016018] [<ffffffff813d6339>] dev_suspend+0x1a9/0x240 [ 194.016018] [<ffffffff813d69fd>] ctl_ioctl+0x12d/0x260 [ 194.016018] [<ffffffff813d6b43>] dm_ctl_ioctl+0x13/0x20 [ 194.016018] [<ffffffff8116907f>] do_vfs_ioctl+0x8f/0x4f0 [ 194.016018] [<ffffffff81081d16>] ? finish_task_switch+0x56/0xb0 [ 194.016018] [<ffffffff8155ae44>] ? __schedule+0x394/0x7c0 [ 194.016018] [<ffffffff81169530>] sys_ioctl+0x50/0x90 [ 194.016018] [<ffffffff8102e425>] ? do_async_page_fault+0x35/0xa0 [ 194.016018] [<ffffffff8155d79d>] system_call_fastpath+0x1a/0x1f [ 194.016018] Code: 30 ff ff ff 48 89 df e8 b2 fd ff ff eb a7 48 8b 0a 48 89 41 08 48 89 08 48 89 50 08 48 89 02 e9 65 ff ff ff b8 f4 ff ff ff eb 93 <0f> 0b 90 66 66 66 66 90 55 48 89 e5 48 83 ec 40 85 f6 48 89 5d [ 194.016018] RIP [<ffffffffa019a00d>] basic_load_mapping+0x1bd/0x1c0 [dm_cache_basic] [ 194.016018] RSP <ffff88007610fb18> [ 194.154633] ---[ end trace 2fbcf20015b55d9f ]---
--D
Re: basic cache policy module fix [was: Re: Another cache target]
Darrick,
thanks for testing.
Bug's a superfluous increment of the number of allocated cache blocks in dm-cache-policy-basic:load_mappings().
Patch is attached and on my [email protected]:lvmguy/linux-2.6, branch dm-devel-cache.
Heinz
Quoted 72 lines · Darrick J. Wong
Quoted 10 lines · Mike Snitzer
Quoted 5 lines · Heinz Mauelshagen
Darrick,
please try attached patch, which is on my [email protected]:lvmguy/linux-2.6, branch thin-dev_Work as well. Does that fix the issue for you?
FYI, I've pushed this fix to the previously mentioned 'dm-devel-cache' branch of my github:
git://github.com/snitm/linux.gitHmm... now I see this:
[ 194.012775] ------------[ cut here ]------------ [ 194.014595] kernel BUG at /storage/home/djwong/cdev/work/linux-dmcache/drivers/md/dm-cache-policy-basic.c:447! [ 194.016018] invalid opcode: 0000 [#1] PREEMPT SMP [ 194.016018] Modules linked in: ext4 mbcache jbd2 dm_cache_basic dm_cache dm_bio_prison dm_persistent_data dm_bufio scsi_debug crc_t10dif sch_fq_codel eeprom nfsv4 nfsd auth_rpcgss exportfs af_packet btrfs zlib_deflate libcrc32c [last unloaded: dm_cache] [ 194.016018] CPU 1 [ 194.016018] Pid: 1572, comm: dmsetup Not tainted 3.7.0-dmcache #7 Bochs Bochs [ 194.016018] RIP: 0010:[<ffffffffa019a00d>] [<ffffffffa019a00d>] basic_load_mapping+0x1bd/0x1c0 [dm_cache_basic] [ 194.016018] RSP: 0018:ffff88007610fb18 EFLAGS: 00010246 [ 194.016018] RAX: 0000000000000700 RBX: ffff88007bedf000 RCX: 0000000000000000 [ 194.016018] RDX: 0000000000000380 RSI: 000000000000c075 RDI: ffff88007bedf000 [ 194.016018] RBP: ffff88007610fb48 R08: 0000000000000001 R09: 0000000000000001 [ 194.016018] R10: 0000000000000000 R11: 0000000000000000 R12: 000000000000c075 [ 194.016018] R13: 0000000000000380 R14: 0000000000000000 R15: 0000000000000001 [ 194.016018] FS: 00007f79095bb7c0(0000) GS:ffff88007fd00000(0000) knlGS:0000000000000000 [ 194.016018] CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 [ 194.016018] CR2: 00007fff3f33a6dc CR3: 0000000029ac4000 CR4: 00000000000407e0 [ 194.016018] DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000 [ 194.016018] DR3: 0000000000000000 DR6: 00000000ffff0ff0 DR7: 0000000000000400 [ 194.016018] Process dmsetup (pid: 1572, threadinfo ffff88007610e000, task ffff880076e3c470) [ 194.016018] Stack: [ 194.016018] ffff88007b715088 ffff880076c9ec00 0000000000000380 000000000000c075 [ 194.016018] 0000000000000001 00000000000001fd ffff88007610fb88 ffffffffa01a47e2 [ 194.016018] 0000000000000000 0000000000000017 ffff88007610fd28 0000000000000380 [ 194.016018] Call Trace: [ 194.016018] [<ffffffffa01a47e2>] load_mapping+0x42/0x90 [dm_cache] [ 194.016018] [<ffffffffa01a6835>] __load_mapping+0x75/0xd0 [dm_cache] [ 194.016018] [<ffffffffa018885e>] walk_ablock+0x8e/0xc0 [dm_persistent_data] [ 194.016018] [<ffffffffa01887d0>] ? get_ablock.isra.1+0x60/0x60 [dm_persistent_data] [ 194.016018] [<ffffffffa018cd64>] walk_node+0xa4/0xe0 [dm_persistent_data] [ 194.016018] [<ffffffffa01887d0>] ? get_ablock.isra.1+0x60/0x60 [dm_persistent_data] [ 194.016018] [<ffffffffa018cf16>] dm_btree_walk+0x46/0x70 [dm_persistent_data] [ 194.016018] [<ffffffffa018802d>] dm_array_walk+0x2d/0x30 [dm_persistent_data] [ 194.016018] [<ffffffffa01a67c0>] ? __dump_mapping+0x40/0x40 [dm_cache] [ 194.016018] [<ffffffffa01a7483>] dm_cache_load_mappings+0xa3/0xd0 [dm_cache] [ 194.016018] [<ffffffffa01a47a0>] ? complete_migration+0x30/0x30 [dm_cache] [ 194.016018] [<ffffffff813d6190>] ? dev_wait+0xc0/0xc0 [ 194.016018] [<ffffffffa01a3733>] cache_preresume+0xa3/0x130 [dm_cache] [ 194.016018] [<ffffffff813d2fa2>] dm_table_resume_targets+0x42/0xa0 [ 194.016018] [<ffffffff813d0b42>] dm_resume+0x62/0xd0 [ 194.016018] [<ffffffff813d6339>] dev_suspend+0x1a9/0x240 [ 194.016018] [<ffffffff813d69fd>] ctl_ioctl+0x12d/0x260 [ 194.016018] [<ffffffff813d6b43>] dm_ctl_ioctl+0x13/0x20 [ 194.016018] [<ffffffff8116907f>] do_vfs_ioctl+0x8f/0x4f0 [ 194.016018] [<ffffffff81081d16>] ? finish_task_switch+0x56/0xb0 [ 194.016018] [<ffffffff8155ae44>] ? __schedule+0x394/0x7c0 [ 194.016018] [<ffffffff81169530>] sys_ioctl+0x50/0x90 [ 194.016018] [<ffffffff8102e425>] ? do_async_page_fault+0x35/0xa0 [ 194.016018] [<ffffffff8155d79d>] system_call_fastpath+0x1a/0x1f [ 194.016018] Code: 30 ff ff ff 48 89 df e8 b2 fd ff ff eb a7 48 8b 0a 48 89 41 08 48 89 08 48 89 50 08 48 89 02 e9 65 ff ff ff b8 f4 ff ff ff eb 93 <0f> 0b 90 66 66 66 66 90 55 48 89 e5 48 83 ec 40 85 f6 48 89 5d [ 194.016018] RIP [<ffffffffa019a00d>] basic_load_mapping+0x1bd/0x1c0 [dm_cache_basic] [ 194.016018] RSP <ffff88007610fb18> [ 194.154633] ---[ end trace 2fbcf20015b55d9f ]-----D
--
dm-devel mailing list
[email protected]
https://www.redhat.com/mailman/listinfo/dm-devel
Signature · 8 lines
=============================================================== Heinz Mauelshagen +49 2626 141200 Consulting Development Engineer FAX +49 2626 924446 Red Hat GmbH Am Sonnenhang 11 56242 Marienrachdorf Germany [email protected] ===============================================================
drivers/md/dm-cache-policy-basic.c +0 -2
@@ -1450,8 +1450,6 @@ static int basic_load_mapping(struct dm_cache_policy *pe,alloc_cblock_insert_cache_and_count_entry (p, e); } - p->nr_cblocks_allocated =to_cblock (from_cblock (p->nr_cblocks_allocated) +1 ); -return 0 ; }
Re: basic cache policy module fix [was: Re: Another cache target]
Quoted 9 lines · Heinz Mauelshagen
Darrick,
thanks for testing.
Bug's a superfluous increment of the number of allocated cache blocks in dm-cache-policy-basic:load_mappings().
Patch is attached and on my [email protected]:lvmguy/linux-2.6, branch dm-devel-cache.
FYI, I merged the fix into my dm-devel-cache too.
Re: basic cache policy module fix [was: Re: Another cache target]
Quoted 7 lines · Mike Snitzer
Quoted 4 lines · Heinz Mauelshagen
Darrick,
thanks for testing.
Quoted 7 lines
Quoted 5 lines
Bug's a superfluous increment of the number of allocated cache blocks in dm-cache-policy-basic:load_mappings().
Patch is attached and on my [email protected]:lvmguy/linux-2.6, branch dm-devel-cache.
FYI, I merged the fix into my dm-devel-cache too.
kbuild had this to say:drivers/md/dm-cache-policy-basic.c: In function ‘basic_map’:drivers/md/dm-cache-policy-basic.c:1252:39: warning: ‘tqe’ may be used uninitialized in this function [-Wuninitialized] drivers/md/dm-cache-policy-basic.c:1271:28: note: ‘tqe’ was declared here
I _think_ it's actually ok, but I'm not 100% sure.
Otherwise it seems to have passed the remove/recreate test. I'll keep pounding on it.
--D
Quoted 5 lines
--
dm-devel mailing list
[email protected]
https://www.redhat.com/mailman/listinfo/dm-devel
--
dm-devel mailing list
[email protected]
https://www.redhat.com/mailman/listinfo/dm-devel
Re: basic cache policy module fix [was: Re: Another cache target]
Quoted 13 lines · Darrick J. Wong
Quoted 12 lines · Mike Snitzer
Quoted 9 lines · Heinz Mauelshagen
Darrick,
thanks for testing.
Bug's a superfluous increment of the number of allocated cache blocks in dm-cache-policy-basic:load_mappings().
Patch is attached and on my [email protected]:lvmguy/linux-2.6, branch dm-devel-cache.
Quoted 7 lines
Quoted 1 line
FYI, I merged the fix into my dm-devel-cache too.
kbuild had this to say:
drivers/md/dm-cache-policy-basic.c: In function ‘basic_map’:drivers/md/dm-cache-policy-basic.c:1252:39: warning: ‘tqe’ may be used uninitialized in this function [-Wuninitialized]drivers/md/dm-cache-policy-basic.c:1271:28: note: ‘tqe’ was declared hereI _think_ it's actually ok, but I'm not 100% sure.
Aware of that and it is ok, _but_ I want to rephrase the code to get rid of it.
Quoted 2 lines
Otherwise it seems to have passed the remove/recreate test.
Nice.
Quoted 2 lines
I'll keep pounding
on it.
Cool, thanks.
Heinz
Quoted 10 lines
--D
Quoted 4 lines
--
dm-devel mailing list
[email protected]
https://www.redhat.com/mailman/listinfo/dm-devel--
dm-devel mailing list
[email protected]
https://www.redhat.com/mailman/listinfo/dm-devel
Signature · 13 lines
=============================================================== Heinz Mauelshagen +49 2626 141200 Consulting Development Engineer FAX +49 2626 924446 Red Hat GmbH Am Sonnenhang 11 56242 Marienrachdorf Germany [email protected] =============================================================== -- dm-devel mailing list [email protected] https://www.redhat.com/mailman/listinfo/dm-devel