[Devel] [RFC PATCH vz9 1/5] ploop: Use READ_ONCE/WRITE_ONCE to access md page data
Alexander Atanasov
alexander.atanasov at virtuozzo.com
Mon Oct 7 14:12:04 MSK 2024
Prepare to reduce locking by using atomic 32 bit access to the fields.
To ensure this we need to use the _ONCE macros.
https://virtuozzo.atlassian.net/browse/VSTOR-91659
Signed-off-by: Alexander Atanasov <alexander.atanasov at virtuozzo.com>
---
drivers/md/dm-ploop-bat.c | 2 +-
drivers/md/dm-ploop-map.c | 18 +++++++++---------
2 files changed, 10 insertions(+), 10 deletions(-)
diff --git a/drivers/md/dm-ploop-bat.c b/drivers/md/dm-ploop-bat.c
index 30c9e45ccf2f..0fce5ed998d6 100644
--- a/drivers/md/dm-ploop-bat.c
+++ b/drivers/md/dm-ploop-bat.c
@@ -143,7 +143,7 @@ bool ploop_try_update_bat_entry(struct ploop *ploop, u32 clu, u8 level, u32 dst_
clu = ploop_bat_clu_idx_in_page(clu); /* relative offset */
- if (md->bat_levels[clu] == level) {
+ if (READ_ONCE(md->bat_levels[clu]) == level) {
bat_entries = md->kmpage;
WRITE_ONCE(bat_entries[clu], dst_clu);
return true;
diff --git a/drivers/md/dm-ploop-map.c b/drivers/md/dm-ploop-map.c
index 481ca6556d69..9f7efed45c2a 100644
--- a/drivers/md/dm-ploop-map.c
+++ b/drivers/md/dm-ploop-map.c
@@ -724,9 +724,9 @@ static void ploop_release_cluster(struct ploop *ploop, u32 clu)
clu = ploop_bat_clu_idx_in_page(clu); /* relative to page */
bat_entries = md->kmpage;
- dst_clu = bat_entries[clu];
- bat_entries[clu] = BAT_ENTRY_NONE;
- md->bat_levels[clu] = 0;
+ dst_clu = READ_ONCE(bat_entries[clu]);
+ WRITE_ONCE(bat_entries[clu], BAT_ENTRY_NONE);
+ WRITE_ONCE(md->bat_levels[clu], 0);
ploop_hole_set_bit(dst_clu, ploop);
}
@@ -794,8 +794,8 @@ static void ploop_advance_local_after_bat_wb(struct ploop *ploop,
}
if (success) {
- bat_entries[i] = dst_clu[i];
- md->bat_levels[i] = ploop_top_level(ploop);
+ bat_entries[i] = READ_ONCE(dst_clu[i]);
+ WRITE_ONCE(md->bat_levels[i], ploop_top_level(ploop));
} else {
ploop_hole_set_bit(i + off, ploop);
}
@@ -1090,9 +1090,9 @@ static int ploop_alloc_cluster(struct ploop *ploop, struct ploop_index_wb *piwb,
clu -= piwb->page_id * PAGE_SIZE / sizeof(map_index_t) - PLOOP_MAP_OFFSET;
to = piwb->kmpage;
- if (to[clu]) {
+ if (READ_ONCE(to[clu])) {
/* Already mapped by one of previous bios */
- *dst_clu = to[clu];
+ *dst_clu = READ_ONCE(to[clu]);
already_alloced = true;
}
@@ -1104,7 +1104,7 @@ static int ploop_alloc_cluster(struct ploop *ploop, struct ploop_index_wb *piwb,
goto out;
to = piwb->kmpage;
- to[clu] = *dst_clu;
+ WRITE_ONCE(to[clu], *dst_clu);
out:
return ret;
}
@@ -1386,7 +1386,7 @@ static void ploop_submit_cow_index_wb(struct ploop_cow *cow)
to = piwb->kmpage;
WARN_ON(to[clu]);
- to[clu] = cow->dst_clu;
+ WRITE_ONCE(to[clu], cow->dst_clu);
/* Prevent double clearing of holes_bitmap bit on complete_cow() */
cow->dst_clu = BAT_ENTRY_NONE;
--
2.43.0
More information about the Devel
mailing list