All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] btrfs: test that we don't create pointless compressed inline extents
@ 2026-09-14 17:54 fdmanana
  2026-09-15 11:44 ` David Disseldorp
  2026-09-15 15:05 ` [PATCH v2] " fdmanana
  0 siblings, 2 replies; 5+ messages in thread
From: fdmanana @ 2026-09-14 17:54 UTC (permalink / raw)
  To: fstests; +Cc: linux-btrfs, Filipe Manana

From: Filipe Manana <fdmanana@suse.com>

Verify that we don't create compressed inline extents when the compressed
data size is not smaller than the uncompressed data size.

This exercises a regression introduced in kernel 7.1 and that is fixed by
the following patch:

  "btrfs: fix creation of compressed inline extents that don't save space"

Signed-off-by: Filipe Manana <fdmanana@suse.com>
---
 tests/btrfs/354     | 44 ++++++++++++++++++++++++++++++++++++++++++++
 tests/btrfs/354.out |  2 ++
 2 files changed, 46 insertions(+)
 create mode 100755 tests/btrfs/354
 create mode 100644 tests/btrfs/354.out

diff --git a/tests/btrfs/354 b/tests/btrfs/354
new file mode 100755
index 00000000..801dc587
--- /dev/null
+++ b/tests/btrfs/354
@@ -0,0 +1,44 @@
+#! /bin/bash
+# SPDX-License-Identifier: GPL-2.0
+# Copyright (c) 2026 SUSE S.A.  All Rights Reserved.
+#
+# FS QA Test 354
+#
+# Verify that we don't create compressed inline extents when the compressed
+# data size is not smaller than the uncompressed data size.
+#
+. ./common/preamble
+_begin_fstest auto quick compress
+
+. ./common/filter
+
+_fixed_by_kernel_commit xxxxxxxxxxxx \
+	"btrfs: fix creation of compressed inline extents that don't save space"
+
+_require_scratch
+_require_btrfs_command inspect-internal dump-tree
+
+algo_list=($(_btrfs_compression_algos))
+for algo in ${algo_list[@]}; do
+	_scratch_mkfs >>$seqres.full 2>&1 || _fail "mkfs failed"
+	_scratch_mount "-o compress=$algo"
+
+	echo 'a file with test content' > $SCRATCH_MNT/foobar
+	_scratch_unmount
+	_check_scratch_fs
+
+	extent_size=$($BTRFS_UTIL_PROG inspect-internal dump-tree -t 5 $SCRATCH_DEV | \
+	      grep 'inline extent' | \
+	      $AWK_PROG '{ for (i = 1; i < NF; i++) if ($i ~ /^size$/) print $(i + 1) }')
+	ram_size=$($BTRFS_UTIL_PROG inspect-internal dump-tree -t 5 $SCRATCH_DEV | \
+		   grep 'inline extent' | \
+		   $AWK_PROG '{ for (i = 1; i < NF; i++) if ($i ~ /^ram_bytes$/) print $(i + 1) }')
+
+	if [ "$extent_size" -gt "$ram_size" ]; then
+		echo "inline extent size ($extent_size) greater than ram_size ($ram_size) for algo $algo"
+	fi
+done
+
+# success, all done
+echo "Silence is golden"
+_exit 0
diff --git a/tests/btrfs/354.out b/tests/btrfs/354.out
new file mode 100644
index 00000000..8bc7ecf6
--- /dev/null
+++ b/tests/btrfs/354.out
@@ -0,0 +1,2 @@
+QA output created by 354
+Silence is golden
-- 
2.47.2


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH] btrfs: test that we don't create pointless compressed inline extents
  2026-09-14 17:54 [PATCH] btrfs: test that we don't create pointless compressed inline extents fdmanana
