<feed xmlns='http://www.w3.org/2005/Atom'>
<title>linux/fs/bcachefs/bkey_sort.c, branch master</title>
<subtitle>Mirror of https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/
</subtitle>
<id>https://git.shady.money/linux/atom?h=master</id>
<link rel='self' href='https://git.shady.money/linux/atom?h=master'/>
<link rel='alternate' type='text/html' href='https://git.shady.money/linux/'/>
<updated>2025-09-29T20:43:52Z</updated>
<entry>
<title>Remove bcachefs core code</title>
<updated>2025-09-29T20:43:52Z</updated>
<author>
<name>Linus Torvalds</name>
<email>torvalds@linux-foundation.org</email>
</author>
<published>2025-09-29T20:43:52Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/linux/commit/?id=f2c61db29f277b9c80de92102fc532cc247495cd'/>
<id>urn:sha1:f2c61db29f277b9c80de92102fc532cc247495cd</id>
<content type='text'>
bcachefs was marked 'externally maintained' in 6.17 but the code
remained to make the transition smoother.

It's now a DKMS module, making the in-kernel code stale, so remove
it to avoid any version confusion.

Link: https://lore.kernel.org/linux-bcachefs/yokpt2d2g2lluyomtqrdvmkl3amv3kgnipmenobkpgx537kay7@xgcgjviv3n7x/T/
Signed-off-by: Linus Torvalds &lt;torvalds@linux-foundation.org&gt;
</content>
</entry>
<entry>
<title>bcachefs: Fix needs_whiteout BUG_ON() in bkey_sort()</title>
<updated>2024-05-08T18:56:09Z</updated>
<author>
<name>Kent Overstreet</name>
<email>kent.overstreet@linux.dev</email>
</author>
<published>2024-05-08T04:29:24Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/linux/commit/?id=5dfd3746b6c486db18bc75de89c7abce41c7826c'/>
<id>urn:sha1:5dfd3746b6c486db18bc75de89c7abce41c7826c</id>
<content type='text'>
Btree nodes are log structured; thus, we need to emit whiteouts when
we're deleting a key that's been written out to disk.

k-&gt;needs_whiteout tracks whether a key will need a whiteout when it's
deleted, and this requires some careful handling; e.g. the key we're
deleting may not have been written out to disk, but it may have
overwritten a key that was - thus we need to carry this flag around on
overwrites.

Invariants:
There may be multiple key for the same position in a given node (because
of overwrites), but only one of them will be a live (non deleted) key,
and only one key for a given position will have the needs_whiteout flag
set.

Additionally, we don't want to carry around whiteouts that need to be
written in the main searchable part of a btree node - btree_iter_peek()
will have to skip past them, and this can lead to an O(n^2) issues when
doing sequential deletions (e.g. inode rm/truncate). So there's a
separate region in the btree node buffer for unwritten whiteouts; these
are merge sorted with the rest of the keys we're writing in the btree
node write path.

The unwritten whiteouts was a later optimization that bch2_sort_keys()
didn't take into account; the unwritten whiteouts area means that we
never have deleted keys with needs_whiteout set in the main searchable
part of a btree node.

That means we can simplify and optimize some sort paths, and eliminate
an assertion that syzbot found:

- Unless we're in the btree node write path, it's always ok to drop
  whiteouts when sorting
- When sorting for a btree node write, we drop the whiteout if it's not
  from the unwritten whiteouts area, or if it's overwritten by a real
  key at the same position.

This completely eliminates some tricky logic for propagating the
needs_whiteout flag: syzbot was able to hit the assertion that checked
that there shouldn't be more than one key at the same pos with
needs_whiteout set, likely due to a combination of flipping on
needs_whiteout on all written keys (they need whiteouts if overwritten),
combined with not always dropping unneeded whiteouts, and the tricky
logic in the sort path for preserving needs_whiteout that wasn't really
needed.

Signed-off-by: Kent Overstreet &lt;kent.overstreet@linux.dev&gt;
</content>
</entry>
<entry>
<title>bcachefs: bkey_copy() is no longer a macro</title>
<updated>2023-11-05T18:12:18Z</updated>
<author>
<name>Kent Overstreet</name>
<email>kent.overstreet@linux.dev</email>
</author>
<published>2023-11-02T23:33:48Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/linux/commit/?id=a8958a1a95b28e16dbca0654eeb6aa458bb1d3b0'/>
<id>urn:sha1:a8958a1a95b28e16dbca0654eeb6aa458bb1d3b0</id>
<content type='text'>
Signed-off-by: Kent Overstreet &lt;kent.overstreet@linux.dev&gt;
</content>
</entry>
<entry>
<title>bcachefs: Use memcpy_u64s_small() for copying keys</title>
<updated>2023-10-22T21:10:01Z</updated>
<author>
<name>Kent Overstreet</name>
<email>kent.overstreet@linux.dev</email>
</author>
<published>2023-05-13T21:21:55Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/linux/commit/?id=d598a9b7e27158d3b6972077e2f7296f279c2e8b'/>
<id>urn:sha1:d598a9b7e27158d3b6972077e2f7296f279c2e8b</id>
<content type='text'>
Small performance optimization; an open coded loop is better than rep ;
movsq for small copies.

