2023-09-16 04:03:37

by Pankaj Raghav (Samsung)

[permalink] [raw]
Subject: [RFC 09/23] filemap: use mapping_min_order while allocating folios

From: Pankaj Raghav <[email protected]>

Allocate al teast mapping_min_order when creating new folio for the
filemap in filemap_create_folio() and do_read_cache_folio().

Signed-off-by: Pankaj Raghav <[email protected]>
---
mm/filemap.c | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/mm/filemap.c b/mm/filemap.c
index 21e1341526ab..e4d46f79e95d 100644
--- a/mm/filemap.c
+++ b/mm/filemap.c
@@ -2502,7 +2502,8 @@ static int filemap_create_folio(struct file *file,
struct folio *folio;
int error;

- folio = filemap_alloc_folio(mapping_gfp_mask(mapping), 0);
+ folio = filemap_alloc_folio(mapping_gfp_mask(mapping),
+ mapping_min_folio_order(mapping));
if (!folio)
return -ENOMEM;

@@ -3696,7 +3697,8 @@ static struct folio *do_read_cache_folio(struct address_space *mapping,
repeat:
folio = filemap_get_folio(mapping, index);
if (IS_ERR(folio)) {
- folio = filemap_alloc_folio(gfp, 0);
+ folio = filemap_alloc_folio(gfp,
+ mapping_min_folio_order(mapping));
if (!folio)
return ERR_PTR(-ENOMEM);
err = filemap_add_folio(mapping, folio, index, gfp);
--
2.40.1


2023-09-16 07:37:08

by Matthew Wilcox

[permalink] [raw]
Subject: Re: [RFC 09/23] filemap: use mapping_min_order while allocating folios

On Fri, Sep 15, 2023 at 08:38:34PM +0200, Pankaj Raghav wrote:
> From: Pankaj Raghav <[email protected]>
>
> Allocate al teast mapping_min_order when creating new folio for the
> filemap in filemap_create_folio() and do_read_cache_folio().

This patch is where you should be doing:

index &= ~(folio_nr_pages(folio) - 1UL);

(or similar)

> Signed-off-by: Pankaj Raghav <[email protected]>
> ---
> mm/filemap.c | 6 ++++--
> 1 file changed, 4 insertions(+), 2 deletions(-)
>
> diff --git a/mm/filemap.c b/mm/filemap.c
> index 21e1341526ab..e4d46f79e95d 100644
> --- a/mm/filemap.c
> +++ b/mm/filemap.c
> @@ -2502,7 +2502,8 @@ static int filemap_create_folio(struct file *file,
> struct folio *folio;
> int error;
>
> - folio = filemap_alloc_folio(mapping_gfp_mask(mapping), 0);
> + folio = filemap_alloc_folio(mapping_gfp_mask(mapping),
> + mapping_min_folio_order(mapping));
> if (!folio)
> return -ENOMEM;
>
> @@ -3696,7 +3697,8 @@ static struct folio *do_read_cache_folio(struct address_space *mapping,
> repeat:
> folio = filemap_get_folio(mapping, index);
> if (IS_ERR(folio)) {
> - folio = filemap_alloc_folio(gfp, 0);
> + folio = filemap_alloc_folio(gfp,
> + mapping_min_folio_order(mapping));
> if (!folio)
> return ERR_PTR(-ENOMEM);
> err = filemap_add_folio(mapping, folio, index, gfp);
> --
> 2.40.1
>