Skip to content

Commit 769b360

Browse files
author
Kent Overstreet
committed
bcachefs: Don't iterate over journal entries just for btree roots
Small performance optimization, and a bit of a code cleanup too. Signed-off-by: Kent Overstreet <[email protected]>
1 parent 80396a4 commit 769b360

File tree

4 files changed

+29
-40
lines changed

4 files changed

+29
-40
lines changed

fs/bcachefs/btree_update_interior.c

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2418,23 +2418,17 @@ void bch2_journal_entry_to_btree_root(struct bch_fs *c, struct jset_entry *entry
24182418

24192419
struct jset_entry *
24202420
bch2_btree_roots_to_journal_entries(struct bch_fs *c,
2421-
struct jset_entry *start,
2422-
struct jset_entry *end)
2421+
struct jset_entry *end,
2422+
unsigned long skip)
24232423
{
2424-
struct jset_entry *entry;
2425-
unsigned long have = 0;
24262424
unsigned i;
24272425

2428-
for (entry = start; entry < end; entry = vstruct_next(entry))
2429-
if (entry->type == BCH_JSET_ENTRY_btree_root)
2430-
__set_bit(entry->btree_id, &have);
2431-
24322426
mutex_lock(&c->btree_root_lock);
24332427

24342428
for (i = 0; i < btree_id_nr_alive(c); i++) {
24352429
struct btree_root *r = bch2_btree_id_root(c, i);
24362430

2437-
if (r->alive && !test_bit(i, &have)) {
2431+
if (r->alive && !test_bit(i, &skip)) {
24382432
journal_entry_set(end, BCH_JSET_ENTRY_btree_root,
24392433
i, r->level, &r->key, r->key.k.u64s);
24402434
end = vstruct_next(end);

fs/bcachefs/btree_update_interior.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,7 @@ bool bch2_btree_interior_updates_flush(struct bch_fs *);
325325

326326
void bch2_journal_entry_to_btree_root(struct bch_fs *, struct jset_entry *);
327327
struct jset_entry *bch2_btree_roots_to_journal_entries(struct bch_fs *,
328-
struct jset_entry *, struct jset_entry *);
328+
struct jset_entry *, unsigned long);
329329

330330
void bch2_do_pending_node_rewrites(struct bch_fs *);
331331
void bch2_free_pending_node_rewrites(struct bch_fs *);

fs/bcachefs/journal_io.c

Lines changed: 24 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1678,9 +1678,15 @@ static void do_journal_write(struct closure *cl)
16781678
continue_at(cl, journal_write_done, c->io_complete_wq);
16791679
}
16801680

1681-
static void bch2_journal_entries_postprocess(struct bch_fs *c, struct jset *jset)
1681+
static int bch2_journal_write_prep(struct journal *j, struct journal_buf *w)
16821682
{
1683-
struct jset_entry *i, *next, *prev = NULL;
1683+
struct bch_fs *c = container_of(j, struct bch_fs, journal);
1684+
struct jset_entry *start, *end, *i, *next, *prev = NULL;
1685+
struct jset *jset = w->data;
1686+
unsigned sectors, bytes, u64s;
1687+
bool validate_before_checksum = false;
1688+
unsigned long btree_roots_have = 0;
1689+
int ret;
16841690

16851691
/*
16861692
* Simple compaction, dropping empty jset_entries (from journal
@@ -1697,8 +1703,20 @@ static void bch2_journal_entries_postprocess(struct bch_fs *c, struct jset *jset
16971703
if (!u64s)
16981704
continue;
16991705

1700-
if (i->type == BCH_JSET_ENTRY_btree_root)
1706+
/*
1707+
* New btree roots are set by journalling them; when the journal
1708+
* entry gets written we have to propagate them to
1709+
* c->btree_roots
1710+
*
1711+
* But, every journal entry we write has to contain all the
1712+
* btree roots (at least for now); so after we copy btree roots
1713+
* to c->btree_roots we have to get any missing btree roots and
1714+
* add them to this journal entry:
1715+
*/
1716+
if (i->type == BCH_JSET_ENTRY_btree_root) {
17011717
bch2_journal_entry_to_btree_root(c, i);
1718+
__set_bit(i->btree_id, &btree_roots_have);
1719+
}
17021720

17031721
/* Can we merge with previous entry? */
17041722
if (prev &&
@@ -1722,35 +1740,10 @@ static void bch2_journal_entries_postprocess(struct bch_fs *c, struct jset *jset
17221740

17231741
prev = prev ? vstruct_next(prev) : jset->start;
17241742
jset->u64s = cpu_to_le32((u64 *) prev - jset->_data);
1725-
}
1726-
1727-
static int bch2_journal_write_prep(struct journal *j, struct journal_buf *w)
1728-
{
1729-
struct bch_fs *c = container_of(j, struct bch_fs, journal);
1730-
struct jset_entry *start, *end;
1731-
struct jset *jset;
1732-
unsigned sectors, bytes, u64s;
1733-
bool validate_before_checksum = false;
1734-
int ret;
1735-
1736-
journal_buf_realloc(j, w);
1737-
jset = w->data;
1738-
1739-
/*
1740-
* New btree roots are set by journalling them; when the journal entry
1741-
* gets written we have to propagate them to c->btree_roots
1742-
*
1743-
* But, every journal entry we write has to contain all the btree roots
1744-
* (at least for now); so after we copy btree roots to c->btree_roots we
1745-
* have to get any missing btree roots and add them to this journal
1746-
* entry:
1747-
*/
1748-
1749-
bch2_journal_entries_postprocess(c, jset);
17501743

17511744
start = end = vstruct_last(jset);
17521745

1753-
end = bch2_btree_roots_to_journal_entries(c, jset->start, end);
1746+
end = bch2_btree_roots_to_journal_entries(c, end, btree_roots_have);
17541747

17551748
bch2_journal_super_entries_add_common(c, &end,
17561749
le64_to_cpu(jset->seq));
@@ -1872,6 +1865,8 @@ void bch2_journal_write(struct closure *cl)
18721865
if (ret)
18731866
goto err;
18741867

1868+
journal_buf_realloc(j, w);
1869+
18751870
ret = bch2_journal_write_prep(j, w);
18761871
if (ret)
18771872
goto err;

fs/bcachefs/sb-clean.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -376,7 +376,7 @@ void bch2_fs_mark_clean(struct bch_fs *c)
376376

377377
entry = sb_clean->start;
378378
bch2_journal_super_entries_add_common(c, &entry, 0);
379-
entry = bch2_btree_roots_to_journal_entries(c, entry, entry);
379+
entry = bch2_btree_roots_to_journal_entries(c, entry, 0);
380380
BUG_ON((void *) entry > vstruct_end(&sb_clean->field));
381381

382382
memset(entry, 0,

0 commit comments

Comments
 (0)