]> git.proxmox.com Git - mirror_ubuntu-kernels.git/log
mirror_ubuntu-kernels.git
13 months agobcachefs: Improve tracepoints slightly in commit path
Kent Overstreet [Thu, 9 Jan 2020 23:30:05 +0000 (18:30 -0500)]
bcachefs: Improve tracepoints slightly in commit path

Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
13 months agobcachefs: Add a cond_resched() to rebalance loop
Kent Overstreet [Thu, 16 Jan 2020 21:20:53 +0000 (16:20 -0500)]
bcachefs: Add a cond_resched() to rebalance loop

Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
13 months agobcachefs: Don't modify existing key in place in sort_repack_merge()
Kent Overstreet [Thu, 16 Jan 2020 21:14:56 +0000 (16:14 -0500)]
bcachefs: Don't modify existing key in place in sort_repack_merge()

This fixes a nasty memory corruption with other threads that are still
reading the btree node being compacted.

Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
13 months agobcachefs: Fix bch2_sort_keys() to not modify src keys
Kent Overstreet [Thu, 16 Jan 2020 03:53:49 +0000 (22:53 -0500)]
bcachefs: Fix bch2_sort_keys() to not modify src keys

Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
13 months agobcachefs: Change btree split threshold to be in u64s
Kent Overstreet [Wed, 15 Jan 2020 20:11:22 +0000 (15:11 -0500)]
bcachefs: Change btree split threshold to be in u64s

This fixes a bug with very small btree nodes where splitting would end
up with one of the new nodes empty.

Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
13 months agobcachefs: Add some comments for btree iterator flags
Kent Overstreet [Fri, 10 Jan 2020 01:43:58 +0000 (20:43 -0500)]
bcachefs: Add some comments for btree iterator flags

Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
13 months agobcachefs: Refactor bch2_btree_bset_insert_key()
Kent Overstreet [Tue, 7 Jan 2020 04:43:04 +0000 (23:43 -0500)]
bcachefs: Refactor bch2_btree_bset_insert_key()

The main thing going on is to separate out the different cases deletion,
overwriting, and inserting a new key.

Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
13 months agobcachefs: Rework iter->pos handling
Kent Overstreet [Tue, 7 Jan 2020 03:25:09 +0000 (22:25 -0500)]
bcachefs: Rework iter->pos handling

- Rework some of the helper comparison functions for consistency

- Currently trying to refactor all the logic that's different for
extents in the btree iterator code. The main difference is that for non
extents we search for a key greater than or equal to the search key,
while for extents we search for a key strictly greater than the search
key (iter->pos).

So that logic is now handled by btree_iter_search_key(), which computes
the real search key based on iter->pos and whether or not we're
searching for a key >= or > iter->pos.

Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
13 months agobcachefs: Don't lose needs_whiteout in overwrite path
Kent Overstreet [Sun, 5 Jan 2020 23:20:23 +0000 (18:20 -0500)]
bcachefs: Don't lose needs_whiteout in overwrite path

Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
13 months agobcachefs: Don't call trans_iter_put() on error pointer
Kent Overstreet [Sun, 5 Jan 2020 00:04:47 +0000 (19:04 -0500)]
bcachefs: Don't call trans_iter_put() on error pointer

Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
13 months agobcachefs: Ensure iterators are valid before calling trans_mark_key()
Kent Overstreet [Sat, 4 Jan 2020 21:46:23 +0000 (16:46 -0500)]
bcachefs: Ensure iterators are valid before calling trans_mark_key()

Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
13 months agobcachefs: Fix extent_to_replicas()
Kent Overstreet [Sat, 4 Jan 2020 21:33:32 +0000 (16:33 -0500)]
bcachefs: Fix extent_to_replicas()

This needs to match bch2_mark_extent()/bch2_trans_mark_extent() in
buckets.c

Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
13 months agobcachefs: Kill bch2_fs_bug()
Kent Overstreet [Sat, 4 Jan 2020 21:09:52 +0000 (16:09 -0500)]
bcachefs: Kill bch2_fs_bug()

These have all been converted to fsck/inconsistent errors

Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
13 months agobcachefs: Hacky fixes for device removal
Kent Overstreet [Sat, 4 Jan 2020 03:38:14 +0000 (22:38 -0500)]
bcachefs: Hacky fixes for device removal

