public inbox for linux-btrfs@vger.kernel.org
 help / color / mirror / Atom feed
From: David Sterba <dsterba@suse.cz>
To: fdmanana@kernel.org
Cc: linux-btrfs@vger.kernel.org
Subject: Re: [PATCH 7/8] btrfs: use a dedicated data structure for chunk maps
Date: Tue, 21 Nov 2023 16:19:33 +0100	[thread overview]
Message-ID: <20231121151933.GR11264@twin.jikos.cz> (raw)
In-Reply-To: <777320fd09dfc68a89180723bf5d7368dab06299.1700573314.git.fdmanana@suse.com>

On Tue, Nov 21, 2023 at 01:38:38PM +0000, fdmanana@kernel.org wrote:
> From: Filipe Manana <fdmanana@suse.com>
> 
> Currently we abuse the extent_map structure for two purposes:
> 
> 1) To actually represent extents for inodes;
> 2) To represent chunk mappings.
> 
> This is odd and has several disadvantages:
> 
> 1) To create a chunk map, we need to do two memory allocations: one for
>    an extent_map structure and another one for a map_lookup structure, so
>    more potential for an allocation failure and more complicated code to
>    manage and link two structures;
> 
> 2) For a chunk map we actually only use 3 fields (24 bytes) of the
>    respective extent map structure: the 'start' field to have the logical
>    start address of the chunk, the 'len' field to have the chunk's size,
>    and the 'orig_block_len' field to contain the chunk's stripe size.
> 
>    Besides wasting a memory, it's also odd and not intuitive at all to
>    have the stripe size in a field named 'orig_block_len'.
> 
>    We are also using 'block_len' of the extent_map structure to contain
>    the chunk size, so we have 2 fields for the same value, 'len' and
>    'block_len', which is pointless;
> 
> 3) When an extent map is associated to a chunk mapping, we set the bit
>    EXTENT_FLAG_FS_MAPPING on its flags and then make its member named
>    'map_lookup' point to the associated map_lookup structure. This means
>    that for an extent map associated to an inode extent, we are not using
>    this 'map_lookup' pointer, so wasting 8 bytes (on a 64 bits platform);
> 
> 4) Extent maps associated to a chunk mapping are never merged or split so
>    it's pointless to use the existing extent map infrastructure.
> 
> So add a dedicated data structure named 'btrfs_chunk_map' to represent
> chunk mappings, this is basically the existing map_lookup structure with
> some extra fields:
> 
> 1) 'start' to contain the chunk logical address;
> 2) 'chunk_len' to contain the chunk's length;
> 3) 'stripe_size' for the stripe size;
> 4) 'rb_node' for insertion into a rb tree;
> 5) 'refs' for reference counting.
> 
> This way we do a single memory allocation for chunk mappings and we don't
> waste memory for them with unused/unnecessary fields from an extent_map.
> 
> We also save 8 bytes from the extent_map structure by removing the
> 'map_lookup' pointer, so the size of struct extent_map is reduced from
> 144 bytes down to 136 bytes, and we can now have 30 extents map per 4K
> page instead of 28.
> 
> Signed-off-by: Filipe Manana <fdmanana@suse.com>
> ---
>  fs/btrfs/block-group.c            | 165 ++++-----
>  fs/btrfs/block-group.h            |   6 +-
>  fs/btrfs/dev-replace.c            |  28 +-
>  fs/btrfs/disk-io.c                |   7 +-
>  fs/btrfs/extent_map.c             |  46 ---
>  fs/btrfs/extent_map.h             |   4 -
>  fs/btrfs/fs.h                     |   3 +-
>  fs/btrfs/inode.c                  |  25 +-
>  fs/btrfs/raid56.h                 |   2 +-
>  fs/btrfs/scrub.c                  |  39 +--
>  fs/btrfs/tests/btrfs-tests.c      |   3 +-
>  fs/btrfs/tests/btrfs-tests.h      |   1 +
>  fs/btrfs/tests/extent-map-tests.c |  40 +--
>  fs/btrfs/volumes.c                | 540 ++++++++++++++++++------------
>  fs/btrfs/volumes.h                |  45 ++-
>  fs/btrfs/zoned.c                  |  24 +-