@ 2026-09-15 11:44 ` David Disseldorp
  2026-09-15 15:05   ` Filipe Manana
  2026-09-15 15:05 ` [PATCH v2] " fdmanana
  1 sibling, 1 reply; 5+ messages in thread
From: David Disseldorp @ 2026-09-15 11:44 UTC (permalink / raw)
  To: fdmanana; +Cc: fstests, linux-btrfs, Filipe Manana

On Mon, 14 Sep 2026 18:54:23 +0100, fdmanana@kernel.org wrote:

> From: Filipe Manana <fdmanana@suse.com>
> 
> Verify that we don't create compressed inline extents when the compressed
> data size is not smaller than the uncompressed data size.
> 
> This exercises a regression introduced in kernel 7.1 and that is fixed by
> the following patch:
> 
>   "btrfs: fix creation of compressed inline extents that don't save space"
> 
> Signed-off-by: Filipe Manana <fdmanana@suse.com>

Looks good and works for me:
Reviewed-by: David Disseldorp <ddiss@suse.de>

A couple of minor nits below...

> ---
>  tests/btrfs/354     | 44 ++++++++++++++++++++++++++++++++++++++++++++
>  tests/btrfs/354.out |  2 ++
>  2 files changed, 46 insertions(+)
>  create mode 100755 tests/btrfs/354
>  create mode 100644 tests/btrfs/354.out
> 
> diff --git a/tests/btrfs/354 b/tests/btrfs/354
> new file mode 100755
> index 00000000..801dc587
> --- /dev/null
> +++ b/tests/btrfs/354
> @@ -0,0 +1,44 @@
> +#! /bin/bash
> +# SPDX-License-Identifier: GPL-2.0
> +# Copyright (c) 2026 SUSE S.A.  All Rights Reserved.
> +#
> +# FS QA Test 354
> +#
> +# Verify that we don't create compressed inline extents when the compressed
> +# data size is not smaller than the uncompressed data size.
> +#
> +. ./common/preamble
> +_begin_fstest auto quick compress
> +
> +. ./common/filter
> +
> +_fixed_by_kernel_commit xxxxxxxxxxxx \
> +	"btrfs: fix creation of compressed inline extents that don't save space"
> +
> +_require_scratch
> +_require_btrfs_command inspect-internal dump-tree
> +
> +algo_list=($(_btrfs_compression_algos))
> +for algo in ${algo_list[@]}; do
> +	_scratch_mkfs >>$seqres.full 2>&1 || _fail "mkfs failed"
> +	_scratch_mount "-o compress=$algo"
> +
> +	echo 'a file with test content' > $SCRATCH_MNT/foobar
> +	_scratch_unmount
> +	_check_scratch_fs
> +
> +	extent_size=$($BTRFS_UTIL_PROG inspect-internal dump-tree -t 5 $SCRATCH_DEV | \
> +	      grep 'inline extent' | \
> +	      $AWK_PROG '{ for (i = 1; i < NF; i++) if ($i ~ /^size$/) print $(i + 1) }')
> +	ram_size=$($BTRFS_UTIL_PROG inspect-internal dump-tree -t 5 $SCRATCH_DEV | \
> +		   grep 'inline extent' | \
> +		   $AWK_PROG '{ for (i = 1; i < NF; i++) if ($i ~ /^ram_bytes$/) print $(i + 1) }')
> +
> +	if [ "$extent_size" -gt "$ram_size" ]; then
> +		echo "inline extent size ($extent_size) greater than ram_size ($ram_size) for algo $algo"
> +	fi

It might be a little nicer to avoid multiple dumps and do the check in
awk. The following works for me, feel free to squash in...

diff --git a/tests/btrfs/354 b/tests/btrfs/354
index 801dc587..e744b945 100755
--- a/tests/btrfs/354
+++ b/tests/btrfs/354
@@ -27,18 +27,20 @@ for algo in ${algo_list[@]}; do
        _scratch_unmount
        _check_scratch_fs
 
-       extent_size=$($BTRFS_UTIL_PROG inspect-internal dump-tree -t 5 $SCRATCH_DEV | \
-             grep 'inline extent' | \
-             $AWK_PROG '{ for (i = 1; i < NF; i++) if ($i ~ /^size$/) print $(i + 1) }')
-       ram_size=$($BTRFS_UTIL_PROG inspect-internal dump-tree -t 5 $SCRATCH_DEV | \
-                  grep 'inline extent' | \
-                  $AWK_PROG '{ for (i = 1; i < NF; i++) if ($i ~ /^ram_bytes$/) print $(i + 1) }')
-
-       if [ "$extent_size" -gt "$ram_size" ]; then
-               echo "inline extent size ($extent_size) greater than ram_size ($ram_size) for algo $algo"
-       fi
+       $BTRFS_UTIL_PROG inspect-internal dump-tree -t 5 $SCRATCH_DEV | \
+               tee -a $seqres.full | \
+               $AWK_PROG -v algo="$algo" '
+                       /inline extent/ {
+                               for (i = 1; i < NF; i++) {
+                                       if ($i ~ /^size$/)
+                                               extent_size = $(i + 1)
+                                       if ($i ~ /^ram_bytes$/)
+                                               ram_size = $(i + 1)
+                               }
+                               if (extent_size > ram_size)
+                                       printf "inline extent size (%d) greater than ram_size (%d) for algo %s\n", extent_size, ram_size, algo
+                       }'

> +done
> +
> +# success, all done

Delete the line above, as we get here on failure too.

> +echo "Silence is golden"
> +_exit 0
> diff --git a/tests/btrfs/354.out b/tests/btrfs/354.out
> new file mode 100644
> index 00000000..8bc7ecf6
> --- /dev/null
> +++ b/tests/btrfs/354.out
> @@ -0,0 +1,2 @@
> +QA output created by 354
> +Silence is golden


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH v2] btrfs: test that we don't create pointless compressed inline extents
  2026-09-14 17:54 [PATCH] btrfs: test that we don't create pointless compressed inline extents fdmanana
  2026-09-15 11:44 ` David Disseldorp
