linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/4] Removing the try_to_release_page() wrapper
@ 2022-11-16  2:10 Vishal Moola (Oracle)
  2022-11-16  2:10 ` [PATCH 1/4] ext4: Convert move_extent_per_page() to use folios Vishal Moola (Oracle)
                   ` (3 more replies)
  0 siblings, 4 replies; 8+ messages in thread
From: Vishal Moola (Oracle) @ 2022-11-16  2:10 UTC (permalink / raw)
  To: linux-mm
  Cc: linux-fsdevel, linux-kernel, linux-ext4, akpm, willy,
	naoya.horiguchi, tytso, Vishal Moola (Oracle)

This patchset replaces the remaining calls of try_to_release_page() with
the folio equivalent: filemap_release_folio(). This allows us to remove
the wrapper.

The set passes fstests on ext4 and xfs.

Vishal Moola (Oracle) (4):
  ext4: Convert move_extent_per_page() to use folios
  khugepage: Replace try_to_release_page() with filemap_release_folio()
  memory-failure: Convert truncate_error_page() to use folio
  folio-compat: Remove try_to_release_page()

 fs/ext4/move_extent.c   | 47 +++++++++++++++++++++++------------------
 include/linux/pagemap.h |  1 -
 mm/folio-compat.c       |  6 ------
 mm/khugepaged.c         | 23 ++++++++++----------
 mm/memory-failure.c     |  5 +++--
 5 files changed, 41 insertions(+), 41 deletions(-)

-- 
2.38.1



^ permalink raw reply	[flat|nested] 8+ messages in thread

* [PATCH 1/4] ext4: Convert move_extent_per_page() to use folios
  2022-11-16  2:10 [PATCH 0/4] Removing the try_to_release_page() wrapper Vishal Moola (Oracle)
@ 2022-11-16  2:10 ` Vishal Moola (Oracle)
  2022-11-16  8:09   ` Matthew Wilcox
  2022-11-16  2:10 ` [PATCH 2/4] khugepage: Replace try_to_release_page() with filemap_release_folio() Vishal Moola (Oracle)
                   ` (2 subsequent siblings)
  3 siblings, 1 reply; 8+ messages in thread
From: Vishal Moola (Oracle) @ 2022-11-16  2:10 UTC (permalink / raw)
  To: linux-mm
  Cc: linux-fsdevel, linux-kernel, linux-ext4, akpm, willy,
	naoya.horiguchi, tytso, Vishal Moola (Oracle)

Converts move_extent_per_page() to use folios. This change removes
5 calls to compound_head() and is in preparation for the removal of
the try_to_release_page() wrapper.

Signed-off-by: Vishal Moola (Oracle) <vishal.moola@gmail.com>
---
 fs/ext4/move_extent.c | 47 ++++++++++++++++++++++++-------------------
 1 file changed, 26 insertions(+), 21 deletions(-)