I see a lot of errors when compiling zoned.c, there are still map_lookup
structures. Do you have the zoned mode config option enabled?

  CC [M]  fs/btrfs/zoned.o                                                                                
fs/btrfs/zoned.c:1293:40: warning: ‘struct map_lookup’ declared inside parameter list will not be visible outside of this definition or declaration
 1293 |                                 struct map_lookup *map)                                                                                                                                                      
      |                                        ^~~~~~~~~~              
fs/btrfs/zoned.c: In function ‘btrfs_load_zone_info’:                                                     
fs/btrfs/zoned.c:1296:42: error: invalid use of undefined type ‘struct map_lookup’                                                                                                                                   
 1296 |         struct btrfs_device *device = map->stripes[zone_idx].dev;                 
      |                                          ^~                                                       
fs/btrfs/zoned.c:1302:29: error: invalid use of undefined type ‘struct map_lookup’                        
 1302 |         info->physical = map->stripes[zone_idx].physical;                         
      |                             ^~                                                                                                                                                                               
fs/btrfs/zoned.c: At top level:                                                                           
fs/btrfs/zoned.c:1396:46: warning: ‘struct map_lookup’ declared inside parameter list will not be visible outside of this definition or declaration
 1396 |                                       struct map_lookup *map,                                                                                                                                                
      |                                              ^~~~~~~~~~                            
fs/btrfs/zoned.c: In function ‘btrfs_load_block_group_dup’:           
fs/btrfs/zoned.c:1402:17: error: invalid use of undefined type ‘struct map_lookup’
 1402 |         if ((map->type & BTRFS_BLOCK_GROUP_DATA) && !fs_info->stripe_root) {       
      |                 ^~
...

  reply	other threads:[~2023-11-21 15:26 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-11-21 13:38 [PATCH 0/8] btrfs: add a btrfs_chunk_map structure and preparatory cleanups fdmanana
2023-11-21 13:38 ` [PATCH 1/8] btrfs: fix off-by-one when checking chunk map includes logical address fdmanana
2023-11-21 13:38 ` [PATCH 2/8] btrfs: make error messages more clear when getting a chunk map fdmanana
2023-11-21 13:38 ` [PATCH 3/8] btrfs: mark sanity checks when getting chunk map as unlikely fdmanana
2023-11-21 13:38 ` [PATCH 4/8] btrfs: split assert into two different asserts when removing block group fdmanana
2023-11-21 13:38 ` [PATCH 5/8] btrfs: unexport extent_map_block_end() fdmanana
2023-11-21 13:38 ` [PATCH 6/8] btrfs: use btrfs_next_item() at scrub.c:find_first_extent_item() fdmanana
2023-11-21 13:38 ` [PATCH 7/8] btrfs: use a dedicated data structure for chunk maps fdmanana
2023-11-21 15:19   ` David Sterba [this message]
2023-11-21 16:50     ` Filipe Manana
2023-11-21 18:08       ` David Sterba
2023-11-21 18:23   ` David Sterba
2023-11-22 11:32     ` Filipe Manana
2023-11-22 14:16       ` David Sterba
2023-11-21 21:25   ` kernel test robot
2023-11-21 13:38 ` [PATCH 8/8] btrfs: remove stripe size local variable from insert_dev_extents() fdmanana
2023-11-21 14:12 ` [PATCH 0/8] btrfs: add a btrfs_chunk_map structure and preparatory cleanups Josef Bacik
2023-11-21 21:03 ` David Sterba

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=20231121151933.GR11264@twin.jikos.cz \
    --to=dsterba@suse.cz \
    --cc=fdmanana@kernel.org \
    --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