All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] dm-integrity: fix inefficient allocation of stack space
@ 2017-07-19 15:23 Mikulas Patocka
  2017-07-19 18:39 ` John Stoffel
  0 siblings, 1 reply; 12+ messages in thread
From: Mikulas Patocka @ 2017-07-19 15:23 UTC (permalink / raw)
  To: Mike Snitzer, Milan Broz; +Cc: dm-devel

When using block size greater than 512 bytes, the dm-integrity target
allocates journal space inefficiently, it allocates one entry for each
512-byte chunk of data, fills entries for each block of data and leaves
the remaining entries unused. This doesn't cause data corruption, but it
causes severe performance degradation.

This patch fixes the journal allocation. As a safety it also adds BUG that
fires if the variables representing journal usage get out of sync (it's
better to crash than continue and corrupt data, so BUG is justified).

Signed-off-by: Mikulas Patocka <mpatocka@redhat.com>
Cc: stable@vger.kernel.org
Fixes: 7eada909bfd7 ("dm: add integrity target")

---
 drivers/md/dm-integrity.c |    7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

Index: linux-2.6/drivers/md/dm-integrity.c
===================================================================
--- linux-2.6.orig/drivers/md/dm-integrity.c
+++ linux-2.6/drivers/md/dm-integrity.c
@@ -1589,14 +1589,14 @@ retry:
 			unsigned next_entry, i, pos;
 			unsigned ws, we;
 
-			dio->range.n_sectors = min(dio->range.n_sectors, ic->free_sectors);
+			dio->range.n_sectors = min(dio->range.n_sectors, ic->free_sectors << ic->sb->log2_sectors_per_block);
 			if (unlikely(!dio->range.n_sectors))
 				goto sleep;
-			ic->free_sectors -= dio->range.n_sectors;
+			ic->free_sectors -= dio->range.n_sectors >> ic->sb->log2_sectors_per_block;
 			journal_section = ic->free_section;
 			journal_entry = ic->free_section_entry;
 
-			next_entry = ic->free_section_entry + dio->range.n_sectors;
+			next_entry = ic->free_section_entry + (dio->range.n_sectors >> ic->sb->log2_sectors_per_block);
 			ic->free_section_entry = next_entry % ic->journal_section_entries;
 			ic->free_section += next_entry / ic->journal_section_entries;
 			ic->n_uncommitted_sections += next_entry / ic->journal_section_entries;
@@ -1727,6 +1727,7 @@ static void pad_uncommitted(struct dm_in
 		wraparound_section(ic, &ic->free_section);
 		ic->n_uncommitted_sections++;
 	}
+	BUG_ON((ic->n_uncommitted_sections + ic->n_committed_sections) * ic->journal_section_entries + ic->free_sectors != ic->journal_sections * ic->journal_section_entries);
 }
 
 static void integrity_commit(struct work_struct *w)

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

end of thread, other threads:[~2017-07-21 12:29 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-07-19 15:23 [PATCH] dm-integrity: fix inefficient allocation of stack space Mikulas Patocka
2017-07-19 18:39 ` John Stoffel
2017-07-19 19:02   ` Mike Snitzer
2017-07-19 21:07     ` John Stoffel
2017-07-20 10:59       ` Mikulas Patocka
2017-07-20 11:25         ` Mikulas Patocka
     [not found]           ` <22896.56378.568488.989656@quad.stoffel.home>
2017-07-21 12:15             ` Mikulas Patocka
2017-07-20 15:46         ` John Stoffel
2017-07-20 10:45     ` Mikulas Patocka
2017-07-20 10:26   ` [PATCH] " Mikulas Patocka
2017-07-20 15:43     ` John Stoffel
2017-07-21 12:29       ` Mikulas Patocka

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.