The device remove test was sporadically failing, because we hadn't
finished dropping btree sector counts for the device when
bch2_replicas_gc2() was called - mainly due to in flight journal writes.
We don't yet have a good mechanism for flushing the counts that
correspend to open journal entries yet.

Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
13 months agobcachefs: Don't print anything when device doesn't have a label
Kent Overstreet [Fri, 3 Jan 2020 23:57:32 +0000 (18:57 -0500)]
bcachefs: Don't print anything when device doesn't have a label

Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
13 months agobcachefs: Fix an iterator error path
Kent Overstreet [Fri, 3 Jan 2020 23:04:19 +0000 (18:04 -0500)]
bcachefs: Fix an iterator error path

On transaction restart (-EINTR), we need to traverse all iterators.

Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
13 months agobcachefs: Make sure bch2_read_extent obeys BCH_READ_MUST_CLONE
Kent Overstreet [Fri, 3 Jan 2020 21:03:10 +0000 (16:03 -0500)]
bcachefs: Make sure bch2_read_extent obeys BCH_READ_MUST_CLONE

This fixes the bch2_read_retry_nodecode() path, we were resubmitting a
bio without properly reinitializing it.

Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
13 months agobcachefs: Sort & deduplicate updates in bch2_trans_update()
Kent Overstreet [Wed, 1 Jan 2020 00:37:10 +0000 (19:37 -0500)]
bcachefs: Sort & deduplicate updates in bch2_trans_update()

Previously, when doing multiple update in the same transaction commit
that overwrote each other, we relied on doing the updates in the same
order as the bch2_trans_update() calls in order to get the correct
result. But that wasn't correct for triggers; bch2_trans_mark_update()
when marking overwrites would do the wrong thing because it hadn't seen
the update that was being overwritten.

Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
13 months agobcachefs: Split out btree_trigger_flags
Kent Overstreet [Tue, 31 Dec 2019 21:17:42 +0000 (16:17 -0500)]
bcachefs: Split out btree_trigger_flags

The trigger flags really belong with individual btree_insert_entries,
not the transaction commit flags - this splits out those  flags and
unifies them with the BCH_BUCKET_MARK flags. Todo - split out
btree_trigger.c from buckets.c

Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
13 months agobcachefs: Make btree_insert_entry more private to update path
Kent Overstreet [Mon, 30 Dec 2019 18:08:26 +0000 (13:08 -0500)]
bcachefs: Make btree_insert_entry more private to update path

This should be private to btree_update_leaf.c, and we might end up
removing it.

Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
13 months agobcachefs: Use bch2_trans_reset in bch2_trans_commit()
Kent Overstreet [Mon, 30 Dec 2019 17:43:19 +0000 (12:43 -0500)]
bcachefs: Use bch2_trans_reset in bch2_trans_commit()

Clean up a bit of duplicated code.

Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
13 months agobcachefs: Use KEY_TYPE_deleted whitouts for extents
Kent Overstreet [Tue, 26 Nov 2019 22:26:04 +0000 (17:26 -0500)]
bcachefs: Use KEY_TYPE_deleted whitouts for extents

Previously, partial overwrites of existing extents were handled
implicitly by the btree code; when reading in a btree node, we'd do a
mergesort of the different bsets and detect and fix partially
overlapping extents during that mergesort.

That approach won't work with snapshots: this changes extents to work
like regular keys as far as the btree code is concerned, where a 0 size
KEY_TYPE_deleted whiteout will completely overwrite an existing extent.

Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
13 months agobcachefs: Convert some enums to x-macros
Kent Overstreet [Sun, 29 Dec 2019 01:17:06 +0000 (20:17 -0500)]
bcachefs: Convert some enums to x-macros

Helps for preventing things from getting out of sync.

Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
13 months agobcachefs: Add an assertion to track down a heisenbug
Kent Overstreet [Sat, 28 Dec 2019 01:42:06 +0000 (20:42 -0500)]
bcachefs: Add an assertion to track down a heisenbug

Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
13 months agobcachefs: Fix a use after free
Kent Overstreet [Fri, 27 Dec 2019 18:44:03 +0000 (13:44 -0500)]
bcachefs: Fix a use after free

