linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/3] optimize writecache_writeback for performance
@ 2019-08-25  7:24 Huaisheng Ye
  2019-08-25  7:24 ` [PATCH 1/3] dm writecache: remove unused member pointer in writeback_struct Huaisheng Ye
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Huaisheng Ye @ 2019-08-25  7:24 UTC (permalink / raw)
  To: mpatocka, snitzer, agk; +Cc: prarit, tyu1, dm-devel, linux-kernel, Huaisheng Ye

From: Huaisheng Ye <yehs1@lenovo.com>

Patch 1 and 2 are used for cleaning the code, and they have got
Acked-by from Mikulas.

Patch 3 is used for performance optimization when writeback_all,
which could save more than half of time.
Of course, if the blocks in writecache are more uncontinuous and
disordered, the more performance improvement would be gained from
this patch.

Huaisheng Ye (3):
  dm writecache: remove unused member pointer in writeback_struct
  dm writecache: add unlikely for getting two block with same LBA
  dm writecache: optimize performance by sorting the blocks for
    writeback_all

 drivers/md/dm-writecache.c | 24 ++++++++++++++++++------
 1 file changed, 18 insertions(+), 6 deletions(-)

-- 
1.8.3.1



^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH 1/3] dm writecache: remove unused member pointer in writeback_struct
  2019-08-25  7:24 [PATCH 0/3] optimize writecache_writeback for performance Huaisheng Ye
@ 2019-08-25  7:24 ` Huaisheng Ye
  2019-08-25  7:24 ` [PATCH 2/3] dm writecache: add unlikely for getting two block with same LBA Huaisheng Ye
  2019-08-25  7:24 ` [PATCH 3/3] dm writecache: optimize performance by sorting the blocks for writeback_all Huaisheng Ye
  2 siblings, 0 replies; 4+ messages in thread
From: Huaisheng Ye @ 2019-08-25  7:24 UTC (permalink / raw)
  To: mpatocka, snitzer, agk; +Cc: prarit, tyu1, dm-devel, linux-kernel, Huaisheng Ye

From: Huaisheng Ye <yehs1@lenovo.com>

The stucture member pointer page in writeback_struct never has been
used actually. Remove it.

Signed-off-by: Huaisheng Ye <yehs1@lenovo.com>
Acked-by: Mikulas Patocka <mpatocka@redhat.com>
---
 drivers/md/dm-writecache.c | 1 -
 1 file changed, 1 deletion(-)

diff --git a/drivers/md/dm-writecache.c b/drivers/md/dm-writecache.c
index 1cb137f..5c7009d 100644
--- a/drivers/md/dm-writecache.c
+++ b/drivers/md/dm-writecache.c
@@ -190,7 +190,6 @@ struct writeback_struct {
 	struct dm_writecache *wc;
 	struct wc_entry **wc_list;
 	unsigned wc_list_n;
-	struct page *page;
 	struct wc_entry *wc_list_inline[WB_LIST_INLINE];
 	struct bio bio;
 };
-- 
1.8.3.1



^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH 2/3] dm writecache: add unlikely for getting two block with same LBA
  2019-08-25  7:24 [PATCH 0/3] optimize writecache_writeback for performance Huaisheng Ye
  2019-08-25  7:24 ` [PATCH 1/3] dm writecache: remove unused member pointer in writeback_struct Huaisheng Ye
@ 2019-08-25  7:24 ` Huaisheng Ye
  2019-08-25  7:24 ` [PATCH 3/3] dm writecache: optimize performance by sorting the blocks for writeback_all Huaisheng Ye
  2 siblings, 0 replies; 4+ messages in thread
From: Huaisheng Ye @ 2019-08-25  7:24 UTC (permalink / raw)
  To: mpatocka, snitzer, agk; +Cc: prarit, tyu1, dm-devel, linux-kernel, Huaisheng Ye

From: Huaisheng Ye <yehs1@lenovo.com>

In function writecache_writeback, entries g and f has same original
sector only happens at entry f has been committed, but entry g has
NOT yet.

The probability of this happening is very low in the following
256 blocks at most of entry e.

Signed-off-by: Huaisheng Ye <yehs1@lenovo.com>
Acked-by: Mikulas Patocka <mpatocka@redhat.com>
---
 drivers/md/dm-writecache.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/md/dm-writecache.c b/drivers/md/dm-writecache.c
index 5c7009d..3643084 100644
--- a/drivers/md/dm-writecache.c
+++ b/drivers/md/dm-writecache.c
@@ -1628,8 +1628,8 @@ static void writecache_writeback(struct work_struct *work)
 			if (unlikely(!next_node))
 				break;
 			g = container_of(next_node, struct wc_entry, rb_node);
-			if (read_original_sector(wc, g) ==
-			    read_original_sector(wc, f)) {
+			if (unlikely(read_original_sector(wc, g) ==
+			    read_original_sector(wc, f))) {
 				f = g;
 				continue;
 			}
-- 
1.8.3.1



^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH 3/3] dm writecache: optimize performance by sorting the blocks for writeback_all
  2019-08-25  7:24 [PATCH 0/3] optimize writecache_writeback for performance Huaisheng Ye
  2019-08-25  7:24 ` [PATCH 1/3] dm writecache: remove unused member pointer in writeback_struct Huaisheng Ye
  2019-08-25  7:24 ` [PATCH 2/3] dm writecache: add unlikely for getting two block with same LBA Huaisheng Ye
@ 2019-08-25  7:24 ` Huaisheng Ye
  2 siblings, 0 replies; 4+ messages in thread
