Skip to content

Commit

Permalink
Update bcachefs sources to 55a65a994ed5 bcachefs: bcachefs_metadata_v…
Browse files Browse the repository at this point in the history
…ersion_persistent_inode_cursors

Signed-off-by: Kent Overstreet <[email protected]>
  • Loading branch information
Kent Overstreet committed Dec 8, 2024
1 parent 2aeeac7 commit 8b31dfb
Show file tree
Hide file tree
Showing 53 changed files with 874 additions and 677 deletions.
2 changes: 1 addition & 1 deletion .bcachefs_revision
Original file line number Diff line number Diff line change
@@ -1 +1 @@
4a32728376a81dd9e75851a49159ff33602840f4
55a65a994ed5fba038fda00f78416faf6f308bb8
2 changes: 2 additions & 0 deletions bch_bindgen/src/bkey.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ pub enum BkeyValC<'a> {
logged_op_truncate(&'a c::bch_logged_op_truncate),
logged_op_finsert(&'a c::bch_logged_op_finsert),
accounting(&'a c::bch_accounting),
inode_alloc_cursor(&'a c::bch_inode_alloc_cursor),
}

impl<'a, 'b> BkeySC<'a> {
Expand Down Expand Up @@ -106,6 +107,7 @@ impl<'a, 'b> BkeySC<'a> {
KEY_TYPE_logged_op_truncate => logged_op_truncate(transmute(self.v)),
KEY_TYPE_logged_op_finsert => logged_op_finsert(transmute(self.v)),
KEY_TYPE_accounting => accounting(transmute(self.v)),
KEY_TYPE_inode_alloc_cursor => inode_alloc_cursor(transmute(self.v)),
KEY_TYPE_MAX => unreachable!(),
}
}
Expand Down
4 changes: 2 additions & 2 deletions include/linux/min_heap.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
*/
#define MIN_HEAP_PREALLOCATED(_type, _name, _nr) \
struct _name { \
int nr; \
int size; \
size_t nr; \
size_t size; \
_type *data; \
_type preallocated[_nr]; \
}
Expand Down
85 changes: 47 additions & 38 deletions libbcachefs/alloc_background.c
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,8 @@ void bch2_alloc_v4_swab(struct bkey_s k)
{
struct bch_alloc_v4 *a = bkey_s_to_alloc_v4(k).v;

a->journal_seq = swab64(a->journal_seq);
a->journal_seq_nonempty = swab64(a->journal_seq_nonempty);
a->journal_seq_empty = swab64(a->journal_seq_empty);
a->flags = swab32(a->flags);
a->dirty_sectors = swab32(a->dirty_sectors);
a->cached_sectors = swab32(a->cached_sectors);
Expand All @@ -346,16 +347,17 @@ void bch2_alloc_to_text(struct printbuf *out, struct bch_fs *c, struct bkey_s_c
prt_printf(out, "gen %u oldest_gen %u data_type ", a->gen, a->oldest_gen);
bch2_prt_data_type(out, a->data_type);
prt_newline(out);
prt_printf(out, "journal_seq %llu\n", a->journal_seq);
prt_printf(out, "need_discard %llu\n", BCH_ALLOC_V4_NEED_DISCARD(a));
prt_printf(out, "need_inc_gen %llu\n", BCH_ALLOC_V4_NEED_INC_GEN(a));
prt_printf(out, "dirty_sectors %u\n", a->dirty_sectors);
prt_printf(out, "stripe_sectors %u\n", a->stripe_sectors);
prt_printf(out, "cached_sectors %u\n", a->cached_sectors);
prt_printf(out, "stripe %u\n", a->stripe);
prt_printf(out, "stripe_redundancy %u\n", a->stripe_redundancy);
prt_printf(out, "io_time[READ] %llu\n", a->io_time[READ]);
prt_printf(out, "io_time[WRITE] %llu\n", a->io_time[WRITE]);
prt_printf(out, "journal_seq_nonempty %llu\n", a->journal_seq_nonempty);
prt_printf(out, "journal_seq_empty %llu\n", a->journal_seq_empty);
prt_printf(out, "need_discard %llu\n", BCH_ALLOC_V4_NEED_DISCARD(a));
prt_printf(out, "need_inc_gen %llu\n", BCH_ALLOC_V4_NEED_INC_GEN(a));
prt_printf(out, "dirty_sectors %u\n", a->dirty_sectors);
prt_printf(out, "stripe_sectors %u\n", a->stripe_sectors);
prt_printf(out, "cached_sectors %u\n", a->cached_sectors);
prt_printf(out, "stripe %u\n", a->stripe);
prt_printf(out, "stripe_redundancy %u\n", a->stripe_redundancy);
prt_printf(out, "io_time[READ] %llu\n", a->io_time[READ]);
prt_printf(out, "io_time[WRITE] %llu\n", a->io_time[WRITE]);

if (ca)
prt_printf(out, "fragmentation %llu\n", alloc_lru_idx_fragmentation(*a, ca));
Expand Down Expand Up @@ -384,7 +386,7 @@ void __bch2_alloc_to_v4(struct bkey_s_c k, struct bch_alloc_v4 *out)
struct bkey_alloc_unpacked u = bch2_alloc_unpack(k);

*out = (struct bch_alloc_v4) {
.journal_seq = u.journal_seq,
.journal_seq_nonempty = u.journal_seq,
.flags = u.need_discard,
.gen = u.gen,
.oldest_gen = u.oldest_gen,
Expand Down Expand Up @@ -856,7 +858,10 @@ int bch2_trigger_alloc(struct btree_trans *trans,
if (flags & BTREE_TRIGGER_transactional) {
alloc_data_type_set(new_a, new_a->data_type);

if (bch2_bucket_sectors_total(*new_a) > bch2_bucket_sectors_total(*old_a)) {
int is_empty_delta = (int) data_type_is_empty(new_a->data_type) -
(int) data_type_is_empty(old_a->data_type);

if (is_empty_delta < 0) {
new_a->io_time[READ] = bch2_current_io_time(c, READ);
new_a->io_time[WRITE]= bch2_current_io_time(c, WRITE);
SET_BCH_ALLOC_V4_NEED_INC_GEN(new_a, true);
Expand Down Expand Up @@ -927,20 +932,31 @@ int bch2_trigger_alloc(struct btree_trans *trans,

if ((flags & BTREE_TRIGGER_atomic) && (flags & BTREE_TRIGGER_insert)) {
u64 transaction_seq = trans->journal_res.seq;
BUG_ON(!transaction_seq);
BUG_ON(transaction_seq < new_a->journal_seq_nonempty);
BUG_ON(transaction_seq < new_a->journal_seq_empty);

if (log_fsck_err_on(transaction_seq && new_a->journal_seq > transaction_seq,
if (log_fsck_err_on(transaction_seq && new_a->journal_seq_nonempty > transaction_seq,
trans, alloc_key_journal_seq_in_future,
"bucket journal seq in future (currently at %llu)\n%s",
journal_cur_seq(&c->journal),
(bch2_bkey_val_to_text(&buf, c, new.s_c), buf.buf)))
new_a->journal_seq = transaction_seq;
new_a->journal_seq_nonempty = transaction_seq;

int is_empty_delta = (int) data_type_is_empty(new_a->data_type) -
(int) data_type_is_empty(old_a->data_type);

/* Record journal sequence number of empty -> nonempty transition: */
if (is_empty_delta < 0)
new_a->journal_seq = max(new_a->journal_seq, transaction_seq);
/*
* Record journal sequence number of empty -> nonempty transition:
* Note that there may be multiple empty -> nonempty
* transitions, data in a bucket may be overwritten while we're
* still writing to it - so be careful to only record the first:
* */
if (is_empty_delta < 0 &&
new_a->journal_seq_empty <= c->journal.flushed_seq_ondisk) {
new_a->journal_seq_nonempty = transaction_seq;
new_a->journal_seq_empty = 0;
}

/*
* Bucket becomes empty: mark it as waiting for a journal flush,
Expand All @@ -949,18 +965,21 @@ int bch2_trigger_alloc(struct btree_trans *trans,
* intermediate sequence numbers:
*/
if (is_empty_delta > 0) {
if (new_a->journal_seq == transaction_seq ||
bch2_journal_noflush_seq(&c->journal, new_a->journal_seq))
new_a->journal_seq = 0;
else {
new_a->journal_seq = transaction_seq;
if (new_a->journal_seq_nonempty == transaction_seq ||
bch2_journal_noflush_seq(&c->journal,
new_a->journal_seq_nonempty,
transaction_seq)) {
new_a->journal_seq_nonempty = new_a->journal_seq_empty = 0;
} else {
new_a->journal_seq_empty = transaction_seq;

ret = bch2_set_bucket_needs_journal_commit(&c->buckets_waiting_for_journal,
c->journal.flushed_seq_ondisk,
new.k->p.inode, new.k->p.offset,
transaction_seq);
c->journal.flushed_seq_ondisk,
new.k->p.inode, new.k->p.offset,
transaction_seq);
if (bch2_fs_fatal_err_on(ret, c,
"setting bucket_needs_journal_commit: %s", bch2_err_str(ret)))
"setting bucket_needs_journal_commit: %s",
bch2_err_str(ret)))
goto err;
}
}
Expand All @@ -978,7 +997,7 @@ int bch2_trigger_alloc(struct btree_trans *trans,

#define eval_state(_a, expr) ({ const struct bch_alloc_v4 *a = _a; expr; })
#define statechange(expr) !eval_state(old_a, expr) && eval_state(new_a, expr)
#define bucket_flushed(a) (!a->journal_seq || a->journal_seq <= c->journal.flushed_seq_ondisk)
#define bucket_flushed(a) (a->journal_seq_empty <= c->journal.flushed_seq_ondisk)

if (statechange(a->data_type == BCH_DATA_free) &&
bucket_flushed(new_a))
Expand Down Expand Up @@ -1840,16 +1859,6 @@ static int bch2_discard_one_bucket(struct btree_trans *trans,
goto out;
}

if (a->v.journal_seq > c->journal.flushed_seq_ondisk) {
if (bch2_trans_inconsistent_on(c->curr_recovery_pass > BCH_RECOVERY_PASS_check_alloc_info,
trans, "clearing need_discard but journal_seq %llu > flushed_seq %llu\n%s",
a->v.journal_seq,
c->journal.flushed_seq_ondisk,
(bch2_bkey_val_to_text(&buf, c, k), buf.buf)))
ret = -EIO;
goto out;
}

if (!fastpath) {
if (discard_in_flight_add(ca, iter.pos.offset, true))
goto out;
Expand Down
4 changes: 2 additions & 2 deletions libbcachefs/alloc_background_format.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ LE32_BITMASK(BCH_ALLOC_V3_NEED_INC_GEN,struct bch_alloc_v3, flags, 1, 2)

struct bch_alloc_v4 {
struct bch_val v;
__u64 journal_seq;
__u64 journal_seq_nonempty;
__u32 flags;
__u8 gen;
__u8 oldest_gen;
Expand All @@ -70,7 +70,7 @@ struct bch_alloc_v4 {
__u32 stripe;
__u32 nr_external_backpointers;
/* end of fields in original version of alloc_v4 */
__u64 _fragmentation_lru; /* obsolete */
__u64 journal_seq_empty;
__u32 stripe_sectors;
__u32 pad;
} __packed __aligned(8);
Expand Down
Loading

0 comments on commit 8b31dfb

Please sign in to comment.