op->end_io may free the op struct

Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
13 months agobcachefs: Don't export __bch2_fs_read_write
Kent Overstreet [Thu, 26 Dec 2019 19:54:43 +0000 (14:54 -0500)]
bcachefs: Don't export __bch2_fs_read_write

BTREE_INSERT_LAZY_RW was added for this since this code was written; use
it instead.

Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
13 months agobcachefs: Don't reexecute triggers when retrying transaction commit
Kent Overstreet [Tue, 24 Dec 2019 23:03:53 +0000 (18:03 -0500)]
bcachefs: Don't reexecute triggers when retrying transaction commit

This was causing a bug with transaction iterators overflowing; now, if
triggers have to be reexecuted we always return -EINTR and retry from
the start of the transaction.

Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
13 months agobcachefs: Kill BTREE_INSERT_ATOMIC
Kent Overstreet [Mon, 23 Dec 2019 04:39:28 +0000 (23:39 -0500)]
bcachefs: Kill BTREE_INSERT_ATOMIC

Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
13 months agobcachefs: Convert all bch2_trans_commit() users to BTREE_INSERT_ATOMIC
Kent Overstreet [Mon, 23 Dec 2019 04:04:30 +0000 (23:04 -0500)]
bcachefs: Convert all bch2_trans_commit() users to BTREE_INSERT_ATOMIC

BTREE_INSERT_ATOMIC should really be the default mode, and there's not
that much code that doesn't need it - so this is prep work for getting
rid of the flag.

Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
13 months agobcachefs: bch2_trans_reset() calls should be at the tops of loops
Kent Overstreet [Fri, 20 Dec 2019 21:35:24 +0000 (16:35 -0500)]
bcachefs: bch2_trans_reset() calls should be at the tops of loops

It needs to be called when we get -EINTR due to e.g. lock restart - this
fixes a transaction iterators overflow bug.

Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
13 months agobcachefs: Drop a faulty assertion
Kent Overstreet [Fri, 20 Dec 2019 21:26:27 +0000 (16:26 -0500)]
bcachefs: Drop a faulty assertion

This assertion was wrong for interior nodes (and wasn't terribly useful
to begin with)

Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
13 months agobcachefs: Redo copygc throttling
Kent Overstreet [Fri, 20 Dec 2019 21:19:46 +0000 (16:19 -0500)]
bcachefs: Redo copygc throttling

The code that checked the current free space and waited if it was too
big was causing issues - btree node allocations do not increment the
write IO clock (perhaps they should); but more broadly the check
wouldn't run copygc at all until the device was mostly full, at which
point it might have to do a bunch of work.

This redoes that logic so that copygc starts to run earlier, smoothly
running more and more often as the device becomes closer to full.

Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
13 months agobcachefs: Make io timers less buggy
Kent Overstreet [Thu, 19 Dec 2019 20:07:51 +0000 (15:07 -0500)]
bcachefs: Make io timers less buggy

Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
13 months agobcachefs: Fix a memory splat
Kent Overstreet [Wed, 18 Dec 2019 22:34:36 +0000 (17:34 -0500)]
bcachefs: Fix a memory splat

In __bch2_sb_field_resize, when a field's old a new size was 0, we were
doing an invalid write just past the end of the superblock.

Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
13 months agobcachefs: Redo filesystem usage ioctls
Kent Overstreet [Mon, 16 Dec 2019 22:53:59 +0000 (17:53 -0500)]
bcachefs: Redo filesystem usage ioctls

When disk space accounting was changed to be tracked by replicas entry,
the ioctl interface was never update: this patch finally does that.

Aditionally, the BCH_IOCTL_USAGE ioctl is now broken out into separate
ioctls for filesystem and device usage.

Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
13 months agobcachefs: Update directory timestamps during link
Justin Husted [Tue, 12 Nov 2019 04:14:30 +0000 (20:14 -0800)]
bcachefs: Update directory timestamps during link

Timestamp updates on the directory during a link operation were cached.
This is inconsistent with other metadata operations such as rename, as
well as being less efficient.

Signed-off-by: Justin Husted <sigstop@gmail.com>
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
13 months agobcachefs: Fix for an assertion on filesystem error
Kent Overstreet [Wed, 18 Dec 2019 18:18:33 +0000 (13:18 -0500)]
bcachefs: Fix for an assertion on filesystem error

