mbox series

[v2,00/10] btrfs: inode management and memory consumption improvements

Message ID cover.1715362104.git.fdmanana@suse.com (mailing list archive)
Headers show
Series btrfs: inode management and memory consumption improvements | expand

Message

Filipe Manana May 10, 2024, 5:32 p.m. UTC
From: Filipe Manana <fdmanana@suse.com>

Some inode related improvements, to use an xarray to track open inodes per
root instead of a red black tree, reduce lock contention and use less memory
per btrfs inode, so now we can fit 4 inodes per 4K page instead of 3.
More details in the change logs.

V2: Added two more patches (9/10 and 10/10) to make sure btrfs_inode size
    is reduced to 1024 bytes when CONFIG_FS_ENCRYPTION and CONFIG_FS_VERITY
    are set. I wasn't using these configs before, and with them the final
    size for btrfs_inode was 1032 bytes and not 1016 bytes as I initially
    had - now the final size is 1024 bytes with those configs enabled.

Filipe Manana (10):
  btrfs: use an xarray to track open inodes in a root
  btrfs: preallocate inodes xarray entry to avoid transaction abort
  btrfs: reduce nesting and deduplicate error handling at btrfs_iget_path()
  btrfs: remove inode_lock from struct btrfs_root and use xarray locks
  btrfs: unify index_cnt and csum_bytes from struct btrfs_inode
  btrfs: don't allocate file extent tree for non regular files
  btrfs: remove location key from struct btrfs_inode
  btrfs: remove objectid from struct btrfs_inode on 64 bits platforms
  btrfs: rename rb_root member of extent_map_tree from map to root
  btrfs: use a regular rb_root instead of cached rb_root for extent_map_tree

 fs/btrfs/btrfs_inode.h            | 130 ++++++++++----
 fs/btrfs/ctree.h                  |   8 +-
 fs/btrfs/delayed-inode.c          |  29 ++-
 fs/btrfs/disk-io.c                |  12 +-
 fs/btrfs/export.c                 |   2 +-
 fs/btrfs/extent_map.c             |  50 +++---
 fs/btrfs/extent_map.h             |   2 +-
 fs/btrfs/file-item.c              |  13 +-
 fs/btrfs/inode.c                  | 286 +++++++++++++++---------------
 fs/btrfs/ioctl.c                  |   8 +-
 fs/btrfs/relocation.c             |  12 +-
 fs/btrfs/tests/btrfs-tests.c      |   5 +-
 fs/btrfs/tests/extent-map-tests.c |   6 +-
 fs/btrfs/tree-log.c               |   9 +-
 14 files changed, 317 insertions(+), 255 deletions(-)

Comments

David Sterba May 14, 2024, 4:08 p.m. UTC | #1
On Fri, May 10, 2024 at 06:32:48PM +0100, fdmanana@kernel.org wrote:
> From: Filipe Manana <fdmanana@suse.com>
> 
> Some inode related improvements, to use an xarray to track open inodes per
> root instead of a red black tree, reduce lock contention and use less memory
> per btrfs inode, so now we can fit 4 inodes per 4K page instead of 3.

That's great, thank you very much.

The slack space per page is slightly less than 1/4 (25%) in SLUB as it
has more pages per slab per object. Depending on that it can go down to
12.5% (for 8 pages per slab). But still this is a noticeable
improvement.

The 4 byte hole after otime members is still there, we might find use
for it in the future.

I'm thinking about adding a _static_assert(sizeof(btrfs_inode) <= 1024)
on a release config (and x86_64). Given the amount of time and efforts
it took to shrink the size I want to make it visible when a deliberate
change to either struct inode or any embedded structure increases the
size again.
David Sterba May 15, 2024, 6:28 p.m. UTC | #2
On Fri, May 10, 2024 at 06:32:48PM +0100, fdmanana@kernel.org wrote:
> From: Filipe Manana <fdmanana@suse.com>
> 
> Some inode related improvements, to use an xarray to track open inodes per
> root instead of a red black tree, reduce lock contention and use less memory
> per btrfs inode, so now we can fit 4 inodes per 4K page instead of 3.
> More details in the change logs.
> 
> V2: Added two more patches (9/10 and 10/10) to make sure btrfs_inode size
>     is reduced to 1024 bytes when CONFIG_FS_ENCRYPTION and CONFIG_FS_VERITY
>     are set. I wasn't using these configs before, and with them the final
>     size for btrfs_inode was 1032 bytes and not 1016 bytes as I initially
>     had - now the final size is 1024 bytes with those configs enabled.
> 
> Filipe Manana (10):
>   btrfs: use an xarray to track open inodes in a root
>   btrfs: preallocate inodes xarray entry to avoid transaction abort
>   btrfs: reduce nesting and deduplicate error handling at btrfs_iget_path()
>   btrfs: remove inode_lock from struct btrfs_root and use xarray locks
>   btrfs: unify index_cnt and csum_bytes from struct btrfs_inode
>   btrfs: don't allocate file extent tree for non regular files
>   btrfs: remove location key from struct btrfs_inode
>   btrfs: remove objectid from struct btrfs_inode on 64 bits platforms
>   btrfs: rename rb_root member of extent_map_tree from map to root
>   btrfs: use a regular rb_root instead of cached rb_root for extent_map_tree

Reviewed-by: David Sterba <dsterba@suse.com>