Skip to contentSkip to conversation

Fix fallout from changes to FUA and PREFLUSH definitions

PATCH Applied Jan Kara 3 participants 5 messages May 31, 2017

Subsystems (3)
lore
Share & tools
lore

Jan Kara

author
#0 lore raw

v2 cover Fix fallout from changes to FUA and PREFLUSH definitions

Hello,

here are patches for DM/MD that address a possible performance issue caused by commit b685d3d65ac7 "block: treat REQ_FUA and REQ_PREFLUSH as synchronous".

The core of the problem is that above mentioned commit removed REQ_SYNC flag from WRITE_{FUA|PREFLUSH|...} definitions. generic_make_request_checks() however strips REQ_FUA and REQ_PREFLUSH flags from a bio when the storage doesn't report volatile write cache and thus write effectively becomes asynchronous which can lead to performance regressions.

DM/MD guys, can you please have a look at patches and take them through your trees? Thanks!

Honza

author
#1 lore raw

PATCH v2 1/2 dm: Make flush bios explicitely sync

Commit b685d3d65ac7 "block: treat REQ_FUA and REQ_PREFLUSH as synchronous" removed REQ_SYNC flag from WRITE_{FUA|PREFLUSH|...} definitions. generic_make_request_checks() however strips REQ_FUA and REQ_PREFLUSH flags from a bio when the storage doesn't report volatile write cache and thus write effectively becomes asynchronous which can lead to performance regressions

Fix the problem by making sure all bios which are synchronous are properly marked with REQ_SYNC.

CC Mike Snitzer <[email protected]>
Fixes b685d3d65ac791406e0dfd8779cc9b3707fea5a3
---
 drivers/md/dm-bufio.c           | 2 +-
 drivers/md/dm-integrity.c       | 3 ++-
 drivers/md/dm-raid1.c           | 2 +-
 drivers/md/dm-snap-persistent.c | 3 ++-
 drivers/md/dm.c                 | 2 +-
 5 files changed, 7 insertions(+), 5 deletions(-)