Normally the in memory i_size is always greater than or equal to i_size
on disk; this doesn't hold on filesystem error.

Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
13 months agobcachefs: Fix a null ptr deref in btree_iter_traverse_one()
Kent Overstreet [Mon, 16 Dec 2019 20:37:47 +0000 (15:37 -0500)]
bcachefs: Fix a null ptr deref in btree_iter_traverse_one()

When traversing nodes and we've reached the end of the btree, the
current btree node will be NULL.

Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
13 months agobcachefs: Kill btree_node_iter_large
Kent Overstreet [Sat, 14 Dec 2019 21:20:33 +0000 (16:20 -0500)]
bcachefs: Kill btree_node_iter_large

Long overdue cleanup - this converts btree_node_iter_large uses to
sort_iter.

Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
13 months agobcachefs: Use one buffer for sorting whiteouts
Kent Overstreet [Sat, 14 Dec 2019 20:55:29 +0000 (15:55 -0500)]
bcachefs: Use one buffer for sorting whiteouts

We're not really supposed to allocate from the same mempool more than
once.

Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
13 months agobcachefs: Refactor whiteouts compaction
Kent Overstreet [Fri, 13 Dec 2019 18:08:37 +0000 (13:08 -0500)]
bcachefs: Refactor whiteouts compaction

The whiteout compaction path - as opposed to just dropping whiteouts -
is now only needed for extents, and soon will only be needed for extent
btree nodes in the old format.

Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
13 months agobcachefs: Whiteout changes
Kent Overstreet [Fri, 29 Nov 2019 19:08:51 +0000 (14:08 -0500)]
bcachefs: Whiteout changes

More prep work for snapshots: extents will soon be using
KEY_TYPE_deleted for whiteouts, with 0 size. But we wen't be able to
keep these whiteouts with the rest of the extents in the btree node, due
to sorting invariants breaking.

We can deal with this by immediately moving the new whiteouts to the
unwritten whiteouts area - this just means those whiteouts won't be
sorted, so we need new code to sort them prior to merging them with the
rest of the keys to be written.

Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
13 months agobcachefs: Always emit new extents on partial overwrite
Kent Overstreet [Wed, 20 Nov 2019 21:22:49 +0000 (16:22 -0500)]
bcachefs: Always emit new extents on partial overwrite

This is prep work for snapshots: the algorithm in
bch2_extent_sort_fix_overlapping() will break when we have multiple
overlapping extents in unrelated snapshots - but, we'll be able to make
extents work like regular keys and use bch2_key_sort_fix_overlapping()
for extent btree nodes if we make a couple changes - the main one being
to always emit new extents when we partially overwrite an existing
(written) extent.

Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
13 months agobcachefs: Fix bch2_verify_insert_pos()
Kent Overstreet [Tue, 26 Nov 2019 22:18:23 +0000 (17:18 -0500)]
bcachefs: Fix bch2_verify_insert_pos()

We were calling __btree_node_key_to_offset() on a key that wasn't in the
btree node.

Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
13 months agobcachefs: Put inline data behind a mount option for now
Kent Overstreet [Fri, 29 Nov 2019 18:48:09 +0000 (13:48 -0500)]
bcachefs: Put inline data behind a mount option for now

Inline data extents + reflink is still broken

Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
13 months agobcachefs: bch2_check_set_feature()
Kent Overstreet [Fri, 29 Nov 2019 18:47:42 +0000 (13:47 -0500)]
bcachefs: bch2_check_set_feature()

New helper function for setting incompatible feature bits

Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
13 months agobcachefs: Switch to macro for bkey_ops
Kent Overstreet [Tue, 26 Nov 2019 22:09:32 +0000 (17:09 -0500)]
bcachefs: Switch to macro for bkey_ops

Older versions of gcc refuse to compile it the other way

Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
13 months agobcachefs: bkey_on_stack_reassemble()
Kent Overstreet [Wed, 20 Nov 2019 19:51:30 +0000 (14:51 -0500)]
bcachefs: bkey_on_stack_reassemble()

