Re: [PATCH v2 5/7] btrfs: convert heuristic_collect_sample() to use folios

From: Tal Zussman

Date: Wed Sep 09 2026 - 00:26:09 EST


On 9/9/26 4:26 AM, David Sterba wrote:
> On Mon, Sep 07, 2026 at 04:19:59PM -0400, Tal Zussman wrote:
>> Convert the sampling loop to folios. This removes the last caller of
>> find_get_page() in btrfs and saves a call to compound_head() per sampled
>> page. Document that the lookup is not supposed to fail with an ASSERT().
>>
>> Reviewed-by: Qu Wenruo <wqu@xxxxxxxx>
>> Signed-off-by: Tal Zussman <tz2294@xxxxxxxxxxxx>
>> ---
>> fs/btrfs/compression.c | 10 ++++++----
>> 1 file changed, 6 insertions(+), 4 deletions(-)
>>
>> diff --git a/fs/btrfs/compression.c b/fs/btrfs/compression.c
>> index 979b2ffbd8fc..fa8b92592321 100644
>> --- a/fs/btrfs/compression.c
>> +++ b/fs/btrfs/compression.c
>> @@ -1488,7 +1488,7 @@ static bool sample_repeated_patterns(struct heuristic_ws *ws)
>> static void heuristic_collect_sample(struct inode *inode, u64 start, u64 end,
>> struct heuristic_ws *ws)
>> {
>> - struct page *page;
>> + struct folio *folio;
>> pgoff_t index, index_end;
>> u32 i, curr_sample_pos;
>> u8 *in_data;
>> @@ -1514,8 +1514,10 @@ static void heuristic_collect_sample(struct inode *inode, u64 start, u64 end,
>>
>> curr_sample_pos = 0;
>> while (index < index_end) {
>> - page = find_get_page(inode->i_mapping, index);
>> - in_data = kmap_local_page(page);
>> + folio = filemap_get_folio(inode->i_mapping, index);
>> + ASSERT(!IS_ERR(folio));
>> + in_data = kmap_local_folio(folio,
>> + offset_in_folio(folio, (u64)index << PAGE_SHIFT));
>
> It would be better to avoid the cast, this is source of subtle errors so
> we try to avoid that. With demise of 32bit architectures it's less of a
> problem because index (pgoff_t) is 64 bit type but still.
>
> Please insert a patch that changes the type of index and index_end to
> u64, we initialize them from a u64 type anyway and we know the value
> fits to pgoff_t (as argument to filemap_get_folio()).
>

Makes sense, will do.