@ 2026-09-15 15:05 ` fdmanana
  2026-09-15 22:16   ` Qu Wenruo
  1 sibling, 1 reply; 5+ messages in thread
From: fdmanana @ 2026-09-15 15:05 UTC (permalink / raw)
  To: fstests; +Cc: linux-btrfs, Filipe Manana, David Disseldorp

From: Filipe Manana <fdmanana@suse.com>

Verify that we don't create compressed inline extents when the compressed
data size is not smaller than the uncompressed data size.

This exercises a regression introduced in kernel 7.1 and that is fixed by
the following patch:

  "btrfs: fix creation of compressed inline extents that don't save space"

Reviewed-by: David Disseldorp <ddiss@suse.de>
Signed-off-by: Filipe Manana <fdmanana@suse.com>
---

V2: Use a single call to btrfs inspect-internal and a single awk
    call (David Disseldorp).

 tests/btrfs/354     | 46 +++++++++++++++++++++++++++++++++++++++++++++
 tests/btrfs/354.out |  2 ++
 2 files changed, 48 insertions(+)
 create mode 100755 tests/btrfs/354
 create mode 100644 tests/btrfs/354.out

diff --git a/tests/btrfs/354 b/tests/btrfs/354
new file mode 100755
index 00000000..1b25ab5d
--- /dev/null
+++ b/tests/btrfs/354
@@ -0,0 +1,46 @@
+#! /bin/bash
+# SPDX-License-Identifier: GPL-2.0
+# Copyright (c) 2026 SUSE S.A.  All Rights Reserved.
+#
+# FS QA Test 354
+#
+# Verify that we don't create compressed inline extents when the compressed
+# data size is not smaller than the uncompressed data size.
+#
+. ./common/preamble
+_begin_fstest auto quick compress
+
+. ./common/filter
+
+_fixed_by_kernel_commit xxxxxxxxxxxx \
+	"btrfs: fix creation of compressed inline extents that don't save space"
+
+_require_scratch
+_require_btrfs_command inspect-internal dump-tree
+
+algo_list=($(_btrfs_compression_algos))
+for algo in ${algo_list[@]}; do
+	_scratch_mkfs >>$seqres.full 2>&1 || _fail "mkfs failed"
+	_scratch_mount "-o compress=$algo"
+
+	echo 'a file with test content' > $SCRATCH_MNT/foobar
+	_scratch_unmount
+	_check_scratch_fs
+
+	$BTRFS_UTIL_PROG inspect-internal dump-tree -t 5 $SCRATCH_DEV | \
+		tee -a $seqres.full | \
+		$AWK_PROG -v algo="$algo" '
+		  /inline extent/ {
+			for (i = 1; i < NF; i++) {
+			      if ($i ~ /^size$/)
+				 extent_size = $(i + 1)
+			      if ($i ~ /^ram_bytes$/)
+			         ram_size = $(i + 1)
+			}
+			if (extent_size > ram_size)
+			   printf "inline extent size (%d) greater than ram_size (%d) for algo %s\n", extent_size, ram_size, algo
+		  }'
+done
+
+echo "Silence is golden"
+_exit 0
diff --git a/tests/btrfs/354.out b/tests/btrfs/354.out
new file mode 100644
index 00000000..8bc7ecf6
--- /dev/null
+++ b/tests/btrfs/354.out
@@ -0,0 +1,2 @@
+QA output created by 354
+Silence is golden
-- 
2.47.2


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH] btrfs: test that we don't create pointless compressed inline extents
  2026-09-15 11:44 ` David Disseldorp
@ 2026-09-15 15:05   ` Filipe Manana
  0 siblings, 0 replies; 5+ messages in thread