From: Huaisheng Ye @ 2019-08-25  7:24 UTC (permalink / raw)
  To: mpatocka, snitzer, agk; +Cc: prarit, tyu1, dm-devel, linux-kernel, Huaisheng Ye

From: Huaisheng Ye <yehs1@lenovo.com>

During the process of writeback, the blocks, which have been placed in wbl.list
for writeback soon, are partially ordered for the contiguous ones.

When writeback_all has been set, for most cases, also by default, there will be
a lot of blocks in pmem need to writeback at the same time.
For this case, we could optimize the performance by sorting all blocks in
wbl.list. writecache_writeback doesn't need to get blocks from the tail of
wc->lru, whereas from the first rb_node from the rb_tree.

The benefit is that, writecache_writeback doesn't need to have any cost to sort
the blocks, because of all blocks are incremental originally in rb_tree.
There will be a writecache_flush when writeback_all begins to work, that will
eliminate duplicate blocks in cache by committed/uncommitted.

Testing platform: Thinksystem SR630 with persistent memory.
The cache comes from pmem, which has 1006MB size. The origin device is HDD, 2GB
of which for using.

Testing steps:
 1) dmsetup create mycache --table '0 4194304 writecache p /dev/sdb1 /dev/pmem4  4096 0'
 2) fio -filename=/dev/mapper/mycache -direct=1 -iodepth=20 -rw=randwrite
 -ioengine=libaio -bs=4k -loops=1  -size=2g -group_reporting -name=mytest1
 3) time dmsetup message /dev/mapper/mycache 0 flush

Here is the results below,
With the patch:
 # fio -filename=/dev/mapper/mycache -direct=1 -iodepth=20 -rw=randwrite
 -ioengine=libaio -bs=4k -loops=1  -size=2g -group_reporting -name=mytest1
   iops        : min= 1582, max=199470, avg=5305.94, stdev=21273.44, samples=197
 # time dmsetup message /dev/mapper/mycache 0 flush
real	0m44.020s
user	0m0.002s
sys	0m0.003s

Without the patch:
 # fio -filename=/dev/mapper/mycache -direct=1 -iodepth=20 -rw=randwrite
 -ioengine=libaio -bs=4k -loops=1  -size=2g -group_reporting -name=mytest1
   iops        : min= 1202, max=197650, avg=4968.67, stdev=20480.17, samples=211
 # time dmsetup message /dev/mapper/mycache 0 flush
real	1m39.221s
user	0m0.001s
sys	0m0.003s

I also have checked the data accuracy with this patch by making EXT4 filesystem
on mycache, then mount it for checking md5 of files on that.
The test result is positive, with this patch it could save more than half of time
when writeback_all.

Signed-off-by: Huaisheng Ye <yehs1@lenovo.com>
---
 drivers/md/dm-writecache.c | 19 ++++++++++++++++---
 1 file changed, 16 insertions(+), 3 deletions(-)

diff --git a/drivers/md/dm-writecache.c b/drivers/md/dm-writecache.c
index 3643084..c481947 100644
--- a/drivers/md/dm-writecache.c
+++ b/drivers/md/dm-writecache.c
@@ -1560,7 +1560,7 @@ static void writecache_writeback(struct work_struct *work)
 {
 	struct dm_writecache *wc = container_of(work, struct dm_writecache, writeback_work);
 	struct blk_plug plug;
-	struct wc_entry *e, *f, *g;
+	struct wc_entry *f, *g, *e = NULL;
 	struct rb_node *node, *next_node;
 	struct list_head skipped;
 	struct writeback_list wbl;
@@ -1597,7 +1597,14 @@ static void writecache_writeback(struct work_struct *work)
 			break;
 		}
 
-		e = container_of(wc->lru.prev, struct wc_entry, lru);
+		if (unlikely(wc->writeback_all)) {
+			if (unlikely(!e)) {
+				writecache_flush(wc);
+				e = container_of(rb_first(&wc->tree), struct wc_entry, rb_node);
+			} else
+				e = g;
+		} else
+			e = container_of(wc->lru.prev, struct wc_entry, lru);
 		BUG_ON(e->write_in_progress);
 		if (unlikely(!writecache_entry_is_committed(wc, e))) {
 			writecache_flush(wc);
@@ -1658,8 +1665,14 @@ static void writecache_writeback(struct work_struct *work)
 			g->wc_list_contiguous = BIO_MAX_PAGES;
 			f = g;
 			e->wc_list_contiguous++;
-			if (unlikely(e->wc_list_contiguous == BIO_MAX_PAGES))
+			if (unlikely(e->wc_list_contiguous == BIO_MAX_PAGES)) {
+				if (unlikely(wc->writeback_all)) {
+					next_node = rb_next(&f->rb_node);
+					if (likely(next_node))
+						g = container_of(next_node, struct wc_entry, rb_node);
+				}
 				break;
+			}
 		}
 		cond_resched();
 	}
-- 
1.8.3.1



^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2019-08-25  7:25 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-08-25  7:24 [PATCH 0/3] optimize writecache_writeback for performance Huaisheng Ye
2019-08-25  7:24 ` [PATCH 1/3] dm writecache: remove unused member pointer in writeback_struct Huaisheng Ye
2019-08-25  7:24 ` [PATCH 2/3] dm writecache: add unlikely for getting two block with same LBA Huaisheng Ye
2019-08-25  7:24 ` [PATCH 3/3] dm writecache: optimize performance by sorting the blocks for writeback_all Huaisheng Ye

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).