dm cache: proposed changes for v3.13 merge
Subsystems (2)
cover dm cache: proposed changes for v3.13 merge
The following patches have been published to the 'for-next' branch of the device-mapper git repository:git://git.kernel.org/pub/scm/linux/kernel/git/device-mapper/linux-dm.git
The patches marked as RFC (19-24) could use the most review. But all review would be appreciated.
Thanks,
Mike
Heinz Mauelshagen (11):
dm cache policy mq: return NULL if mq->free list is empty in alloc_entry dm cache policy: variable hints support
dm cache policy: have policy_writeback_work return -ENODATA by default dm cache: use is_write_io() in more places
dm cache: use cell_defer() boolean argument consistently
dm cache: log error message if dm_kcopyd_copy() fails
dm cache: use a boolean when setting cache->quiescing
dm cache: optimize commit_if_needed
dm cache: add hints policy
dm cache: add cache block invalidation API
dm cache policy era: add cache block invalidation support
Joe Thornber (9):
dm: nest targets used for testing under DM_TEST_TARGETS
dm space map disk: optimise sm_disk_dec_block
dm cache policy: remove return from void policy_remove_mapping dm cache policy mq: a few small fixes
dm cache policy mq: implement writeback_work() and mq_{set,clear}_dirty() dm cache: be much more aggressive about promoting writes to discarded blocks dm cache metadata: return bool from __superblock_all_zeroes
dm cache metadata: check the metadata version when reading the superblock dm cache: add passthrough mode
Mike Snitzer (1):
dm table: print error on preresume failure
Morgan Mears (3):
dm cache: support for stackable caching policies dm cache: add era policy shim
dm cache: add trc policy shim
drivers/md/Kconfig | 68 ++- drivers/md/Makefile | 9 +- drivers/md/dm-cache-metadata.c | 189 +++++- drivers/md/dm-cache-metadata.h | 28 +- drivers/md/dm-cache-policy-cleaner.c | 10 +- drivers/md/dm-cache-policy-era.c | 542 +++++++++++++++++ drivers/md/dm-cache-policy-hints.c | 769 +++++++++++++++++++++++++ drivers/md/dm-cache-policy-internal.h | 31 +- drivers/md/dm-cache-policy-mq.c | 343 ++++++++--- drivers/md/dm-cache-policy-trc.c | 263 +++++++++ drivers/md/dm-cache-policy.c | 66 ++- drivers/md/dm-cache-policy.h | 77 ++- drivers/md/dm-cache-shim-utils.c | 217 +++++++ drivers/md/dm-cache-shim-utils.h | 73 +++ drivers/md/dm-cache-stack-utils.c | 239 ++++++++ drivers/md/dm-cache-stack-utils.h | 34 ++ drivers/md/dm-cache-target.c | 417 ++++++++++++-- drivers/md/dm-table.c | 5 +- drivers/md/persistent-data/dm-space-map-disk.c | 18 +- 19 files changed, 3167 insertions(+), 231 deletions(-) create mode 100644 drivers/md/dm-cache-policy-era.c create mode 100644 drivers/md/dm-cache-policy-hints.c create mode 100644 drivers/md/dm-cache-policy-trc.c create mode 100644 drivers/md/dm-cache-shim-utils.c create mode 100644 drivers/md/dm-cache-shim-utils.h create mode 100644 drivers/md/dm-cache-stack-utils.c create mode 100644 drivers/md/dm-cache-stack-utils.h
Signature · 1 line
1.8.1.4
PATCH 1/24 dm: nest targets used for testing under DM_TEST_TARGETS
From: Joe Thornber <[email protected]>
Both the flakey and delay targets are generally used for testing. Other test targets (and cache policies) will be introduced in the future.
--- drivers/md/Kconfig | 36 +++++++++++++++++++++--------------- 1 file changed, 21 insertions(+), 15 deletions(-)
drivers/md/Kconfig +21 -15
@@ -371,27 +371,12 @@ config DM_MULTIPATH_ST If unsure, say N. -config DM_DELAY - tristate "I/O delaying target" - depends on BLK_DEV_DM - ---help--- - A target that delays reads and/or writes and can send - them to different devices. Useful for testing. - - If unsure, say N. - config DM_UEVENT bool "DM uevents" depends on BLK_DEV_DM ---help--- Generate udev events for DM events. -config DM_FLAKEY - tristate "Flakey target" - depends on BLK_DEV_DM - ---help--- - A target that intermittently fails I/O for debugging purposes. - config DM_VERITY tristate "Verity target support" depends on BLK_DEV_DM
@@ -426,4 +411,25 @@ config DM_SWITCH If unsure, say N. +config DM_TEST_TARGETS + bool "DM test targets" + depends on BLK_DEV_DM + ---help--- + Targets that are only useful for testing. + +config DM_FLAKEY + tristate "Flakey target (EXPERIMENTAL)" + depends on DM_TEST_TARGETS + ---help--- + A target that intermittently fails I/O for debugging purposes. + +config DM_DELAY + tristate "I/O delaying target (EXPERIMENTAL)" + depends on DM_TEST_TARGETS + ---help--- + A target that delays reads and/or writes and can send + them to different devices. Useful for testing. + + If unsure, say N. + endif # MD
Signature · 1 line
1.8.1.4
Alasdair G Kergon
maintainerRe: [PATCH 01/24] dm: nest targets used for testing under DM_TEST_TARGETS
drivers/md/Kconfig config DM_MULTIPATH_ST · line 374
Quoted 9 lines
drivers/md/Kconfig +2
-2@@ -371,27 +371,12 @@ config DM_MULTIPATH_ST -config DM_DELAY - tristate "I/O delaying target" +config DM_DELAY + tristate "I/O delaying target (EXPERIMENTAL)"
Why has EXPERIMENTAL reappeared???
See d57916a00fd749ccd354a7f754c2aba98f86d064
Please regenerate these patches against an up-to-date upstream base!
Thanks,
Alasdair
Re: [PATCH 01/24] dm: nest targets used for testing under DM_TEST_TARGETS
Quoted 7 lines · Alasdair G Kergon
Quoted 6 lines
drivers/md/Kconfig +0
-2@@ -371,27 +371,12 @@ config DM_MULTIPATH_ST -config DM_DELAY - tristate "I/O delaying target"
Quoted 7 lines
drivers/md/Kconfig config DM_SWITCH · line 427
Quoted 2 lines
drivers/md/Kconfig +2
-0+config DM_DELAY + tristate "I/O delaying target (EXPERIMENTAL)"Why has EXPERIMENTAL reappeared???
Seed57916a00fd749ccd354a7f754c2aba98f86d064Please regenerate these patches against an up-to-date upstream base!
The base for these patches is v3.12-rc5, certainly recent enough.
What you took issue with here has nothing to do with an older base being used for the patches. It has everything to do with Joe having made this change in his thin-dev branch quite a while ago -- when I rebased I didn't change the text the patch moved. Will remove the EXPERIMENTALs.
As for delay being useful for non-test use-cases, that may be but classifying it as a target that is used for testing is fair (hence "Useful for testing." in the DM_DELAY help text). That said, if you'd really prefer DM_DELAY not be nested under DM_TEST_TARGETS I can revert it.
Alasdair G Kergon
maintainerRe: [PATCH 01/24] dm: nest targets used for testing under DM_TEST_TARGETS
Quoted 5 lines · Mike Snitzer
As for delay being useful for non-test use-cases, that may be but classifying it as a target that is used for testing is fair (hence "Useful for testing." in the
DM_DELAYhelp text). That said, if you'd really preferDM_DELAYnot be nested underDM_TEST_TARGETSI can revert it.
I'm not objecting to its inclusion with the TEST TARGETS, as that remains the primary use of it, but with the statement that the target is then meant only for testing.
Alasdair
Alasdair G Kergon
maintainerRe: [PATCH 01/24] dm: nest targets used for testing under DM_TEST_TARGETS
In reply to Mike SnitzerQuoted 1 line · Mike Snitzer
Both the flakey and delay targets are generally used for testing.
^^^^^^^^^
Indeed - not exclusively.
drivers/md/Kconfig config DM_SWITCH · line 418
Quoted 5 lines
--- a/drivers/md/Kconfig
drivers/md/Kconfig +2
-0+config DM_TEST_TARGETS + Targets that are only useful for testing.
Could we delete the word 'only'? Or replace it with something like 'primarily'?
(I don't like this classification for DM_DELAY: I think it can have uses in non-testing scenarios.)
Alasdair
PATCH 2/24 dm space map disk: optimise sm_disk_dec_block
In reply to Mike SnitzerFrom: Joe Thornber <[email protected]>
Don't waste time spotting blocks that have been allocated and then freed in the same transaction.
The extra lookup is expensive, and I don't think it really gives us much.
--- drivers/md/persistent-data/dm-space-map-disk.c | 18 +----------------- 1 file changed, 1 insertion(+), 17 deletions(-)
drivers/md/persistent-data/dm-space-map-disk.c +1 -17
@@ -140,26 +140,10 @@ static int sm_disk_inc_block(struct dm_space_map *sm, dm_block_t b)static int sm_disk_dec_block (struct dm_space_map *sm,dm_block_t b) { -int r; -uint32_t old_count;enum allocation_event ev; struct sm_disk *smd = container_of(sm, struct sm_disk, sm); - r =sm_ll_dec (&smd->ll, b, &ev); -if (!r && (ev ==SM_FREE )) { -/* -* It's only free if it's also free in the last -* transaction. -*/ - r =sm_ll_lookup (&smd->old_ll, b, &old_count); -if (r) -return r; - -if (!old_count) - smd->nr_allocated_this_transaction--; - } - -return r; +return sm_ll_dec (&smd->ll, b, &ev); }static int sm_disk_new_block (struct dm_space_map *sm,dm_block_t *b)
Signature · 1 line
1.8.1.4
PATCH 3/24 dm cache policy: remove return from void policy_remove_mapping
In reply to Mike SnitzerFrom: Joe Thornber <[email protected]>
No need to return from a void function.
--- drivers/md/dm-cache-policy-internal.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/md/dm-cache-policy-internal.h +1 -1
@@ -61,7 +61,7 @@ static inline int policy_writeback_work(struct dm_cache_policy *p,static inline void policy_remove_mapping (struct dm_cache_policy *p,dm_oblock_t oblock) { -return p->remove_mapping (p, oblock); + p->remove_mapping (p, oblock); } static inline void policy_force_mapping(struct dm_cache_policy *p,
Signature · 1 line
1.8.1.4
PATCH 4/24 dm cache policy mq: a few small fixes
In reply to Mike SnitzerFrom: Joe Thornber <[email protected]>
Rename takeout_queue to concat_queue.
Fix a harmless bug in mq policies pop() function. Currently pop() always succeeds, with up coming changes this wont be the case.
Fix typo in comment above pre_cache_to_cache prototype.
--- drivers/md/dm-cache-policy-mq.c | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-)
drivers/md/dm-cache-policy-mq.c +12 -10
@@ -311,7 +311,7 @@ struct mq_policy {/*----------------------------------------------------------------*/ /* Free/alloc mq cache entry structures. */ -static void takeout_queue (struct list_head *lh,struct queue *q) +static void concat_queue (struct list_head *lh,struct queue *q) {unsigned level;
@@ -323,8 +323,8 @@ 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); +concat_queue (&mq->free, &mq->pre_cache); +concat_queue (&mq->free, &mq->cache);list_for_each_entry_safe (e, tmp, &mq->free, list)kmem_cache_free (mq_entry_cache, e);
@@ -531,14 +531,16 @@ static void del(struct mq_policy *mq, struct entry *e)*/ static struct entry *pop (struct mq_policy *mq,struct queue *q) { - struct entry *e = container_of(queue_pop(q), struct entry, list); +struct entry *e; +struct list_head *h =queue_pop (q); -if (e) { -hash_remove (e); +if (!h) +return NULL ; -if (e->in_cache) -free_cblock (mq, e->cblock); - } + e = container_of(h, struct entry, list); +hash_remove (e); +if (e->in_cache) +free_cblock (mq, e->cblock);return e; }
@@ -697,7 +699,7 @@ static int cache_entry_found(struct mq_policy *mq, }/* -* Moves and entry from the pre_cache to the cache. The main work is +* Moves an 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,
Signature · 1 line
1.8.1.4
PATCH 5/24 dm cache policy mq: implement writeback_work() and mq_{set, clear}_dirty()
In reply to Mike SnitzerFrom: Joe Thornber <[email protected]>
There are now two multiqueues for in cache blocks. A clean one and a dirty one.
writeback_work comes from the dirty one. Demotions come from the clean one.
There are two benefits:
- Performance improvement, since demoting a clean block is a noop.
- The cache cleans itself when io load is light.
--- drivers/md/dm-cache-policy-mq.c | 140 ++++++++++++++++++++++++++++++++++------ 1 file changed, 122 insertions(+), 18 deletions(-)
drivers/md/dm-cache-policy-mq.c +122 -18
@@ -224,6 +224,7 @@ struct entry {* FIXME: pack these better */ bool in_cache:1; + bool dirty:1;unsigned hit_count;unsigned generation;unsigned tick;
@@ -238,13 +239,15 @@ struct mq_policy {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. +* We maintain three queues of entries. The cache proper, +* consisting of a clean and dirty queue, 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; +struct queue cache_clean; +struct queue cache_dirty;/* * Keeps track of time, incremented by the core. We use this to
@@ -324,7 +327,8 @@ static void free_entries(struct mq_policy *mq)struct entry *e, *tmp;concat_queue (&mq->free, &mq->pre_cache); -concat_queue (&mq->free, &mq->cache); +concat_queue (&mq->free, &mq->cache_clean); +concat_queue (&mq->free, &mq->cache_dirty);list_for_each_entry_safe (e, tmp, &mq->free, list)kmem_cache_free (mq_entry_cache, e);
@@ -508,7 +512,8 @@ static void push(struct mq_policy *mq, struct entry *e)if (e->in_cache) {alloc_cblock (mq, e->cblock); -queue_push (&mq->cache,queue_level (e), &e->list); +queue_push (e->dirty ? &mq->cache_dirty : &mq->cache_clean, +queue_level (e), &e->list); }else queue_push (&mq->pre_cache,queue_level (e), &e->list); }
@@ -580,7 +585,16 @@ static void check_generation(struct mq_policy *mq) mq->generation++;for (level =0 ; level <NR_QUEUE_LEVELS && count <MAX_TO_AVERAGE ; level++) { - head = mq->cache.qs + level; + head = mq->cache_clean.qs + level; +list_for_each_entry (e, head, list) { + nr++; + total += e->hit_count; + +if (++count >=MAX_TO_AVERAGE ) +break ; + } + + head = mq->cache_dirty.qs + level;list_for_each_entry (e, head, list) { nr++; total += e->hit_count;
@@ -633,19 +647,28 @@ static void requeue_and_update_tick(struct mq_policy *mq, struct entry *e)* - 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) +static int demote_cblock (struct mq_policy *mq,dm_oblock_t *oblock,dm_cblock_t *cblock) { -dm_cblock_t result; -struct entry *demoted =pop (mq, &mq->cache); +struct entry *demoted =pop (mq, &mq->cache_clean); -BUG_ON (!demoted); - result = demoted->cblock; +if (!demoted) +/* +* We could get a block from mq->cache_dirty, but that +* would add extra latency to the triggering bio as it +* waits for the writeback. Better to not promote this +* time and hope there's a clean block next time this block +* is hit. +*/ +return -ENOSPC ; + + *cblock = demoted->cblock; *oblock = demoted->oblock; demoted->in_cache = false; + demoted->dirty = false; demoted->hit_count =1 ;push (mq, demoted); -return result; +return 0 ; }/*
@@ -705,11 +728,16 @@ static int cache_entry_found(struct mq_policy *mq,static int pre_cache_to_cache (struct mq_policy *mq,struct entry *e,struct policy_result *result) { +int r;dm_cblock_t cblock;if (find_free_cblock (mq, &cblock) == -ENOSPC ) { result->op =POLICY_REPLACE ; - cblock =demote_cblock (mq, &result->old_oblock); + r =demote_cblock (mq, &result->old_oblock, &cblock); +if (r) { + result->op =POLICY_MISS ; +return 0 ; + } }else result->op =POLICY_NEW ;
@@ -717,6 +745,7 @@ static int pre_cache_to_cache(struct mq_policy *mq, struct entry *e,del (mq, e); e->in_cache = true; + e->dirty = false;push (mq, e);return 0 ;
@@ -760,6 +789,7 @@ static void insert_in_pre_cache(struct mq_policy *mq, } e->in_cache = false; + e->dirty = false; e->oblock = oblock; e->hit_count =1 ; e->generation = mq->generation;
@@ -787,6 +817,7 @@ static void insert_in_cache(struct mq_policy *mq, dm_oblock_t oblock, e->oblock = oblock; e->cblock = cblock; e->in_cache = true; + e->dirty = false; e->hit_count =1 ; e->generation = mq->generation;push (mq, e);
@@ -917,6 +948,36 @@ static int mq_lookup(struct dm_cache_policy *p, dm_oblock_t oblock, dm_cblock_treturn r; } +// FIXME: can __mq_set_clear_dirty block? +static void __mq_set_clear_dirty (struct dm_cache_policy *p,dm_oblock_t oblock,bool set) +{ +struct mq_policy *mq =to_mq_policy (p); +struct entry *e; + +mutex_lock (&mq->lock); + e =hash_lookup (mq, oblock); +if (!e) +DMWARN ("__mq_set_clear_dirty called for a block that isn't in the cache" ); +else { +BUG_ON (!e->in_cache); + +del (mq, e); + e->dirty = set; +push (mq, e); + } +mutex_unlock (&mq->lock); +} + +static void mq_set_dirty (struct dm_cache_policy *p,dm_oblock_t oblock) +{ +__mq_set_clear_dirty (p, oblock, true); +} + +static void mq_clear_dirty (struct dm_cache_policy *p,dm_oblock_t oblock) +{ +__mq_set_clear_dirty (p, oblock, false); +} +static int mq_load_mapping (struct dm_cache_policy *p,dm_oblock_t oblock,dm_cblock_t cblock,uint32_t hint,bool hint_valid)
@@ -931,6 +992,7 @@ static int mq_load_mapping(struct dm_cache_policy *p, e->cblock = cblock; e->oblock = oblock; e->in_cache = true; + e->dirty = true;/* this gets corrected in a minute */ e->hit_count = hint_valid ? hint :1 ; e->generation = mq->generation;push (mq, e);
@@ -949,7 +1011,14 @@ static int mq_walk_mappings(struct dm_cache_policy *p, policy_walk_fn fn,mutex_lock (&mq->lock);for (level =0 ; level <NR_QUEUE_LEVELS ; level++) -list_for_each_entry (e, &mq->cache.qs[level], list) { +list_for_each_entry (e, &mq->cache_clean.qs[level], list) { + r =fn (context, e->cblock, e->oblock, e->hit_count); +if (r) + goto out; + } + +for (level =0 ; level <NR_QUEUE_LEVELS ; level++) +list_for_each_entry (e, &mq->cache_dirty.qs[level], list) { r =fn (context, e->cblock, e->oblock, e->hit_count);if (r) goto out;
@@ -974,9 +1043,39 @@ static void mq_remove_mapping(struct dm_cache_policy *p, dm_oblock_t oblock)del (mq, e); e->in_cache = false; + e->dirty = false; +push (mq, e); + +mutex_unlock (&mq->lock); +} + +static int __mq_writeback_work (struct mq_policy *mq,dm_oblock_t *oblock, +dm_cblock_t *cblock) +{ +struct entry *e =pop (mq, &mq->cache_dirty); + +if (!e) +return -ENODATA ; + + *oblock = e->oblock; + *cblock = e->cblock; + e->dirty = false;push (mq, e); +return 0 ; +} + +static int mq_writeback_work (struct dm_cache_policy *p,dm_oblock_t *oblock, +dm_cblock_t *cblock) +{ +int r; +struct mq_policy *mq =to_mq_policy (p); + +mutex_lock (&mq->lock); + r =__mq_writeback_work (mq, oblock, cblock);mutex_unlock (&mq->lock); + +return r; } static void force_mapping(struct mq_policy *mq,
@@ -988,6 +1087,7 @@ static void force_mapping(struct mq_policy *mq,del (mq, e); e->oblock = new_oblock; + e->dirty = true;push (mq, e); }
@@ -1059,10 +1159,12 @@ static void init_policy_functions(struct mq_policy *mq) mq->policy.destroy = mq_destroy; mq->policy.map = mq_map; mq->policy.lookup = mq_lookup; + mq->policy.set_dirty = mq_set_dirty; + mq->policy.clear_dirty = mq_clear_dirty; mq->policy.load_mapping = mq_load_mapping; mq->policy.walk_mappings = mq_walk_mappings; mq->policy.remove_mapping = mq_remove_mapping; - mq->policy.writeback_work =NULL ; + mq->policy.writeback_work = mq_writeback_work; mq->policy.force_mapping = mq_force_mapping; mq->policy.residency = mq_residency; mq->policy.tick = mq_tick;
@@ -1095,7 +1197,9 @@ static struct dm_cache_policy *mq_create(dm_cblock_t cache_size, mq->find_free_last_word =0 ;queue_init (&mq->pre_cache); -queue_init (&mq->cache); +queue_init (&mq->cache_clean); +queue_init (&mq->cache_dirty); + mq->generation_period =max ((unsigned )from_cblock (cache_size),1024U ); mq->nr_entries =2 *from_cblock (cache_size);
Signature · 1 line
1.8.1.4
Alasdair G Kergon
maintainerRe: [PATCH 05/24] dm cache policy mq: implement writeback_work() and mq_{set, clear}_dirty()
drivers/md/dm-cache-policy-mq.c struct mq_policy {
Quoted 7 lines · Mike Snitzer
From: Joe Thornber <[email protected]>
---
a/drivers/md/dm-cache-policy-mq.cdrivers/md/dm-cache-policy-mq.c +1
-1-* We maintain two queues of entries. The cache proper contains +* We maintain three queues of entries. The cache proper,
Does the Documentation file need updating too?
: The multiqueue policy has two sets of 16 queues: one set for entries : waiting for the cache and another one for those in the cache.
Review static void check_generation(struct mq_policy *mq)
Quoted 1 line
(quoted diff) +0
-0@@ -580,7 +585,16 @@ static void check_generation(struct mq_policy *mq)
Is the comment about this function no longer accurate?
: * 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).
- It looks at clean before dirty?
- It looks at more than just the first level if it needs to?
drivers/md/dm-cache-policy-mq.c static int mq_lookup(struct dm_cache_policy *p, dm_oblock_t oblock, dm_cblock_t · line 951
Quoted 1 line
drivers/md/dm-cache-policy-mq.c +1
-0+// FIXME: can __mq_set_clear_dirty block?
Still to check this before inclusion upstream?
Alasdair
Re: [PATCH 05/24] dm cache policy mq: implement writeback_work() and mq_{set, clear}_dirty()
Quoted 10 lines · Alasdair G Kergon
drivers/md/dm-cache-policy-mq.c struct mq_policy {
Quoted 7 lines · Mike Snitzer
From: Joe Thornber <[email protected]>
---
a/drivers/md/dm-cache-policy-mq.cdrivers/md/dm-cache-policy-mq.c +1
-1-* We maintain two queues of entries. The cache proper contains +* We maintain three queues of entries. The cache proper, Does the Documentation file need updating too?
will fix.
Quoted 11 lines
: The multiqueue policy has two sets of 16 queues: one set for entries : waiting for the cache and another one for those in the cache.
Review static void check_generation(struct mq_policy *mq)
Quoted 1 line
(quoted diff) +0
-0@@ -580,7 +585,16 @@ static void check_generation(struct mq_policy *mq)Is the comment about this function no longer accurate?
: * 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).
- It looks at clean before dirty?
yes, that is new. will fix.
Quoted 1 line
- It looks at more than just the first level if it needs to?
was always the case, so docs were already stale. will fix.
Quoted 3 lines
drivers/md/dm-cache-policy-mq.c static int mq_lookup(struct dm_cache_policy *p, dm_oblock_t oblock, dm_cblock_t · line 951
Quoted 1 line
drivers/md/dm-cache-policy-mq.c +1
-0+// FIXME: can __mq_set_clear_dirty block? Still to check this before inclusion upstream?
yeah, Joe said he'd have a look.
PATCH 6/24 dm cache policy mq: return NULL if mq->free list is empty in alloc_entry
In reply to Mike SnitzerFrom: Heinz Mauelshagen <[email protected]>
Addresses callers' (insert_in*cache()) requirement that alloc_entry() return NULL when an entry isn't able to be allocated.
--- drivers/md/dm-cache-policy-mq.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-)
drivers/md/dm-cache-policy-mq.c +7 -5
@@ -399,18 +399,20 @@ static void hash_remove(struct entry *e)*/ static struct entry *alloc_entry (struct mq_policy *mq) { -struct entry *e; +struct entry *e =NULL ;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); +if (!list_empty (&mq->free)) { + e = list_entry(list_pop(&mq->free), struct entry, list); +INIT_LIST_HEAD (&e->list); +INIT_HLIST_NODE (&e->hlist); + mq->nr_entries_allocated++; + } - mq->nr_entries_allocated++;return e; }
Signature · 1 line
1.8.1.4
Alasdair G Kergon
maintainerRe: [PATCH 06/24] dm cache policy mq: return NULL if mq->free list is empty in alloc_entry
Quoted 3 lines · Mike Snitzer
From: Heinz Mauelshagen <[email protected]>
Addresses callers' (insert_in*cache()) requirement thatalloc_entry()return NULL when an entry isn't able to be allocated.
What is the code path that leads to the requirement for this patch?
Quoted 9 lines
+++
b/drivers/md/dm-cache-policy-mq.c
static struct entry *alloc_entry(structmq_policy*mq)drivers/md/dm-cache-policy-mq.c +1
-0+struct entry *e =NULL ;if (mq->nr_entries_allocated >= mq->nr_entries) {BUG_ON (!list_empty (&mq->free));return NULL ; }
drivers/md/dm-cache-policy-mq.c static void hash_remove(struct entry *e) · line 414
Quoted 10 lines
drivers/md/dm-cache-policy-mq.c +6
-3- e = list_entry(list_pop(&mq->free), struct entry, list); -INIT_LIST_HEAD (&e->list); -INIT_HLIST_NODE (&e->hlist); +if (!list_empty (&mq->free)) { + e = list_entry(list_pop(&mq->free), struct entry, list); +INIT_LIST_HEAD (&e->list); +INIT_HLIST_NODE (&e->hlist); + mq->nr_entries_allocated++; + }
In other words, under what circumstances is mq->nr_entries_allocated less then mq->nr_entries, yet the mq->free list is empty?
Is it better to apply a patch like this, or rather to fix whatever situation leads to those circumstances? Has the bug/race always been there or is it a regression?
Alasdair
Re: [PATCH 06/24] dm cache policy mq: return NULL if mq->free list is empty in alloc_entry
Quoted 30 lines · Alasdair G Kergon
Quoted 3 lines · Mike Snitzer
From: Heinz Mauelshagen <[email protected]>
Addresses callers' (insert_in*cache()) requirement thatalloc_entry()return NULL when an entry isn't able to be allocated.What is the code path that leads to the requirement for this patch?
Quoted 9 lines
+++
b/drivers/md/dm-cache-policy-mq.c
static struct entry *alloc_entry(structmq_policy*mq)drivers/md/dm-cache-policy-mq.c +1
-0+struct entry *e =NULL ;if (mq->nr_entries_allocated >= mq->nr_entries) {BUG_ON (!list_empty (&mq->free));return NULL ; }drivers/md/dm-cache-policy-mq.c static void hash_remove(struct entry *e) · line 414
Quoted 10 lines
drivers/md/dm-cache-policy-mq.c +6
-3- e = list_entry(list_pop(&mq->free), struct entry, list); -INIT_LIST_HEAD (&e->list); -INIT_HLIST_NODE (&e->hlist); +if (!list_empty (&mq->free)) { + e = list_entry(list_pop(&mq->free), struct entry, list); +INIT_LIST_HEAD (&e->list); +INIT_HLIST_NODE (&e->hlist); + mq->nr_entries_allocated++; + }In other words, under what circumstances is
mq->nr_entries_allocatedless thenmq->nr_entries, yet themq->freelist is empty?
Quoted 3 lines
Is it better to apply a patch like this, or rather to fix whatever situation leads to those circumstances? Has the bug/race always been there or is it a regression?
Fair questions, Heinz should explain further.
IIRC this change was needed as a prereq for the conversion of his out-of-tree "background" policy to a shim (layered ontop of mq).
So will drop for now, can revisit if/when the need is clearer (e.g. when background policy goes upstream). TBD if we need it in the near-term, but will table this for now. Dropping patch until more context from Heinz is provided.
Re: [PATCH 06/24] dm cache policy mq: return NULL if mq->free list is empty in alloc_entry
Quoted 31 lines · Mike Snitzer
Quoted 28 lines · Alasdair G Kergon
Quoted 3 lines · Mike Snitzer
From: Heinz Mauelshagen <[email protected]>
Addresses callers' (insert_in*cache()) requirement thatalloc_entry()return NULL when an entry isn't able to be allocated.What is the code path that leads to the requirement for this patch?
Quoted 8 lines
+++
b/drivers/md/dm-cache-policy-mq.c
static struct entry *alloc_entry(structmq_policy*mq)drivers/md/dm-cache-policy-mq.c +1
-0+struct entry *e =NULL ;if (mq->nr_entries_allocated >= mq->nr_entries) {BUG_ON (!list_empty (&mq->free));return NULL ; }drivers/md/dm-cache-policy-mq.c static void hash_remove(struct entry *e) · line 414
Quoted 10 lines
drivers/md/dm-cache-policy-mq.c +6
-3- e = list_entry(list_pop(&mq->free), struct entry, list); -INIT_LIST_HEAD (&e->list); -INIT_HLIST_NODE (&e->hlist); +if (!list_empty (&mq->free)) { + e = list_entry(list_pop(&mq->free), struct entry, list); +INIT_LIST_HEAD (&e->list); +INIT_HLIST_NODE (&e->hlist); + mq->nr_entries_allocated++; + }In other words, under what circumstances is
mq->nr_entries_allocatedless thenmq->nr_entries, yet themq->freelist is empty?
Quoted 7 lines
Quoted 3 lines
Is it better to apply a patch like this, or rather to fix whatever situation leads to those circumstances? Has the bug/race always been there or is it a regression?
Fair questions, Heinz should explain further.
IIRC this change was needed as a prereq for the conversion of his out-of-tree "background" policy to a shim (layered ontop of mq).
Has nothing to do with that.
It is a fix for existing callers presuming that alloc_entry() could return NULL but the callee did not handle this properly.
Quoted 5 lines
So will drop for now, can revisit if/when the need is clearer (e.g. when background policy goes upstream). TBD if we need it in the near-term, but will table this for now. Dropping patch until more context from Heinz is provided.
Leave it in for the aforementioned reason.
Heinz
Quoted 5 lines
--
dm-devel mailing list
[email protected]
https://www.redhat.com/mailman/listinfo/dm-devel
PATCH v2 6/24 dm cache policy mq: return NULL from alloc_entry if cache is full
In reply to Mike SnitzerFrom: Heinz Mauelshagen <[email protected]>
alloc_entry() must return NULL if the cache is full (mq->free list is empty). To be clear, it is not a bug if the alloc_entry() logic tries to alloc from the free list before it falls back to pop from pre cache. The free list is simply a resource priority list that alloc_entry() tries to claim a block from but sometimes cannot (e.g. cache is full).
This fix addresses callers' (insert_in*cache()) requirement that alloc_entry() return NULL when an entry isn't able to be allocated.
--- drivers/md/dm-cache-policy-mq.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-)
drivers/md/dm-cache-policy-mq.c +7 -5
@@ -415,18 +415,20 @@ static void hash_remove(struct entry *e)*/ static struct entry *alloc_entry (struct mq_policy *mq) { -struct entry *e; +struct entry *e =NULL ;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); +if (!list_empty (&mq->free)) { + e = list_entry(list_pop(&mq->free), struct entry, list); +INIT_LIST_HEAD (&e->list); +INIT_HLIST_NODE (&e->hlist); + mq->nr_entries_allocated++; + } - mq->nr_entries_allocated++;return e; }
PATCH 7/24 dm cache: be much more aggressive about promoting writes to discarded blocks
In reply to Mike SnitzerFrom: Joe Thornber <[email protected]>
Previously these promotions only got priority if there were unused cache blocks. Now we give them priority if there are any clean blocks in the cache.
The fio_soak_test in the device-mapper-test-suite now gives uniform performance across subvolumes (~16 seconds).
--- drivers/md/dm-cache-policy-mq.c | 84 ++++++++++++++++++++++++++++++----------- 1 file changed, 63 insertions(+), 21 deletions(-)
drivers/md/dm-cache-policy-mq.c +63 -21
@@ -151,6 +151,21 @@ static void queue_init(struct queue *q) }/* +* Checks to see if the queue is empty. +* FIXME: reduce cpu usage. +*/ +static bool queue_empty (struct queue *q) +{ +unsigned i; + +for (i =0 ; i <NR_QUEUE_LEVELS ; i++) +if (!list_empty (q->qs + i)) +return false; + +return true; +} + +/* * Insert an entry to the back of the given level. */ static void queue_push (struct queue *q,unsigned level,struct list_head *elt)
@@ -444,6 +459,11 @@ static bool any_free_cblocks(struct mq_policy *mq)return mq->nr_cblocks_allocated <from_cblock (mq->cache_size); } +static bool any_clean_cblocks (struct mq_policy *mq) +{ +return !queue_empty (&mq->cache_clean); +} +/* * 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
@@ -689,17 +709,18 @@ static int demote_cblock(struct mq_policy *mq, dm_oblock_t *oblock, dm_cblock_tstatic unsigned adjusted_promote_threshold (struct mq_policy *mq,bool discarded_oblock,int data_dir) { -if (discarded_oblock &&any_free_cblocks (mq) && data_dir ==WRITE ) +if (data_dir ==READ ) +return mq->promote_threshold +READ_PROMOTE_THRESHOLD ; + +if (discarded_oblock && (any_free_cblocks (mq) ||any_clean_cblocks (mq))) {/* * 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. +* very low threshold. */ return DISCARDED_PROMOTE_THRESHOLD ; + } -return data_dir ==READ ? - (mq->promote_threshold +READ_PROMOTE_THRESHOLD ) : - (mq->promote_threshold +WRITE_PROMOTE_THRESHOLD ); +return mq->promote_threshold +WRITE_PROMOTE_THRESHOLD ; } static bool should_promote(struct mq_policy *mq, struct entry *e,
@@ -773,6 +794,17 @@ static int pre_cache_entry_found(struct mq_policy *mq, struct entry *e,return r; } +static void insert_entry_in_pre_cache (struct mq_policy *mq, +struct entry *e,dm_oblock_t oblock) +{ + e->in_cache = false; + e->dirty = false; + e->oblock = oblock; + e->hit_count =1 ; + e->generation = mq->generation; +push (mq, e); +} +static void insert_in_pre_cache (struct mq_policy *mq,dm_oblock_t oblock) {
@@ -790,30 +822,41 @@ static void insert_in_pre_cache(struct mq_policy *mq,return ; } - e->in_cache = false; - e->dirty = false; - e->oblock = oblock; - e->hit_count =1 ; - e->generation = mq->generation; -push (mq, e); +insert_entry_in_pre_cache (mq, e, oblock); }static void insert_in_cache (struct mq_policy *mq,dm_oblock_t oblock,struct policy_result *result) { +int r;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 ; - } + r =demote_cblock (mq, &result->old_oblock, &cblock); +if (unlikely (r)) { + result->op =POLICY_MISS ; +insert_in_pre_cache (mq, oblock); +return ; + } - e =alloc_entry (mq); -if (unlikely (!e)) { - result->op =POLICY_MISS ; -return ; +/* +* This will always succeed, since we've just demoted. +*/ + e =pop (mq, &mq->pre_cache); + result->op =POLICY_REPLACE ; + + }else { + e =alloc_entry (mq); +if (unlikely (!e)) + e =pop (mq, &mq->pre_cache); + +if (unlikely (!e)) { + result->op =POLICY_MISS ; +return ; + } + + result->op =POLICY_NEW ; } e->oblock = oblock;
@@ -824,7 +867,6 @@ static void insert_in_cache(struct mq_policy *mq, dm_oblock_t oblock, e->generation = mq->generation;push (mq, e); - result->op =POLICY_NEW ; result->cblock = e->cblock; }
Signature · 1 line
1.8.1.4
PATCH 8/24 dm cache metadata: return bool from __superblock_all_zeroes
In reply to Mike SnitzerFrom: Joe Thornber <[email protected]>
--- drivers/md/dm-cache-metadata.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-)
drivers/md/dm-cache-metadata.c +5 -4
@@ -198,7 +198,7 @@ static int superblock_lock(struct dm_cache_metadata *cmd,/*----------------------------------------------------------------*/ -static int __superblock_all_zeroes (struct dm_block_manager *bm,int *result) +static int __superblock_all_zeroes (struct dm_block_manager *bm,bool *result) {int r;unsigned i;
@@ -214,10 +214,10 @@ static int __superblock_all_zeroes(struct dm_block_manager *bm, int *result)return r; data_le =dm_block_data (b); - *result =1 ; + *result = true;for (i =0 ; i < sb_block_size; i++) {if (data_le[i] != zero) { - *result =0 ; + *result = false;break ; } }
@@ -411,7 +411,8 @@ bad:static int __open_or_format_metadata (struct dm_cache_metadata *cmd,bool format_device) { -int r, unformatted; +int r; +bool unformatted = false; r =__superblock_all_zeroes (cmd->bm, &unformatted);if (r)
Signature · 1 line
1.8.1.4
PATCH 9/24 dm cache metadata: check the metadata version when reading the superblock
In reply to Mike SnitzerFrom: Joe Thornber <[email protected]>
Need to check the version to verify on-disk metadata is supported.
--- drivers/md/dm-cache-metadata.c | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-)
drivers/md/dm-cache-metadata.c +21 -3
@@ -20,7 +20,13 @@#define CACHE_SUPERBLOCK_MAGIC 06142003#define CACHE_SUPERBLOCK_LOCATION 0 -#define CACHE_VERSION 1 + +/* +* defines a range of metadata versions that this module can handle. +*/ +#define MIN_CACHE_VERSION 1 +#define MAX_CACHE_VERSION 1 +#define CACHE_METADATA_CACHE_SIZE 64/*
@@ -134,6 +140,18 @@ static void sb_prepare_for_write(struct dm_block_validator *v, SUPERBLOCK_CSUM_XOR)); } +static int check_metadata_version (struct cache_disk_superblock *disk_super) +{ +uint32_t metadata_version =le32_to_cpu (disk_super->version); +if (metadata_version <MIN_CACHE_VERSION || metadata_version >MAX_CACHE_VERSION ) { +DMERR ("kernel does not support this version of cache metadata (%u)" , + metadata_version); +return -EINVAL ; + } + +return 0 ; +} +static int sb_check (struct dm_block_validator *v,struct dm_block *b,size_t sb_block_size)
@@ -164,7 +182,7 @@ static int sb_check(struct dm_block_validator *v,return -EILSEQ ; } -return 0 ; +return check_metadata_version (disk_super); }static struct dm_block_validator sb_validator = {
@@ -270,7 +288,7 @@ static int __write_initial_superblock(struct dm_cache_metadata *cmd) 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 ); + disk_super->version =cpu_to_le32 (MAX_CACHE_VERSION );memset (disk_super->policy_name,0 ,sizeof (disk_super->policy_name));memset (disk_super->policy_version,0 ,sizeof (disk_super->policy_version)); disk_super->policy_hint_size =0 ;
Signature · 1 line
1.8.1.4
Alasdair G Kergon
maintainerRe: [PATCH 09/24] dm cache metadata: check the metadata version when reading the superblock
drivers/md/dm-cache-metadata.c line 24
Quoted 9 lines · Mike Snitzer
From: Joe Thornber <[email protected]>
+++
b/drivers/md/dm-cache-metadata.cdrivers/md/dm-cache-metadata.c +3
-0@@ -20,7 +20,13 @@ + * defines a range of metadata versions that this module can handle. +{ +uint32_t metadata_version =le32_to_cpu (disk_super->version);
+
drivers/md/dm-cache-metadata.c static void sb_prepare_for_write(struct dm_block_validator *v, · line 148
Quoted 3 lines
drivers/md/dm-cache-metadata.c +3
-0+if (metadata_version <MIN_CACHE_VERSION || metadata_version >MAX_CACHE_VERSION ) { +DMERR ("kernel does not support this version of cache metadata (%u)" , + metadata_version);
- Also state the range supported?
"Cache metadata version %u found, but only versions between %u and %u supported."
Alasdair
Re: [PATCH 09/24] dm cache metadata: check the metadata version when reading the superblock
Quoted 13 lines · Alasdair G Kergon
drivers/md/dm-cache-metadata.c line 24
Quoted 9 lines · Mike Snitzer
From: Joe Thornber <[email protected]>
+++
b/drivers/md/dm-cache-metadata.cdrivers/md/dm-cache-metadata.c +3
-0@@ -20,7 +20,13 @@ + * defines a range of metadata versions that this module can handle. +{ +uint32_t metadata_version =le32_to_cpu (disk_super->version);+
Quoted 6 lines
drivers/md/dm-cache-metadata.c static void sb_prepare_for_write(struct dm_block_validator *v, · line 148
Quoted 3 lines
drivers/md/dm-cache-metadata.c +3
-0+if (metadata_version <MIN_CACHE_VERSION || metadata_version >MAX_CACHE_VERSION ) { +DMERR ("kernel does not support this version of cache metadata (%u)" , + metadata_version);- Also state the range supported?
"Cache metadata version %u found, but only versions between %u and %u supported."
Done.
PATCH 10/24 dm cache policy: variable hints support
In reply to Mike SnitzerFrom: Heinz Mauelshagen <[email protected]>
Policies can now specify a hint size other than 0 or 4. The DM_CACHE_POLICY_MAX_HINT_SIZE is 128.
Upcoming policy stack support will make use of variable hints.
--- drivers/md/dm-cache-metadata.c | 104 +++++++++++++++++++++++++++------- drivers/md/dm-cache-metadata.h | 23 +++++--- drivers/md/dm-cache-policy-cleaner.c | 2 +- drivers/md/dm-cache-policy-internal.h | 5 +- drivers/md/dm-cache-policy-mq.c | 44 ++++++++------ drivers/md/dm-cache-policy.c | 19 ++++++- drivers/md/dm-cache-policy.h | 14 +++-- drivers/md/dm-cache-target.c | 8 ++- 8 files changed, 159 insertions(+), 60 deletions(-)
drivers/md/dm-cache-metadata.c +83 -21
@@ -119,6 +119,7 @@ struct dm_cache_metadata {char policy_name[CACHE_POLICY_NAME_SIZE ];unsigned policy_version[CACHE_POLICY_VERSION_SIZE ];size_t policy_hint_size; +void *policy_hint_value_buffer;struct dm_cache_statistics stats; };
@@ -243,7 +244,7 @@ static int __superblock_all_zeroes(struct dm_block_manager *bm, bool *result)return dm_bm_unlock (b); } -static void __setup_mapping_info (struct dm_cache_metadata *cmd) +static int __setup_mapping_info (struct dm_cache_metadata *cmd) {struct dm_btree_value_type vt;
@@ -255,9 +256,30 @@ static void __setup_mapping_info(struct dm_cache_metadata *cmd)dm_array_info_init (&cmd->info, cmd->tm, &vt);if (cmd->policy_hint_size) { - vt.size =sizeof (__le32); +if (cmd->policy_hint_size >DM_CACHE_POLICY_MAX_HINT_SIZE || + cmd->policy_hint_size %4 ) { +DMERR ("hint size not divisible by 4 or is larger than %d" , + (int )DM_CACHE_POLICY_MAX_HINT_SIZE ); +return -EINVAL ; + } + + vt.size = cmd->policy_hint_size;dm_array_info_init (&cmd->hint_info, cmd->tm, &vt); - } + + cmd->policy_hint_value_buffer =kmalloc (cmd->policy_hint_size,GFP_KERNEL ); +if (!cmd->policy_hint_value_buffer) { +DMERR ("unable to allocate hint value buffer" ); +return -ENOMEM ; + } + }else + cmd->policy_hint_value_buffer =NULL ; + +return 0 ; +} + +static void __destroy_mapping_info (struct dm_cache_metadata *cmd) +{ +kfree (cmd->policy_hint_value_buffer); }static int __write_initial_superblock (struct dm_cache_metadata *cmd)
@@ -330,7 +352,9 @@ static int __format_metadata(struct dm_cache_metadata *cmd)return r; } -__setup_mapping_info (cmd); + r =__setup_mapping_info (cmd); +if (r <0 ) + goto bad_mapping_info; r =dm_array_empty (&cmd->info, &cmd->root);if (r <0 )
@@ -353,6 +377,8 @@ static int __format_metadata(struct dm_cache_metadata *cmd)return 0 ; bad: +__destroy_mapping_info (cmd); +bad_mapping_info:dm_tm_destroy (cmd->tm);dm_sm_destroy (cmd->metadata_sm);
@@ -387,6 +413,12 @@ static int __check_incompat_features(struct cache_disk_superblock *disk_super,return 0 ; } +static bool using_variable_size_hints (struct cache_disk_superblock *disk_super) +{ +unsigned long iflags =le32_to_cpu (disk_super->incompat_flags); +return test_bit (DM_CACHE_VARIABLE_HINT_SIZE , &iflags); +} +static int __open_metadata (struct dm_cache_metadata *cmd) {int r;
@@ -415,7 +447,18 @@ static int __open_metadata(struct dm_cache_metadata *cmd) goto bad; } -__setup_mapping_info (cmd); +/* +* We need to set the hint size before calling __setup_mapping_info() +*/ +if (using_variable_size_hints (disk_super)) + cmd->policy_hint_size =le32_to_cpu (disk_super->policy_hint_size); +else + cmd->policy_hint_size =DM_CACHE_POLICY_DEF_HINT_SIZE ; + + r =__setup_mapping_info (cmd); +if (r <0 ) + goto bad; +dm_disk_bitset_init (cmd->tm, &cmd->discard_info); sb_flags =le32_to_cpu (disk_super->flags); cmd->clean_when_opened =test_bit (CLEAN_SHUTDOWN , &sb_flags);
@@ -503,7 +546,16 @@ static void read_superblock_fields(struct dm_cache_metadata *cmd, cmd->policy_version[0 ] =le32_to_cpu (disk_super->policy_version[0 ]); cmd->policy_version[1 ] =le32_to_cpu (disk_super->policy_version[1 ]); cmd->policy_version[2 ] =le32_to_cpu (disk_super->policy_version[2 ]); - cmd->policy_hint_size =le32_to_cpu (disk_super->policy_hint_size); + +if (using_variable_size_hints (disk_super)) + cmd->policy_hint_size =le32_to_cpu (disk_super->policy_hint_size); +else { +/* +* Must establish policy_hint_size because older superblock +* wouldn't have it. +*/ + cmd->policy_hint_size =DM_CACHE_POLICY_DEF_HINT_SIZE ; + } cmd->stats.read_hits =le32_to_cpu (disk_super->read_hits); cmd->stats.read_misses =le32_to_cpu (disk_super->read_misses);
@@ -601,6 +653,15 @@ static int __commit_transaction(struct dm_cache_metadata *cmd, disk_super->policy_version[1 ] =cpu_to_le32 (cmd->policy_version[1 ]); disk_super->policy_version[2 ] =cpu_to_le32 (cmd->policy_version[2 ]); +if (cmd->policy_hint_size !=DM_CACHE_POLICY_DEF_HINT_SIZE ) { +unsigned long iflags =0 ; +set_bit (DM_CACHE_VARIABLE_HINT_SIZE , &iflags); + disk_super->incompat_flags =cpu_to_le32 (iflags); + }else + disk_super->incompat_flags =cpu_to_le32 (0u ); + + disk_super->policy_hint_size =cpu_to_le32 (cmd->policy_hint_size); + 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);
@@ -666,6 +727,7 @@ struct dm_cache_metadata *dm_cache_metadata_open(struct block_device *bdev, r =__create_persistent_data_objects (cmd, may_format_device);if (r) { +__destroy_mapping_info (cmd);kfree (cmd);return ERR_PTR (r); }
@@ -682,6 +744,7 @@ struct dm_cache_metadata *dm_cache_metadata_open(struct block_device *bdev,void dm_cache_metadata_close (struct dm_cache_metadata *cmd) {__destroy_persistent_data_objects (cmd); +__destroy_mapping_info (cmd);kfree (cmd); }
@@ -927,7 +990,6 @@ 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;
@@ -939,14 +1001,14 @@ static int __load_mapping(void *context, uint64_t cblock, void *leaf)if (flags &M_VALID ) {if (thunk->hints_valid) { r =dm_array_get_value (&cmd->hint_info, cmd->hint_root, - cblock, &hint_value); + cblock, cmd->policy_hint_value_buffer);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); + dirty, cmd->policy_hint_value_buffer, thunk->hints_valid); }return r;
@@ -1122,8 +1184,6 @@ int dm_cache_get_metadata_dev_size(struct dm_cache_metadata *cmd,static int begin_hints (struct dm_cache_metadata *cmd,struct dm_cache_policy *policy) {int r; -__le32 value; -size_t hint_size;const char *policy_name =dm_cache_policy_get_name (policy);const unsigned *policy_version =dm_cache_policy_get_version (policy);
@@ -1132,6 +1192,8 @@ static int begin_hints(struct dm_cache_metadata *cmd, struct dm_cache_policy *poreturn -EINVAL ;if (!policy_unchanged (cmd, policy)) { +size_t hint_size; +strncpy (cmd->policy_name, policy_name,sizeof (cmd->policy_name));memcpy (cmd->policy_version, policy_version,sizeof (cmd->policy_version));
@@ -1150,11 +1212,11 @@ static int begin_hints(struct dm_cache_metadata *cmd, struct dm_cache_policy *poif (r)return r; - value =cpu_to_le32 (0 ); +memset (cmd->policy_hint_value_buffer,0 , hint_size);__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); + cmd->policy_hint_value_buffer, &cmd->hint_root);if (r)return r; }
@@ -1173,27 +1235,27 @@ int dm_cache_begin_hints(struct dm_cache_metadata *cmd, struct dm_cache_policy *return r; } -static int save_hint (struct dm_cache_metadata *cmd,dm_cblock_t cblock, -uint32_t hint) +static int save_hint (struct dm_cache_metadata *cmd,dm_cblock_t cblock,void *hint) +__dm_written_to_disk (hint) {int r; -__le32 value =cpu_to_le32 (hint); -__dm_bless_for_disk (&value); r =dm_array_set_value (&cmd->hint_info, cmd->hint_root, -from_cblock (cblock), &value, &cmd->hint_root); +from_cblock (cblock), hint, &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 dm_cache_save_hint (struct dm_cache_metadata *cmd,dm_cblock_t cblock,void *hint) +__dm_written_to_disk (hint) {int r; -if (!hints_array_initialized (cmd)) +if (!hints_array_initialized (cmd)) { +__dm_unbless_for_disk (hint);return 0 ; + }down_write (&cmd->root_lock); r =save_hint (cmd, cblock, hint);
drivers/md/dm-cache-metadata.h +16 -7
@@ -49,7 +49,12 @@*/ #define DM_CACHE_FEATURE_COMPAT_SUPP 0UL#define DM_CACHE_FEATURE_COMPAT_RO_SUPP 0UL -#define DM_CACHE_FEATURE_INCOMPAT_SUPP 0UL + +enum dm_cache_incompat_bits { +DM_CACHE_VARIABLE_HINT_SIZE =0 +}; + +#define DM_CACHE_FEATURE_INCOMPAT_SUPP (1 << DM_CACHE_VARIABLE_HINT_SIZE)/* * Reopens or creates a new, empty metadata volume.
@@ -87,7 +92,7 @@ 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); +void *hint,bool hint_valid); int dm_cache_load_mappings(struct dm_cache_metadata *cmd, struct dm_cache_policy *policy, load_mapping_fn fn,
@@ -118,9 +123,10 @@ int dm_cache_get_metadata_dev_size(struct dm_cache_metadata *cmd,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, +* The policy is invited to save a hint (void* sequence of bytes) for every +* cblock (eg, for a hit count) and is reponsible to do endianess conversions. +* 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
@@ -132,10 +138,13 @@ void dm_cache_dump(struct dm_cache_metadata *cmd);int dm_cache_begin_hints (struct dm_cache_metadata *cmd,struct dm_cache_policy *p);/* -* requests hints for every cblock and stores in the metadata device. +* Saves the hint for a given cblock in the metadata device. Policy +* modules must perform any endian conversions needed and bless the hints +* for disk. */ int dm_cache_save_hint(struct dm_cache_metadata *cmd, -dm_cblock_t cblock,uint32_t hint); + dm_cblock_t cblock, void *hint) + __dm_written_to_disk(hint);/*----------------------------------------------------------------*/
drivers/md/dm-cache-policy-cleaner.c +1 -1
@@ -274,7 +274,7 @@ static void add_cache_entry(struct policy *p, struct wb_cache_entry *e)static int wb_load_mapping (struct dm_cache_policy *pe,dm_oblock_t oblock,dm_cblock_t cblock, -uint32_t hint,bool hint_valid) +void *hint,bool hint_valid) {int r;struct policy *p =to_policy (pe);
drivers/md/dm-cache-policy-internal.h +4 -1
@@ -41,7 +41,7 @@ static inline void policy_clear_dirty(struct dm_cache_policy *p, dm_oblock_t oblstatic inline int policy_load_mapping (struct dm_cache_policy *p,dm_oblock_t oblock,dm_cblock_t cblock, -uint32_t hint,bool hint_valid) +void *hint,bool hint_valid) {return p->load_mapping (p, oblock, cblock, hint, hint_valid); }
@@ -119,6 +119,9 @@ const char *dm_cache_policy_get_name(struct dm_cache_policy *p);const unsigned *dm_cache_policy_get_version (struct dm_cache_policy *p); +#define DM_CACHE_POLICY_DEF_HINT_SIZE 4U +#define DM_CACHE_POLICY_MAX_HINT_SIZE 128U +int dm_cache_policy_set_hint_size (struct dm_cache_policy *p,unsigned hint_size);size_t dm_cache_policy_get_hint_size (struct dm_cache_policy *p);/*----------------------------------------------------------------*/
drivers/md/dm-cache-policy-mq.c +26 -18
77 lines not on this page · raw message
drivers/md/dm-cache-policy.c +16 -3
@@ -80,9 +80,10 @@ 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 ) { -DMWARN ("hint size must be 0 or 4 but %llu supplied." , (unsigned long long ) type->hint_size); +if (type->hint_size >DM_CACHE_POLICY_MAX_HINT_SIZE ) { +DMWARN ("hint size must be <= %llu but %llu was supplied." , + (unsigned long long )DM_CACHE_POLICY_MAX_HINT_SIZE , + (unsigned long long ) type->hint_size);return -EINVAL ; }
@@ -166,4 +167,16 @@ size_t dm_cache_policy_get_hint_size(struct dm_cache_policy *p) }EXPORT_SYMBOL_GPL (dm_cache_policy_get_hint_size); +int dm_cache_policy_set_hint_size (struct dm_cache_policy *p,unsigned hint_size) +{ +struct dm_cache_policy_type *t = p->private; + +if (hint_size >DM_CACHE_POLICY_MAX_HINT_SIZE ) +return -EPERM ; + + t->hint_size = hint_size; +return 0 ; +} +EXPORT_SYMBOL_GPL (dm_cache_policy_set_hint_size); +/*----------------------------------------------------------------*/
drivers/md/dm-cache-policy.h +8 -6
@@ -8,6 +8,7 @@#define DM_CACHE_POLICY_H #include "dm-cache-block-types.h" +#include "persistent-data/dm-btree.h" #include <linux/device-mapper.h>
@@ -79,7 +80,8 @@ struct policy_result { };typedef int (*policy_walk_fn )(void *context,dm_cblock_t cblock, -dm_oblock_t oblock,uint32_t hint); + dm_oblock_t oblock, void *hint) +__dm_written_to_disk (hint);/* * The cache policy object. Just a bunch of methods. It is envisaged that
@@ -146,7 +148,7 @@ struct dm_cache_policy {* mapping from the metadata device into the policy. */ int (*load_mapping)(struct dm_cache_policy *p,dm_oblock_t oblock, -dm_cblock_t cblock,uint32_t hint,bool hint_valid); +dm_cblock_t cblock,void *hint,bool hint_valid);int (*walk_mappings)(struct dm_cache_policy *p,policy_walk_fn fn,void *context);
@@ -210,9 +212,9 @@ struct dm_cache_policy_type {unsigned version[CACHE_POLICY_VERSION_SIZE ];/* -* Policies may store a hint for each each cache block. -* Currently the size of this hint must be 0 or 4 bytes but we -* expect to relax this in future. +* Policies may store a hint for each cache block. +* Currently the size of this hint must be <= +* DM_CACHE_POLICY_MAX_HINT_SIZE bytes. */ size_t hint_size;
@@ -227,4 +229,4 @@ void dm_cache_policy_unregister(struct dm_cache_policy_type *type);/*----------------------------------------------------------------*/ -#endif /* DM_CACHE_POLICY_H */ +#endif /* DM_CACHE_POLICY_H */
drivers/md/dm-cache-target.c +5 -3
@@ -2304,9 +2304,11 @@ static int write_discard_bitset(struct cache *cache) }static int save_hint (void *context,dm_cblock_t cblock,dm_oblock_t oblock, -uint32_t hint) +void *hint) {struct cache *cache = context; + +__dm_bless_for_disk (hint);return dm_cache_save_hint (cache->cmd, cblock, hint); }
@@ -2374,7 +2376,7 @@ static void cache_postsuspend(struct dm_target *ti) }static int load_mapping (void *context,dm_oblock_t oblock,dm_cblock_t cblock, -bool dirty,uint32_t hint,bool hint_valid) +bool dirty,void *hint,bool hint_valid) {int r;struct cache *cache = context;
@@ -2630,7 +2632,7 @@ static void cache_io_hints(struct dm_target *ti, struct queue_limits *limits)static struct target_type cache_target = { .name ="cache" , - .version = {1 ,1 ,1 }, + .version = {1 ,2 ,0 }, .module =THIS_MODULE , .ctr = cache_ctr, .dtr = cache_dtr,
Signature · 1 line
1.8.1.4
PATCH 11/24 dm table: print error on preresume failure
In reply to Mike SnitzerIf preresume fails it is worth logging an error given that a device is left suspended due to the failure.
This change was motivated by local preresume error logging that was added to the cache target. Elevating this error logging to DM core makes sense.
--- drivers/md/dm-table.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/md/dm-table.c +4 -1
@@ -1548,8 +1548,11 @@ int dm_table_resume_targets(struct dm_table *t)continue ; r = ti->type->preresume (ti); -if (r) +if (r) { +DMERR ("%s: %s: preresume failed, error = %d" , +dm_device_name (t->md), ti->type->name, r);return r; + } }for (i =0 ; i < t->num_targets; i++) {
Signature · 1 line
1.8.1.4
Alasdair G Kergon
maintainerRe: [PATCH 11/24] dm table: print error on preresume failure
Quoted 2 lines · Mike Snitzer
If preresume fails it is worth logging an error given that a device is left suspended due to the failure.
Indeed.
Quoted 3 lines
This change was motivated by local preresume error logging that was added to the cache target. Elevating this error logging to DM core makes sense.
But here I disagree: I think it makes more sense not to elevate this logging, but to leave the responsibility for it with the targets themselves.
drivers/md/dm-table.c int dm_table_resume_targets(struct dm_table *t) · line 1553
Quoted 2 lines
drivers/md/dm-table.c +2
-0+DMERR ("%s: %s: preresume failed, error = %d" , +dm_device_name (t->md), ti->type->name, r);
Elevated, you're only getting a single number displayed.
If the targets retain the responsibility, then you should get a more-detailed error message such as:
DMERR("aborting resume - crypt key is not set.");
DMERR("Unable to resume snapshot source until "
"handover completes.");
DMERR("Unable to perform snapshot handover until "
"source is suspended.");
DMERR("could not resize cache metadata");
DMERR("could not load cache mappings");
DMERR("could not load origin discards");I think we should retain the requirement that each target must log a meaningful message whenever preresume fails.
Alasdair
Re: [PATCH 11/24] dm table: print error on preresume failure
Quoted 10 lines · Alasdair G Kergon
Quoted 2 lines · Mike Snitzer
If preresume fails it is worth logging an error given that a device is left suspended due to the failure.
Indeed.
Quoted 3 lines
This change was motivated by local preresume error logging that was added to the cache target. Elevating this error logging to DM core makes sense.
Quoted 8 lines
But here I disagree: I think it makes more sense not to elevate this logging, but to leave the responsibility for it with the targets themselves.
drivers/md/dm-table.c int dm_table_resume_targets(struct dm_table *t) · line 1553
Quoted 2 lines
drivers/md/dm-table.c +2
-0+DMERR ("%s: %s: preresume failed, error = %d" , +dm_device_name (t->md), ti->type->name, r);Elevated, you're only getting a single number displayed.
Elevated was over-stated, I'll revise the header. I was trying to say that the target shouldn't need to worry about stating that the failure happens to be in the preresume method on the target.
Quoted 15 lines
If the targets retain the responsibility, then you should get a more-detailed error message such as:
DMERR("aborting resume - crypt key is not set."); DMERR("Unable to resume snapshot source until " "handover completes."); DMERR("Unable to perform snapshot handover until " "source is suspended."); DMERR("could not resize cache metadata"); DMERR("could not load cache mappings"); DMERR("could not load origin discards");
Quoted 2 lines
I think we should retain the requirement that each target must log a meaningful message whenever preresume fails.
Yeah, I agree. I just want DM core to make it clear that the target failure resulted in preresume failing.
PATCH 12/24 dm cache: add passthrough mode
In reply to Mike SnitzerFrom: Joe Thornber <[email protected]>
"Passthrough" is a dm-cache operating mode (like writethrough or writeback) which is intended to be used when the cache contents are not known to be coherent with the origin device. It behaves as follows:
* All reads are served from the origin device (all reads miss the cache)
* All writes are forwarded to the origin device; additionally, write hits cause cache block invalidates
This mode decouples cache coherency checks from cache device creation, largely to avoid having to perform coherency checks while booting. Boot scripts can create cache devices in passthrough mode and put them into service (mount cached filesystems, for example) without having to worry about coherency. Coherency that exists is maintained, although the cache will gradually cool as writes take place.
Later, applications can perform coherency checks, the nature of which will depend on the type of the underlying storage. If coherency can be verified, the cache device can be transitioned to writethrough or writeback mode while still warm; otherwise, the cache contents can be discarded prior to transitioning to the desired operating mode.
--- drivers/md/dm-cache-metadata.c | 52 +++++++++++ drivers/md/dm-cache-metadata.h | 5 + drivers/md/dm-cache-target.c | 208 +++++++++++++++++++++++++++++++++++------ 3 files changed, 234 insertions(+), 31 deletions(-)
drivers/md/dm-cache-metadata.c +52 -0
@@ -748,6 +748,53 @@ void dm_cache_metadata_close(struct dm_cache_metadata *cmd)kfree (cmd); } +/* +* Checks that the given cache block is either unmapped, or clean. +*/ +static int block_unmapped_or_clean (struct dm_cache_metadata *cmd,dm_cblock_t b, +bool *result) +{ +int r; +__le64 value; +dm_oblock_t ob; +unsigned flags; + + r =dm_array_get_value (&cmd->info, cmd->root,from_cblock (b), &value); +if (r) { +DMERR ("block_unmapped_or_clean failed" ); +return r; + } + +unpack_value (value, &ob, &flags); + *result = !((flags &M_VALID ) && (flags &M_DIRTY )); + +return 0 ; +} + +static int blocks_are_unmapped_or_clean (struct dm_cache_metadata *cmd, +dm_cblock_t begin, +dm_cblock_t end, +bool *result) +{ +int r; + +while (begin != end) { + r =block_unmapped_or_clean (cmd, begin, result); +if (r) +return r; + +if (!*result) { +DMERR ("cache block %llu is dirty" , + (unsigned long long )from_cblock (begin)); +return 0 ; + } + + begin =to_cblock (from_cblock (begin) +1 ); + } + +return 0 ; +} +int dm_cache_resize (struct dm_cache_metadata *cmd,dm_cblock_t new_cache_size) {int r;
@@ -1263,3 +1310,8 @@ int dm_cache_save_hint(struct dm_cache_metadata *cmd, dm_cblock_t cblock, void *return r; } + +int dm_cache_metadata_all_clean (struct dm_cache_metadata *cmd,bool *result) +{ +return blocks_are_unmapped_or_clean (cmd,0 , cmd->cache_blocks, result); +}
drivers/md/dm-cache-metadata.h +5 -0
@@ -146,6 +146,11 @@ int dm_cache_save_hint(struct dm_cache_metadata *cmd, dm_cblock_t cblock, void *hint)__dm_written_to_disk (hint ); +/* +* Query method. Are all the blocks in the cache clean? +*/ +int dm_cache_metadata_all_clean (struct dm_cache_metadata *cmd,bool *result); +/*----------------------------------------------------------------*/ #endif /* DM_CACHE_METADATA_H */
drivers/md/dm-cache-target.c +177 -31
305 lines not on this page · raw message
Signature · 1 line
1.8.1.4
PATCH 13/24 dm cache policy: have policy_writeback_work return -ENODATA by default
In reply to Mike SnitzerFrom: Heinz Mauelshagen <[email protected]>
Caller of policy_writeback_work doesn't care, so doesn't actually fix anything but increases consistency of returns used (which helps debugging).
--- drivers/md/dm-cache-policy-internal.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/md/dm-cache-policy-internal.h +1 -1
@@ -56,7 +56,7 @@ 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 ; +return p->writeback_work ? p->writeback_work (p, oblock, cblock) : -ENODATA ; }static inline void policy_remove_mapping (struct dm_cache_policy *p,dm_oblock_t oblock)
Signature · 1 line
1.8.1.4
PATCH 14/24 dm cache: use is_write_io() in more places
In reply to Mike SnitzerFrom: Heinz Mauelshagen <[email protected]>
Use is_write_io() consistently where it is makes sense.
--- drivers/md/dm-cache-target.c | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-)
drivers/md/dm-cache-target.c +11 -11
@@ -631,12 +631,17 @@ static void check_if_tick_bio_needed(struct cache *cache, struct bio *bio)spin_unlock_irqrestore (&cache->lock, flags); } +static bool is_write_io (struct bio *bio) +{ +return bio_data_dir (bio) ==WRITE ; +} +static void remap_to_origin_clear_discard (struct cache *cache,struct bio *bio,dm_oblock_t oblock) {check_if_tick_bio_needed (cache, bio);remap_to_origin (cache, bio); -if (bio_data_dir (bio) ==WRITE ) +if (is_write_io (bio))clear_discard (cache,oblock_to_dblock (cache, oblock)); }
@@ -644,7 +649,7 @@ static void remap_to_cache_dirty(struct cache *cache, struct bio *bio, dm_oblock_t oblock, dm_cblock_t cblock) {remap_to_cache (cache ,bio ,cblock ); -if (bio_data_dir (bio) ==WRITE ) { +if (is_write_io (bio)) {set_dirty (cache, oblock, cblock);clear_discard (cache,oblock_to_dblock (cache, oblock)); }
@@ -1172,21 +1177,16 @@ static bool spare_migration_bandwidth(struct cache *cache)return current_volume < cache->migration_threshold; } -static bool is_write_io (struct bio *bio) -{ -return bio_data_dir (bio) ==WRITE ; -} -static void inc_hit_counter (struct cache *cache,struct bio *bio) { -atomic_inc (bio_data_dir (bio) ==READ ? - &cache->stats.read_hit : &cache->stats.write_hit); +atomic_inc (is_write_io (bio) ? + &cache->stats.write_hit : &cache->stats.read_hit); }static void inc_miss_counter (struct cache *cache,struct bio *bio) { -atomic_inc (bio_data_dir (bio) ==READ ? - &cache->stats.read_miss : &cache->stats.write_miss); +atomic_inc (is_write_io (bio) ? + &cache->stats.write_miss : &cache->stats.read_miss); } static void issue_cache_bio(struct cache *cache, struct bio *bio,
Signature · 1 line
1.8.1.4
Alasdair G Kergon
maintainerRe: [PATCH 14/24] dm cache: use is_write_io() in more places
drivers/md/dm-cache-target.c static void check_if_tick_bio_needed(struct cache *cache, struct bio *bio) · line 637
Quoted 10 lines · Mike Snitzer
From: Heinz Mauelshagen <[email protected]>
Use
is_write_io()consistently where it is makes sense.+++
b/drivers/md/dm-cache-target.cdrivers/md/dm-cache-target.c +4
-0+static bool is_write_io (struct bio *bio) +{ +return bio_data_dir (bio) ==WRITE ; +}
I'm not really convinced about this one, though I can see some superficial attractiveness. I think introducing it in a single file (rather than kernel-wide) is obfuscating the code rather than making it more readable.
If a change like this were to happen, wouldn't fs.h be a better place?
Alasdair
Re: [PATCH 14/24] dm cache: use is_write_io() in more places
Quoted 16 lines · Alasdair G Kergon
drivers/md/dm-cache-target.c static void check_if_tick_bio_needed(struct cache *cache, struct bio *bio) · line 637
Quoted 10 lines · Mike Snitzer
From: Heinz Mauelshagen <[email protected]>
Use
is_write_io()consistently where it is makes sense.+++
b/drivers/md/dm-cache-target.cdrivers/md/dm-cache-target.c +4
-0+static bool is_write_io (struct bio *bio) +{ +return bio_data_dir (bio) ==WRITE ; +}I'm not really convinced about this one, though I can see some superficial attractiveness. I think introducing it in a single file (rather than kernel-wide) is obfuscating the code rather than making it more readable.
Quoted 1 line
If a change like this were to happen, wouldn't
fs.hbe a better place?
is_write_io() was already in dm-cache-target.c, this patch just makes use of it in more applicable places.
But I'm fine with completely eliminating is_write_io()... whatever others would prefer.
PATCH 15/24 dm cache: use cell_defer() boolean argument consistently
In reply to Mike SnitzerFrom: Heinz Mauelshagen <[email protected]>
Fix a few cell_defer() calls that weren't passing a bool.
--- drivers/md/dm-cache-target.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/md/dm-cache-target.c +4 -4
@@ -808,13 +808,13 @@ static void migration_failure(struct dm_cache_migration *mg)DMWARN_LIMIT ("demotion failed; couldn't copy block" );policy_force_mapping (cache->policy, mg->new_oblock, mg->old_oblock); -cell_defer (cache, mg->old_ocell, mg->promote ?0 :1 ); +cell_defer (cache, mg->old_ocell, mg->promote ? false : true);if (mg->promote) -cell_defer (cache, mg->new_ocell,1 ); +cell_defer (cache, mg->new_ocell, true); }else {DMWARN_LIMIT ("promotion failed; couldn't copy block" );policy_remove_mapping (cache->policy, mg->new_oblock); -cell_defer (cache, mg->new_ocell,1 ); +cell_defer (cache, mg->new_ocell, true); }cleanup_migration (mg);
@@ -866,7 +866,7 @@ static void migration_success_post_commit(struct dm_cache_migration *mg)return ; }else if (mg->demote) { -cell_defer (cache, mg->old_ocell, mg->promote ?0 :1 ); +cell_defer (cache, mg->old_ocell, mg->promote ? false : true);if (mg->promote) { mg->demote = false;
Signature · 1 line
1.8.1.4
PATCH 16/24 dm cache: log error message if dm_kcopyd_copy() fails
In reply to Mike SnitzerFrom: Heinz Mauelshagen <[email protected]>
A migration failure should be logged (albeit limited).
--- drivers/md/dm-cache-target.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/md/dm-cache-target.c +3 -1
@@ -924,8 +924,10 @@ static void issue_copy_real(struct dm_cache_migration *mg) r =dm_kcopyd_copy (cache->copier, &o_region,1 , &c_region,0 , copy_complete, mg); } -if (r <0 ) +if (r <0 ) { +DMERR_LIMIT ("issuing migration failed" );migration_failure (mg); + } }static void avoid_copy (struct dm_cache_migration *mg)
Signature · 1 line
1.8.1.4
Alasdair G Kergon
maintainerRe: [PATCH 16/24] dm cache: log error message if dm_kcopyd_copy() fails
Quoted 1 line · Mike Snitzer
A migration failure should be logged (albeit limited).
Does this *really* add anything useful?
migration_failure() already always logs a message, so you'll now get two (throttled) messages instead of one every time.
Would it be better to log not just the type of failure but also some details about the data block location too?
And if you really need to know "issuing migration failed" then why not just add the string to the existing log message?
Alasdair
PATCH 17/24 dm cache: use a boolean when setting cache->quiescing
In reply to Mike SnitzerFrom: Heinz Mauelshagen <[email protected]>
--- drivers/md/dm-cache-target.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/md/dm-cache-target.c +2 -2
@@ -1448,7 +1448,7 @@ static void start_quiescing(struct cache *cache)unsigned long flags;spin_lock_irqsave (&cache->lock, flags); - cache->quiescing =1 ; + cache->quiescing = true;spin_unlock_irqrestore (&cache->lock, flags); }
@@ -1457,7 +1457,7 @@ static void stop_quiescing(struct cache *cache)unsigned long flags;spin_lock_irqsave (&cache->lock, flags); - cache->quiescing =0 ; + cache->quiescing = false;spin_unlock_irqrestore (&cache->lock, flags); }
Signature · 1 line
1.8.1.4
Alasdair G Kergon
maintainerRe: [PATCH 17/24] dm cache: use a boolean when setting cache->quiescing
Quoted 4 lines · Mike Snitzer
From: Heinz Mauelshagen <[email protected]>
Signed-off-by Heinz Mauelshagen <[email protected]>Signed-off-by Mike Snitzer <[email protected]>
Please could we drop this one?
It looks pointless to me, with this one following:
dm cache: improve effciency of quiescing flag management
Alasdair
Re: [PATCH 17/24] dm cache: use a boolean when setting cache->quiescing
Quoted 10 lines · Alasdair G Kergon
Quoted 4 lines · Mike Snitzer
From: Heinz Mauelshagen <[email protected]>
Signed-off-by Heinz Mauelshagen <[email protected]>Signed-off-by Mike Snitzer <[email protected]>Please could we drop this one?
It looks pointless to me, with this one following:
dm cache: improve effciency of quiescing flag management
It was just a change for consistency that happened during the natural flow of development. Really didn't see a problem with preserving the evolution of the code...
But sure, I can drop it.
PATCH 18/24 dm cache: optimize commit_if_needed
In reply to Mike SnitzerFrom: Heinz Mauelshagen <[email protected]>
Check commit_requested flag _before_ calling dm_cache_changed_this_transaction() superfluously.
--- drivers/md/dm-cache-target.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/md/dm-cache-target.c +2 -2
@@ -1324,8 +1324,8 @@ static int need_commit_due_to_time(struct cache *cache)static int commit_if_needed (struct cache *cache) { -if (dm_cache_changed_this_transaction (cache->cmd) && - (cache->commit_requested ||need_commit_due_to_time (cache))) { +if ((cache->commit_requested ||need_commit_due_to_time (cache)) && +dm_cache_changed_this_transaction (cache->cmd)) {atomic_inc (&cache->stats.commit_count); cache->last_commit_jiffies = jiffies; cache->commit_requested = false;
Signature · 1 line
1.8.1.4
PATCH 19/24 dm cache: support for stackable caching policies
In reply to Mike SnitzerFrom: Morgan Mears <[email protected]>
This commit implements support for stacking caching policies by concatenating policy names.
A policy stack includes zero or more non-terminal policies, or shims, followed by exactly one terminal policy which actually maintains the cache-to-origin block mappings.
Non-terminal policy shims will be added in later patches. Each policy shim must set the DM_CACHE_POLICY_SHIM feature flag in the "features" member of the dm_cache_policy_type structure.
--- drivers/md/Makefile | 3 +- drivers/md/dm-cache-policy-internal.h | 6 + drivers/md/dm-cache-policy.c | 47 ++++++- drivers/md/dm-cache-policy.h | 17 +++ drivers/md/dm-cache-shim-utils.c | 210 +++++++++++++++++++++++++++++ drivers/md/dm-cache-shim-utils.h | 73 +++++++++++ drivers/md/dm-cache-stack-utils.c | 239 ++++++++++++++++++++++++++++++++++ drivers/md/dm-cache-stack-utils.h | 34 +++++ 8 files changed, 626 insertions(+), 3 deletions(-) create mode 100644 drivers/md/dm-cache-shim-utils.c create mode 100644 drivers/md/dm-cache-shim-utils.h create mode 100644 drivers/md/dm-cache-stack-utils.c create mode 100644 drivers/md/dm-cache-stack-utils.h
drivers/md/Makefile +2 -1
@@ -11,7 +11,8 @@ 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-y += dm-cache-target.o dm-cache-metadata.o dm-cache-policy.o \ + dm-cache-shim-utils.o dm-cache-stack-utils.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
drivers/md/dm-cache-policy-internal.h +6 -0
@@ -124,6 +124,12 @@ const unsigned *dm_cache_policy_get_version(struct dm_cache_policy *p);int dm_cache_policy_set_hint_size (struct dm_cache_policy *p,unsigned hint_size);size_t dm_cache_policy_get_hint_size (struct dm_cache_policy *p); +/* +* Return bool that reflects whether or not policy is only a shim +* layer in a policy stack. +*/ +bool dm_cache_policy_is_shim (struct dm_cache_policy *p); +/*----------------------------------------------------------------*/ #endif /* DM_CACHE_POLICY_INTERNAL_H */
drivers/md/dm-cache-policy.c +45 -2
81 lines not on this page · raw message
drivers/md/dm-cache-policy.h +17 -0
@@ -190,11 +190,26 @@ struct dm_cache_policy {* Book keeping ptr for the policy register, not for general use. */ void *private; + +/* +* Support for stackable policies. A policy stack consists of 0 or more +* "non-terminal" policies (which can intercept requests to provide +* additional functionality, but ultimately hand them down the stack) +* followed by one "terminal" policy which actually runs a caching +* algorithm. This is the pointer to the "next" policy in a +* non-terminal policy. It will always be NULL in a terminal policy. +*/ +struct dm_cache_policy *child; };/*----------------------------------------------------------------*/ /* +* Indicates that a policy is only a shim layer in a policy stack. +*/ +#define DM_CACHE_POLICY_SHIM (1 << 0) + +/* * We maintain a little register of the different policy types. */ #define CACHE_POLICY_NAME_SIZE 16
@@ -222,6 +237,8 @@ struct dm_cache_policy_type {struct dm_cache_policy *(*create)(dm_cblock_t cache_size,sector_t origin_size,sector_t block_size); + +unsigned long features; };int dm_cache_policy_register (struct dm_cache_policy_type *type);
drivers/md/dm-cache-shim-utils.c new file +210 -0
210 lines not on this page · raw message
drivers/md/dm-cache-shim-utils.h new file +73 -0
73 lines not on this page · raw message
drivers/md/dm-cache-stack-utils.c new file +239 -0
239 lines not on this page · raw message
drivers/md/dm-cache-stack-utils.h new file +34 -0
@@ -0,0 +1,34 @@ +/* +* Copyright 2013 NetApp, Inc. All Rights Reserved, contribution by +* Morgan Mears. +* +* This program is free software; you can redistribute it and/or modify it +* under the terms of the GNU General Public License as published by the +* Free Software Foundation; either version 2 of the License, or (at your +* option) any later version. +* +* This program is distributed in the hope that it will be useful, but +* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +* for more details +* +*/ + +#ifndef DM_CACHE_STACK_UTILS_H +#define DM_CACHE_STACK_UTILS_H + +#include "dm-cache-policy.h" + +#define DM_CACHE_POLICY_STACK_DELIM '+' + +int dm_cache_stack_utils_string_is_policy_stack (const char *string); + +struct dm_cache_policy *dm_cache_stack_utils_policy_stack_create ( +const char *policy_stack_string, +dm_cblock_t cache_size, +sector_t origin_size, +sector_t cache_block_size); + +void dm_cache_stack_utils_policy_stack_destroy (struct dm_cache_policy *p); + +#endif /* DM_CACHE_STACK_UTILS_H */
Signature · 1 line
1.8.1.4
PATCH 20/24 dm cache: add era policy shim
In reply to Mike SnitzerFrom: Morgan Mears <[email protected]>
This commit includes a non-terminal policy (aka "shim") called era that may be stacked ontop of a terminal policy (e.g. mq).
The era policy adds:
- an era number to every cache block that gets updated on write hits
- an interface that allows an application to read and increment the current era value
- an interface to invalidate cache blocks that have been written to before or after a given era
This functionality can be used to partially invalidate the cache contents to restore cache coherency after a snapshot rollback.
--- drivers/md/Kconfig | 17 ++ drivers/md/Makefile | 2 + drivers/md/dm-cache-policy-era.c | 428 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 447 insertions(+) create mode 100644 drivers/md/dm-cache-policy-era.c
drivers/md/Kconfig +17 -0
@@ -282,6 +282,23 @@ config DM_CACHE_MQ This is meant to be a general purpose policy. It prioritises reads over writes. +config DM_CACHE_ERA + tristate "ERA Cache Policy shim (EXPERIMENTAL)" + depends on DM_CACHE + ---help--- + A cache policy shim that adds an "era" property to the + per-cache-block metadata, to facilitate the implementation of + cache coherency validation and recovery tools. This mechanism + works as follows. There is a monotonically increasing 32-bit + era counter associated with each cache instance. Each cache + block is tagged with the era during which it was last written. + A device mapper message interface is provided to obtain the + current era, advance to the next era, and invalidate blocks + from before or after a given era. Note that you can use this + policy shim to add the era functionality to any cache policy + via name concatenation -- specify era+mq instead of just mq to + add the era mechanism to the mq policy, for example. + config DM_CACHE_CLEANER tristate "Cleaner Cache Policy (EXPERIMENTAL)" depends on DM_CACHE
drivers/md/Makefile +2 -0
@@ -15,6 +15,7 @@ dm-cache-y += dm-cache-target.o dm-cache-metadata.o dm-cache-policy.o \ dm-cache-shim-utils.o dm-cache-stack-utils.o dm-cache-mq-y += dm-cache-policy-mq.o dm-cache-cleaner-y += dm-cache-policy-cleaner.o +dm-cache-era-y += dm-cache-policy-era.o md-mod-y += md.o bitmap.o raid456-y += raid5.o
@@ -53,6 +54,7 @@ obj-$(CONFIG_DM_VERITY) += dm-verity.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_CACHE_ERA) += dm-cache-era.o ifeq ($(CONFIG_DM_UEVENT),y) dm-mod-objs += dm-uevent.o
drivers/md/dm-cache-policy-era.c new file +428 -0
428 lines not on this page · raw message
Signature · 1 line
1.8.1.4
PATCH 21/24 dm cache: add trc policy shim
In reply to Mike SnitzerFrom: Morgan Mears <[email protected]>
This commit includes a non-terminal policy (aka "shim") called trc that may be stacked ontop of a terminal policy (e.g. mq).
The second shim, trc, adds function-call-level tracing to the policy stack. By default, an INFO-level log message including function name and parameter(s) will be generated whenever most of the cache policy interface functions are called. An interface to increase or decrease the verbosity of the trace output is also provided.
--- drivers/md/Kconfig | 8 ++ drivers/md/Makefile | 2 + drivers/md/dm-cache-policy-trc.c | 255 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 265 insertions(+) create mode 100644 drivers/md/dm-cache-policy-trc.c
drivers/md/Kconfig +8 -0
@@ -449,4 +449,12 @@ config DM_DELAY If unsure, say N. +config DM_CACHE_TRC + tristate "Tracing Cache Policy shim (EXPERIMENTAL)" + depends on DM_CACHE + depends on DM_TEST_TARGETS + ---help--- + A cache policy shim that adds debug tracing for all cache policy + interface function calls, along with a configurable trace level. + endif # MD
drivers/md/Makefile +2 -0
@@ -16,6 +16,7 @@ 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 dm-cache-era-y += dm-cache-policy-era.o +dm-cache-trc-y += dm-cache-policy-trc.o md-mod-y += md.o bitmap.o raid456-y += raid5.o
@@ -55,6 +56,7 @@ 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_CACHE_ERA) += dm-cache-era.o +obj-$(CONFIG_DM_CACHE_TRC) += dm-cache-trc.o ifeq ($(CONFIG_DM_UEVENT),y) dm-mod-objs += dm-uevent.o
drivers/md/dm-cache-policy-trc.c new file +255 -0
255 lines not on this page · raw message
Signature · 1 line
1.8.1.4
Alasdair G Kergon
maintainerRe: [PATCH 21/24] dm cache: add trc policy shim
Quoted 9 lines · Mike Snitzer
From: Morgan Mears <[email protected]>
This commit includes a non-terminal policy (aka "shim") called trc that may be stacked ontop of a terminal policy (e.g. mq).
The second shim, trc, adds function-call-level tracing to the policy stack. By default, an INFO-level log message including function name and parameter(s) will be generated whenever most of the cache policy interface functions are called. An interface to increase or decrease the verbosity of the trace output is also provided.
Firstly, why not call it 'trace' in full, rather than abbreviating it to 3 consonants?
drivers/md/dm-cache-policy-trc.c line 31
Quoted 7 lines
+++
b/drivers/md/dm-cache-policy-trc.cdrivers/md/dm-cache-policy-trc.c new file +5
-0+#define DM_TRC_OUT(lev, p, f, arg...) \ + do { \ + if (to_trc_policy(p)->trace_level >= lev) \ + DMINFO("%s: " f, __func__, ## arg); \ + } while (0)
OK for private debugging, but I can't pretend to be very keen on this
one going upstream in this form. Might this not need to support high
volumes of messages sometimes? Were other upstream mechanisms considered? (E.g. see Documentation/trace).
Alasdair
Re: [PATCH 21/24] dm cache: add trc policy shim
Quoted 11 lines · Alasdair G Kergon
Quoted 9 lines · Mike Snitzer
From: Morgan Mears <[email protected]>
This commit includes a non-terminal policy (aka "shim") called trc that may be stacked ontop of a terminal policy (e.g. mq).
The second shim, trc, adds function-call-level tracing to the policy stack. By default, an INFO-level log message including function name and parameter(s) will be generated whenever most of the cache policy interface functions are called. An interface to increase or decrease the verbosity of the trace output is also provided.
Quoted 2 lines
Firstly, why not call it 'trace' in full, rather than abbreviating it to 3 consonants?
We can easily rename.
Quoted 12 lines
Review
Quoted 7 lines
+++
b/drivers/md/dm-cache-policy-trc.c(quoted diff) +5
-0+#define DM_TRC_OUT(lev, p, f, arg...) \ + do { \ + if (to_trc_policy(p)->trace_level >= lev) \ + DMINFO("%s: " f, __func__, ## arg); \ + } while (0)OK for private debugging, but I can't pretend to be very keen on this
one going upstream in this form. Might this not need to support high
volumes of messages sometimes? Were other upstream mechanisms considered? (E.g. seeDocumentation/trace).
Think this would take care of it (not full-blown tracepoints like blktrace but certainly more performant than standard printk):
--- drivers/md/dm-cache-policy-trc.c | 2 +- include/linux/device-mapper.h | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-)
drivers/md/dm-cache-policy-trc.c +1 -1
@@ -27,7 +27,7 @@ #define DM_TRC_OUT(lev, p, f, arg...) \ do { \ if (to_trc_policy(p)->trace_level >= lev) \ - DMINFO("%s: " f, __func__, ## arg); \ + DMTRACE("%s: " f, __func__, ## arg); \ } while (0)enum dm_trace_lev_e {
include/linux/device-mapper.h +3 -0
@@ -520,6 +520,9 @@ extern struct ratelimit_state dm_ratelim "\n", ## arg); \ } while (0) +#define DMTRACE(f, arg...) \ + trace_printk(DM_NAME ": " DM_MSG_PREFIX ": " f "\n", ## arg) +#ifdef CONFIG_DM_DEBUG # define DMDEBUG(f, arg...) \ printk(KERN_DEBUG DM_NAME ": " DM_MSG_PREFIX " DEBUG: " f "\n", ## arg)
Re: [PATCH 21/24] dm cache: add trc policy shim
Quoted 32 lines · Mike Snitzer
Quoted 11 lines · Alasdair G Kergon
Quoted 9 lines · Mike Snitzer
From: Morgan Mears <[email protected]>
This commit includes a non-terminal policy (aka "shim") called trc that may be stacked ontop of a terminal policy (e.g. mq).
The second shim, trc, adds function-call-level tracing to the policy stack. By default, an INFO-level log message including function name and parameter(s) will be generated whenever most of the cache policy interface functions are called. An interface to increase or decrease the verbosity of the trace output is also provided.Quoted 2 lines
Firstly, why not call it 'trace' in full, rather than abbreviating it to 3 consonants?
We can easily rename.
Quoted 12 lines
Review
Quoted 7 lines
+++
b/drivers/md/dm-cache-policy-trc.c(quoted diff) +5
-0+#define DM_TRC_OUT(lev, p, f, arg...) \ + do { \ + if (to_trc_policy(p)->trace_level >= lev) \ + DMINFO("%s: " f, __func__, ## arg); \ + } while (0)OK for private debugging, but I can't pretend to be very keen on this
one going upstream in this form. Might this not need to support high
volumes of messages sometimes? Were other upstream mechanisms considered? (E.g. seeDocumentation/trace).
Quoted 2 lines
Think this would take care of it (not full-blown tracepoints like blktrace but certainly more performant than standard printk):
I folded this trace_printk change in and renamed from trc to trace, see:
https://git.kernel.org/cgit/linux/kernel/git/device-mapper/linux-dm.git/commit/?h=for-next&id=f6f5db50495b16ff23a0febf38f9ee9d964b12dd
Re: [PATCH 21/24] dm cache: add trc policy shim
Quoted 35 lines · Mike Snitzer
Quoted 32 lines · Mike Snitzer
Quoted 11 lines · Alasdair G Kergon
Quoted 9 lines · Mike Snitzer
From: Morgan Mears <[email protected]>
This commit includes a non-terminal policy (aka "shim") called trc that may be stacked ontop of a terminal policy (e.g. mq).
The second shim, trc, adds function-call-level tracing to the policy stack. By default, an INFO-level log message including function name and parameter(s) will be generated whenever most of the cache policy interface functions are called. An interface to increase or decrease the verbosity of the trace output is also provided.Quoted 2 lines
Firstly, why not call it 'trace' in full, rather than abbreviating it to 3 consonants?
We can easily rename.
Quoted 12 lines
Review
Quoted 7 lines
+++
b/drivers/md/dm-cache-policy-trc.c(quoted diff) +5
-0+#define DM_TRC_OUT(lev, p, f, arg...) \ + do { \ + if (to_trc_policy(p)->trace_level >= lev) \ + DMINFO("%s: " f, __func__, ## arg); \ + } while (0)OK for private debugging, but I can't pretend to be very keen on this
one going upstream in this form. Might this not need to support high
volumes of messages sometimes? Were other upstream mechanisms considered? (E.g. seeDocumentation/trace).
Quoted 2 lines
Quoted 2 lines
Think this would take care of it (not full-blown tracepoints like blktrace but certainly more performant than standard printk):
What's wrong with full blown tracepoints?
Quoted 4 lines
I folded this
trace_printkchange in and renamed from trc to trace, see:
https://git.kernel.org/cgit/linux/kernel/git/device-mapper/linux-dm.git/commit/?h=for-next&id=f6f5db50495b16ff23a0febf38f9ee9d964b12dd
Please please please DO NOT USE TRACE_PRINTK!
It's a debugging tool, and should never be used in the kernel proper. It was meant for users to use it for debugging and then strip it out.
Now what you could do is to set up tracepoints to record the information you want, either in the function itself, or add the wrapper function too as a separate policy. Not sure if that would be any help or not.
But unless this is something that is considered "debug use only" and never put into a production kernel, do not use trace_printk().
Note, tracepoints will also give you the ability to pick and choose the traces instead of doing it by trace_level.
Thanks,
-- Steve
Re: [PATCH 21/24] dm cache: add trc policy shim
Quoted 5 lines · Steven Rostedt
Quoted 3 lines
Quoted 3 lines
Think this would take care of it (not full-blown tracepoints like blktrace but certainly more performant than standard printk):
What's wrong with full blown tracepoints?
Nothing. Just wasn't as quick to switch to while keeping the intent of the original implementation.
Quoted 5 lines
Quoted 3 lines
I folded this
trace_printkchange in and renamed from trc to trace, see:
https://git.kernel.org/cgit/linux/kernel/git/device-mapper/linux-dm.git/commit/?h=for-next&id=f6f5db50495b16ff23a0febf38f9ee9d964b12ddPlease please please DO NOT USE
TRACE_PRINTK!
Sure, I'll have a look at using proper tracepoints. Worst case, in the near-term, we drop this type of patch for v3.13 considering how close we are to merge.
Quoted 9 lines
It's a debugging tool, and should never be used in the kernel proper. It was meant for users to use it for debugging and then strip it out.
Now what you could do is to set up tracepoints to record the information you want, either in the function itself, or add the wrapper function too as a separate policy. Not sure if that would be any help or not.
But unless this is something that is considered "debug use only" and never put into a production kernel, do not use
trace_printk().
It really is debug only, but I cannot promise nobody will ever add a trace layer in production -- especially if it is as easy as using "trace+mq" vs "mq" when specifying the policy name.
Quoted 2 lines
Note, tracepoints will also give you the ability to pick and choose the traces instead of doing it by
trace_level.
Yeap, I'm aware.
Thanks for your feedback Steve.
PATCH 22/24 dm cache: add hints policy
In reply to Mike SnitzerFrom: Heinz Mauelshagen <[email protected]>
A dumb cache policy just to test variable hint size support
--- drivers/md/Kconfig | 7 + drivers/md/Makefile | 2 + drivers/md/dm-cache-policy-hints.c | 769 +++++++++++++++++++++++++++++++++++++ 3 files changed, 778 insertions(+) create mode 100644 drivers/md/dm-cache-policy-hints.c
drivers/md/Kconfig +7 -0
@@ -449,6 +449,13 @@ config DM_DELAY If unsure, say N. +config DM_CACHE_HINTS + tristate "Hint Size Test Cache Policy (EXPERIMENTAL)" + depends on DM_CACHE + depends on DM_TEST_TARGETS + ---help--- + A dumb cache policy just to test variable hint size + config DM_CACHE_TRC tristate "Tracing Cache Policy shim (EXPERIMENTAL)" depends on DM_CACHE
drivers/md/Makefile +2 -0
@@ -17,6 +17,7 @@ dm-cache-mq-y += dm-cache-policy-mq.o dm-cache-cleaner-y += dm-cache-policy-cleaner.o dm-cache-era-y += dm-cache-policy-era.o dm-cache-trc-y += dm-cache-policy-trc.o +dm-cache-hints-y += dm-cache-policy-hints.o md-mod-y += md.o bitmap.o raid456-y += raid5.o
@@ -57,6 +58,7 @@ obj-$(CONFIG_DM_CACHE_MQ) += dm-cache-mq.o obj-$(CONFIG_DM_CACHE_CLEANER) += dm-cache-cleaner.o obj-$(CONFIG_DM_CACHE_ERA) += dm-cache-era.o obj-$(CONFIG_DM_CACHE_TRC) += dm-cache-trc.o +obj-$(CONFIG_DM_CACHE_HINTS) += dm-cache-hints.o ifeq ($(CONFIG_DM_UEVENT),y) dm-mod-objs += dm-uevent.o
drivers/md/dm-cache-policy-hints.c new file +769 -0
769 lines not on this page · raw message
Signature · 1 line
1.8.1.4
PATCH 23/24 dm cache: add cache block invalidation API
In reply to Mike SnitzerFrom: Heinz Mauelshagen <[email protected]>
This commit introduces an invalidation API to dm-cache in order to allow for full functionality of the stackable "era" policy shim.
It adds:
- a core target worker function, invalidate_mappings(), to invalidate a range of blocks being requested by a message
- a respective policy_invalidate_mapping() function to carry out a cache block invalidation
--- drivers/md/dm-cache-policy-cleaner.c | 8 +- drivers/md/dm-cache-policy-internal.h | 16 ++-- drivers/md/dm-cache-policy-mq.c | 85 ++++++++++++------ drivers/md/dm-cache-policy-trc.c | 16 +++- drivers/md/dm-cache-policy.h | 46 +++++++++- drivers/md/dm-cache-shim-utils.c | 15 +++- drivers/md/dm-cache-target.c | 165 ++++++++++++++++++++++++++++++++-- 7 files changed, 297 insertions(+), 54 deletions(-)
drivers/md/dm-cache-policy-cleaner.c +6 -2
@@ -243,7 +243,7 @@ static void __set_clear_dirty(struct dm_cache_policy *pe, dm_oblock_t oblock, bo } } -static void wb_set_dirty (struct dm_cache_policy *pe,dm_oblock_t oblock) +static int wb_set_dirty (struct dm_cache_policy *pe,dm_oblock_t oblock) {struct policy *p =to_policy (pe);unsigned long flags;
@@ -251,9 +251,11 @@ static void wb_set_dirty(struct dm_cache_policy *pe, dm_oblock_t oblock)spin_lock_irqsave (&p->lock, flags);__set_clear_dirty (pe, oblock, true);spin_unlock_irqrestore (&p->lock, flags); + +return 0 ; } -static void wb_clear_dirty (struct dm_cache_policy *pe,dm_oblock_t oblock) +static int wb_clear_dirty (struct dm_cache_policy *pe,dm_oblock_t oblock) {struct policy *p =to_policy (pe);unsigned long flags;
@@ -261,6 +263,8 @@ static void wb_clear_dirty(struct dm_cache_policy *pe, dm_oblock_t oblock)spin_lock_irqsave (&p->lock, flags);__set_clear_dirty (pe, oblock, false);spin_unlock_irqrestore (&p->lock, flags); + +return 0 ; }static void add_cache_entry (struct policy *p,struct wb_cache_entry *e)
drivers/md/dm-cache-policy-internal.h +10 -6
@@ -27,16 +27,14 @@ static inline int policy_lookup(struct dm_cache_policy *p, dm_oblock_t oblock, dreturn p->lookup (p, oblock, cblock); } -static inline void policy_set_dirty (struct dm_cache_policy *p,dm_oblock_t oblock) +static inline int policy_set_dirty (struct dm_cache_policy *p,dm_oblock_t oblock) { -if (p->set_dirty) - p->set_dirty (p, oblock); +return p->set_dirty ? p->set_dirty (p, oblock) : -EINVAL ; } -static inline void policy_clear_dirty (struct dm_cache_policy *p,dm_oblock_t oblock) +static inline int policy_clear_dirty (struct dm_cache_policy *p,dm_oblock_t oblock) { -if (p->clear_dirty) - p->clear_dirty (p, oblock); +return p->clear_dirty ? p->clear_dirty (p, oblock) : -EINVAL ; } static inline int policy_load_mapping(struct dm_cache_policy *p,
@@ -70,6 +68,12 @@ static inline void policy_force_mapping(struct dm_cache_policy *p,return p->force_mapping (p, current_oblock, new_oblock); } +static inline int policy_invalidate_mapping (struct dm_cache_policy *p, +dm_oblock_t *oblock,dm_cblock_t *cblock) +{ +return p->invalidate_mapping ? p->invalidate_mapping (p, oblock, cblock) : -EINVAL ; +} +static inline dm_cblock_t policy_residency (struct dm_cache_policy *p) {return p->residency (p);
drivers/md/dm-cache-policy-mq.c +60 -25
148 lines not on this page · raw message
drivers/md/dm-cache-policy-trc.c +12 -4
@@ -87,16 +87,16 @@ static int trc_lookup(struct dm_cache_policy *p, dm_oblock_t oblock,return policy_lookup (p->child, oblock, cblock); } -static void trc_set_dirty (struct dm_cache_policy *p,dm_oblock_t oblock) +static int trc_set_dirty (struct dm_cache_policy *p,dm_oblock_t oblock) {DM_TRC_OUT (DM_TRC_LEV_NORMAL , p,"%p %llu" , p, oblock); -policy_set_dirty (p->child, oblock); +return policy_set_dirty (p->child, oblock); } -static void trc_clear_dirty (struct dm_cache_policy *p,dm_oblock_t oblock) +static int trc_clear_dirty (struct dm_cache_policy *p,dm_oblock_t oblock) {DM_TRC_OUT (DM_TRC_LEV_NORMAL , p,"%p %llu" , p, oblock); -policy_clear_dirty (p->child, oblock); +return policy_clear_dirty (p->child, oblock); } static int trc_load_mapping(struct dm_cache_policy *p,
@@ -137,6 +137,13 @@ static void trc_force_mapping(struct dm_cache_policy *p,policy_force_mapping (p->child, old_oblock, new_oblock); } +static int trc_invalidate_mapping (struct dm_cache_policy *p, +dm_oblock_t *oblock,dm_cblock_t *cblock) +{ +DM_TRC_OUT (DM_TRC_LEV_NORMAL , p,"%p %llu %u" , p,from_oblock (*oblock),from_cblock (*cblock)); +return policy_invalidate_mapping (p->child, oblock, cblock); +} +static dm_cblock_t trc_residency (struct dm_cache_policy *p) {DM_TRC_OUT (DM_TRC_LEV_NORMAL , p,"%p" , p);
@@ -191,6 +198,7 @@ static void init_policy_functions(struct trc_policy *trc) trc->policy.remove_mapping = trc_remove_mapping; trc->policy.writeback_work = trc_writeback_work; trc->policy.force_mapping = trc_force_mapping; + trc->policy.invalidate_mapping = trc_invalidate_mapping; trc->policy.residency = trc_residency; trc->policy.tick = trc_tick; trc->policy.emit_config_values = trc_emit_config_values;
drivers/md/dm-cache-policy.h +42 -4
60 lines not on this page · raw message
drivers/md/dm-cache-shim-utils.c +11 -4
@@ -76,14 +76,14 @@ static int shim_lookup(struct dm_cache_policy *p, dm_oblock_t oblock,return policy_lookup (p->child, oblock, cblock); } -static void shim_set_dirty (struct dm_cache_policy *p,dm_oblock_t oblock) +static int shim_set_dirty (struct dm_cache_policy *p,dm_oblock_t oblock) { -policy_set_dirty (p->child, oblock); +return policy_set_dirty (p->child, oblock); } -static void shim_clear_dirty (struct dm_cache_policy *p,dm_oblock_t oblock) +static int shim_clear_dirty (struct dm_cache_policy *p,dm_oblock_t oblock) { -policy_clear_dirty (p->child, oblock); +return policy_clear_dirty (p->child, oblock); } static int shim_load_mapping(struct dm_cache_policy *p,
@@ -130,6 +130,12 @@ static void shim_force_mapping(struct dm_cache_policy *p,policy_force_mapping (p->child, current_oblock, new_oblock); } +static int shim_invalidate_mapping (struct dm_cache_policy *p, +dm_oblock_t *oblock,dm_cblock_t *cblock) +{ +return policy_invalidate_mapping (p->child, oblock, cblock); +} +static dm_cblock_t shim_residency (struct dm_cache_policy *p) {return policy_residency (p->child);
@@ -164,6 +170,7 @@ void dm_cache_shim_utils_init_shim_policy(struct dm_cache_policy *p) p->remove_mapping = shim_remove_mapping; p->writeback_work = shim_writeback_work; p->force_mapping = shim_force_mapping; + p->invalidate_mapping = shim_invalidate_mapping; p->residency = shim_residency; p->tick = shim_tick; p->emit_config_values = shim_emit_config_values;
drivers/md/dm-cache-target.c +156 -9
270 lines not on this page · raw message
Signature · 1 line
1.8.1.4
PATCH 24/24 dm cache policy era: add cache block invalidation support
In reply to Mike SnitzerFrom: Heinz Mauelshagen <[email protected]>
This commit adds support for the cache block invalidation API to the "era" policy shim.
It provides:
- a temporary store containing selected cache blocks filtered based on a message requesting eras equal to, less than, less equal, greater than or greater equal to an era number
- provisioning of the entries, to be invalidated in that temporary store, to the cache core target
--- drivers/md/dm-cache-policy-era.c | 194 +++++++++++++++++++++++++++++++-------- 1 file changed, 154 insertions(+), 40 deletions(-)
drivers/md/dm-cache-policy-era.c +154 -40
@@ -2,6 +2,8 @@* Copyright 2013 NetApp, Inc. All Rights Reserved, contribution by * Morgan Mears. * +* Copyright 2013 Red Hat, Inc. All Rights Reserved. +* * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License as published by the * Free Software Foundation; either version 2 of the License, or (at your
@@ -44,6 +46,13 @@ struct era_policy {era_t *cb_to_era;era_t era_counter; + +/* Temporary store for unmap information during invalidation. */ +struct { +unsigned long *bitset; +dm_oblock_t *oblocks; +unsigned long last_cblock; + } invalidate; };/*----------------------------------------------------------------*/
@@ -53,7 +62,69 @@ static struct era_policy *to_era_policy(struct dm_cache_policy *p) return container_of(p, struct era_policy, policy); } -static int incr_era_counter (struct era_policy *era,const char *curr_era_str) +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); +} + +static dm_oblock_t *alloc_oblocks (unsigned nr_entries) +{ +size_t s =sizeof (dm_oblock_t) * nr_entries; +return vmalloc (s); +} + +static void free_oblocks (dm_oblock_t *blocks) +{ +vfree (blocks); +} + +static void free_invalidate (struct era_policy *era) +{ +if (era->invalidate.oblocks) { +free_oblocks (era->invalidate.oblocks); + era->invalidate.oblocks =NULL ; + } + +if (era->invalidate.bitset) { +free_bitset (era->invalidate.bitset); + era->invalidate.bitset =NULL ;/* Being checked for! */ + } +} + +static int alloc_invalidate (struct era_policy *era) +{ +/* FIXME: memory consumption! */ + era->invalidate.oblocks =alloc_oblocks (from_cblock (era->cache_size)); +if (!era->invalidate.oblocks) { +DMERR ("failed to allocate original blocks unmap array" ); + goto err; + } + + era->invalidate.bitset =alloc_bitset (from_cblock (era->cache_size)); +if (!era->invalidate.bitset) { +DMERR ("failed to allocate cache blocks unmap bitset" ); + goto err; + } + + era->invalidate.last_cblock =0 ; +return 0 ; + +err: +free_invalidate (era); +return -ENOMEM ; +} + + +typedef int (*era_match_fn_t )(era_t ,era_t ); + +static int incr_era_counter (struct era_policy *era,const char *curr_era_str, +era_match_fn_t dummy) {era_t curr_era_counter;int r;
@@ -119,8 +190,6 @@ static int era_is_lt_value(era_t era, era_t value)return era < value; } -typedef int (*era_match_fn_t )(era_t ,era_t ); -struct inval_oblocks_ctx {struct era_policy *era;era_match_fn_t era_match_fn;
@@ -131,26 +200,16 @@ static int era_inval_oblocks(void *context, dm_cblock_t cblock, dm_oblock_t oblock, void *unused) { struct inval_oblocks_ctx *ctx = (struct inval_oblocks_ctx *)context; -struct dm_cache_policy *child; -era_t act_era; +era_t act_era = ctx->era->cb_to_era[from_cblock (cblock)]; - act_era = ctx->era->cb_to_era[from_cblock (cblock)];if (ctx->era_match_fn (act_era, ctx->test_era)) {#if DEBUG_ERA DMDEBUG ("cblock %u has era %u matching test_era %u; " "marking mapping to be removed for oblock %llu." ,from_cblock (cblock), act_era, ctx->test_era, oblock);#endif - child = ctx->era->policy.child; - -/* -* This deadlocks (lock against self) because child is calling -* us via the walk_mappings context callback, child's -* walk_mappings holds child's lock, and child's remove_mappings -* tries to get it again. Not fixing because I believe the -* invalidate API is going to change. -*/ -/* child->remove_mapping(child, oblock); */ +set_bit (from_cblock (cblock), ctx->era->invalidate.bitset); + ctx->era->invalidate.oblocks[from_cblock (cblock)] = oblock; }return 0 ;
@@ -164,6 +223,11 @@ static int cond_unmap_by_era(struct era_policy *era, const char *test_era_str,era_t test_era;int r; +if (era->invalidate.bitset) { +DMERR ("previous unmap request exists" ); +return -EPERM ; + } +/* * Unmap blocks with eras matching the given era, according to the * given matching function.
@@ -172,6 +236,10 @@ static int cond_unmap_by_era(struct era_policy *era, const char *test_era_str,if (kstrtou32 (test_era_str,10 , &test_era))return -EINVAL ; + r =alloc_invalidate (era); +if (r) +return r; + io_ctx.era = era; io_ctx.era_match_fn = era_match_fn; io_ctx.test_era = test_era;
@@ -197,10 +265,12 @@ static int cond_unmap_by_era(struct era_policy *era, const char *test_era_str,static void era_destroy (struct dm_cache_policy *p) {struct era_policy *era =to_era_policy (p); +#if DEBUG_ERA -DMDEBUG ("destroyed era %p" , era); +DMDEBUG ("destroying era %p" , era);#endif -kfree (era->cb_to_era); +free_invalidate (era); +vfree (era->cb_to_era);kfree (era); }
@@ -216,6 +286,7 @@ static int era_map(struct dm_cache_policy *p, dm_oblock_t oblock,if (can_block)mutex_lock (&era->lock); +else if (!mutex_trylock (&era->lock))return -EWOULDBLOCK ;
@@ -257,6 +328,7 @@ static int era_load_mapping(struct dm_cache_policy *p, r =policy_load_mapping (child, oblock, cblock, hint, hint_valid); +/* FIXME: recovered area valid on reload called from cache core invalidate mapping error path? */ if (!r && hint_valid && (from_cblock (cblock) <from_cblock (era->cache_size))) { recovered_era =le32_to_cpu (*le32_hint);
@@ -313,28 +385,71 @@ static void era_force_mapping(struct dm_cache_policy *p, dm_oblock_t old_oblock,mutex_unlock (&era->lock); } -static int era_set_config_value (struct dm_cache_policy *p,const char *key, -const char *value) +/* Find next block to invalidate. */ +static int __find_invalidate_block (struct era_policy *era,dm_cblock_t *cblock) +{ +int bit =find_next_bit (era->invalidate.bitset,from_cblock (era->cache_size), + era->invalidate.last_cblock); + + *cblock =to_cblock (bit); + era->invalidate.last_cblock = bit; +return bit <from_cblock (era->cache_size) ?0 : -ENODATA ; +} + +static int era_invalidate_mapping (struct dm_cache_policy *p, +dm_oblock_t *oblock,dm_cblock_t *cblock) {struct era_policy *era =to_era_policy (p);int r; -if (!strcasecmp (key,"increment_era_counter" )) - r =incr_era_counter (era, value); -else if (!strcasecmp (key,"unmap_blocks_from_later_eras" )) - r =cond_unmap_by_era (era, value, era_is_gt_value); -else if (!strcasecmp (key,"unmap_blocks_from_this_era_and_later" )) - r =cond_unmap_by_era (era, value, era_is_gte_value); -else if (!strcasecmp (key,"unmap_blocks_from_this_era_and_earlier" )) - r =cond_unmap_by_era (era, value, era_is_lte_value); -else if (!strcasecmp (key,"unmap_blocks_from_earlier_eras" )) - r =cond_unmap_by_era (era, value, era_is_lt_value); -else - r =policy_set_config_value (p->child, key, value); +if (!era->invalidate.bitset) +return -ENODATA ; + + r =__find_invalidate_block (era, cblock); +if (r <0 ) +free_invalidate (era); +else { +BUG_ON (from_cblock (*cblock) >=from_cblock (era->cache_size)); +BUG_ON (!test_bit (from_cblock (*cblock), era->invalidate.bitset)); +clear_bit (from_cblock (*cblock), era->invalidate.bitset); + *oblock = era->invalidate.oblocks[from_cblock (*cblock)]; + r =policy_invalidate_mapping (p->child, oblock, cblock); +#if DEBUG_ERA +DMDEBUG ("unmapped cblock=%u oblock=%llu" ,from_cblock (*cblock),from_oblock (*oblock)); +#endif + }return r; } +struct config_value_handler { +const char *cmd; +int (*handler_fn)(struct era_policy *,const char *,era_match_fn_t ); +era_match_fn_t match_fn; +}; + +/* FIXME: is a delete unmap request needed or is reloading the mapping sufficient to achieve it? */ +static int era_set_config_value (struct dm_cache_policy *p,const char *key, +const char *value) +{ +struct era_policy *era =to_era_policy (p); +struct config_value_handler *vh, value_handlers[] = { + {"increment_era_counter" , incr_era_counter,NULL }, + {"unmap_blocks_from_later_eras" , cond_unmap_by_era, era_is_gt_value }, + {"unmap_blocks_from_this_era_and_later" , cond_unmap_by_era, era_is_gte_value }, + {"unmap_blocks_from_this_era_and_earlier" , cond_unmap_by_era, era_is_lte_value }, + {"unmap_blocks_from_earlier_eras" , cond_unmap_by_era, era_is_lt_value }, + {NULL } + }; + +for (vh = value_handlers; vh->cmd; vh++) { +if (!strcasecmp (key, vh->cmd)) +return vh->handler_fn (era, value, vh->match_fn); + } + +return policy_set_config_value (p->child, key, value); +} +static int era_emit_config_values (struct dm_cache_policy *p,char *result,unsigned maxlen) {
@@ -355,6 +470,7 @@ static void init_policy_functions(struct era_policy *era) era->policy.load_mapping = era_load_mapping; era->policy.walk_mappings = era_walk_mappings; era->policy.force_mapping = era_force_mapping; + era->policy.invalidate_mapping = era_invalidate_mapping; era->policy.emit_config_values = era_emit_config_values; era->policy.set_config_value = era_set_config_value; }
@@ -372,15 +488,13 @@ static struct dm_cache_policy *era_create(dm_cblock_t cache_size, era->cache_size = cache_size;mutex_init (&era->lock); - era->cb_to_era =kzalloc (from_cblock (era->cache_size) * -sizeof (*(era->cb_to_era)),GFP_KERNEL ); -if (!era->cb_to_era) - goto bad_alloc_cb_to_era; - era->era_counter =1 ; - -return &era->policy; + era->cb_to_era =vzalloc (from_cblock (era->cache_size) * +sizeof (*era->cb_to_era)); +if (era->cb_to_era) { + era->era_counter =1 ; +return &era->policy; + } -bad_alloc_cb_to_era:kfree (era);return NULL ; }
Signature · 1 line
1.8.1.4