From: Qu Wenruo <quwenruo.btrfs@gmx.com>
To: David Sterba <dsterba@suse.com>, linux-btrfs@vger.kernel.org
Subject: Re: [PATCH 09/10] btrfs: reduce size of struct btrfs_ref
Date: Fri, 8 Sep 2023 08:06:04 +0800 [thread overview]
Message-ID: <d2f53cb0-7e09-4211-bc21-e2a4fc195dfa@gmx.com> (raw)
In-Reply-To: <c9b508651bafb53e98b9f194271d4b7b2d309cba.1694126893.git.dsterba@suse.com>
On 2023/9/8 07:09, David Sterba wrote:
> We can reduce two members' size that in turn reduce size of struct
> btrfs_ref from 64 to 56 bytes. As the structure is often used as a local
> variable several functions reduce their stack usage.
>
> - make enum btrfs_ref_type packed, there are only 4 values
>
> - switch action and its values to a packed enum
>
> Final structure layout:
>
> struct btrfs_ref {
> enum btrfs_ref_type type; /* 0 1 */
> enum btrfs_delayed_ref_action action; /* 1 1 */
Considering both type and action have only 4 values, we can further pack
them into a single u8.
Although this means we can not directly use enum type, but u8 type instead.
Thanks,
Qu
> bool skip_qgroup; /* 2 1 */
>
> /* XXX 5 bytes hole, try to pack */
>
> u64 bytenr; /* 8 8 */
> u64 len; /* 16 8 */
> u64 parent; /* 24 8 */
> union {
> struct btrfs_data_ref data_ref; /* 32 24 */
> struct btrfs_tree_ref tree_ref; /* 32 16 */
> }; /* 32 24 */
>
> /* size: 56, cachelines: 1, members: 7 */
> /* sum members: 51, holes: 1, sum holes: 5 */
> /* last cacheline: 56 bytes */
> };
>
> Signed-off-by: David Sterba <dsterba@suse.com>
> ---
> fs/btrfs/delayed-ref.h | 18 ++++++++++++------
> 1 file changed, 12 insertions(+), 6 deletions(-)
>
> diff --git a/fs/btrfs/delayed-ref.h b/fs/btrfs/delayed-ref.h
> index b8e14b0ba5f1..224278d4516f 100644
> --- a/fs/btrfs/delayed-ref.h
> +++ b/fs/btrfs/delayed-ref.h
> @@ -9,10 +9,16 @@
> #include <linux/refcount.h>
>
> /* these are the possible values of struct btrfs_delayed_ref_node->action */
> -#define BTRFS_ADD_DELAYED_REF 1 /* add one backref to the tree */
> -#define BTRFS_DROP_DELAYED_REF 2 /* delete one backref from the tree */
> -#define BTRFS_ADD_DELAYED_EXTENT 3 /* record a full extent allocation */
> -#define BTRFS_UPDATE_DELAYED_HEAD 4 /* not changing ref count on head ref */
> +enum btrfs_delayed_ref_action {
> + /* Add one backref to the tree */
> + BTRFS_ADD_DELAYED_REF = 1,
> + /* Delete one backref from the tree */
> + BTRFS_DROP_DELAYED_REF,
> + /* Record a full extent allocation */
> + BTRFS_ADD_DELAYED_EXTENT,
> + /* Not changing ref count on head ref */
> + BTRFS_UPDATE_DELAYED_HEAD,
> +} __packed;
>
> struct btrfs_delayed_ref_node {
> struct rb_node ref_node;
> @@ -183,7 +189,7 @@ enum btrfs_ref_type {
> BTRFS_REF_DATA,
> BTRFS_REF_METADATA,
> BTRFS_REF_LAST,
> -};
> +} __packed;
>
> struct btrfs_data_ref {
> /* For EXTENT_DATA_REF */
> @@ -223,7 +229,7 @@ struct btrfs_tree_ref {
>
> struct btrfs_ref {
> enum btrfs_ref_type type;
> - int action;
> + enum btrfs_delayed_ref_action action;
>
> /*
> * Whether this extent should go through qgroup record.
next prev parent reply other threads:[~2023-09-08 0:06 UTC|newest]
Thread overview: 27+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-09-07 23:09 [PATCH 00/10] Cleanups and struct packing David Sterba
2023-09-07 23:09 ` [PATCH 01/10] btrfs: move functions comments from qgroup.h to qgroup.c David Sterba
2023-09-07 23:47 ` Qu Wenruo
2023-09-07 23:09 ` [PATCH 02/10] btrfs: reformat remaining kdoc style comments David Sterba
2023-09-07 23:51 ` Qu Wenruo
2023-09-08 0:14 ` David Sterba
2023-09-07 23:09 ` [PATCH 03/10] btrfs: drop __must_check annotations David Sterba
2023-09-07 23:56 ` Qu Wenruo
2023-09-08 0:34 ` David Sterba
2023-09-08 12:33 ` David Sterba
2023-09-07 23:09 ` [PATCH 04/10] btrfs: reduce parameters of btrfs_pin_reserved_extent David Sterba
2023-09-07 23:57 ` Qu Wenruo
2023-09-07 23:09 ` [PATCH 05/10] btrfs: reduce parameters of btrfs_pin_extent_for_log_replay David Sterba
2023-09-07 23:57 ` Qu Wenruo
2023-09-07 23:09 ` [PATCH 06/10] btrfs: reduce arguments of helpers space accounting root item David Sterba
2023-09-07 23:59 ` Qu Wenruo
2023-09-07 23:09 ` [PATCH 07/10] btrfs: reduce size of prelim_ref::level David Sterba
2023-09-08 0:01 ` Qu Wenruo
2023-09-07 23:09 ` [PATCH 08/10] btrfs: reduce size and reorder compression members in struct btrfs_inode David Sterba
2023-09-08 0:02 ` Qu Wenruo
2023-09-07 23:09 ` [PATCH 09/10] btrfs: reduce size of struct btrfs_ref David Sterba
2023-09-08 0:06 ` Qu Wenruo [this message]
2023-09-08 0:46 ` David Sterba
2023-09-07 23:09 ` [PATCH 10/10] btrfs: move extent_buffer::lock_owner to debug section David Sterba
2023-09-08 0:11 ` Qu Wenruo
2023-09-08 0:56 ` David Sterba
2023-09-08 1:29 ` Qu Wenruo
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=d2f53cb0-7e09-4211-bc21-e2a4fc195dfa@gmx.com \
--to=quwenruo.btrfs@gmx.com \
--cc=dsterba@suse.com \
--cc=linux-btrfs@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox