<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">From: Joe Thornber &lt;ejt@redhat.com&gt;

Introduce bitmap_index_changed to track whether or not the index changed
then only commit a space map if it did.

Signed-off-by: Joe Thornber &lt;ejt@redhat.com&gt;
Signed-off-by: Mike Snitzer &lt;snitzer@redhat.com&gt;
Signed-off-by: Alasdair G Kergon &lt;agk@redhat.com&gt;

---
 drivers/md/persistent-data/dm-space-map-common.c |   12 +++++++++++-
 drivers/md/persistent-data/dm-space-map-common.h |    1 +
 2 files changed, 12 insertions(+), 1 deletion(-)

Index: linux/drivers/md/persistent-data/dm-space-map-common.c
===================================================================
--- linux.orig/drivers/md/persistent-data/dm-space-map-common.c
+++ linux/drivers/md/persistent-data/dm-space-map-common.c
@@ -224,6 +224,7 @@ static int sm_ll_init(struct ll_disk *ll
 	ll-&gt;nr_blocks = 0;
 	ll-&gt;bitmap_root = 0;
 	ll-&gt;ref_count_root = 0;
+	ll-&gt;bitmap_index_changed = false;
 
 	return 0;
 }
@@ -476,7 +477,15 @@ int sm_ll_dec(struct ll_disk *ll, dm_blo
 
 int sm_ll_commit(struct ll_disk *ll)
 {
-	return ll-&gt;commit(ll);
+	int r = 0;
+
+	if (ll-&gt;bitmap_index_changed) {
+		r = ll-&gt;commit(ll);
+		if (!r)
+			ll-&gt;bitmap_index_changed = false;
+	}
+
+	return r;
 }
 
 /*----------------------------------------------------------------*/
@@ -491,6 +500,7 @@ static int metadata_ll_load_ie(struct ll
 static int metadata_ll_save_ie(struct ll_disk *ll, dm_block_t index,
 			       struct disk_index_entry *ie)
 {
+	ll-&gt;bitmap_index_changed = true;
 	memcpy(ll-&gt;mi_le.index + index, ie, sizeof(*ie));
 	return 0;
 }
Index: linux/drivers/md/persistent-data/dm-space-map-common.h
===================================================================
--- linux.orig/drivers/md/persistent-data/dm-space-map-common.h
+++ linux/drivers/md/persistent-data/dm-space-map-common.h
@@ -78,6 +78,7 @@ struct ll_disk {
 	open_index_fn open_index;
 	max_index_entries_fn max_entries;
 	commit_fn commit;
+	bool bitmap_index_changed:1;
 };
 
 struct disk_sm_root {
</pre></body></html>