Small helper function.

Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
13 months agobcachefs: kill ca->freelist_lock
Kent Overstreet [Wed, 20 Nov 2019 21:16:57 +0000 (16:16 -0500)]
bcachefs: kill ca->freelist_lock

All uses were supposed to be switched over to c->freelist_lock

Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
13 months agobcachefs: Reorganize extents.c
Kent Overstreet [Sat, 16 Nov 2019 21:25:58 +0000 (16:25 -0500)]
bcachefs: Reorganize extents.c

Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
13 months agobcachefs: Inline data extents
Kent Overstreet [Sat, 9 Nov 2019 21:43:16 +0000 (16:43 -0500)]
bcachefs: Inline data extents

This implements extents that have their data inline, in the value,
instead of the bkey value being pointers to the data - and the read and
write paths are updated to read from these new extent types and write
them out, when the write size is small enough.

Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
13 months agobcachefs: Split out extent_update.c
Kent Overstreet [Fri, 15 Nov 2019 20:52:28 +0000 (15:52 -0500)]
bcachefs: Split out extent_update.c

Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
13 months agobcachefs: Rework of cut_front & cut_back
Kent Overstreet [Sun, 10 Nov 2019 00:02:48 +0000 (19:02 -0500)]
bcachefs: Rework of cut_front & cut_back

This changes bch2_cut_front and bch2_cut_back so that they're able to
shorten the size of the value, and it also changes the extent update
path to update the accounting in the btree node when this happens.

When the size of the value is shortened, they zero out the space that's
no longer used, so it's interpreted as noops (as implemented in the last
patch).

Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
13 months agobcachefs: bkey noops
Kent Overstreet [Sun, 10 Nov 2019 04:50:52 +0000 (23:50 -0500)]
bcachefs: bkey noops

For upcoming inline data extents, we're going to need to be able to
shorten the value of existing bkeys in the btree - and to make that work
we're going to be able to need to pad out the space the value previously
took up with something.

This patch changes the various code that iterates over bkeys to handle
k->u64s == 0 as meaning "skip the next 8 bytes".

Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
13 months agobcachefs: kill bch2_extent_has_device()
Kent Overstreet [Sat, 16 Nov 2019 01:40:15 +0000 (20:40 -0500)]
bcachefs: kill bch2_extent_has_device()

Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
13 months agobcachefs: bkey_on_stack
Kent Overstreet [Sat, 9 Nov 2019 21:01:15 +0000 (16:01 -0500)]
bcachefs: bkey_on_stack

This implements code for storing small bkeys on the stack and allocating
out of a mempool if they're too big.

Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
13 months agobcachefs: Make memcpy_to_bio() param const
Kent Overstreet [Thu, 14 Nov 2019 00:46:11 +0000 (19:46 -0500)]
bcachefs: Make memcpy_to_bio() param const

Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
13 months agobcachefs: Use wbc_to_write_flags()
Kent Overstreet [Thu, 14 Nov 2019 00:45:48 +0000 (19:45 -0500)]
bcachefs: Use wbc_to_write_flags()

Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
13 months agobcachefs: Fix erorr path in bch2_write()
Kent Overstreet [Mon, 11 Nov 2019 18:42:10 +0000 (13:42 -0500)]
bcachefs: Fix erorr path in bch2_write()

The error path in bch2_write wasn't updated when the end_io callback was
added to bch_write_op.

Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
13 months agobcachefs: Set lost+found mode to 0700
Justin Husted [Sun, 10 Nov 2019 03:15:40 +0000 (19:15 -0800)]
bcachefs: Set lost+found mode to 0700

For security and conformance with other filesystems, the lost+found
directory should not be world or group accessible.

Signed-off-by: Justin Husted <sigstop@gmail.com>
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
13 months agobcachefs: Be slightly less tricky with union usage
Kent Overstreet [Sat, 9 Nov 2019 19:58:09 +0000 (14:58 -0500)]
bcachefs: Be slightly less tricky with union usage

This is to fix a valgrind complaint - the code was correct, but too
tricky for valgrind to know that.

Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
13 months agobcachefs: Remove some BKEY_PADDED uses
Kent Overstreet [Fri, 8 Nov 2019 20:09:36 +0000 (15:09 -0500)]
bcachefs: Remove some BKEY_PADDED uses

