Skip to contentSkip to conversation

btrfs: add little-endian optimized key helpers

PATCH In review David Sterba 4 participants 4 messages Jun 9, 2020 – Jun 10, 2020 Btrfs file system

lore
Share & tools
lore

David Sterba

author maintainer
#0 lore raw

PATCH 1/1 btrfs: add little-endian optimized key helpers

The CPU and on-disk keys are mapped to two different structures because of the endianity. There's an intermediate buffer used to do the conversion, but this is not necessary when CPU and on-disk endianity matches.

Add optimized versions of helpers that take disk_key and use the buffer directly for CPU keys or drop the intermediate buffer and conversion.

This saves a lot of stack space accross many functions and removes about 6K of generated binary code:

text data bss dec hex filename

1090439   17468   14912 1122819  112203 pre/btrfs.ko
1084613   17456   14912 1116981  110b35 post/btrfs.ko

Delta: -5826

---
 fs/btrfs/ctree.c | 17 +++++++++++++++++
 fs/btrfs/ctree.h | 48 ++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 65 insertions(+)
fs/btrfs/ctree.c +17 -0
index 3a7648bff42c..de7ad39bcafd 100644
@@ -1501,6 +1501,22 @@ static int close_blocks(u64 blocknr, u64 other, u32 blocksize)
 	return 0;
 }
 
+#ifdef __LITTLE_ENDIAN
+
+/*
+ * Compare two keys, on little-endian the disk order is same as CPU order and
+ * we can avoid the conversion.
+ */
+static int comp_keys(const struct btrfs_disk_key *disk_key,
+		     const struct btrfs_key *k2)
+{
+	const struct btrfs_key *k1 = (const struct btrfs_key *)disk_key;
+
+	return btrfs_comp_cpu_keys(k1, k2);
+}
+
+#else
+
 /*
  * compare two keys in a memcmp fashion
  */
@@ -1513,6 +1529,7 @@ static int comp_keys(const struct btrfs_disk_key *disk,
 
 	return btrfs_comp_cpu_keys(&k1, k2);
 }
+#endif
 
 /*
  * same as comp_keys only with two btrfs_key's
fs/btrfs/ctree.h +48 -0

60 lines not on this page · raw message

Signature · 1 line
2.25.0
Reviewed-by on v1 1/1
#1 lore raw
Quoted 11 lines · David Sterba

The CPU and on-disk keys are mapped to two different structures because of the endianity. There's an intermediate buffer used to do the conversion, but this is not necessary when CPU and on-disk endianity matches.

Add optimized versions of helpers that take disk_key and use the buffer directly for CPU keys or drop the intermediate buffer and conversion.

This saves a lot of stack space accross many functions and removes about 6K of generated binary code:

Quoted 7 lines

text data bss dec hex filename

1090439   17468   14912 1122819  112203 pre/btrfs.ko
1084613   17456   14912 1116981  110b35 post/btrfs.ko

Delta: -5826

#3 lore raw
Quoted 3 lines · Johannes Thumshirn

One question, why endianity instead of endianess? I think the latter is more common (in fact I had to google to see if the former even exists)

It exists but you're right that endianness (double n) is more common, I'll fix it. Thanks.