bcachefs: Add missing smp_rmb()
PATCH 1/2 bcachefs: Add missing smp_rmb()
The smp_rmb() guarantees that reads from reservations.counter occur before accessing cur_entry_u64s. It's paired with the atomic64_try_cmpxchg in journal_entry_open.
--- fs/bcachefs/journal.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
fs/bcachefs/journal.h +3 -1
@@ -350,8 +350,10 @@ static inline int journal_res_get_fast(struct journal *j,/* * Check if there is still room in the current journal -* entry: +* entry, smp_rmb() guarantees that reads from reservations.counter +* occur before accessing cur_entry_u64s: */ +smp_rmb ();if (new.cur_entry_offset + res->u64s > j->cur_entry_u64s)return 0 ;
Signature · 1 line
2.48.1
PATCH 2/2 bcachefs: Remove spurious smp_mb()
The smp_mb() is paired with nothing.
--- fs/bcachefs/journal.c | 1 - 1 file changed, 1 deletion(-)
fs/bcachefs/journal.c +0 -1
@@ -761,7 +761,6 @@ void bch2_journal_entry_res_resize(struct journal *j, goto out; j->cur_entry_u64s =max_t (int,0 , j->cur_entry_u64s - d); -smp_mb (); state =READ_ONCE (j->reservations); if (state.cur_entry_offset < JOURNAL_ENTRY_CLOSED_VAL &&
Signature · 1 line
2.48.1
Kent Overstreet
AppliedRe: [PATCH 2/2] bcachefs: Remove spurious smp_mb()
Quoted 3 lines · Alan Huang
The
smp_mb()is paired with nothing.Signed-off-by Alan Huang <[email protected]>
Applied
Quoted 19 lines
--- fs/bcachefs/journal.c | 1 - 1 file changed, 1 deletion(-)fs/bcachefs/journal.c +0
-1@@ -761,7 +761,6 @@ void bch2_journal_entry_res_resize(struct journal *j, goto out; j->cur_entry_u64s =max_t (int,0 , j->cur_entry_u64s - d); -smp_mb (); state =READ_ONCE (j->reservations); if (state.cur_entry_offset < JOURNAL_ENTRY_CLOSED_VAL &&Signature · 1 line
2.48.1
Quoted 5 lines · Alan Huang
The
smp_rmb()guarantees that reads from reservations.counter occur before accessingcur_entry_u64s. It's paired with theatomic64_try_cmpxchginjournal_entry_open.Signed-off-by Alan Huang <[email protected]>
It would also work to recheck j->cur_entry_u64s after the cmxpchg() and acquiring the journal reservation, backing out in the event of a race.
This is performance sensitive enough that we may want to test both options, as well as moving cur_entry_u64s to the same cacheline as the journal reservation state.
Quoted 23 lines
--- fs/bcachefs/journal.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)fs/bcachefs/journal.h +3
-1@@ -350,8 +350,10 @@ static inline int journal_res_get_fast(struct journal *j,/* * Check if there is still room in the current journal -* entry: +* entry, smp_rmb() guarantees that reads from reservations.counter +* occur before accessing cur_entry_u64s: */ +smp_rmb ();if (new.cur_entry_offset + res->u64s > j->cur_entry_u64s)return 0 ;Signature · 1 line
2.48.1