Prep work for extents with inline data

Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
13 months agobcachefs: Go back to 16 bit mantissa bkey floats
Kent Overstreet [Thu, 7 Nov 2019 00:40:09 +0000 (19:40 -0500)]
bcachefs: Go back to 16 bit mantissa bkey floats

The previous optimizations means using 32 bit mantissas are now a net
loss - having bkey_float be only 4 bytes is good for prefetching.

Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
13 months agobcachefs: Fall back to slowpath on exact comparison
Kent Overstreet [Wed, 23 Oct 2019 18:56:20 +0000 (14:56 -0400)]
bcachefs: Fall back to slowpath on exact comparison

This is basically equivalent to the original strategy of falling back to
checking against the original key when the original key and previous key
didn't differ in the required bits - except, now we only fall back when
the search key doesn't differ in the required bits, which ends up being
a bit faster.

Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
13 months agobcachefs: kill BFLOAT_FAILED_PREV
Kent Overstreet [Wed, 6 Nov 2019 21:37:29 +0000 (16:37 -0500)]
bcachefs: kill BFLOAT_FAILED_PREV

The assumption underlying BFLOAT_FAILED_PREV was wrong; the comparison
we're doing in bset_search_tree() doesn't have to tell the pivot apart
from the previous key, it just has to tell if search is definitely
greater than or equal to the pivot.

Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
13 months agobcachefs: bch2_read_extent() microoptimizations
Kent Overstreet [Thu, 7 Nov 2019 20:04:13 +0000 (15:04 -0500)]
bcachefs: bch2_read_extent() microoptimizations

Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
13 months agobcachefs: Pipeline binary searches and linear searches
Kent Overstreet [Thu, 7 Nov 2019 20:14:10 +0000 (15:14 -0500)]
bcachefs: Pipeline binary searches and linear searches

This makes prefetching for the linear search at the end of the lookup
much more effective, and is a couple percent speedup.

Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
13 months agobcachefs: Make __bch2_bkey_cmp_packed() smaller
Kent Overstreet [Thu, 7 Nov 2019 20:03:09 +0000 (15:03 -0500)]
bcachefs: Make __bch2_bkey_cmp_packed() smaller

We can probably get rid of the version that dispatches based on type
checking too.

Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
13 months agobcachefs: Inline fast path of bch2_increment_clock()
Kent Overstreet [Thu, 7 Nov 2019 20:00:08 +0000 (15:00 -0500)]
bcachefs: Inline fast path of bch2_increment_clock()

Shaving more cycles.

Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
13 months agobcachefs: Avoid calling bch2_btree_iter_relock() in bch2_btree_iter_traverse()
Kent Overstreet [Mon, 4 Nov 2019 20:56:04 +0000 (15:56 -0500)]
bcachefs: Avoid calling bch2_btree_iter_relock() in bch2_btree_iter_traverse()

Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
13 months agobcachefs: Add an option for fsck error ratelimiting
Kent Overstreet [Wed, 6 Nov 2019 20:32:11 +0000 (15:32 -0500)]
bcachefs: Add an option for fsck error ratelimiting

Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
13 months agobcachefs: Don't BUG_ON() sector count overflow
Kent Overstreet [Sat, 26 Oct 2019 18:58:36 +0000 (14:58 -0400)]
bcachefs: Don't BUG_ON() sector count overflow

Return an error instead (still work in progress...)

Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
13 months agobcachefs: Some reflink fixes
Kent Overstreet [Tue, 5 Nov 2019 03:22:13 +0000 (22:22 -0500)]
bcachefs: Some reflink fixes

len might fit into a loff_t when aligned_len does not - make sure we use
a u64 for aligned_len. Also, we weren't always extending the inode
correctly.

Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
13 months agobcachefs: Fix setting of attributes mask in getattr
Kent Overstreet [Wed, 6 Nov 2019 19:29:30 +0000 (14:29 -0500)]
bcachefs: Fix setting of attributes mask in getattr

Discovered by xfstests generic/553

Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
13 months agobcachefs: Eliminate function calls in DIO fastpaths
Kent Overstreet [Wed, 2 Nov 2022 20:45:28 +0000 (16:45 -0400)]
bcachefs: Eliminate function calls in DIO fastpaths

