public inbox for linux-btrfs@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] btrfs: remove the folio ref count ASSERT() from btrfs_free_comp_folio()
@ 2026-02-26  0:20 Qu Wenruo
  2026-02-26  0:43 ` Boris Burkov
  2026-02-26  6:43 ` Johannes Thumshirn
  0 siblings, 2 replies; 5+ messages in thread
From: Qu Wenruo @ 2026-02-26  0:20 UTC (permalink / raw)
  To: linux-btrfs

Inside btrfs_free_compr_folio() we have an ASSERT() to make sure when we
free the folio it should only have one reference (by btrfs).

However there is never any guarantee that btrfs is the only holder of
the folio. Memory management may have acquired that folio for whatever
reasons.

I do not think we should poke into the very low-level implementation
of memory management code, and I didn't find any fs code really using
folio_ref_count() other than during debugging output.

Just remove the ASSERT() to avoid false triggering.

Signed-off-by: Qu Wenruo <wqu@suse.com>
---
 fs/btrfs/compression.c | 1 -
 1 file changed, 1 deletion(-)

diff --git a/fs/btrfs/compression.c b/fs/btrfs/compression.c
index e897342bece1..192f133d9eb5 100644
--- a/fs/btrfs/compression.c
+++ b/fs/btrfs/compression.c
@@ -224,7 +224,6 @@ void btrfs_free_compr_folio(struct folio *folio)
 		return;
 
 free:
-	ASSERT(folio_ref_count(folio) == 1);
 	folio_put(folio);
 }
 
-- 
2.53.0


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

* Re: [PATCH] btrfs: remove the folio ref count ASSERT() from btrfs_free_comp_folio()
  2026-02-26  0:20 [PATCH] btrfs: remove the folio ref count ASSERT() from btrfs_free_comp_folio() Qu Wenruo
@ 2026-02-26  0:43 ` Boris Burkov
  2026-02-26  6:43 ` Johannes Thumshirn
  1 sibling, 0 replies; 5+ messages in thread
From: Boris Burkov @ 2026-02-26  0:43 UTC (permalink / raw)
  To: Qu Wenruo; +Cc: linux-btrfs

On Thu, Feb 26, 2026 at 10:50:38AM +1030, Qu Wenruo wrote:
> Inside btrfs_free_compr_folio() we have an ASSERT() to make sure when we
> free the folio it should only have one reference (by btrfs).
> 
> However there is never any guarantee that btrfs is the only holder of
> the folio. Memory management may have acquired that folio for whatever
> reasons.
> 
> I do not think we should poke into the very low-level implementation
> of memory management code, and I didn't find any fs code really using
> folio_ref_count() other than during debugging output.
> 
> Just remove the ASSERT() to avoid false triggering.
> 

Reviewed-by: Boris Burkov <boris@bur.io>

> Signed-off-by: Qu Wenruo <wqu@suse.com>
> ---
>  fs/btrfs/compression.c | 1 -
>  1 file changed, 1 deletion(-)
> 
> diff --git a/fs/btrfs/compression.c b/fs/btrfs/compression.c
> index e897342bece1..192f133d9eb5 100644
> --- a/fs/btrfs/compression.c
> +++ b/fs/btrfs/compression.c
> @@ -224,7 +224,6 @@ void btrfs_free_compr_folio(struct folio *folio)
>  		return;
>  
>  free:
> -	ASSERT(folio_ref_count(folio) == 1);
>  	folio_put(folio);
>  }
>  
> -- 
> 2.53.0
> 

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

* Re: [PATCH] btrfs: remove the folio ref count ASSERT() from btrfs_free_comp_folio()
  2026-02-26  0:20 [PATCH] btrfs: remove the folio ref count ASSERT() from btrfs_free_comp_folio() Qu Wenruo
  2026-02-26  0:43 ` Boris Burkov
@ 2026-02-26  6:43 ` Johannes Thumshirn
  2026-02-26  6:46   ` Qu Wenruo
  2026-02-26 18:34   ` David Sterba
  1 sibling, 2 replies; 5+ messages in thread