From: Filipe Manana @ 2026-09-15 15:05 UTC (permalink / raw)
  To: David Disseldorp; +Cc: fstests, linux-btrfs, Filipe Manana

On Tue, Sep 15, 2026 at 12:45 PM David Disseldorp <ddiss@suse.de> wrote:
>
> On Mon, 14 Sep 2026 18:54:23 +0100, fdmanana@kernel.org wrote:
>
> > From: Filipe Manana <fdmanana@suse.com>
> >
> > Verify that we don't create compressed inline extents when the compressed
> > data size is not smaller than the uncompressed data size.
> >
> > This exercises a regression introduced in kernel 7.1 and that is fixed by
> > the following patch:
> >
> >   "btrfs: fix creation of compressed inline extents that don't save space"
> >
> > Signed-off-by: Filipe Manana <fdmanana@suse.com>
>
> Looks good and works for me:
> Reviewed-by: David Disseldorp <ddiss@suse.de>
>
> A couple of minor nits below...
>
> > ---
> >  tests/btrfs/354     | 44 ++++++++++++++++++++++++++++++++++++++++++++
> >  tests/btrfs/354.out |  2 ++
> >  2 files changed, 46 insertions(+)
> >  create mode 100755 tests/btrfs/354
> >  create mode 100644 tests/btrfs/354.out
> >
> > diff --git a/tests/btrfs/354 b/tests/btrfs/354
> > new file mode 100755
> > index 00000000..801dc587
> > --- /dev/null
> > +++ b/tests/btrfs/354
> > @@ -0,0 +1,44 @@
> > +#! /bin/bash
> > +# SPDX-License-Identifier: GPL-2.0
> > +# Copyright (c) 2026 SUSE S.A.  All Rights Reserved.
> > +#
> > +# FS QA Test 354
> > +#
> > +# Verify that we don't create compressed inline extents when the compressed
> > +# data size is not smaller than the uncompressed data size.
> > +#
> > +. ./common/preamble
> > +_begin_fstest auto quick compress
> > +
> > +. ./common/filter
> > +
> > +_fixed_by_kernel_commit xxxxxxxxxxxx \
> > +     "btrfs: fix creation of compressed inline extents that don't save space"
> > +
> > +_require_scratch
> > +_require_btrfs_command inspect-internal dump-tree
> > +
> > +algo_list=($(_btrfs_compression_algos))
> > +for algo in ${algo_list[@]}; do
> > +     _scratch_mkfs >>$seqres.full 2>&1 || _fail "mkfs failed"
> > +     _scratch_mount "-o compress=$algo"
> > +
> > +     echo 'a file with test content' > $SCRATCH_MNT/foobar
> > +     _scratch_unmount
> > +     _check_scratch_fs
> > +
> > +     extent_size=$($BTRFS_UTIL_PROG inspect-internal dump-tree -t 5 $SCRATCH_DEV | \
> > +           grep 'inline extent' | \
> > +           $AWK_PROG '{ for (i = 1; i < NF; i++) if ($i ~ /^size$/) print $(i + 1) }')
> > +     ram_size=$($BTRFS_UTIL_PROG inspect-internal dump-tree -t 5 $SCRATCH_DEV | \
> > +                grep 'inline extent' | \
> > +                $AWK_PROG '{ for (i = 1; i < NF; i++) if ($i ~ /^ram_bytes$/) print $(i + 1) }')
> > +
> > +     if [ "$extent_size" -gt "$ram_size" ]; then
> > +             echo "inline extent size ($extent_size) greater than ram_size ($ram_size) for algo $algo"
> > +     fi
>
> It might be a little nicer to avoid multiple dumps and do the check in
> awk. The following works for me, feel free to squash in...

Integrated in v2, thanks.

>
> diff --git a/tests/btrfs/354 b/tests/btrfs/354
> index 801dc587..e744b945 100755
> --- a/tests/btrfs/354
> +++ b/tests/btrfs/354
> @@ -27,18 +27,20 @@ for algo in ${algo_list[@]}; do
>         _scratch_unmount
>         _check_scratch_fs
>
> -       extent_size=$($BTRFS_UTIL_PROG inspect-internal dump-tree -t 5 $SCRATCH_DEV | \
> -             grep 'inline extent' | \
> -             $AWK_PROG '{ for (i = 1; i < NF; i++) if ($i ~ /^size$/) print $(i + 1) }')
> -       ram_size=$($BTRFS_UTIL_PROG inspect-internal dump-tree -t 5 $SCRATCH_DEV | \
> -                  grep 'inline extent' | \
> -                  $AWK_PROG '{ for (i = 1; i < NF; i++) if ($i ~ /^ram_bytes$/) print $(i + 1) }')
> -
> -       if [ "$extent_size" -gt "$ram_size" ]; then
> -               echo "inline extent size ($extent_size) greater than ram_size ($ram_size) for algo $algo"
> -       fi
> +       $BTRFS_UTIL_PROG inspect-internal dump-tree -t 5 $SCRATCH_DEV | \
> +               tee -a $seqres.full | \
> +               $AWK_PROG -v algo="$algo" '
> +                       /inline extent/ {
> +                               for (i = 1; i < NF; i++) {
> +                                       if ($i ~ /^size$/)
> +                                               extent_size = $(i + 1)
> +                                       if ($i ~ /^ram_bytes$/)
> +                                               ram_size = $(i + 1)
> +                               }
> +                               if (extent_size > ram_size)
> +                                       printf "inline extent size (%d) greater than ram_size (%d) for algo %s\n", extent_size, ram_size, algo
> +                       }'
>
> > +done
> > +
> > +# success, all done
>
> Delete the line above, as we get here on failure too.
>
> > +echo "Silence is golden"
> > +_exit 0
> > diff --git a/tests/btrfs/354.out b/tests/btrfs/354.out
> > new file mode 100644
> > index 00000000..8bc7ecf6
> > --- /dev/null
> > +++ b/tests/btrfs/354.out
> > @@ -0,0 +1,2 @@
> > +QA output created by 354
> > +Silence is golden
>

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH v2] btrfs: test that we don't create pointless compressed inline extents
  2026-09-15 15:05 ` [PATCH v2] " fdmanana
@ 2026-09-15 22:16   ` Qu Wenruo
  0 siblings, 0 replies; 5+ messages in thread
