mbox series

[0/9] Parameter cleanups in extent state helpers

Message ID cover.1684967923.git.dsterba@suse.com (mailing list archive)
Headers show
Series Parameter cleanups in extent state helpers | expand

Message

David Sterba May 24, 2023, 11:04 p.m. UTC
This is motivated by the gfp parameter passed to all the helpers and how
to get rid of it. Most of the values are GFP_NOFS with some exceptions.
One of them (GFP_NOFAIL) can be removed the other one (GFP_NOWAIT) is
transformed to existing parameters.

Module code size is lower for the whole series and stack is reduced in
about 50 functions by 8 bytes.

David Sterba (9):
  btrfs: open code set_extent_defrag
  btrfs: open code set_extent_delalloc
  btrfs: open code set_extent_new
  btrfs: open code set_extent_dirty
  btrfs: open code set_extent_bits_nowait
  btrfs: open code set_extent_bits
  btrfs: drop NOFAIL from set_extent_bit allocation masks
  btrfs: pass NOWAIT for set/clear extent bits as another bit
  btrfs: drop gfp from parameter extent state helpers

 fs/btrfs/block-group.c           |  6 ++--
 fs/btrfs/defrag.c                |  3 +-
 fs/btrfs/dev-replace.c           |  4 +--
 fs/btrfs/extent-io-tree.c        | 37 ++++++++++++-------
 fs/btrfs/extent-io-tree.h        | 62 ++++++++------------------------
 fs/btrfs/extent-tree.c           | 27 +++++++-------
 fs/btrfs/extent_io.c             |  3 +-
 fs/btrfs/extent_map.c            | 10 +++---
 fs/btrfs/file-item.c             | 10 +++---
 fs/btrfs/inode.c                 |  9 +++--
 fs/btrfs/relocation.c            | 10 +++---
 fs/btrfs/tests/extent-io-tests.c | 16 ++++-----
 fs/btrfs/zoned.c                 |  4 +--
 13 files changed, 91 insertions(+), 110 deletions(-)

Comments

Qu Wenruo May 25, 2023, 10:25 a.m. UTC | #1
On 2023/5/25 07:04, David Sterba wrote:
> This is motivated by the gfp parameter passed to all the helpers and how
> to get rid of it. Most of the values are GFP_NOFS with some exceptions.
> One of them (GFP_NOFAIL) can be removed the other one (GFP_NOWAIT) is
> transformed to existing parameters.

The patchset gives me some inspiration on a wild idea to completely
remove the memory allocation inside set/clear_bits().

The core idea is to change extent io tree to have "hole" extent_state,
so that every set/clear_bits() call will only need to allocate 2 new
extent states, thus we can pre-allocate them.


Currently the extent io tree behaves much like no-hole, we only insert
new extent_state if there is any bit set for a certain range.
Thus the following case will need as many new extent states as the holes:

           |<------- Range to set bits ------------->|
           |///|   |////|    |////|   ....     |/////|
                 ^         ^                 ^
                 |         |                 \- hole N
                 hole 1    hole 2

But if we keep hole state extents, the above case will only need to
allocate 0 new extent state:

           |<------- Range to set bits ------------->|
           |///|000|////|0000|////|   .... 0000|/////|

Although we may still need to allocate up to 2 new extent states even
with hole states.
The most straightforward example is:

                |<- Range to clear bits ---->|
           |//////////////////////////////////////////|


But this greatly limits the new allocation needed, thus can make the
set/clear_bits() to return void and avoid memory allocation at all (all
pre-allocated by callers).

Obviously there would be no free lunch, the overall memory usage would
increase, especially for fragmented extent io tree.

Thus I'm not sure if the hole extent state idea is really a good idea or
the existing NOWAIT/NOFAIL allocation is more acceptable...

Thanks,
Qu
>
> Module code size is lower for the whole series and stack is reduced in
> about 50 functions by 8 bytes.
>
> David Sterba (9):
>    btrfs: open code set_extent_defrag
>    btrfs: open code set_extent_delalloc
>    btrfs: open code set_extent_new
>    btrfs: open code set_extent_dirty
>    btrfs: open code set_extent_bits_nowait
>    btrfs: open code set_extent_bits
>    btrfs: drop NOFAIL from set_extent_bit allocation masks
>    btrfs: pass NOWAIT for set/clear extent bits as another bit
>    btrfs: drop gfp from parameter extent state helpers
>
>   fs/btrfs/block-group.c           |  6 ++--
>   fs/btrfs/defrag.c                |  3 +-
>   fs/btrfs/dev-replace.c           |  4 +--
>   fs/btrfs/extent-io-tree.c        | 37 ++++++++++++-------
>   fs/btrfs/extent-io-tree.h        | 62 ++++++++------------------------
>   fs/btrfs/extent-tree.c           | 27 +++++++-------
>   fs/btrfs/extent_io.c             |  3 +-
>   fs/btrfs/extent_map.c            | 10 +++---
>   fs/btrfs/file-item.c             | 10 +++---
>   fs/btrfs/inode.c                 |  9 +++--
>   fs/btrfs/relocation.c            | 10 +++---
>   fs/btrfs/tests/extent-io-tests.c | 16 ++++-----
>   fs/btrfs/zoned.c                 |  4 +--
>   13 files changed, 91 insertions(+), 110 deletions(-)
>