From: Johannes Thumshirn @ 2026-02-26  6:43 UTC (permalink / raw)
  To: WenRuo Qu, linux-btrfs@vger.kernel.org

On 2/26/26 1:21 AM, Qu Wenruo wrote:
> Inside btrfs_free_compr_folio() we have an ASSERT() to make sure when we
> free the folio it should only have one reference (by btrfs).
>
> However there is never any guarantee that btrfs is the only holder of
> the folio. Memory management may have acquired that folio for whatever
> reasons.
>
> I do not think we should poke into the very low-level implementation
> of memory management code, and I didn't find any fs code really using
> folio_ref_count() other than during debugging output.
>
> Just remove the ASSERT() to avoid false triggering.
>
Just curious, did this trigger any bug or did you find it by coincidence?


Anyways,

Reviewed-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>


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

* Re: [PATCH] btrfs: remove the folio ref count ASSERT() from btrfs_free_comp_folio()
  2026-02-26  6:43 ` Johannes Thumshirn
@ 2026-02-26  6:46   ` Qu Wenruo
  2026-02-26 18:34   ` David Sterba
  1 sibling, 0 replies; 5+ messages in thread
From: Qu Wenruo @ 2026-02-26  6:46 UTC (permalink / raw)
  To: Johannes Thumshirn, WenRuo Qu, linux-btrfs@vger.kernel.org



在 2026/2/26 17:13, Johannes Thumshirn 写道:
> On 2/26/26 1:21 AM, Qu Wenruo wrote:
>> Inside btrfs_free_compr_folio() we have an ASSERT() to make sure when we
>> free the folio it should only have one reference (by btrfs).
>>
>> However there is never any guarantee that btrfs is the only holder of
>> the folio. Memory management may have acquired that folio for whatever
>> reasons.
>>
>> I do not think we should poke into the very low-level implementation
>> of memory management code, and I didn't find any fs code really using
>> folio_ref_count() other than during debugging output.
>>
>> Just remove the ASSERT() to avoid false triggering.
>>
> Just curious, did this trigger any bug or did you find it by coincidence?

David found one, and I failed to trigger it.

The deeper problem here is not the ASSERT() itself, it's the ref count 
reached 0 already before we call folio_put().

In that case, even without our ASSERT(), VM_BUG_ON() will still be 
triggered.

Thanks,
Qu

> 
> 
> Anyways,
> 
> Reviewed-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
> 


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

* Re: [PATCH] btrfs: remove the folio ref count ASSERT() from btrfs_free_comp_folio()
  2026-02-26  6:43 ` Johannes Thumshirn
  2026-02-26  6:46   ` Qu Wenruo
@ 2026-02-26 18:34   ` David Sterba
  1 sibling, 0 replies; 5+ messages in thread
From: David Sterba @ 2026-02-26 18:34 UTC (permalink / raw)
  To: Johannes Thumshirn; +Cc: WenRuo Qu, linux-btrfs@vger.kernel.org

On Thu, Feb 26, 2026 at 06:43:07AM +0000, Johannes Thumshirn wrote:
> On 2/26/26 1:21 AM, Qu Wenruo wrote:
> > Inside btrfs_free_compr_folio() we have an ASSERT() to make sure when we
> > free the folio it should only have one reference (by btrfs).
> >
> > However there is never any guarantee that btrfs is the only holder of
> > the folio. Memory management may have acquired that folio for whatever
> > reasons.
> >
> > I do not think we should poke into the very low-level implementation
> > of memory management code, and I didn't find any fs code really using
> > folio_ref_count() other than during debugging output.
> >
> > Just remove the ASSERT() to avoid false triggering.
> >
> Just curious, did this trigger any bug or did you find it by coincidence?

With other tests' workload it was triggered by btrfs/011 on a machine
with 1G of memory.

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

end of thread, other threads:[~2026-02-26 18:34 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-02-26  0:20 [PATCH] btrfs: remove the folio ref count ASSERT() from btrfs_free_comp_folio() Qu Wenruo
2026-02-26  0:43 ` Boris Burkov
2026-02-26  6:43 ` Johannes Thumshirn
2026-02-26  6:46   ` Qu Wenruo
2026-02-26 18:34   ` David Sterba

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox