Skip to content

Commit

Permalink
Merge tag 'bcachefs-2024-02-25' of https://evilpiepirate.org/git/bcac…
Browse files Browse the repository at this point in the history
…hefs

Pull bcachefs fixes from Kent Overstreet:
 "Some more mostly boring fixes, but some not

  User reported ones:

   - the BTREE_ITER_FILTER_SNAPSHOTS one fixes a really nasty
     performance bug; user reported an untar initially taking two
     seconds and then ~2 minutes

   - kill a __GFP_NOFAIL in the buffered read path; this was a leftover
     from the trickier fix to kill __GFP_NOFAIL in readahead, where we
     can't return errors (and have to silently truncate the read
     ourselves).

     bcachefs can't use GFP_NOFAIL for folio state unlike iomap based
     filesystems because our folio state is just barely too big, 2MB
     hugepages cause us to exceed the 2 page threshhold for GFP_NOFAIL.

     additionally, the flags argument was just buggy, we weren't
     supplying GFP_KERNEL previously (!)"

* tag 'bcachefs-2024-02-25' of https://evilpiepirate.org/git/bcachefs:
  bcachefs: fix bch2_save_backtrace()
  bcachefs: Fix check_snapshot() memcpy
  bcachefs: Fix bch2_journal_flush_device_pins()
  bcachefs: fix iov_iter count underflow on sub-block dio read
  bcachefs: Fix BTREE_ITER_FILTER_SNAPSHOTS on inodes btree
  bcachefs: Kill __GFP_NOFAIL in buffered read path
  bcachefs: fix backpointer_to_text() when dev does not exist
  • Loading branch information
Linus Torvalds committed Feb 25, 2024
2 parents 70ff1fe + 5197728 commit e231dbd
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 22 deletions.
8 changes: 5 additions & 3 deletions fs/bcachefs/backpointers.c
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,11 @@ void bch2_backpointer_to_text(struct printbuf *out, const struct bch_backpointer

void bch2_backpointer_k_to_text(struct printbuf *out, struct bch_fs *c, struct bkey_s_c k)
{
prt_str(out, "bucket=");
bch2_bpos_to_text(out, bp_pos_to_bucket(c, k.k->p));
prt_str(out, " ");
if (bch2_dev_exists2(c, k.k->p.inode)) {
prt_str(out, "bucket=");
bch2_bpos_to_text(out, bp_pos_to_bucket(c, k.k->p));
prt_str(out, " ");
}

bch2_backpointer_to_text(out, bkey_s_c_to_backpointer(k).v);
}
Expand Down
4 changes: 3 additions & 1 deletion fs/bcachefs/btree_iter.c
Original file line number Diff line number Diff line change
Expand Up @@ -2156,7 +2156,9 @@ struct bkey_s_c bch2_btree_iter_peek_upto(struct btree_iter *iter, struct bpos e
* isn't monotonically increasing before FILTER_SNAPSHOTS, and
* that's what we check against in extents mode:
*/
if (k.k->p.inode > end.inode)
if (unlikely(!(iter->flags & BTREE_ITER_IS_EXTENTS)
? bkey_gt(k.k->p, end)
: k.k->p.inode > end.inode))
goto end;

if (iter->update_path &&
Expand Down
21 changes: 8 additions & 13 deletions fs/bcachefs/fs-io-buffered.c
Original file line number Diff line number Diff line change
Expand Up @@ -303,18 +303,6 @@ void bch2_readahead(struct readahead_control *ractl)
darray_exit(&readpages_iter.folios);
}

static void __bchfs_readfolio(struct bch_fs *c, struct bch_read_bio *rbio,
subvol_inum inum, struct folio *folio)
{
bch2_folio_create(folio, __GFP_NOFAIL);

rbio->bio.bi_opf = REQ_OP_READ|REQ_SYNC;
rbio->bio.bi_iter.bi_sector = folio_sector(folio);
BUG_ON(!bio_add_folio(&rbio->bio, folio, folio_size(folio), 0));

bch2_trans_run(c, (bchfs_read(trans, rbio, inum, NULL), 0));
}

static void bch2_read_single_folio_end_io(struct bio *bio)
{
complete(bio->bi_private);
Expand All @@ -329,14 +317,21 @@ int bch2_read_single_folio(struct folio *folio, struct address_space *mapping)
int ret;
DECLARE_COMPLETION_ONSTACK(done);

if (!bch2_folio_create(folio, GFP_KERNEL))
return -ENOMEM;

bch2_inode_opts_get(&opts, c, &inode->ei_inode);

rbio = rbio_init(bio_alloc_bioset(NULL, 1, REQ_OP_READ, GFP_KERNEL, &c->bio_read),
opts);
rbio->bio.bi_private = &done;
rbio->bio.bi_end_io = bch2_read_single_folio_end_io;

__bchfs_readfolio(c, rbio, inode_inum(inode), folio);
rbio->bio.bi_opf = REQ_OP_READ|REQ_SYNC;
rbio->bio.bi_iter.bi_sector = folio_sector(folio);
BUG_ON(!bio_add_folio(&rbio->bio, folio, folio_size(folio), 0));

bch2_trans_run(c, (bchfs_read(trans, rbio, inode_inum(inode), NULL), 0));
wait_for_completion(&done);

ret = blk_status_to_errno(rbio->bio.bi_status);
Expand Down
2 changes: 2 additions & 0 deletions fs/bcachefs/fs-io-direct.c
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ static int bch2_direct_IO_read(struct kiocb *req, struct iov_iter *iter)
return ret;

shorten = iov_iter_count(iter) - round_up(ret, block_bytes(c));
if (shorten >= iter->count)
shorten = 0;
iter->count -= shorten;

bio = bio_alloc_bioset(NULL,
Expand Down
8 changes: 5 additions & 3 deletions fs/bcachefs/journal_reclaim.c
Original file line number Diff line number Diff line change
Expand Up @@ -892,9 +892,11 @@ int bch2_journal_flush_device_pins(struct journal *j, int dev_idx)
journal_seq_pin(j, seq)->devs);
seq++;

spin_unlock(&j->lock);
ret = bch2_mark_replicas(c, &replicas.e);
spin_lock(&j->lock);
if (replicas.e.nr_devs) {
spin_unlock(&j->lock);
ret = bch2_mark_replicas(c, &replicas.e);
spin_lock(&j->lock);
}
}
spin_unlock(&j->lock);
err:
Expand Down
2 changes: 1 addition & 1 deletion fs/bcachefs/snapshot.c
Original file line number Diff line number Diff line change
Expand Up @@ -728,7 +728,7 @@ static int check_snapshot(struct btree_trans *trans,
return 0;

memset(&s, 0, sizeof(s));
memcpy(&s, k.v, bkey_val_bytes(k.k));
memcpy(&s, k.v, min(sizeof(s), bkey_val_bytes(k.k)));

id = le32_to_cpu(s.parent);
if (id) {
Expand Down
2 changes: 1 addition & 1 deletion fs/bcachefs/util.c
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ int bch2_save_backtrace(bch_stacktrace *stack, struct task_struct *task, unsigne
do {
nr_entries = stack_trace_save_tsk(task, stack->data, stack->size, skipnr + 1);
} while (nr_entries == stack->size &&
!(ret = darray_make_room(stack, stack->size * 2)));
!(ret = darray_make_room_gfp(stack, stack->size * 2, gfp)));

stack->nr = nr_entries;
up_read(&task->signal->exec_update_lock);
Expand Down

0 comments on commit e231dbd

Please sign in to comment.