add parameter for pmem cache device init
Subsystems (3)
v2 cover add parameter for pmem cache device init
From: Huaisheng Ye <[email protected]>
This patch set could be used for dm-writecache when use persistent memory as cache data device.
Patch 1 and 2 go towards removing unused parameter and codes which actually doesn't really work.
Patch 3 and 4 are targeted at solving problem fn ctr failed to work due to invalid magic or version, which is caused by the super block of pmem has messy data stored.
Changes Since v1:
- add optional parameter reinit to avoid invalid magic or version. [1]: https://lkml.org/lkml/2019/1/3/43
Huaisheng Ye (4):
dm-writecache: remove unused size to writecache_flush_region
dm-writecache: get rid of memory_data flush to writecache_flush_entry
dm-writecache: expand pmem_reinit for struct dm_writecache Documentation/device-mapper: add optional parameter reinit
Documentation/device-mapper/writecache.txt | 4 ++++ drivers/md/dm-writecache.c | 19 +++++++++++-------- 2 files changed, 15 insertions(+), 8 deletions(-)
Signature · 1 line
1.8.3.1
RFC PATCH v2 1/4 dm-writecache: remove unused size to writecache_flush_region
From: Huaisheng Ye <[email protected]>
writecache_flush_region doesn't use size to calculate flush region. That uses _set_bits to mark the region in dirty_bitmap directly.
--- drivers/md/dm-writecache.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-)
drivers/md/dm-writecache.c +6 -6
@@ -418,7 +418,7 @@ static void writecache_flush_all_metadata(struct dm_writecache *wc)memset (wc->dirty_bitmap,-1 , wc->dirty_bitmap_size); } -static void writecache_flush_region (struct dm_writecache *wc,void *ptr,size_t size) +static void writecache_flush_region (struct dm_writecache *wc,void *ptr) {if (!WC_MODE_PMEM (wc)) __set_bit(((char *)ptr - (char *)wc->memory_map) / BITMAP_GRANULARITY,
@@ -657,7 +657,7 @@ static void writecache_free_entry(struct dm_writecache *wc, struct wc_entry *e)writecache_unlink (wc, e);writecache_add_to_freelist (wc, e);clear_seq_count (wc, e); -writecache_flush_region (wc,memory_entry (wc, e),sizeof (struct wc_memory_entry )); +writecache_flush_region (wc,memory_entry (wc, e));if (unlikely (waitqueue_active (&wc->freelist_wait)))wake_up (&wc->freelist_wait); }
@@ -687,9 +687,9 @@ static void writecache_poison_lists(struct dm_writecache *wc)static void writecache_flush_entry (struct dm_writecache *wc,struct wc_entry *e) { -writecache_flush_region (wc,memory_entry (wc, e),sizeof (struct wc_memory_entry )); +writecache_flush_region (wc,memory_entry (wc, e));if (WC_MODE_PMEM (wc)) -writecache_flush_region (wc,memory_data (wc, e), wc->block_size); +writecache_flush_region (wc,memory_data (wc, e)); }static bool writecache_entry_is_committed (struct dm_writecache *wc,struct wc_entry *e)
@@ -733,7 +733,7 @@ static void writecache_flush(struct dm_writecache *wc) wc->seq_count++;pmem_assign (sb (wc)->seq_count,cpu_to_le64 (wc->seq_count)); -writecache_flush_region (wc, &sb (wc)->seq_count,sizeof sb (wc)->seq_count); +writecache_flush_region (wc, &sb (wc)->seq_count);writecache_commit_flushed (wc); wc->overwrote_committed = false;
@@ -1757,7 +1757,7 @@ static int init_memory(struct dm_writecache *wc)writecache_flush_all_metadata (wc);writecache_commit_flushed (wc);pmem_assign (sb (wc)->magic,cpu_to_le32 (MEMORY_SUPERBLOCK_MAGIC )); -writecache_flush_region (wc, &sb (wc)->magic,sizeof sb (wc)->magic); +writecache_flush_region (wc, &sb (wc)->magic);writecache_commit_flushed (wc);return 0 ;
Signature · 1 line
1.8.3.1
RFC PATCH v2 2/4 dm-writecache: get rid of memory_data flush to writecache_flush_entry
In reply to Huaisheng YeFrom: Huaisheng Ye <[email protected]>
writecache_flush_region only works when SSD mode.
If wc->pmem_mode sets, writecache_flush_region doesn't need to be called in writecache_flush_entry.
--- drivers/md/dm-writecache.c | 2 -- 1 file changed, 2 deletions(-)
drivers/md/dm-writecache.c +0 -2
@@ -688,8 +688,6 @@ static void writecache_poison_lists(struct dm_writecache *wc)static void writecache_flush_entry (struct dm_writecache *wc,struct wc_entry *e) {writecache_flush_region (wc,memory_entry (wc, e)); -if (WC_MODE_PMEM (wc)) -writecache_flush_region (wc,memory_data (wc, e)); }static bool writecache_entry_is_committed (struct dm_writecache *wc,struct wc_entry *e)
Signature · 1 line
1.8.3.1
RFC PATCH v2 3/4 dm-writecache: expand pmem_reinit for struct dm_writecache
In reply to Huaisheng YeFrom: Huaisheng Ye <[email protected]>
When use persistent memory as cache data device, sometimes the super block of pmem has messy data stored in it. That would have risk to lead fn ctr failed to work due to invalid magic or version.
Here we expand pmem_reinit to optional parameters in order to solve this issue. When user gets pmem device, which has unrelated data in it, as cache device, he should use paramenter 'reinit' to avoid s.magic and s.version don't equal to NULL or correct MEMORY_SUPERBLOCK_MAGIC/VERSION.
--- drivers/md/dm-writecache.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)
drivers/md/dm-writecache.c +6 -1
@@ -149,6 +149,7 @@ struct dm_writecache { bool pmem_mode:1; bool writeback_fua:1; + bool pmem_reinit:1; bool overwrote_committed:1; bool memory_vmapped:1;
@@ -2026,6 +2027,10 @@ static int writecache_ctr(struct dm_target *ti, unsigned argc, char **argv) wc->writeback_fua = false; wc->writeback_fua_set = true; }else goto invalid_optional; + }else if (!strcasecmp (string,"reinit" )) { +if (WC_MODE_PMEM (wc)) + wc->pmem_reinit = true; +else goto invalid_optional; }else { invalid_optional: r = -EINVAL ;
@@ -2127,7 +2132,7 @@ static int writecache_ctr(struct dm_target *ti, unsigned argc, char **argv) ti->error ="Hardware memory error when reading superblock" ; goto bad; } -if (!le32_to_cpu (s.magic) && !le32_to_cpu (s.version)) { +if (wc->pmem_reinit || (!le32_to_cpu (s.magic) && !le32_to_cpu (s.version))) { r =init_memory (wc);if (r) { ti->error ="Unable to initialize device" ;
Signature · 1 line
1.8.3.1
RFC PATCH v2 4/4 Documentation/device-mapper: add optional parameter reinit
In reply to Huaisheng YeFrom: Huaisheng Ye <[email protected]>
Add intro and usage guide for reinit.
--- Documentation/device-mapper/writecache.txt | 4 ++++ 1 file changed, 4 insertions(+)
Documentation/device-mapper/writecache.txt +4 -0
@@ -45,6 +45,10 @@ Constructor parameters: afterwards - some underlying devices perform better with fua, some with nofua. The user should test it + reinit (by default off) + applicable only to persistent memory - use the REINIT flag + when the surper block has messy data, that would cause fn ctr + failed to work with invalid magic or version in the superblock Status: 1. error indicator - 0 if there was no error, otherwise error number
Signature · 1 line
1.8.3.1