btrfs: be better releasing extent maps at try_release_extent_mapping()
authorFilipe Manana <fdmanana@suse.com>
Tue, 16 Apr 2024 14:34:51 +0000 (15:34 +0100)
committerDavid Sterba <dsterba@suse.com>
Tue, 7 May 2024 19:31:07 +0000 (21:31 +0200)
commit2e504418e4645302c40982a64de6a6979ec5489d
tree910cb27f83742b074936b0c23b97257b65870ae2
parent433a3e01dda1d463159a9620b40ba027514f0ea5
btrfs: be better releasing extent maps at try_release_extent_mapping()

At try_release_extent_mapping(), called during the release folio callback
(btrfs_release_folio() callchain), we don't release any extent maps in the
range if the GFP flags don't allow blocking. This behaviour is exaggerated
because:

1) Both searching for extent maps and removing them are not blocking
   operations. The only thing that it is the cond_resched() call at the
   end of the loop that searches for and removes extent maps;

2) We currently only operate on a single page, so for the case where
   block size matches the page size, we can only have one extent map,
   and for the case where the block size is smaller than the page size,
   we can have at most 16 extent maps.

So it's very unlikely the cond_resched() call will ever block even in the
block size smaller than page size scenario.

So instead of not removing any extent maps at all in case the GFP glags
don't allow blocking, keep removing extent maps while we don't need to
reschedule. This makes it safe for the subpage case and for a future
where we can process folios with a size larger than a page.

Reviewed-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
Signed-off-by: Filipe Manana <fdmanana@suse.com>
Reviewed-by: David Sterba <dsterba@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
fs/btrfs/extent_io.c