We can assume that usually buffered and O_DIRECT IO won't be mixed, and
the calls to flush the page cache won't be needed.

Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
13 months agobcachefs: DIO write path only needs to shoot down pagecache once, not twice
Kent Overstreet [Mon, 4 Nov 2019 19:11:53 +0000 (14:11 -0500)]
bcachefs: DIO write path only needs to shoot down pagecache once, not twice

Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
13 months agobcachefs: Add pagecache_add lock to buffered IO path, fault path
Kent Overstreet [Fri, 18 Oct 2019 22:24:26 +0000 (18:24 -0400)]
bcachefs: Add pagecache_add lock to buffered IO path, fault path

Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
13 months agobcachefs: Fix uninitialized field in hash_check_init()
Justin Husted [Mon, 4 Nov 2019 05:50:32 +0000 (21:50 -0800)]
bcachefs: Fix uninitialized field in hash_check_init()

The chain_end field was not initialized before use in
hash_set_chain_start.

Signed-off-by: Justin Husted <sigstop@gmail.com>
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
13 months agobcachefs: Don't hold inode lock longer than necessary in dio write path
Kent Overstreet [Sat, 2 Nov 2019 01:35:25 +0000 (21:35 -0400)]
bcachefs: Don't hold inode lock longer than necessary in dio write path

In theory we should be able to do (non appending/extending) dio writes
without taking the inode lock at all - but this gets us most of the way
there.

Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
13 months agobcachefs: Avoid atomics in write fast path
Kent Overstreet [Sat, 2 Nov 2019 01:16:51 +0000 (21:16 -0400)]
bcachefs: Avoid atomics in write fast path

This adds some horrible hacks, but the atomic ops for closures were
getting to be a pretty expensive part of the write path. We don't want
to rip out closures entirely from the write path, because they're used
for e.g. waiting on the allocator, or waiting on the journal flush, and
that stuff would get really ugly without closures.

Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
13 months agobcachefs: Don't use extent_ptr_decoded_append() in write path (fixup patch)
Kent Overstreet [Tue, 29 Oct 2019 07:57:58 +0000 (03:57 -0400)]
bcachefs: Don't use extent_ptr_decoded_append() in write path (fixup patch)

bch2_extent_ptr_decoded_append() is more general than we need here; we
know we're initializing a new extent so e.g. we're going to need the crc
entry.

Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
13 months agobcachefs: bch2_btree_iter_fix_key_modified()
Kent Overstreet [Wed, 2 Oct 2019 13:56:39 +0000 (09:56 -0400)]
bcachefs: bch2_btree_iter_fix_key_modified()

This is considerably cheaper than bch2_btree_node_iter_fix(), for cases
where the key was only modified and key ordering isn't changing.

Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
13 months agobcachefs: Inline more of bch2_trans_commit hot path
Kent Overstreet [Mon, 28 Oct 2019 23:35:13 +0000 (19:35 -0400)]
bcachefs: Inline more of bch2_trans_commit hot path

The main optimization here is that if we let
bch2_replicas_delta_list_apply() fail, we can completely skip calling
bch2_bkey_replicas_marked_locked().

And assorted other small optimizations.

Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
13 months agobcachefs: Trust btree alloc info at runtime
Kent Overstreet [Mon, 28 Oct 2019 23:33:59 +0000 (19:33 -0400)]
bcachefs: Trust btree alloc info at runtime

This lets us avoid a cache miss in the write path.

Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
13 months agobcachefs: More bset.c microoptimization
Kent Overstreet [Wed, 23 Oct 2019 23:50:01 +0000 (19:50 -0400)]
bcachefs: More bset.c microoptimization

Improve a few paper cuts that've shown up during profiling.

Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
13 months agobcachefs: Initialize btree_node flags field in bch2_btree_root_alloc.
Justin Husted [Sat, 12 Oct 2019 00:56:27 +0000 (17:56 -0700)]
bcachefs: Initialize btree_node flags field in bch2_btree_root_alloc.

Valgrind data indicated that the flags field was only partially
initialized when written to disk.

Signed-off-by: Justin Husted <sigstop@gmail.com>
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
13 months agobcachefs: Further padding fixes in bch2_journal_super_entries_add_common()
Justin Husted [Sat, 12 Oct 2019 00:05:11 +0000 (17:05 -0700)]
bcachefs: Further padding fixes in bch2_journal_super_entries_add_common()