Signed-off-by: Kent Overstreet &lt;kent.overstreet@linux.dev&gt;
</content>
</entry>
<entry>
<title>bcachefs: Drop some anonymous structs, unions</title>
<updated>2023-10-22T21:09:55Z</updated>
<author>
<name>Kent Overstreet</name>
<email>kent.overstreet@linux.dev</email>
</author>
<published>2023-03-05T04:05:55Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/linux/commit/?id=ac2ccddc2689d5889fd1520383738b60dbafc1d0'/>
<id>urn:sha1:ac2ccddc2689d5889fd1520383738b60dbafc1d0</id>
<content type='text'>
Rust bindgen doesn't cope well with anonymous structs and unions. This
patch drops the fancy anonymous structs &amp; unions in bkey_i that let us
use the same helpers for bkey_i and bkey_packed; since bkey_packed is an
internal type that's never exposed to outside code, it's only a minor
inconvenienc.

Signed-off-by: Kent Overstreet &lt;kent.overstreet@linux.dev&gt;
</content>
</entry>
<entry>
<title>bcachefs: Btree split improvement</title>
<updated>2023-10-22T21:09:46Z</updated>
<author>
<name>Kent Overstreet</name>
<email>kent.overstreet@linux.dev</email>
</author>
<published>2022-11-16T02:52:12Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/linux/commit/?id=4fcdd6ec345e1aeed23fbdbe53d62965c1a79b99'/>
<id>urn:sha1:4fcdd6ec345e1aeed23fbdbe53d62965c1a79b99</id>
<content type='text'>
This improves the bkey_format calculation when splitting btree nodes.
Previously, we'd use a format calculated for the original node for the
lower of the two new nodes.

This was particularly bad on sequential insertions, where we iteratively
split the last btree node, whos format has to include KEY_MAX.

Now, we calculate formats precisely for the keys the two new nodes will
contain. This also should make splitting a bit more efficient, since
we're only copying keys once (from the original node to the new node,
instead of new node, replacement node, then upper split).

Signed-off-by: Kent Overstreet &lt;kent.overstreet@linux.dev&gt;
</content>
</entry>
<entry>
<title>bcachefs: bch2_bkey_cmp_packed_inlined()</title>
<updated>2023-10-22T21:09:45Z</updated>
<author>
<name>Kent Overstreet</name>
<email>kent.overstreet@linux.dev</email>
</author>
<published>2022-10-21T23:20:09Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/linux/commit/?id=e5baf3dad91a6561ab81e2514217876d58648c1a'/>
<id>urn:sha1:e5baf3dad91a6561ab81e2514217876d58648c1a</id>
<content type='text'>
This adds an inlined version of bch2_bkey_cmp_packed(), and uses it in
bch2_sort_keys(), where it's part of the inner loop.

Signed-off-by: Kent Overstreet &lt;kent.overstreet@linux.dev&gt;
</content>
</entry>
<entry>
<title>bcachefs: Don't call bch2_bkey_transform() unnecessarily</title>
<updated>2023-10-22T21:09:19Z</updated>
<author>
<name>Kent Overstreet</name>
<email>kent.overstreet@gmail.com</email>
</author>
<published>2021-12-20T00:01:41Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/linux/commit/?id=7a0e4afb1a1116a3580144c7c902e6024333f20e'/>
<id>urn:sha1:7a0e4afb1a1116a3580144c7c902e6024333f20e</id>
<content type='text'>
If the packed format isn't changing, there's no need to call
bch2_bkey_transform().

Signed-off-by: Kent Overstreet &lt;kent.overstreet@gmail.com&gt;
</content>
</entry>
<entry>
<title>bcachefs: Kill bch2_sort_repack_merge()</title>
<updated>2023-10-22T21:09:19Z</updated>
<author>
<name>Kent Overstreet</name>
<email>kent.overstreet@gmail.com</email>
</author>
<published>2021-12-19T23:59:22Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/linux/commit/?id=62d5bd955fd81320d1e03fdebb4342ee14df1d1f'/>
<id>urn:sha1:62d5bd955fd81320d1e03fdebb4342ee14df1d1f</id>
<content type='text'>
The main function of bch2_sort_repack_merge() was to call .key_normalize
on every key, which drops stale (cached) pointers - it hasn't actually
merged extents in quite some time.

But bch2_gc_gens() now works on individual keys - we used to gc old gens
by rewriting entire btree nodes. With that gone, there's no need for
internal btree code to be calling .key_normalize anymore.

Signed-off-by: Kent Overstreet &lt;kent.overstreet@gmail.com&gt;
</content>
</entry>
<entry>
<title>bcachefs: Drop bkey noops</title>
<updated>2023-10-22T21:08:57Z</updated>
<author>
<name>Kent Overstreet</name>
<email>kent.overstreet@gmail.com</email>
</author>
<published>2021-03-25T00:22:51Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/linux/commit/?id=0390ea8ad8f4079c25d47e8c249a2f621aaec3c0'/>
<id>urn:sha1:0390ea8ad8f4079c25d47e8c249a2f621aaec3c0</id>
<content type='text'>
Bkey noops were introduced to deal with trimming inline data extents in
place in the btree: if the u64s field of a bkey was 0, that u64 was a
noop and we'd start looking for the next bkey immediately after it.

But extent handling has been lifted above the btree - we no longer
modify existing extents in place in the btree, and the compatibilty code
for old style extent btree nodes is gone, so we can completely drop this
code.

Signed-off-by: Kent Overstreet &lt;kent.overstreet@gmail.com&gt;
Signed-off-by: Kent Overstreet &lt;kent.overstreet@linux.dev&gt;
</content>
</entry>
</feed>