drivers/md/dm-bufio.c +1 -1
index cd8139593ccd..840c1496b2b1 100644
@@ -1334,7 +1334,7 @@ int dm_bufio_issue_flush(struct dm_bufio_client *c)
 {
 	struct dm_io_request io_req = {
 		.bi_op = REQ_OP_WRITE,
-		.bi_op_flags = REQ_PREFLUSH,
+		.bi_op_flags = REQ_PREFLUSH | REQ_SYNC,
 		.mem.type = DM_IO_KMEM,
 		.mem.ptr.addr = NULL,
 		.client = c->dm_io,
drivers/md/dm-integrity.c +2 -1
index c7f7c8d76576..923323e22320 100644
@@ -783,7 +783,8 @@ static void write_journal(struct dm_integrity_c *ic, unsigned commit_start, unsi
 			for (i = 0; i < commit_sections; i++)
 				rw_section_mac(ic, commit_start + i, true);
 		}
-		rw_journal(ic, REQ_OP_WRITE, REQ_FUA, commit_start, commit_sections, &io_comp);
+		rw_journal(ic, REQ_OP_WRITE, REQ_FUA | REQ_SYNC, commit_start,
+			   commit_sections, &io_comp);
 	} else {
 		unsigned to_end;
 		io_comp.in_flight = (atomic_t)ATOMIC_INIT(2);
drivers/md/dm-raid1.c +1 -1
index a95cbb80fb34..e61c45047c25 100644
@@ -260,7 +260,7 @@ static int mirror_flush(struct dm_target *ti)
 	struct mirror *m;
 	struct dm_io_request io_req = {
 		.bi_op = REQ_OP_WRITE,
-		.bi_op_flags = REQ_PREFLUSH,
+		.bi_op_flags = REQ_PREFLUSH | REQ_SYNC,
 		.mem.type = DM_IO_KMEM,
 		.mem.ptr.addr = NULL,
 		.client = ms->io_client,
drivers/md/dm-snap-persistent.c +2 -1
index b93476c3ba3f..c5534d294773 100644
@@ -741,7 +741,8 @@ static void persistent_commit_exception(struct dm_exception_store *store,
 	/*
 	 * Commit exceptions to disk.
 	 */
-	if (ps->valid && area_io(ps, REQ_OP_WRITE, REQ_PREFLUSH | REQ_FUA))
+	if (ps->valid && area_io(ps, REQ_OP_WRITE,
+				 REQ_PREFLUSH | REQ_FUA | REQ_SYNC))
 		ps->valid = 0;
 
 	/*
drivers/md/dm.c +1 -1
index 6ef9500226c0..37ccd73c79ec 100644
@@ -1657,7 +1657,7 @@ static struct mapped_device *alloc_dev(int minor)
 
 	bio_init(&md->flush_bio, NULL, 0);
 	md->flush_bio.bi_bdev = md->bdev;
-	md->flush_bio.bi_opf = REQ_OP_WRITE | REQ_PREFLUSH;
+	md->flush_bio.bi_opf = REQ_OP_WRITE | REQ_PREFLUSH | REQ_SYNC;
 
 	dm_stats_init(&md->stats);
 
Signature · 1 line
2.12.3
#2 lore raw

Re: [PATCH 1/2] dm: Make flush bios explicitely sync

Quoted 7 lines · Jan Kara

Commit b685d3d65ac7 "block: treat REQ_FUA and REQ_PREFLUSH as synchronous" removed REQ_SYNC flag from WRITE_{FUA|PREFLUSH|...} definitions. generic_make_request_checks() however strips REQ_FUA and REQ_PREFLUSH flags from a bio when the storage doesn't report volatile write cache and thus write effectively becomes asynchronous which can lead to performance regressions

Quoted 8 lines

Fix the problem by making sure all bios which are synchronous are properly marked with REQ_SYNC.

CC Mike Snitzer <[email protected]>
Fixes b685d3d65ac791406e0dfd8779cc9b3707fea5a3

thanks, staged for 4.12-rc4

author
#3 lore raw

PATCH v2 2/2 md: Make flush bios explicitely sync

In reply to Jan Kara

Commit b685d3d65ac7 "block: treat REQ_FUA and REQ_PREFLUSH as synchronous" removed REQ_SYNC flag from WRITE_{FUA|PREFLUSH|...} definitions. generic_make_request_checks() however strips REQ_FUA and REQ_PREFLUSH flags from a bio when the storage doesn't report volatile write cache and thus write effectively becomes asynchronous which can lead to performance regressions

Fix the problem by making sure all bios which are synchronous are properly marked with REQ_SYNC.

CC Shaohua Li <[email protected]>
Fixes b685d3d65ac791406e0dfd8779cc9b3707fea5a3
---
 drivers/md/md.c          | 2 +-
 drivers/md/raid5-cache.c | 4 ++--
 drivers/md/raid5-ppl.c   | 4 ++--
 3 files changed, 5 insertions(+), 5 deletions(-)
drivers/md/md.c +1 -1
index 10367ffe92e3..212a6777ff31 100644
@@ -765,7 +765,7 @@ void md_super_write(struct mddev *mddev, struct md_rdev *rdev,
 	    test_bit(FailFast, &rdev->flags) &&
 	    !test_bit(LastDev, &rdev->flags))
 		ff = MD_FAILFAST;
-	bio->bi_opf = REQ_OP_WRITE | REQ_PREFLUSH | REQ_FUA | ff;
+	bio->bi_opf = REQ_OP_WRITE | REQ_SYNC | REQ_PREFLUSH | REQ_FUA | ff;
 
 	atomic_inc(&mddev->pending_writes);
 	submit_bio(bio);
drivers/md/raid5-cache.c +2 -2
index 4c00bc248287..0a7af8b0a80a 100644
@@ -1782,7 +1782,7 @@ static int r5l_log_write_empty_meta_block(struct r5l_log *log, sector_t pos,
 	mb->checksum = cpu_to_le32(crc32c_le(log->uuid_checksum,
 					     mb, PAGE_SIZE));
 	if (!sync_page_io(log->rdev, pos, PAGE_SIZE, page, REQ_OP_WRITE,
-			  REQ_FUA, false)) {
+			  REQ_SYNC | REQ_FUA, false)) {
 		__free_page(page);
 		return -EIO;
 	}
@@ -2388,7 +2388,7 @@ r5c_recovery_rewrite_data_only_stripes(struct r5l_log *log,
 		mb->checksum = cpu_to_le32(crc32c_le(log->uuid_checksum,
 						     mb, PAGE_SIZE));
 		sync_page_io(log->rdev, ctx->pos, PAGE_SIZE, page,
-			     REQ_OP_WRITE, REQ_FUA, false);
+			     REQ_OP_WRITE, REQ_SYNC | REQ_FUA, false);
 		sh->log_start = ctx->pos;
 		list_add_tail(&sh->r5c, &log->stripe_in_journal_list);
 		atomic_inc(&log->stripe_in_journal_count);
drivers/md/raid5-ppl.c +2 -2
index 5d25bebf3328..ccce92e68d7f 100644
@@ -907,8 +907,8 @@ static int ppl_write_empty_header(struct ppl_log *log)
 	pplhdr->checksum = cpu_to_le32(~crc32c_le(~0, pplhdr, PAGE_SIZE));
 
 	if (!sync_page_io(rdev, rdev->ppl.sector - rdev->data_offset,
-			  PPL_HEADER_SIZE, page, REQ_OP_WRITE | REQ_FUA, 0,
-			  false)) {
+			  PPL_HEADER_SIZE, page, REQ_OP_WRITE | REQ_SYNC |
+			  REQ_FUA, 0, false)) {
 		md_error(rdev->mddev, rdev);
 		ret = -EIO;
 	}
Signature · 1 line
2.12.3
Applied
#4 lore raw

Re: [PATCH 2/2] md: Make flush bios explicitely sync

Quoted 9 lines · Jan Kara

Commit b685d3d65ac7 "block: treat REQ_FUA and REQ_PREFLUSH as synchronous" removed REQ_SYNC flag from WRITE_{FUA|PREFLUSH|...} definitions. generic_make_request_checks() however strips REQ_FUA and REQ_PREFLUSH flags from a bio when the storage doesn't report volatile write cache and thus write effectively becomes asynchronous which can lead to performance regressions

Fix the problem by making sure all bios which are synchronous are properly marked with REQ_SYNC.

Applied, thanks!

Quoted 64 lines
CC Shaohua Li <[email protected]>
Fixes b685d3d65ac791406e0dfd8779cc9b3707fea5a3
---
 drivers/md/md.c          | 2 +-
 drivers/md/raid5-cache.c | 4 ++--
 drivers/md/raid5-ppl.c   | 4 ++--
 3 files changed, 5 insertions(+), 5 deletions(-)
drivers/md/md.c +1 -1
index 10367ffe92e3..212a6777ff31 100644
@@ -765,7 +765,7 @@ void md_super_write(struct mddev *mddev, struct md_rdev *rdev,
 	    test_bit(FailFast, &rdev->flags) &&
 	    !test_bit(LastDev, &rdev->flags))
 		ff = MD_FAILFAST;
-	bio->bi_opf = REQ_OP_WRITE | REQ_PREFLUSH | REQ_FUA | ff;
+	bio->bi_opf = REQ_OP_WRITE | REQ_SYNC | REQ_PREFLUSH | REQ_FUA | ff;
 
 	atomic_inc(&mddev->pending_writes);
 	submit_bio(bio);
drivers/md/raid5-cache.c +2 -2
index 4c00bc248287..0a7af8b0a80a 100644
@@ -1782,7 +1782,7 @@ static int r5l_log_write_empty_meta_block(struct r5l_log *log, sector_t pos,
 	mb->checksum = cpu_to_le32(crc32c_le(log->uuid_checksum,
 					     mb, PAGE_SIZE));
 	if (!sync_page_io(log->rdev, pos, PAGE_SIZE, page, REQ_OP_WRITE,
-			  REQ_FUA, false)) {
+			  REQ_SYNC | REQ_FUA, false)) {
 		__free_page(page);
 		return -EIO;
 	}
@@ -2388,7 +2388,7 @@ r5c_recovery_rewrite_data_only_stripes(struct r5l_log *log,
 		mb->checksum = cpu_to_le32(crc32c_le(log->uuid_checksum,
 						     mb, PAGE_SIZE));
 		sync_page_io(log->rdev, ctx->pos, PAGE_SIZE, page,
-			     REQ_OP_WRITE, REQ_FUA, false);
+			     REQ_OP_WRITE, REQ_SYNC | REQ_FUA, false);
 		sh->log_start = ctx->pos;
 		list_add_tail(&sh->r5c, &log->stripe_in_journal_list);
 		atomic_inc(&log->stripe_in_journal_count);
drivers/md/raid5-ppl.c +2 -2
index 5d25bebf3328..ccce92e68d7f 100644
@@ -907,8 +907,8 @@ static int ppl_write_empty_header(struct ppl_log *log)
 	pplhdr->checksum = cpu_to_le32(~crc32c_le(~0, pplhdr, PAGE_SIZE));
 
 	if (!sync_page_io(rdev, rdev->ppl.sector - rdev->data_offset,
-			  PPL_HEADER_SIZE, page, REQ_OP_WRITE | REQ_FUA, 0,
-			  false)) {
+			  PPL_HEADER_SIZE, page, REQ_OP_WRITE | REQ_SYNC |
+			  REQ_FUA, 0, false)) {
 		md_error(rdev->mddev, rdev);
 		ret = -EIO;
 	}
Signature · 1 line
2.12.3