From: Mikulas Patocka <mpatocka@redhat.com>
To: Mikulas Patocka <mpatocka@redhat.com>,
Mike Snitzer <msnitzer@redhat.com>,
Dan Williams <dan.j.williams@intel.com>
Cc: dm-devel@redhat.com
Subject: [patch 4/4] dm-writecache: use new API for flushing
Date: Sat, 19 May 2018 07:25:07 +0200 [thread overview]
Message-ID: <20180519052635.567438191@debian.vm> (raw)
In-Reply-To: 20180519052503.325953342@debian.vm
[-- Attachment #1: dm-writecache-interface.patch --]
[-- Type: text/plain, Size: 7451 bytes --]
Use new API for flushing persistent memory.
The problem is this:
* on X86-64, non-temporal stores have the best performance
* ARM64 doesn't have non-temporal stores, so we must flush cache. We
should flush cache as late as possible, because it performs better this
way.
We introduce functions pmem_memcpy, pmem_flush and pmem_commit. To commit
data persistently, all three functions must be called.
The macro pmem_assign may be used instead of pmem_memcpy. pmem_assign
(unlike pmem_memcpy) guarantees that 8-byte values are written atomically.
On X86, pmem_memcpy is memcpy_flushcache, pmem_flush is empty and
pmem_commit is wmb.
On ARM64, pmem_memcpy is memcpy, pmem_flush is arch_wb_cache_pmem and
pmem_commit is empty.
Signed-off-by: Mike Snitzer <msnitzer@redhat.com>
Signed-off-by: Mikulas Patocka <mpatocka@redhat.com>
---
drivers/md/dm-writecache.c | 100 +++++++++++++++++++++++++--------------------
1 file changed, 56 insertions(+), 44 deletions(-)
Index: linux-2.6/drivers/md/dm-writecache.c
===================================================================
--- linux-2.6.orig/drivers/md/dm-writecache.c 2018-05-19 06:20:28.000000000 +0200
+++ linux-2.6/drivers/md/dm-writecache.c 2018-05-19 07:10:26.000000000 +0200
@@ -14,6 +14,7 @@
#include <linux/dm-kcopyd.h>
#include <linux/dax.h>
#include <linux/pfn_t.h>
+#include <linux/libnvdimm.h>
#define DM_MSG_PREFIX "writecache"
@@ -47,14 +48,48 @@
* On ARM64, cache flushing is more efficient.
*/
#if defined(CONFIG_X86_64)
-#define EAGER_DATA_FLUSH
-#define NT_STORE(dest, src) \
-do { \
- typeof(src) val = (src); \
- memcpy_flushcache(&(dest), &val, sizeof(src)); \
+
+static void pmem_memcpy(void *dest, void *src, size_t len)
+{
+ memcpy_flushcache(dest, src, len);
+}
+
+#define __pmem_assign(dest, src, uniq) \
+do { \
+ typeof(dest) uniq = (src); \
+ memcpy_flushcache(&(dest), &uniq, sizeof(dest)); \
} while (0)
+
+#define pmem_assign(dest, src) \
+ __pmem_assign(dest, src, __UNIQUE_ID(pmem_assign))
+
+static void pmem_flush(void *dest, size_t len)
+{
+}
+
+static void pmem_commit(void)
+{
+ wmb();
+}
+
#else
-#define NT_STORE(dest, src) WRITE_ONCE(dest, src)
+
+static void pmem_memcpy(void *dest, void *src, size_t len)
+{
+ memcpy(dest, src, len);
+}
+
+#define pmem_assign(dest, src) WRITE_ONCE(dest, src)
+
+static void pmem_flush(void *dest, size_t len)
+{
+ arch_wb_cache_pmem(dest, len);
+}
+
+static void pmem_commit(void)
+{
+}
+
#endif
#if defined(__HAVE_ARCH_MEMCPY_MCSAFE) && !defined(DM_WRITECACHE_ONLY_SSD)
@@ -105,7 +140,7 @@ struct wc_entry {
};
#ifndef DM_WRITECACHE_ONLY_SSD
-#define WC_MODE_PMEM(wc) ((wc)->pmem_mode)
+#define WC_MODE_PMEM(wc) (likely((wc)->pmem_mode))
#define WC_MODE_FUA(wc) ((wc)->writeback_fua)
#else
#define WC_MODE_PMEM(wc) false
@@ -400,21 +435,6 @@ static void persistent_memory_invalidate
invalidate_kernel_vmap_range(ptr, size);
}
-static void persistent_memory_flush(struct dm_writecache *wc, void *ptr, size_t size)
-{
-#ifndef EAGER_DATA_FLUSH
- dax_flush(wc->ssd_dev->dax_dev, ptr, size);
-#endif
-}
-
-static void persistent_memory_commit_flushed(void)
-{
-#ifdef EAGER_DATA_FLUSH
- /* needed since memcpy_flushcache is used instead of dax_flush */
- wmb();
-#endif
-}
-
static struct wc_memory_superblock *sb(struct dm_writecache *wc)
{
return wc->memory_map;
@@ -462,21 +482,20 @@ static void clear_seq_count(struct dm_wr
#ifdef DM_WRITECACHE_HANDLE_HARDWARE_ERRORS
e->seq_count = -1;
#endif
- NT_STORE(memory_entry(wc, e)->seq_count, cpu_to_le64(-1));
+ pmem_assign(memory_entry(wc, e)->seq_count, cpu_to_le64(-1));
}
static void write_original_sector_seq_count(struct dm_writecache *wc, struct wc_entry *e,
uint64_t original_sector, uint64_t seq_count)
{
- struct wc_memory_entry *me_p, me;
+ struct wc_memory_entry me;
#ifdef DM_WRITECACHE_HANDLE_HARDWARE_ERRORS
e->original_sector = original_sector;
e->seq_count = seq_count;
#endif
- me_p = memory_entry(wc, e);
me.original_sector = cpu_to_le64(original_sector);
me.seq_count = cpu_to_le64(seq_count);
- NT_STORE(*me_p, me);
+ pmem_assign(*memory_entry(wc, e), me);
}
#define writecache_error(wc, err, msg, arg...) \
@@ -491,8 +510,7 @@ do { \
static void writecache_flush_all_metadata(struct dm_writecache *wc)
{
if (WC_MODE_PMEM(wc)) {
- persistent_memory_flush(wc,
- sb(wc), offsetof(struct wc_memory_superblock, entries[wc->n_blocks]));
+ pmem_flush(sb(wc), offsetof(struct wc_memory_superblock, entries[wc->n_blocks]));
} else {
memset(wc->dirty_bitmap, -1, wc->dirty_bitmap_size);
}
@@ -501,7 +519,7 @@ static void writecache_flush_all_metadat
static void writecache_flush_region(struct dm_writecache *wc, void *ptr, size_t size)
{
if (WC_MODE_PMEM(wc))
- persistent_memory_flush(wc, ptr, size);
+ pmem_flush(ptr, size);
else
__set_bit(((char *)ptr - (char *)wc->memory_map) / BITMAP_GRANULARITY,
wc->dirty_bitmap);
@@ -579,7 +597,7 @@ static void ssd_commit_flushed(struct dm
static void writecache_commit_flushed(struct dm_writecache *wc)
{
if (WC_MODE_PMEM(wc))
- persistent_memory_commit_flushed();
+ pmem_commit();
else
ssd_commit_flushed(wc);
}
@@ -788,10 +806,8 @@ static void writecache_poison_lists(stru
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));
-#ifndef EAGER_DATA_FLUSH
if (WC_MODE_PMEM(wc))
writecache_flush_region(wc, memory_data(wc, e), wc->block_size);
-#endif
}
static bool writecache_entry_is_committed(struct dm_writecache *wc, struct wc_entry *e)
@@ -834,7 +850,7 @@ static void writecache_flush(struct dm_w
writecache_wait_for_ios(wc, WRITE);
wc->seq_count++;
- NT_STORE(sb(wc)->seq_count, cpu_to_le64(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_commit_flushed(wc);
@@ -1152,11 +1168,7 @@ static void bio_copy_block(struct dm_wri
}
} else {
flush_dcache_page(bio_page(bio));
-#ifdef EAGER_DATA_FLUSH
- memcpy_flushcache(data, buf, size);
-#else
- memcpy(data, buf, size);
-#endif
+ pmem_memcpy(data, buf, size);
}
bvec_kunmap_irq(buf, &flags);
@@ -1850,18 +1862,18 @@ static int init_memory(struct dm_writeca
return r;
for (b = 0; b < ARRAY_SIZE(sb(wc)->padding); b++)
- NT_STORE(sb(wc)->padding[b], cpu_to_le64(0));
- NT_STORE(sb(wc)->version, cpu_to_le32(MEMORY_SUPERBLOCK_VERSION));
- NT_STORE(sb(wc)->block_size, cpu_to_le32(wc->block_size));
- NT_STORE(sb(wc)->n_blocks, cpu_to_le64(wc->n_blocks));
- NT_STORE(sb(wc)->seq_count, cpu_to_le64(0));
+ pmem_assign(sb(wc)->padding[b], cpu_to_le64(0));
+ pmem_assign(sb(wc)->version, cpu_to_le32(MEMORY_SUPERBLOCK_VERSION));
+ pmem_assign(sb(wc)->block_size, cpu_to_le32(wc->block_size));
+ pmem_assign(sb(wc)->n_blocks, cpu_to_le64(wc->n_blocks));
+ pmem_assign(sb(wc)->seq_count, cpu_to_le64(0));
for (b = 0; b < wc->n_blocks; b++)
write_original_sector_seq_count(wc, &wc->entries[b], -1, -1);
writecache_flush_all_metadata(wc);
writecache_commit_flushed(wc);
- NT_STORE(sb(wc)->magic, cpu_to_le32(MEMORY_SUPERBLOCK_MAGIC));
+ pmem_assign(sb(wc)->magic, cpu_to_le32(MEMORY_SUPERBLOCK_MAGIC));
writecache_flush_region(wc, &sb(wc)->magic, sizeof sb(wc)->magic);
writecache_commit_flushed(wc);
next prev parent reply other threads:[~2018-05-19 5:25 UTC|newest]
Thread overview: 66+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-05-19 5:25 [patch 0/4] dm-writecache patches Mikulas Patocka
2018-05-19 5:25 ` [patch 1/4] x86: optimize memcpy_flushcache Mikulas Patocka
2018-05-19 14:21 ` Dan Williams
2018-05-24 18:20 ` [PATCH v2] " Mike Snitzer
2018-06-18 13:23 ` [PATCH v2 RESEND] " Mike Snitzer
2018-06-21 14:31 ` Ingo Molnar
2018-06-22 1:19 ` Mikulas Patocka
2018-06-22 1:30 ` Ingo Molnar
2018-08-08 21:22 ` [PATCH v3 " Mikulas Patocka
2018-09-10 13:18 ` Ingo Molnar
2018-09-11 6:22 ` [tip:x86/asm] x86/asm: Optimize memcpy_flushcache() tip-bot for Mikulas Patocka
2018-05-19 5:25 ` [patch 2/4] swait: export the symbols __prepare_to_swait and __finish_swait Mikulas Patocka
2018-05-22 6:34 ` Christoph Hellwig
2018-05-22 18:52 ` Mike Snitzer
2018-05-23 9:21 ` Peter Zijlstra
2018-05-23 15:10 ` Mike Snitzer
2018-05-23 18:10 ` [PATCH v2] swait: export " Mike Snitzer
2018-05-23 20:38 ` Mikulas Patocka
2018-05-23 21:51 ` Mike Snitzer
2018-05-24 14:10 ` Peter Zijlstra
2018-05-24 15:09 ` Mike Snitzer
2018-05-19 5:25 ` [patch 3/4] dm-writecache Mikulas Patocka
2018-05-22 6:37 ` Christoph Hellwig
2018-05-19 5:25 ` Mikulas Patocka [this message]
[not found] ` <20180519052635.567438191-59tzFEB+POEAvxtiuMwx3w@public.gmane.org>
2018-05-22 6:39 ` [dm-devel] [patch 4/4] dm-writecache: use new API for flushing Christoph Hellwig
[not found] ` <20180522063946.GB8054-wEGCiKHe2LqWVfeAwA7xHQ@public.gmane.org>
2018-05-22 18:41 ` Mike Snitzer
[not found] ` <20180522184103.GA25826-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
2018-05-22 19:00 ` Dan Williams
[not found] ` <CAPcyv4g395RccdEPF=sCu5RdCH9zwD+GvOfSp7-F0Oh64CeDgA-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2018-05-22 19:19 ` Mike Snitzer
[not found] ` <20180522191942.GB25904-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
2018-05-22 19:27 ` Dan Williams
[not found] ` <CAPcyv4hWswV=VCfB7KatoW_zc-kUUju2jD45N-Gsg4sW-XFe-A-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2018-05-22 20:52 ` Mike Snitzer
[not found] ` <20180522205214.GA26259-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
2018-05-22 22:53 ` [dm-devel] " Jeff Moyer
[not found] ` <x49r2m3nvyk.fsf-RRHT56Q3PSP4kTEheFKJxxDDeQx5vsVwAInAS/Ez/D0@public.gmane.org>
2018-05-23 20:57 ` Mikulas Patocka
2018-05-28 13:52 ` Mikulas Patocka
[not found] ` <alpine.LRH.2.02.1805280943460.16538-Hpncn10jQN4oNljnaZt3ZvA+iT7yCHsGwRM8/txMwJMAicBL8TP8PQ@public.gmane.org>
2018-05-28 17:41 ` Dan Williams
[not found] ` <CAPcyv4gxCNqqG2G3R6f=kH3zNbByhgE2R-trJWurH49-p+51Gg-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2018-05-30 13:42 ` [dm-devel] " Jeff Moyer
[not found] ` <x49h8mpmf8v.fsf-RRHT56Q3PSP4kTEheFKJxxDDeQx5vsVwAInAS/Ez/D0@public.gmane.org>
2018-05-30 13:51 ` Mikulas Patocka
2018-05-30 13:52 ` Jeff Moyer
2018-05-24 8:15 ` Mikulas Patocka
2018-05-25 3:12 ` Dan Williams
2018-05-25 6:17 ` Mikulas Patocka
[not found] ` <alpine.LRH.2.02.1805250213270.13894-Hpncn10jQN4oNljnaZt3ZvA+iT7yCHsGwRM8/txMwJMAicBL8TP8PQ@public.gmane.org>
2018-05-25 12:51 ` Mike Snitzer
[not found] ` <20180525125126.GA9275-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
2018-05-25 15:57 ` Dan Williams
[not found] ` <CAPcyv4j-v5HGBg9JMBXt7UUyw=K_bGC7t5tQGfXM9G4qjOpFjQ-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2018-05-26 7:02 ` Mikulas Patocka
[not found] ` <alpine.LRH.2.02.1805260246250.15978-Hpncn10jQN4oNljnaZt3ZvA+iT7yCHsGwRM8/txMwJMAicBL8TP8PQ@public.gmane.org>
2018-05-26 15:26 ` Dan Williams
[not found] ` <CAPcyv4jwLsCNvNhgvv2DDSZuQsQXYEpKUU_5w1pTnyKj-uDBbQ-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2018-05-28 13:32 ` Mikulas Patocka
[not found] ` <alpine.LRH.2.02.1805280922190.13486-Hpncn10jQN4oNljnaZt3ZvA+iT7yCHsGwRM8/txMwJMAicBL8TP8PQ@public.gmane.org>
2018-05-28 18:14 ` Dan Williams
[not found] ` <CAPcyv4jXV4aZ6wqqjVPL8J4LxwTtXnzQCLZ0Wk5oB4_0uxpg7g-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2018-05-30 13:07 ` Mikulas Patocka
[not found] ` <alpine.LRH.2.02.1805300903220.1090-Hpncn10jQN4oNljnaZt3ZvA+iT7yCHsGwRM8/txMwJMAicBL8TP8PQ@public.gmane.org>
2018-05-30 13:16 ` Mike Snitzer
[not found] ` <20180530131623.GB2106-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
2018-05-30 13:21 ` Mikulas Patocka
[not found] ` <alpine.LRH.2.02.1805300919070.11327-Hpncn10jQN4oNljnaZt3ZvA+iT7yCHsGwRM8/txMwJMAicBL8TP8PQ@public.gmane.org>
2018-05-30 13:26 ` Mike Snitzer
[not found] ` <20180530132647.GB5157-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
2018-05-30 13:33 ` Mikulas Patocka
[not found] ` <alpine.LRH.2.02.1805300929500.11327-Hpncn10jQN4oNljnaZt3ZvA+iT7yCHsGwRM8/txMwJMAicBL8TP8PQ@public.gmane.org>
2018-05-30 13:54 ` Mike Snitzer
[not found] ` <20180530135421.GA81788-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
2018-05-30 14:09 ` Mikulas Patocka
[not found] ` <alpine.LRH.2.02.1805300959460.16696-Hpncn10jQN4oNljnaZt3ZvA+iT7yCHsGwRM8/txMwJMAicBL8TP8PQ@public.gmane.org>
2018-05-30 14:21 ` Mike Snitzer
[not found] ` <20180530142104.GA5416-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
2018-05-30 14:46 ` Mikulas Patocka
[not found] ` <alpine.LRH.2.02.1805301023380.21890-Hpncn10jQN4oNljnaZt3ZvA+iT7yCHsGwRM8/txMwJMAicBL8TP8PQ@public.gmane.org>
2018-05-31 3:42 ` Mike Snitzer
[not found] ` <20180531034216.GB88973-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
2018-06-03 15:03 ` Mikulas Patocka
2018-05-31 3:39 ` Mike Snitzer
[not found] ` <20180531033919.GA88973-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
2018-05-31 8:16 ` Mikulas Patocka
[not found] ` <alpine.LRH.2.02.1805310412240.30096-Hpncn10jQN4oNljnaZt3ZvA+iT7yCHsGwRM8/txMwJMAicBL8TP8PQ@public.gmane.org>
2018-05-31 12:09 ` Mike Snitzer
2018-05-30 15:58 ` Dan Williams
[not found] ` <CAPcyv4j3pDQ3YMK5Eije0dgGw+1CQYazPJ-zvqfvGF-9O_gVJw-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2018-05-30 22:39 ` Dan Williams
[not found] ` <CAPcyv4gD-ZaXyV1SFAndobUYJOGLkx9rOyb5zNbzJXB_kVCzoA-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2018-05-31 8:19 ` Mikulas Patocka
[not found] ` <alpine.LRH.2.02.1805310416540.30096-Hpncn10jQN4oNljnaZt3ZvA+iT7yCHsGwRM8/txMwJMAicBL8TP8PQ@public.gmane.org>
2018-05-31 14:51 ` Dan Williams
[not found] ` <CAPcyv4gzFbdBbUhPJ6W4mTJWAkvqVw_4FVhVdePEJzc28Sg-Sg-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2018-05-31 15:31 ` Mikulas Patocka
[not found] ` <alpine.LRH.2.02.1805311127001.31059-Hpncn10jQN4oNljnaZt3ZvA+iT7yCHsGwRM8/txMwJMAicBL8TP8PQ@public.gmane.org>
2018-05-31 16:39 ` Dan Williams
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20180519052635.567438191@debian.vm \
--to=mpatocka@redhat.com \
--cc=dan.j.williams@intel.com \
--cc=dm-devel@redhat.com \
--cc=msnitzer@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox