diff options
author | Kent Overstreet <kent.overstreet@gmail.com> | 2018-02-07 05:12:22 -0500 |
---|---|---|
committer | Kent Overstreet <kent.overstreet@gmail.com> | 2018-03-06 15:27:06 -0500 |
commit | 728326ec0af72bc7457c539d71fae09a54ef6abb (patch) | |
tree | 3f79c5c54ebea1e8958231de79dfda2a34b5a006 | |
parent | 54fb0e10e1317285fa71a59d3b182d082b318959 (diff) |
bcachefs: cacheline align journal reservations
-rw-r--r-- | fs/bcachefs/btree_update_leaf.c | 4 | ||||
-rw-r--r-- | fs/bcachefs/journal.c | 26 | ||||
-rw-r--r-- | fs/bcachefs/journal.h | 25 |
3 files changed, 25 insertions, 30 deletions
diff --git a/fs/bcachefs/btree_update_leaf.c b/fs/bcachefs/btree_update_leaf.c index 852310de94d6..956d56dbd1cb 100644 --- a/fs/bcachefs/btree_update_leaf.c +++ b/fs/bcachefs/btree_update_leaf.c @@ -336,9 +336,7 @@ retry: memset(&trans->journal_res, 0, sizeof(trans->journal_res)); ret = !(trans->flags & BTREE_INSERT_JOURNAL_REPLAY) - ? bch2_journal_res_get(&c->journal, - &trans->journal_res, - u64s, u64s) + ? bch2_journal_res_get(&c->journal, &trans->journal_res, u64s) : 0; if (ret) goto err; diff --git a/fs/bcachefs/journal.c b/fs/bcachefs/journal.c index ea8a6282ad26..ca39a729f026 100644 --- a/fs/bcachefs/journal.c +++ b/fs/bcachefs/journal.c @@ -2466,13 +2466,13 @@ u64 bch2_inode_journal_seq(struct journal *j, u64 inode) } static int __journal_res_get(struct journal *j, struct journal_res *res, - unsigned u64s_min, unsigned u64s_max) + unsigned u64s) { struct bch_fs *c = container_of(j, struct bch_fs, journal); struct journal_buf *buf; int ret; retry: - ret = journal_res_get_fast(j, res, u64s_min, u64s_max); + ret = journal_res_get_fast(j, res, u64s); if (ret) return ret; @@ -2482,7 +2482,7 @@ retry: * that just did journal_entry_open() and call journal_entry_close() * unnecessarily */ - ret = journal_res_get_fast(j, res, u64s_min, u64s_max); + ret = journal_res_get_fast(j, res, u64s); if (ret) { spin_unlock(&j->lock); return 1; @@ -2553,13 +2553,11 @@ blocked: * btree node write locks. */ int bch2_journal_res_get_slowpath(struct journal *j, struct journal_res *res, - unsigned u64s_min, unsigned u64s_max) + unsigned u64s) { int ret; - wait_event(j->wait, - (ret = __journal_res_get(j, res, u64s_min, - u64s_max))); + wait_event(j->wait, (ret = __journal_res_get(j, res, u64s))); return ret < 0 ? ret : 0; } @@ -2750,12 +2748,9 @@ int bch2_journal_flush_seq(struct journal *j, u64 seq) void bch2_journal_meta_async(struct journal *j, struct closure *parent) { - struct journal_res res; - unsigned u64s = jset_u64s(0); + struct journal_res res = { 0 }; - memset(&res, 0, sizeof(res)); - - bch2_journal_res_get(j, &res, u64s, u64s); + bch2_journal_res_get(j, &res, jset_u64s(0)); bch2_journal_res_put(j, &res); bch2_journal_flush_seq_async(j, res.seq, parent); @@ -2763,13 +2758,10 @@ void bch2_journal_meta_async(struct journal *j, struct closure *parent) int bch2_journal_meta(struct journal *j) { - struct journal_res res; - unsigned u64s = jset_u64s(0); + struct journal_res res = { 0 }; int ret; - memset(&res, 0, sizeof(res)); - - ret = bch2_journal_res_get(j, &res, u64s, u64s); + ret = bch2_journal_res_get(j, &res, jset_u64s(0)); if (ret) return ret; diff --git a/fs/bcachefs/journal.h b/fs/bcachefs/journal.h index 46ae8f0d256d..744eed1ea4a4 100644 --- a/fs/bcachefs/journal.h +++ b/fs/bcachefs/journal.h @@ -283,7 +283,7 @@ static inline void bch2_journal_buf_put(struct journal *j, unsigned idx, * then proceed to add their keys as well. */ static inline void bch2_journal_res_put(struct journal *j, - struct journal_res *res) + struct journal_res *res) { if (!res->ref) return; @@ -301,28 +301,34 @@ static inline void bch2_journal_res_put(struct journal *j, } int bch2_journal_res_get_slowpath(struct journal *, struct journal_res *, - unsigned, unsigned); + unsigned); static inline int journal_res_get_fast(struct journal *j, struct journal_res *res, - unsigned u64s_min, - unsigned u64s_max) + unsigned u64s) { union journal_res_state old, new; u64 v = atomic64_read(&j->reservations.counter); + unsigned end_offset, u64s_padded; do { old.v = new.v = v; + end_offset = (offsetof(struct jset, start) / sizeof(u64) + + old.cur_entry_offset + u64s); + u64s_padded = u64s + + round_up(end_offset, INTERNODE_CACHE_BYTES / sizeof(u64)) - + end_offset; + /* * Check if there is still room in the current journal * entry: */ - if (old.cur_entry_offset + u64s_min > j->cur_entry_u64s) + if (old.cur_entry_offset + u64s > j->cur_entry_u64s) return 0; res->offset = old.cur_entry_offset; - res->u64s = min(u64s_max, j->cur_entry_u64s - + res->u64s = min(u64s_padded, j->cur_entry_u64s - old.cur_entry_offset); journal_state_inc(&new); @@ -337,18 +343,17 @@ static inline int journal_res_get_fast(struct journal *j, } static inline int bch2_journal_res_get(struct journal *j, struct journal_res *res, - unsigned u64s_min, unsigned u64s_max) + unsigned u64s) { int ret; EBUG_ON(res->ref); - EBUG_ON(u64s_max < u64s_min); EBUG_ON(!test_bit(JOURNAL_STARTED, &j->flags)); - if (journal_res_get_fast(j, res, u64s_min, u64s_max)) + if (journal_res_get_fast(j, res, u64s)) goto out; - ret = bch2_journal_res_get_slowpath(j, res, u64s_min, u64s_max); + ret = bch2_journal_res_get_slowpath(j, res, u64s); if (ret) return ret; out: |