The previous patch 128cb1a to fix uninitialized data was incorrect and
did not initialize the padding space correctly. Furthermore, several
other cases in this function do not initialize their padding space
correctly.

Move initialization into some helper functions in a more robust way.

Signed-off-by: Justin Husted <sigstop@gmail.com>
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
13 months agobcachefs: Initialize padding space after alloc bkey
Justin Husted [Sat, 12 Oct 2019 00:20:30 +0000 (17:20 -0700)]
bcachefs: Initialize padding space after alloc bkey

Packed bkeys are padded up to 64 bit alignment, but the alloc bkey type
was not clearing the pad bytes after the last data byte. This left the
key possibly containing some random garbage at the end.

This problem was found using valgrind.

This patch also changes a path with the inode bkey to clear in the same
way.

Signed-off-by: Justin Husted <sigstop@gmail.com>
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
13 months agobcachefs: Add missing error checking in bch2_find_by_inum_trans()
Kent Overstreet [Fri, 25 Oct 2019 23:06:26 +0000 (19:06 -0400)]
bcachefs: Add missing error checking in bch2_find_by_inum_trans()

Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
13 months agobcachefs: Fix an error path race
Kent Overstreet [Fri, 25 Oct 2019 22:54:58 +0000 (18:54 -0400)]
bcachefs: Fix an error path race

On IO error, bch2_writepages_io_done() will set the page state to
indicate nothing's already reserved (since the write didn't happen, we
don't know what's already reserved). This can race with the buffered IO
path, in between getting a disk reservation and calling
bch2_set_page_dirty().

Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
13 months agobcachefs: Don't reuse bio in retry path
Kent Overstreet [Thu, 24 Oct 2019 18:22:29 +0000 (14:22 -0400)]
bcachefs: Don't reuse bio in retry path

We can't reuse bios without reinitializing them, and in the retry path
it's safer to just make sure we don't reuse them at all.

Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
13 months agobcachefs: Don't use rep movsq for small memcopies
Kent Overstreet [Tue, 22 Oct 2019 21:35:35 +0000 (17:35 -0400)]
bcachefs: Don't use rep movsq for small memcopies

Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
13 months agobcachefs: Avoid calling iter_prev() in extent update path
Kent Overstreet [Tue, 22 Oct 2019 01:15:08 +0000 (21:15 -0400)]
bcachefs: Avoid calling iter_prev() in extent update path

Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
13 months agobcachefs: kill bch2_extent_merge_inline()
Kent Overstreet [Tue, 22 Oct 2019 01:27:10 +0000 (21:27 -0400)]
bcachefs: kill bch2_extent_merge_inline()

Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
13 months agobcachefs: Don't use FUA unnecessarily
Kent Overstreet [Mon, 21 Oct 2019 23:38:08 +0000 (19:38 -0400)]
bcachefs: Don't use FUA unnecessarily

Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
13 months agobcachefs: Refactor bch2_trans_commit() path
Kent Overstreet [Sat, 19 Oct 2019 23:03:23 +0000 (19:03 -0400)]
bcachefs: Refactor bch2_trans_commit() path

Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
13 months agobcachefs: Make btree_node_type_needs_gc() cheaper
Kent Overstreet [Sun, 20 Oct 2019 04:24:51 +0000 (00:24 -0400)]
bcachefs: Make btree_node_type_needs_gc() cheaper

Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
13 months agobcachefs: Make replicas_delta_list smaller
Kent Overstreet [Sun, 20 Oct 2019 02:22:29 +0000 (22:22 -0400)]
bcachefs: Make replicas_delta_list smaller

Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
13 months agobcachefs: Don't submit bio in write path under lock
Kent Overstreet [Mon, 21 Oct 2019 23:58:06 +0000 (19:58 -0400)]
bcachefs: Don't submit bio in write path under lock

Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
13 months agobcachefs: Drop bch_write_op->io_wq
Kent Overstreet [Tue, 22 Oct 2019 00:40:53 +0000 (20:40 -0400)]
bcachefs: Drop bch_write_op->io_wq

This is dead code

Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>