diff --git a/fs/ext4/move_extent.c b/fs/ext4/move_extent.c
index 044e34cd835c..0c680d4a2929 100644
--- a/fs/ext4/move_extent.c
+++ b/fs/ext4/move_extent.c
@@ -253,6 +253,7 @@ move_extent_per_page(struct file *o_filp, struct inode *donor_inode,
 {
 	struct inode *orig_inode = file_inode(o_filp);
 	struct page *pagep[2] = {NULL, NULL};
+	struct folio *folio[2] = {NULL, NULL};
 	handle_t *handle;
 	ext4_lblk_t orig_blk_offset, donor_blk_offset;
 	unsigned long blocksize = orig_inode->i_sb->s_blocksize;
@@ -313,6 +314,8 @@ move_extent_per_page(struct file *o_filp, struct inode *donor_inode,
 	 * hold page's lock, if it is still the case data copy is not
 	 * necessary, just swap data blocks between orig and donor.
 	 */
+	folio[0] = page_folio(pagep[0]);
+	folio[1] = page_folio(pagep[1]);
 	if (unwritten) {
 		ext4_double_down_write_data_sem(orig_inode, donor_inode);
 		/* If any of extents in range became initialized we have to
@@ -331,10 +334,10 @@ move_extent_per_page(struct file *o_filp, struct inode *donor_inode,
 			ext4_double_up_write_data_sem(orig_inode, donor_inode);
 			goto data_copy;
 		}
-		if ((page_has_private(pagep[0]) &&
-		     !try_to_release_page(pagep[0], 0)) ||
-		    (page_has_private(pagep[1]) &&
-		     !try_to_release_page(pagep[1], 0))) {
+		if ((folio_has_private(folio[0]) &&
+		     !filemap_release_folio(folio[0], 0)) ||
+		    (folio_has_private(folio[1]) &&
+		     !filemap_release_folio(folio[1], 0))) {
 			*err = -EBUSY;
 			goto drop_data_sem;
 		}
@@ -344,19 +347,21 @@ move_extent_per_page(struct file *o_filp, struct inode *donor_inode,
 						   block_len_in_page, 1, err);
 	drop_data_sem:
 		ext4_double_up_write_data_sem(orig_inode, donor_inode);
-		goto unlock_pages;
+		goto unlock_folios;
 	}
 data_copy:
-	*err = mext_page_mkuptodate(pagep[0], from, from + replaced_size);
+	*err = mext_page_mkuptodate(&folio[0]->page, from, from + replaced_size);
 	if (*err)
-		goto unlock_pages;
+		goto unlock_folios;
 
 	/* At this point all buffers in range are uptodate, old mapping layout
 	 * is no longer required, try to drop it now. */
-	if ((page_has_private(pagep[0]) && !try_to_release_page(pagep[0], 0)) ||
-	    (page_has_private(pagep[1]) && !try_to_release_page(pagep[1], 0))) {
+	if ((folio_has_private(folio[0]) &&
+		!filemap_release_folio(folio[0], 0)) ||
+	    (folio_has_private(folio[1]) &&
+		!filemap_release_folio(folio[1], 0))) {
 		*err = -EBUSY;
-		goto unlock_pages;
+		goto unlock_folios;
 	}
 	ext4_double_down_write_data_sem(orig_inode, donor_inode);
 	replaced_count = ext4_swap_extents(handle, orig_inode, donor_inode,
@@ -369,13 +374,13 @@ move_extent_per_page(struct file *o_filp, struct inode *donor_inode,
 			replaced_size =
 				block_len_in_page << orig_inode->i_blkbits;
 		} else
-			goto unlock_pages;
+			goto unlock_folios;
 	}
 	/* Perform all necessary steps similar write_begin()/write_end()
 	 * but keeping in mind that i_size will not change */
-	if (!page_has_buffers(pagep[0]))
-		create_empty_buffers(pagep[0], 1 << orig_inode->i_blkbits, 0);
-	bh = page_buffers(pagep[0]);
+	if (!folio_buffers(folio[0]))
+		create_empty_buffers(&folio[0]->page, 1 << orig_inode->i_blkbits, 0);
+	bh = folio_buffers(folio[0]);
 	for (i = 0; i < data_offset_in_page; i++)
 		bh = bh->b_this_page;
 	for (i = 0; i < block_len_in_page; i++) {
@@ -385,7 +390,7 @@ move_extent_per_page(struct file *o_filp, struct inode *donor_inode,
 		bh = bh->b_this_page;
 	}
 	if (!*err)
-		*err = block_commit_write(pagep[0], from, from + replaced_size);
+		*err = block_commit_write(&folio[0]->page, from, from + replaced_size);
 
 	if (unlikely(*err < 0))
 		goto repair_branches;
@@ -395,11 +400,11 @@ move_extent_per_page(struct file *o_filp, struct inode *donor_inode,
 	*err = ext4_jbd2_inode_add_write(handle, orig_inode,
 			(loff_t)orig_page_offset << PAGE_SHIFT, replaced_size);
 
-unlock_pages:
-	unlock_page(pagep[0]);
-	put_page(pagep[0]);
-	unlock_page(pagep[1]);
-	put_page(pagep[1]);
+unlock_folios:
+	folio_unlock(folio[0]);
+	folio_put(folio[0]);
+	folio_unlock(folio[1]);
+	folio_put(folio[1]);
 stop_journal:
 	ext4_journal_stop(handle);
 	if (*err == -ENOSPC &&
@@ -430,7 +435,7 @@ move_extent_per_page(struct file *o_filp, struct inode *donor_inode,
 		*err = -EIO;
 	}
 	replaced_count = 0;
-	goto unlock_pages;
+	goto unlock_folios;
 }
 
 /**
-- 
2.38.1



^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH 2/4] khugepage: Replace try_to_release_page() with filemap_release_folio()
  2022-11-16  2:10 [PATCH 0/4] Removing the try_to_release_page() wrapper Vishal Moola (Oracle)
  2022-11-16  2:10 ` [PATCH 1/4] ext4: Convert move_extent_per_page() to use folios Vishal Moola (Oracle)
@ 2022-11-16  2:10 ` Vishal Moola (Oracle)
  2022-11-16  2:10 ` [PATCH 3/4] memory-failure: Convert truncate_error_page() to use folio Vishal Moola (Oracle)
  2022-11-16  2:10 ` [PATCH 4/4] folio-compat: Remove try_to_release_page() Vishal Moola (Oracle)
  3 siblings, 0 replies; 8+ messages in thread
From: Vishal Moola (Oracle) @ 2022-11-16  2:10 UTC (permalink / raw)
  To: linux-mm
  Cc: linux-fsdevel, linux-kernel, linux-ext4, akpm, willy,
	naoya.horiguchi, tytso, Vishal Moola (Oracle)

Replaces some calls with their folio equivalents. This change removes
4 calls to compound_head() and is in preparation for the removal of the
try_to_release_page() wrapper.

Signed-off-by: Vishal Moola (Oracle) <vishal.moola@gmail.com>
---
 mm/khugepaged.c | 23 ++++++++++++-----------
 1 file changed, 12 insertions(+), 11 deletions(-)

diff --git a/mm/khugepaged.c b/mm/khugepaged.c
index 4734315f7940..3f21c010d2bd 100644
--- a/mm/khugepaged.c
+++ b/mm/khugepaged.c
@@ -1747,6 +1747,7 @@ static int collapse_file(struct mm_struct *mm, unsigned long addr,
 	xas_set(&xas, start);
 	for (index = start; index < end; index++) {
 		struct page *page = xas_next(&xas);
+		struct folio *folio;
 
 		VM_BUG_ON(index != xas.xa_index);
 		if (is_shmem) {
@@ -1773,8 +1774,6 @@ static int collapse_file(struct mm_struct *mm, unsigned long addr,
 			}
 
 			if (xa_is_value(page) || !PageUptodate(page)) {
-				struct folio *folio;
-
 				xas_unlock_irq(&xas);
 				/* swap in or instantiate fallocated page */
 				if (shmem_get_folio(mapping->host, index,
@@ -1862,13 +1861,15 @@ static int collapse_file(struct mm_struct *mm, unsigned long addr,
 			goto out_unlock;
 		}
 
-		if (page_mapping(page) != mapping) {
+		folio = page_folio(page);
+
+		if (folio_mapping(folio) != mapping) {
 			result = SCAN_TRUNCATED;
 			goto out_unlock;
 		}
 
-		if (!is_shmem && (PageDirty(page) ||
-				  PageWriteback(page))) {
+		if (!is_shmem && (folio_test_dirty(folio) ||
+				  folio_test_writeback(folio))) {
 			/*
 			 * khugepaged only works on read-only fd, so this
 			 * page is dirty because it hasn't been flushed
@@ -1878,20 +1879,20 @@ static int collapse_file(struct mm_struct *mm, unsigned long addr,
 			goto out_unlock;
 		}
 
-		if (isolate_lru_page(page)) {
+		if (folio_isolate_lru(folio)) {
 			result = SCAN_DEL_PAGE_LRU;
 			goto out_unlock;
 		}
 
-		if (page_has_private(page) &&
-		    !try_to_release_page(page, GFP_KERNEL)) {
+		if (folio_has_private(folio) &&
+		    !filemap_release_folio(folio, GFP_KERNEL)) {
 			result = SCAN_PAGE_HAS_PRIVATE;
-			putback_lru_page(page);
+			folio_putback_lru(folio);
 			goto out_unlock;
 		}
 
-		if (page_mapped(page))
-			try_to_unmap(page_folio(page),
+		if (folio_mapped(folio))
+			try_to_unmap(folio,
 					TTU_IGNORE_MLOCK | TTU_BATCH_FLUSH);
 
 		xas_lock_irq(&xas);
-- 
2.38.1



^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH 3/4] memory-failure: Convert truncate_error_page() to use folio
  2022-11-16  2:10 [PATCH 0/4] Removing the try_to_release_page() wrapper Vishal Moola (Oracle)
  2022-11-16  2:10 ` [PATCH 1/4] ext4: Convert move_extent_per_page() to use folios Vishal Moola (Oracle)
  2022-11-16  2:10 ` [PATCH 2/4] khugepage: Replace try_to_release_page() with filemap_release_folio() Vishal Moola (Oracle)
@ 2022-11-16  2:10 ` Vishal Moola (Oracle)
  2022-11-17  5:49   ` HORIGUCHI NAOYA(堀口 直也)
  2022-11-16  2:10 ` [PATCH 4/4] folio-compat: Remove try_to_release_page() Vishal Moola (Oracle)
  3 siblings, 1 reply; 8+ messages in thread
From: Vishal Moola (Oracle) @ 2022-11-16  2:10 UTC (permalink / raw)
  To: linux-mm
  Cc: linux-fsdevel, linux-kernel, linux-ext4, akpm, willy,
	naoya.horiguchi, tytso, Vishal Moola (Oracle)

Replaces try_to_release_page() with filemap_release_folio(). This change
is in preparation for the removal of the try_to_release_page() wrapper.

Signed-off-by: Vishal Moola (Oracle) <vishal.moola@gmail.com>
---
 mm/memory-failure.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/mm/memory-failure.c b/mm/memory-failure.c
index 145bb561ddb3..92ec9b0e58a3 100644
--- a/mm/memory-failure.c
+++ b/mm/memory-failure.c
@@ -827,12 +827,13 @@ static int truncate_error_page(struct page *p, unsigned long pfn,
 	int ret = MF_FAILED;
 
 	if (mapping->a_ops->error_remove_page) {
+		struct folio *folio = page_folio(p);
 		int err = mapping->a_ops->error_remove_page(mapping, p);
 
 		if (err != 0) {
 			pr_info("%#lx: Failed to punch page: %d\n", pfn, err);
-		} else if (page_has_private(p) &&
-			   !try_to_release_page(p, GFP_NOIO)) {
+		} else if (folio_has_private(folio) &&
+			   !filemap_release_folio(folio, GFP_NOIO)) {
 			pr_info("%#lx: failed to release buffers\n", pfn);
 		} else {
 			ret = MF_RECOVERED;
-- 
2.38.1



^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH 4/4] folio-compat: Remove try_to_release_page()
  2022-11-16  2:10 [PATCH 0/4] Removing the try_to_release_page() wrapper Vishal Moola (Oracle)
                   ` (2 preceding siblings ...)
  2022-11-16  2:10 ` [PATCH 3/4] memory-failure: Convert truncate_error_page() to use folio Vishal Moola (Oracle)
@ 2022-11-16  2:10 ` Vishal Moola (Oracle)
  3 siblings, 0 replies; 8+ messages in thread
From: Vishal Moola (Oracle) @ 2022-11-16  2:10 UTC (permalink / raw)
  To: linux-mm
  Cc: linux-fsdevel, linux-kernel, linux-ext4, akpm, willy,
	naoya.horiguchi, tytso, Vishal Moola (Oracle)

There are no more callers of try_to_release_page(), so remove it. This
saves 149 bytes of kernel text.

Signed-off-by: Vishal Moola (Oracle) <vishal.moola@gmail.com>
---
 include/linux/pagemap.h | 1 -
 mm/folio-compat.c       | 6 ------
 2 files changed, 7 deletions(-)

diff --git a/include/linux/pagemap.h b/include/linux/pagemap.h
index bbccb4044222..daf5e1a1d313 100644
--- a/include/linux/pagemap.h
+++ b/include/linux/pagemap.h
@@ -1107,7 +1107,6 @@ void __filemap_remove_folio(struct folio *folio, void *shadow);
 void replace_page_cache_page(struct page *old, struct page *new);
 void delete_from_page_cache_batch(struct address_space *mapping,
 				  struct folio_batch *fbatch);
-int try_to_release_page(struct page *page, gfp_t gfp);
 bool filemap_release_folio(struct folio *folio, gfp_t gfp);
 loff_t mapping_seek_hole_data(struct address_space *, loff_t start, loff_t end,
 		int whence);
diff --git a/mm/folio-compat.c b/mm/folio-compat.c
index e1e23b4947d7..9318a0bd9155 100644
--- a/mm/folio-compat.c
+++ b/mm/folio-compat.c
@@ -129,12 +129,6 @@ void delete_from_page_cache(struct page *page)
 	return filemap_remove_folio(page_folio(page));
 }
 
-int try_to_release_page(struct page *page, gfp_t gfp)
-{
-	return filemap_release_folio(page_folio(page), gfp);
-}
-EXPORT_SYMBOL(try_to_release_page);
-
 int isolate_lru_page(struct page *page)
 {
 	if (WARN_RATELIMIT(PageTail(page), "trying to isolate tail page"))
-- 
2.38.1



^ permalink raw reply related	[flat|nested] 8+ messages in thread

* Re: [PATCH 1/4] ext4: Convert move_extent_per_page() to use folios
  2022-11-16  2:10 ` [PATCH 1/4] ext4: Convert move_extent_per_page() to use folios Vishal Moola (Oracle)
@ 2022-11-16  8:09   ` Matthew Wilcox
  2022-11-16 19:49     ` Vishal Moola
  0 siblings, 1 reply; 8+ messages in thread
From: Matthew Wilcox @ 2022-11-16  8:09 UTC (permalink / raw)
  To: Vishal Moola (Oracle)
  Cc: linux-mm, linux-fsdevel, linux-kernel, linux-ext4, akpm,
	naoya.horiguchi, tytso

On Tue, Nov 15, 2022 at 06:10:08PM -0800, Vishal Moola (Oracle) wrote:
>  {
>  	struct inode *orig_inode = file_inode(o_filp);
>  	struct page *pagep[2] = {NULL, NULL};
> +	struct folio *folio[2] = {NULL, NULL};

I have a feeling that mext_page_double_lock() should also be converted
to use folios.  But this makes me nervous:

        int blocks_per_page = PAGE_SIZE >> orig_inode->i_blkbits;

and I'm not sure what will happen if one or both of the orig_page
and donor_page is large -- possibly different sizes of large.

Obviously ext4 doesn't allow large folios today, but it would be good to
get some reasoning about why this isn't laying a trap for later (or at
least assertions that neither folio is large so that there's an obvious
scream instead of silent data corruption).


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH 1/4] ext4: Convert move_extent_per_page() to use folios
  2022-11-16  8:09   ` Matthew Wilcox
@ 2022-11-16 19:49     ` Vishal Moola
  0 siblings, 0 replies; 8+ messages in thread
From: Vishal Moola @ 2022-11-16 19:49 UTC (permalink / raw)
  To: Matthew Wilcox
  Cc: linux-mm, linux-fsdevel, linux-kernel, linux-ext4, akpm,
	naoya.horiguchi, tytso

On Wed, Nov 16, 2022 at 12:09 AM Matthew Wilcox <willy@infradead.org> wrote:
>
> On Tue, Nov 15, 2022 at 06:10:08PM -0800, Vishal Moola (Oracle) wrote:
> >  {
> >       struct inode *orig_inode = file_inode(o_filp);
> >       struct page *pagep[2] = {NULL, NULL};
> > +     struct folio *folio[2] = {NULL, NULL};
>
> I have a feeling that mext_page_double_lock() should also be converted
> to use folios.  But this makes me nervous:
>
>         int blocks_per_page = PAGE_SIZE >> orig_inode->i_blkbits;
>
> and I'm not sure what will happen if one or both of the orig_page
> and donor_page is large -- possibly different sizes of large.
>
> Obviously ext4 doesn't allow large folios today, but it would be good to
> get some reasoning about why this isn't laying a trap for later (or at
> least assertions that neither folio is large so that there's an obvious
> scream instead of silent data corruption).

I had thought once mext_page_mkuptodate() and block_commit_write()
were converted to folios, large folios wouldn't be a problem. I hadn't
considered
that the folios may be of different sizes. I can add assertions about both
folios being large and the same size in v2.


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH 3/4] memory-failure: Convert truncate_error_page() to use folio
  2022-11-16  2:10 ` [PATCH 3/4] memory-failure: Convert truncate_error_page() to use folio Vishal Moola (Oracle)
@ 2022-11-17  5:49   ` HORIGUCHI NAOYA(堀口 直也)
  0 siblings, 0 replies; 8+ messages in thread
From: HORIGUCHI NAOYA(堀口 直也) @ 2022-11-17  5:49 UTC (permalink / raw)
  To: Vishal Moola (Oracle)
  Cc: linux-mm, linux-fsdevel, linux-kernel, linux-ext4, akpm, willy, tytso

On Tue, Nov 15, 2022 at 06:10:10PM -0800, Vishal Moola (Oracle) wrote:
> Replaces try_to_release_page() with filemap_release_folio(). This change
> is in preparation for the removal of the try_to_release_page() wrapper.
> 
> Signed-off-by: Vishal Moola (Oracle) <vishal.moola@gmail.com>

Looks good to me, thank you.

Acked-by: Naoya Horiguchi <naoya.horiguchi@nec.com>

> ---
>  mm/memory-failure.c | 5 +++--
>  1 file changed, 3 insertions(+), 2 deletions(-)
> 
> diff --git a/mm/memory-failure.c b/mm/memory-failure.c
> index 145bb561ddb3..92ec9b0e58a3 100644
> --- a/mm/memory-failure.c
> +++ b/mm/memory-failure.c
> @@ -827,12 +827,13 @@ static int truncate_error_page(struct page *p, unsigned long pfn,
>  	int ret = MF_FAILED;
>  
>  	if (mapping->a_ops->error_remove_page) {
> +		struct folio *folio = page_folio(p);
>  		int err = mapping->a_ops->error_remove_page(mapping, p);
>  
>  		if (err != 0) {
>  			pr_info("%#lx: Failed to punch page: %d\n", pfn, err);
> -		} else if (page_has_private(p) &&
> -			   !try_to_release_page(p, GFP_NOIO)) {
> +		} else if (folio_has_private(folio) &&
> +			   !filemap_release_folio(folio, GFP_NOIO)) {
>  			pr_info("%#lx: failed to release buffers\n", pfn);
>  		} else {
>  			ret = MF_RECOVERED;
> -- 
> 2.38.1

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2022-11-17  5:49 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-11-16  2:10 [PATCH 0/4] Removing the try_to_release_page() wrapper Vishal Moola (Oracle)
2022-11-16  2:10 ` [PATCH 1/4] ext4: Convert move_extent_per_page() to use folios Vishal Moola (Oracle)
2022-11-16  8:09   ` Matthew Wilcox
2022-11-16 19:49     ` Vishal Moola
2022-11-16  2:10 ` [PATCH 2/4] khugepage: Replace try_to_release_page() with filemap_release_folio() Vishal Moola (Oracle)
2022-11-16  2:10 ` [PATCH 3/4] memory-failure: Convert truncate_error_page() to use folio Vishal Moola (Oracle)
2022-11-17  5:49   ` HORIGUCHI NAOYA(堀口 直也)
2022-11-16  2:10 ` [PATCH 4/4] folio-compat: Remove try_to_release_page() Vishal Moola (Oracle)

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).