diff mbox series

[RFC,05/23] filemap: align index to mapping_min_order in filemap_range_has_page()

Message ID 20230915183848.1018717-6-kernel@pankajraghav.com (mailing list archive)
State New, archived
Headers show
Series Enable block size > page size in XFS | expand

Commit Message

Pankaj Raghav (Samsung) Sept. 15, 2023, 6:38 p.m. UTC
From: Luis Chamberlain <mcgrof@kernel.org>

page cache is mapping min_folio_order aligned. Use mapping min_folio_order
to align the start_byte and end_byte in filemap_range_has_page().

Signed-off-by: Luis Chamberlain <mcgrof@kernel.org>
---
 mm/filemap.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

Comments

Matthew Wilcox Sept. 15, 2023, 7:45 p.m. UTC | #1
On Fri, Sep 15, 2023 at 08:38:30PM +0200, Pankaj Raghav wrote:
> From: Luis Chamberlain <mcgrof@kernel.org>
> 
> page cache is mapping min_folio_order aligned. Use mapping min_folio_order
> to align the start_byte and end_byte in filemap_range_has_page().

What goes wrong if you don't?  Seems to me like it should work.

> Signed-off-by: Luis Chamberlain <mcgrof@kernel.org>
> ---
>  mm/filemap.c | 7 +++++--
>  1 file changed, 5 insertions(+), 2 deletions(-)
> 
> diff --git a/mm/filemap.c b/mm/filemap.c
> index 2c47729dc8b0..4dee24b5b61c 100644
> --- a/mm/filemap.c
> +++ b/mm/filemap.c
> @@ -477,9 +477,12 @@ EXPORT_SYMBOL(filemap_flush);
>  bool filemap_range_has_page(struct address_space *mapping,
>  			   loff_t start_byte, loff_t end_byte)
>  {
> +	unsigned int min_order = mapping_min_folio_order(mapping);
> +	unsigned int nrpages = 1UL << min_order;
> +	pgoff_t index = round_down(start_byte >> PAGE_SHIFT, nrpages);
>  	struct folio *folio;
> -	XA_STATE(xas, &mapping->i_pages, start_byte >> PAGE_SHIFT);
> -	pgoff_t max = end_byte >> PAGE_SHIFT;
> +	XA_STATE(xas, &mapping->i_pages, index);
> +	pgoff_t max = round_down(end_byte >> PAGE_SHIFT, nrpages);
>  
>  	if (end_byte < start_byte)
>  		return false;
> -- 
> 2.40.1
>
Luis Chamberlain Sept. 18, 2023, 6:25 p.m. UTC | #2
On Fri, Sep 15, 2023 at 08:45:20PM +0100, Matthew Wilcox wrote:
> On Fri, Sep 15, 2023 at 08:38:30PM +0200, Pankaj Raghav wrote:
> > From: Luis Chamberlain <mcgrof@kernel.org>
> > 
> > page cache is mapping min_folio_order aligned. Use mapping min_folio_order
> > to align the start_byte and end_byte in filemap_range_has_page().
> 
> What goes wrong if you don't?  Seems to me like it should work.

Will drop from the series after confirming, thanks.

  Luis
diff mbox series

Patch

diff --git a/mm/filemap.c b/mm/filemap.c
index 2c47729dc8b0..4dee24b5b61c 100644
--- a/mm/filemap.c
+++ b/mm/filemap.c
@@ -477,9 +477,12 @@  EXPORT_SYMBOL(filemap_flush);
 bool filemap_range_has_page(struct address_space *mapping,
 			   loff_t start_byte, loff_t end_byte)
 {
+	unsigned int min_order = mapping_min_folio_order(mapping);
+	unsigned int nrpages = 1UL << min_order;
+	pgoff_t index = round_down(start_byte >> PAGE_SHIFT, nrpages);
 	struct folio *folio;
-	XA_STATE(xas, &mapping->i_pages, start_byte >> PAGE_SHIFT);
-	pgoff_t max = end_byte >> PAGE_SHIFT;
+	XA_STATE(xas, &mapping->i_pages, index);
+	pgoff_t max = round_down(end_byte >> PAGE_SHIFT, nrpages);
 
 	if (end_byte < start_byte)
 		return false;