Skip to content

Commit 006ccc3

Browse files
author
Kent Overstreet
committed
bcachefs: Kill journal pre-reservations
This deletes the complicated and somewhat expensive journal pre-reservation machinery in favor of just using journal watermarks: when the journal is more than half full, we run journal reclaim more aggressively, and when the journal is more than 3/4s full we only allow journal reclaim to get new journal reservations. Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
1 parent 701ff57 commit 006ccc3

11 files changed

Lines changed: 19 additions & 275 deletions

fs/bcachefs/btree_iter.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3087,8 +3087,6 @@ void bch2_trans_put(struct btree_trans *trans)
30873087
srcu_read_unlock(&c->btree_trans_barrier, trans->srcu_idx);
30883088
}
30893089

3090-
bch2_journal_preres_put(&c->journal, &trans->journal_preres);
3091-
30923090
kfree(trans->extra_journal_entries.data);
30933091

30943092
if (trans->fs_usage_deltas) {

fs/bcachefs/btree_key_cache.c

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -672,7 +672,6 @@ static int btree_key_cache_flush_pos(struct btree_trans *trans,
672672
goto out;
673673

674674
bch2_journal_pin_drop(j, &ck->journal);
675-
bch2_journal_preres_put(j, &ck->res);
676675

677676
BUG_ON(!btree_node_locked(c_iter.path, 0));
678677

@@ -770,18 +769,6 @@ bool bch2_btree_insert_key_cached(struct btree_trans *trans,
770769

771770
BUG_ON(insert->k.u64s > ck->u64s);
772771

773-
if (likely(!(flags & BTREE_INSERT_JOURNAL_REPLAY))) {
774-
int difference;
775-
776-
BUG_ON(jset_u64s(insert->k.u64s) > trans->journal_preres.u64s);
777-
778-
difference = jset_u64s(insert->k.u64s) - ck->res.u64s;
779-
if (difference > 0) {
780-
trans->journal_preres.u64s -= difference;
781-
ck->res.u64s += difference;
782-
}
783-
}
784-
785772
bkey_copy(ck->k, insert);
786773
ck->valid = true;
787774

@@ -1006,7 +993,6 @@ void bch2_fs_btree_key_cache_exit(struct btree_key_cache *bc)
1006993
cond_resched();
1007994

1008995
bch2_journal_pin_drop(&c->journal, &ck->journal);
1009-
bch2_journal_preres_put(&c->journal, &ck->res);
1010996

1011997
list_del(&ck->list);
1012998
kfree(ck->k);

fs/bcachefs/btree_trans_commit.c

Lines changed: 2 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -323,17 +323,6 @@ static inline void btree_insert_entry_checks(struct btree_trans *trans,
323323
bch2_snapshot_is_internal_node(trans->c, i->k->k.p.snapshot));
324324
}
325325

326-
static noinline int
327-
bch2_trans_journal_preres_get_cold(struct btree_trans *trans, unsigned flags,
328-
unsigned long trace_ip)
329-
{
330-
return drop_locks_do(trans,
331-
bch2_journal_preres_get(&trans->c->journal,
332-
&trans->journal_preres,
333-
trans->journal_preres_u64s,
334-
(flags & BCH_WATERMARK_MASK)));
335-
}
336-
337326
static __always_inline int bch2_trans_journal_res_get(struct btree_trans *trans,
338327
unsigned flags)
339328
{
@@ -882,14 +871,6 @@ static inline int do_bch2_trans_commit(struct btree_trans *trans, unsigned flags
882871
}
883872
}
884873

885-
ret = bch2_journal_preres_get(&c->journal,
886-
&trans->journal_preres, trans->journal_preres_u64s,
887-
(flags & BCH_WATERMARK_MASK)|JOURNAL_RES_GET_NONBLOCK);
888-
if (unlikely(ret == -BCH_ERR_journal_preres_get_blocked))
889-
ret = bch2_trans_journal_preres_get_cold(trans, flags, trace_ip);
890-
if (unlikely(ret))
891-
return ret;
892-
893874
ret = bch2_trans_lock_write(trans);
894875
if (unlikely(ret))
895876
return ret;
@@ -1052,7 +1033,6 @@ int __bch2_trans_commit(struct btree_trans *trans, unsigned flags)
10521033
struct bch_fs *c = trans->c;
10531034
struct btree_insert_entry *i = NULL;
10541035
struct btree_write_buffered_key *wb;
1055-
unsigned u64s;
10561036
int ret = 0;
10571037

10581038
if (!trans->nr_updates &&
@@ -1112,13 +1092,8 @@ int __bch2_trans_commit(struct btree_trans *trans, unsigned flags)
11121092

11131093
EBUG_ON(test_bit(BCH_FS_CLEAN_SHUTDOWN, &c->flags));
11141094

1115-
memset(&trans->journal_preres, 0, sizeof(trans->journal_preres));
1116-
11171095
trans->journal_u64s = trans->extra_journal_entries.nr;
1118-
trans->journal_preres_u64s = 0;
1119-
11201096
trans->journal_transaction_names = READ_ONCE(c->opts.journal_transaction_names);
1121-
11221097
if (trans->journal_transaction_names)
11231098
trans->journal_u64s += jset_u64s(JSET_ENTRY_LOG_U64s);
11241099

@@ -1134,16 +1109,11 @@ int __bch2_trans_commit(struct btree_trans *trans, unsigned flags)
11341109
if (i->key_cache_already_flushed)
11351110
continue;
11361111

1137-
/* we're going to journal the key being updated: */
1138-
u64s = jset_u64s(i->k->k.u64s);
1139-
if (i->cached &&
1140-
likely(!(flags & BTREE_INSERT_JOURNAL_REPLAY)))
1141-
trans->journal_preres_u64s += u64s;
1142-
11431112
if (i->flags & BTREE_UPDATE_NOJOURNAL)
11441113
continue;
11451114

1146-
trans->journal_u64s += u64s;
1115+
/* we're going to journal the key being updated: */
1116+
trans->journal_u64s += jset_u64s(i->k->k.u64s);
11471117

11481118
/* and we're also going to log the overwrite: */
11491119
if (trans->journal_transaction_names)
@@ -1175,8 +1145,6 @@ int __bch2_trans_commit(struct btree_trans *trans, unsigned flags)
11751145

11761146
trace_and_count(c, transaction_commit, trans, _RET_IP_);
11771147
out:
1178-
bch2_journal_preres_put(&c->journal, &trans->journal_preres);
1179-
11801148
if (likely(!(flags & BTREE_INSERT_NOCHECK_RW)))
11811149
bch2_write_ref_put(c, BCH_WRITE_REF_trans);
11821150
out_reset:

fs/bcachefs/btree_types.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,6 @@ struct bkey_cached {
327327
struct rhash_head hash;
328328
struct list_head list;
329329

330-
struct journal_preres res;
331330
struct journal_entry_pin journal;
332331
u64 seq;
333332

@@ -441,11 +440,9 @@ struct btree_trans {
441440
struct journal_entry_pin *journal_pin;
442441

443442
struct journal_res journal_res;
444-
struct journal_preres journal_preres;
445443
u64 *journal_seq;
446444
struct disk_reservation *disk_res;
447445
unsigned journal_u64s;
448-
unsigned journal_preres_u64s;
449446
struct replicas_delta_list *fs_usage_deltas;
450447
};
451448

fs/bcachefs/btree_update_interior.c

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -513,8 +513,6 @@ static void bch2_btree_update_free(struct btree_update *as, struct btree_trans *
513513
up_read(&c->gc_lock);
514514
as->took_gc_lock = false;
515515

516-
bch2_journal_preres_put(&c->journal, &as->journal_preres);
517-
518516
bch2_journal_pin_drop(&c->journal, &as->journal);
519517
bch2_journal_pin_flush(&c->journal, &as->journal);
520518
bch2_disk_reservation_put(c, &as->disk_res);
@@ -734,8 +732,6 @@ static void btree_update_nodes_written(struct btree_update *as)
734732

735733
bch2_journal_pin_drop(&c->journal, &as->journal);
736734

737-
bch2_journal_preres_put(&c->journal, &as->journal_preres);
738-
739735
mutex_lock(&c->btree_interior_update_lock);
740736
for (i = 0; i < as->nr_new_nodes; i++) {
741737
b = as->new_nodes[i];
@@ -1047,7 +1043,6 @@ bch2_btree_update_start(struct btree_trans *trans, struct btree_path *path,
10471043
unsigned nr_nodes[2] = { 0, 0 };
10481044
unsigned update_level = level;
10491045
enum bch_watermark watermark = flags & BCH_WATERMARK_MASK;
1050-
unsigned journal_flags = 0;
10511046
int ret = 0;
10521047
u32 restart_count = trans->restart_count;
10531048

@@ -1061,10 +1056,6 @@ bch2_btree_update_start(struct btree_trans *trans, struct btree_path *path,
10611056
flags &= ~BCH_WATERMARK_MASK;
10621057
flags |= watermark;
10631058

1064-
if (flags & BTREE_INSERT_JOURNAL_RECLAIM)
1065-
journal_flags |= JOURNAL_RES_GET_NONBLOCK;
1066-
journal_flags |= watermark;
1067-
10681059
while (1) {
10691060
nr_nodes[!!update_level] += 1 + split;
10701061
update_level++;
@@ -1129,27 +1120,6 @@ bch2_btree_update_start(struct btree_trans *trans, struct btree_path *path,
11291120
if (ret)
11301121
goto err;
11311122

1132-
ret = bch2_journal_preres_get(&c->journal, &as->journal_preres,
1133-
BTREE_UPDATE_JOURNAL_RES,
1134-
journal_flags|JOURNAL_RES_GET_NONBLOCK);
1135-
if (ret) {
1136-
if (flags & BTREE_INSERT_JOURNAL_RECLAIM) {
1137-
ret = -BCH_ERR_journal_reclaim_would_deadlock;
1138-
goto err;
1139-
}
1140-
1141-
ret = drop_locks_do(trans,
1142-
bch2_journal_preres_get(&c->journal, &as->journal_preres,
1143-
BTREE_UPDATE_JOURNAL_RES,
1144-
journal_flags));
1145-
if (ret == -BCH_ERR_journal_preres_get_blocked) {
1146-
trace_and_count(c, trans_restart_journal_preres_get, trans, _RET_IP_, journal_flags);
1147-
ret = btree_trans_restart(trans, BCH_ERR_transaction_restart_journal_preres_get);
1148-
}
1149-
if (ret)
1150-
goto err;
1151-
}
1152-
11531123
ret = bch2_disk_reservation_get(c, &as->disk_res,
11541124
(nr_nodes[0] + nr_nodes[1]) * btree_sectors(c),
11551125
c->opts.metadata_replicas,

fs/bcachefs/btree_update_interior.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@ struct btree_update {
5555
unsigned update_level;
5656

5757
struct disk_reservation disk_res;
58-
struct journal_preres journal_preres;
5958

6059
/*
6160
* BTREE_INTERIOR_UPDATING_NODE:

fs/bcachefs/journal.c

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -526,36 +526,6 @@ int bch2_journal_res_get_slowpath(struct journal *j, struct journal_res *res,
526526
return ret;
527527
}
528528

529-
/* journal_preres: */
530-
531-
static bool journal_preres_available(struct journal *j,
532-
struct journal_preres *res,
533-
unsigned new_u64s,
534-
unsigned flags)
535-
{
536-
bool ret = bch2_journal_preres_get_fast(j, res, new_u64s, flags, true);
537-
538-
if (!ret && mutex_trylock(&j->reclaim_lock)) {
539-
bch2_journal_reclaim(j);
540-
mutex_unlock(&j->reclaim_lock);
541-
}
542-
543-
return ret;
544-
}
545-
546-
int __bch2_journal_preres_get(struct journal *j,
547-
struct journal_preres *res,
548-
unsigned new_u64s,
549-
unsigned flags)
550-
{
551-
int ret;
552-
553-
closure_wait_event(&j->preres_wait,
554-
(ret = bch2_journal_error(j)) ||
555-
journal_preres_available(j, res, new_u64s, flags));
556-
return ret;
557-
}
558-
559529
/* journal_entry_res: */
560530

561531
void bch2_journal_entry_res_resize(struct journal *j,
@@ -1306,7 +1276,6 @@ void __bch2_journal_debug_to_text(struct printbuf *out, struct journal *j)
13061276
prt_printf(out, "last_seq:\t\t%llu\n", journal_last_seq(j));
13071277
prt_printf(out, "last_seq_ondisk:\t%llu\n", j->last_seq_ondisk);
13081278
prt_printf(out, "flushed_seq_ondisk:\t%llu\n", j->flushed_seq_ondisk);
1309-
prt_printf(out, "prereserved:\t\t%u/%u\n", j->prereserved.reserved, j->prereserved.remaining);
13101279
prt_printf(out, "watermark:\t\t%s\n", bch2_watermarks[j->watermark]);
13111280
prt_printf(out, "each entry reserved:\t%u\n", j->entry_u64s_reserved);
13121281
prt_printf(out, "nr flush writes:\t%llu\n", j->nr_flush_writes);

fs/bcachefs/journal.h

Lines changed: 0 additions & 98 deletions
Original file line numberDiff line numberDiff line change
@@ -395,104 +395,6 @@ static inline int bch2_journal_res_get(struct journal *j, struct journal_res *re
395395
return 0;
396396
}
397397

398-
/* journal_preres: */
399-
400-
static inline void journal_set_watermark(struct journal *j)
401-
{
402-
union journal_preres_state s = READ_ONCE(j->prereserved);
403-
unsigned watermark = BCH_WATERMARK_stripe;
404-
405-
if (fifo_free(&j->pin) < j->pin.size / 4)
406-
watermark = max_t(unsigned, watermark, BCH_WATERMARK_copygc);
407-
if (fifo_free(&j->pin) < j->pin.size / 8)
408-
watermark = max_t(unsigned, watermark, BCH_WATERMARK_reclaim);
409-
410-
if (s.reserved > s.remaining)
411-
watermark = max_t(unsigned, watermark, BCH_WATERMARK_copygc);
412-
if (!s.remaining)
413-
watermark = max_t(unsigned, watermark, BCH_WATERMARK_reclaim);
414-
415-
if (watermark == j->watermark)
416-
return;
417-
418-
swap(watermark, j->watermark);
419-
if (watermark > j->watermark)
420-
journal_wake(j);
421-
}
422-
423-
static inline void bch2_journal_preres_put(struct journal *j,
424-
struct journal_preres *res)
425-
{
426-
union journal_preres_state s = { .reserved = res->u64s };
427-
428-
if (!res->u64s)
429-
return;
430-
431-
s.v = atomic64_sub_return(s.v, &j->prereserved.counter);
432-
res->u64s = 0;
433-
434-
if (unlikely(s.waiting)) {
435-
clear_bit(ilog2((((union journal_preres_state) { .waiting = 1 }).v)),
436-
(unsigned long *) &j->prereserved.v);
437-
closure_wake_up(&j->preres_wait);
438-
}
439-
440-
if (s.reserved <= s.remaining && j->watermark)
441-
journal_set_watermark(j);
442-
}
443-
444-
int __bch2_journal_preres_get(struct journal *,
445-
struct journal_preres *, unsigned, unsigned);
446-
447-
static inline int bch2_journal_preres_get_fast(struct journal *j,
448-
struct journal_preres *res,
449-
unsigned new_u64s,
450-
unsigned flags,
451-
bool set_waiting)
452-
{
453-
int d = new_u64s - res->u64s;
454-
union journal_preres_state old, new;
455-
u64 v = atomic64_read(&j->prereserved.counter);
456-
enum bch_watermark watermark = flags & BCH_WATERMARK_MASK;
457-
int ret;
458-
459-
do {
460-
old.v = new.v = v;
461-
ret = 0;
462-
463-
if (watermark == BCH_WATERMARK_reclaim ||
464-
new.reserved + d < new.remaining) {
465-
new.reserved += d;
466-
ret = 1;
467-
} else if (set_waiting && !new.waiting)
468-
new.waiting = true;
469-
else
470-
return 0;
471-
} while ((v = atomic64_cmpxchg(&j->prereserved.counter,
472-
old.v, new.v)) != old.v);
473-
474-
if (ret)
475-
res->u64s += d;
476-
return ret;
477-
}
478-
479-
static inline int bch2_journal_preres_get(struct journal *j,
480-
struct journal_preres *res,
481-
unsigned new_u64s,
482-
unsigned flags)
483-
{
484-
if (new_u64s <= res->u64s)
485-
return 0;
486-
487-
if (bch2_journal_preres_get_fast(j, res, new_u64s, flags, false))
488-
return 0;
489-
490-
if (flags & JOURNAL_RES_GET_NONBLOCK)
491-
return -BCH_ERR_journal_preres_get_blocked;
492-
493-
return __bch2_journal_preres_get(j, res, new_u64s, flags);
494-
}
495-
496398
/* journal_entry_res: */
497399

498400
void bch2_journal_entry_res_resize(struct journal *,

0 commit comments

Comments
 (0)