From: Qu Wenruo @ 2026-09-15 22:16 UTC (permalink / raw)
  To: fdmanana, fstests; +Cc: linux-btrfs, Filipe Manana, David Disseldorp



在 2026/9/16 00:35, fdmanana@kernel.org 写道:
> From: Filipe Manana <fdmanana@suse.com>
> 
> Verify that we don't create compressed inline extents when the compressed
> data size is not smaller than the uncompressed data size.
> 
> This exercises a regression introduced in kernel 7.1 and that is fixed by
> the following patch:
> 
>    "btrfs: fix creation of compressed inline extents that don't save space"
> 
> Reviewed-by: David Disseldorp <ddiss@suse.de>
> Signed-off-by: Filipe Manana <fdmanana@suse.com>

Reviewed-by: Qu Wenruo <wqu@suse.com>

Thanks,
Qu

> ---
> 
> V2: Use a single call to btrfs inspect-internal and a single awk
>      call (David Disseldorp).
> 
>   tests/btrfs/354     | 46 +++++++++++++++++++++++++++++++++++++++++++++
>   tests/btrfs/354.out |  2 ++
>   2 files changed, 48 insertions(+)
>   create mode 100755 tests/btrfs/354
>   create mode 100644 tests/btrfs/354.out
> 
> diff --git a/tests/btrfs/354 b/tests/btrfs/354
> new file mode 100755
> index 00000000..1b25ab5d
> --- /dev/null
> +++ b/tests/btrfs/354
> @@ -0,0 +1,46 @@
> +#! /bin/bash
> +# SPDX-License-Identifier: GPL-2.0
> +# Copyright (c) 2026 SUSE S.A.  All Rights Reserved.
> +#
> +# FS QA Test 354
> +#
> +# Verify that we don't create compressed inline extents when the compressed
> +# data size is not smaller than the uncompressed data size.
> +#
> +. ./common/preamble
> +_begin_fstest auto quick compress
> +
> +. ./common/filter
> +
> +_fixed_by_kernel_commit xxxxxxxxxxxx \
> +	"btrfs: fix creation of compressed inline extents that don't save space"
> +
> +_require_scratch
> +_require_btrfs_command inspect-internal dump-tree
> +
> +algo_list=($(_btrfs_compression_algos))
> +for algo in ${algo_list[@]}; do
> +	_scratch_mkfs >>$seqres.full 2>&1 || _fail "mkfs failed"
> +	_scratch_mount "-o compress=$algo"
> +
> +	echo 'a file with test content' > $SCRATCH_MNT/foobar
> +	_scratch_unmount
> +	_check_scratch_fs
> +
> +	$BTRFS_UTIL_PROG inspect-internal dump-tree -t 5 $SCRATCH_DEV | \
> +		tee -a $seqres.full | \
> +		$AWK_PROG -v algo="$algo" '
> +		  /inline extent/ {
> +			for (i = 1; i < NF; i++) {
> +			      if ($i ~ /^size$/)
> +				 extent_size = $(i + 1)
> +			      if ($i ~ /^ram_bytes$/)
> +			         ram_size = $(i + 1)
> +			}
> +			if (extent_size > ram_size)
> +			   printf "inline extent size (%d) greater than ram_size (%d) for algo %s\n", extent_size, ram_size, algo
> +		  }'
> +done
> +
> +echo "Silence is golden"
> +_exit 0
> diff --git a/tests/btrfs/354.out b/tests/btrfs/354.out
> new file mode 100644
> index 00000000..8bc7ecf6
> --- /dev/null
> +++ b/tests/btrfs/354.out
> @@ -0,0 +1,2 @@
> +QA output created by 354
> +Silence is golden


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2026-09-15 22:16 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-09-14 17:54 [PATCH] btrfs: test that we don't create pointless compressed inline extents fdmanana
2026-09-15 11:44 ` David Disseldorp
2026-09-15 15:05   ` Filipe Manana
2026-09-15 15:05 ` [PATCH v2] " fdmanana
2026-09-15 22:16   ` Qu Wenruo

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.