diff mbox series

[v3,2/4] btrfs: create structure to encode checksum type and length

Message ID 20190826114834.14789-3-jthumshirn@suse.de (mailing list archive)
State New, archived
Headers show
Series btrfs: support xxhash64 checksums | expand

Commit Message

Johannes Thumshirn Aug. 26, 2019, 11:48 a.m. UTC
Create a structure to encode the type and length for the known on-disk
checksums.

This makes it easier to add new checksums later.

Signed-off-by: Johannes Thumshirn <jthumshirn@suse.de>

---
Changes to v2:
- Really remove initializer macro *doh*

Changes to v1:
- Remove initializer macro (David)
---
 fs/btrfs/ctree.h | 13 ++++++++-----
 1 file changed, 8 insertions(+), 5 deletions(-)

Comments

David Sterba Aug. 28, 2019, 7:19 p.m. UTC | #1
On Mon, Aug 26, 2019 at 01:48:32PM +0200, Johannes Thumshirn wrote:
> Create a structure to encode the type and length for the known on-disk
> checksums.
> 
> This makes it easier to add new checksums later.
> 
> Signed-off-by: Johannes Thumshirn <jthumshirn@suse.de>
> 
> ---
> Changes to v2:
> - Really remove initializer macro *doh*
> 
> Changes to v1:
> - Remove initializer macro (David)
> ---
>  fs/btrfs/ctree.h | 13 ++++++++-----
>  1 file changed, 8 insertions(+), 5 deletions(-)
> 
> diff --git a/fs/btrfs/ctree.h b/fs/btrfs/ctree.h
> index b161224b5a0b..139354d02dfa 100644
> --- a/fs/btrfs/ctree.h
> +++ b/fs/btrfs/ctree.h
> @@ -82,9 +82,12 @@ struct btrfs_ref;
>   */
>  #define BTRFS_LINK_MAX 65535U
>  
> -/* four bytes for CRC32 */
> -static const int btrfs_csum_sizes[] = { 4 };
> -static const char *btrfs_csum_names[] = { "crc32c" };
> +static const struct btrfs_csums {
> +	u16		size;
> +	const char	*name;
> +} btrfs_csums[] = {
> +	[BTRFS_CSUM_TYPE_CRC32] = { .size = 4, .name = "crc32c" },
> +};

In one of the previous iterations, I pointed out that the definition is
in a header, thus each file that includes "ctree.h" (many of them)
has a private copy of the table. With just crc32c it's just a few bytes
that gets lost in the noise but now the table is going to be larger the
impact will be noticeable.
David Sterba Aug. 28, 2019, 7:38 p.m. UTC | #2
On Wed, Aug 28, 2019 at 09:19:52PM +0200, David Sterba wrote:
> On Mon, Aug 26, 2019 at 01:48:32PM +0200, Johannes Thumshirn wrote:
> > Create a structure to encode the type and length for the known on-disk
> > checksums.
> > 
> > This makes it easier to add new checksums later.
> > 
> > Signed-off-by: Johannes Thumshirn <jthumshirn@suse.de>
> > 
> > ---
> > Changes to v2:
> > - Really remove initializer macro *doh*
> > 
> > Changes to v1:
> > - Remove initializer macro (David)
> > ---
> >  fs/btrfs/ctree.h | 13 ++++++++-----
> >  1 file changed, 8 insertions(+), 5 deletions(-)
> > 
> > diff --git a/fs/btrfs/ctree.h b/fs/btrfs/ctree.h
> > index b161224b5a0b..139354d02dfa 100644
> > --- a/fs/btrfs/ctree.h
> > +++ b/fs/btrfs/ctree.h
> > @@ -82,9 +82,12 @@ struct btrfs_ref;
> >   */
> >  #define BTRFS_LINK_MAX 65535U
> >  
> > -/* four bytes for CRC32 */
> > -static const int btrfs_csum_sizes[] = { 4 };
> > -static const char *btrfs_csum_names[] = { "crc32c" };
> > +static const struct btrfs_csums {
> > +	u16		size;
> > +	const char	*name;
> > +} btrfs_csums[] = {
> > +	[BTRFS_CSUM_TYPE_CRC32] = { .size = 4, .name = "crc32c" },
> > +};
> 
> In one of the previous iterations, I pointed out that the definition is
> in a header, thus each file that includes "ctree.h" (many of them)
> has a private copy of the table. With just crc32c it's just a few bytes
> that gets lost in the noise but now the table is going to be larger the
> impact will be noticeable.

With definitions moved to ctree.c and only exported the two helpers that
need btrfs_csumss

   text    data     bss     dec     hex filename
1080108   17316   14912 1112336  10f910 btrfs.ko.before
1079655   17316   14912 1111883  10f74b btrfs.ko.after

The difference is 453.
diff mbox series

Patch

diff --git a/fs/btrfs/ctree.h b/fs/btrfs/ctree.h
index b161224b5a0b..139354d02dfa 100644
--- a/fs/btrfs/ctree.h
+++ b/fs/btrfs/ctree.h
@@ -82,9 +82,12 @@  struct btrfs_ref;
  */
 #define BTRFS_LINK_MAX 65535U
 
-/* four bytes for CRC32 */
-static const int btrfs_csum_sizes[] = { 4 };
-static const char *btrfs_csum_names[] = { "crc32c" };
+static const struct btrfs_csums {
+	u16		size;
+	const char	*name;
+} btrfs_csums[] = {
+	[BTRFS_CSUM_TYPE_CRC32] = { .size = 4, .name = "crc32c" },
+};
 
 #define BTRFS_EMPTY_DIR_SIZE 0
 
@@ -2207,13 +2210,13 @@  static inline int btrfs_super_csum_size(const struct btrfs_super_block *s)
 	/*
 	 * csum type is validated at mount time
 	 */
-	return btrfs_csum_sizes[t];
+	return btrfs_csums[t].size;
 }
 
 static inline const char *btrfs_super_csum_name(u16 csum_type)
 {
 	/* csum type is validated at mount time */
-	return btrfs_csum_names[csum_type];
+	return btrfs_csums[csum_type].name;
 }
 
 /*