diff mbox series

[02/12] filemap: Use folio_put_refs() in filemap_free_folio()

Message ID 20220116121822.1727633-3-willy@infradead.org (mailing list archive)
State New, archived
Headers show
Series Enabling large folios for 5.17 | expand

Commit Message

Matthew Wilcox Jan. 16, 2022, 12:18 p.m. UTC
This shrinks filemap_free_folio() by 55 bytes in my .config; 24 bytes
from removing the VM_BUG_ON_FOLIO() and 31 bytes from unifying the
small/large folio paths.

We could just use folio_ref_sub() here since the caller should hold a
reference (as the VM_BUG_ON_FOLIO() was asserting), but that's fragile.

Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
---
 mm/filemap.c | 10 ++++------
 1 file changed, 4 insertions(+), 6 deletions(-)

Comments

Kirill A . Shutemov Jan. 17, 2022, 3:56 p.m. UTC | #1
On Sun, Jan 16, 2022 at 12:18:12PM +0000, Matthew Wilcox (Oracle) wrote:
> This shrinks filemap_free_folio() by 55 bytes in my .config; 24 bytes
> from removing the VM_BUG_ON_FOLIO() and 31 bytes from unifying the
> small/large folio paths.
> 
> We could just use folio_ref_sub() here since the caller should hold a
> reference (as the VM_BUG_ON_FOLIO() was asserting), but that's fragile.
> 
> Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
> ---
>  mm/filemap.c | 10 ++++------
>  1 file changed, 4 insertions(+), 6 deletions(-)
> 
> diff --git a/mm/filemap.c b/mm/filemap.c
> index 2fd9b2f24025..afc8f5ca85ac 100644
> --- a/mm/filemap.c
> +++ b/mm/filemap.c
> @@ -231,17 +231,15 @@ void __filemap_remove_folio(struct folio *folio, void *shadow)
>  void filemap_free_folio(struct address_space *mapping, struct folio *folio)
>  {
>  	void (*freepage)(struct page *);
> +	int refs = 1;
>  
>  	freepage = mapping->a_ops->freepage;
>  	if (freepage)
>  		freepage(&folio->page);
>  
> -	if (folio_test_large(folio) && !folio_test_hugetlb(folio)) {
> -		folio_ref_sub(folio, folio_nr_pages(folio));
> -		VM_BUG_ON_FOLIO(folio_ref_count(folio) <= 0, folio);
> -	} else {
> -		folio_put(folio);
> -	}
> +	if (folio_test_large(folio) && !folio_test_hugetlb(folio))
> +		refs = folio_nr_pages(folio);

Isn't folio_test_large() check redundant? folio_nr_pages() would return 1
for non-large folio, wouldn't it?

> +	folio_put_refs(folio, refs);
>  }
>  
>  /**
> -- 
> 2.34.1
>
Matthew Wilcox Jan. 17, 2022, 4:11 p.m. UTC | #2
On Mon, Jan 17, 2022 at 06:56:41PM +0300, Kirill A. Shutemov wrote:
> On Sun, Jan 16, 2022 at 12:18:12PM +0000, Matthew Wilcox (Oracle) wrote:
> > +	if (folio_test_large(folio) && !folio_test_hugetlb(folio))
> > +		refs = folio_nr_pages(folio);
> 
> Isn't folio_test_large() check redundant? folio_nr_pages() would return 1
> for non-large folio, wouldn't it?

I'm trying to avoid the function call for !hugetlb pages.
diff mbox series

Patch

diff --git a/mm/filemap.c b/mm/filemap.c
index 2fd9b2f24025..afc8f5ca85ac 100644
--- a/mm/filemap.c
+++ b/mm/filemap.c
@@ -231,17 +231,15 @@  void __filemap_remove_folio(struct folio *folio, void *shadow)
 void filemap_free_folio(struct address_space *mapping, struct folio *folio)
 {
 	void (*freepage)(struct page *);
+	int refs = 1;
 
 	freepage = mapping->a_ops->freepage;
 	if (freepage)
 		freepage(&folio->page);
 
-	if (folio_test_large(folio) && !folio_test_hugetlb(folio)) {
-		folio_ref_sub(folio, folio_nr_pages(folio));
-		VM_BUG_ON_FOLIO(folio_ref_count(folio) <= 0, folio);
-	} else {
-		folio_put(folio);
-	}
+	if (folio_test_large(folio) && !folio_test_hugetlb(folio))
+		refs = folio_nr_pages(folio);
+	folio_put_refs(folio, refs);
 }
 
 /**