On Tue, Mar 18, 2025 at 03:50:00PM +0800, Alan Huang wrote: > 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. > > 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. > --- > fs/bcachefs/journal.h | 4 +++- > 1 file changed, 3 insertions(+), 1 deletion(-) > > diff --git a/fs/bcachefs/journal.h b/fs/bcachefs/journal.h > index ab68c5c4d8d8..47828771f9c2 100644 > --- a/fs/bcachefs/journal.h > +++ b/fs/bcachefs/journal.h > @@ -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; > > -- > 2.48.1 >
