All of lore.kernel.org
 help / color / mirror / Atom feed
From: Joseph Qi <joseph.qi@linux.alibaba.com>
To: "Matthew Wilcox (Oracle)" <willy@infradead.org>,
	akpm <akpm@linux-foundation.org>
Cc: Mark Tinguely <mark.tinguely@oracle.com>, ocfs2-devel@lists.linux.dev
Subject: Re: [PATCH 16/23] ocfs2: Use an array of folios instead of an array of pages
Date: Sat, 14 Dec 2024 22:34:16 +0800	[thread overview]
Message-ID: <7ede4cc2-8026-4622-87ae-23d2eec5b4c4@linux.alibaba.com> (raw)
In-Reply-To: <20241205171653.3179945-17-willy@infradead.org>



On 2024/12/6 01:16, Matthew Wilcox (Oracle) wrote:
> From: Mark Tinguely <mark.tinguely@oracle.com>
> 
> The ocfs2_zero_cluster_folios() / ocfs2_grab_folios() /
> ocfs2_grab_eof_folios() family of functions pass around an array of
> pages.  Convert them to pass around an array of folios.  This removes
> the last caller of ocfs2_unlock_and_free_pages(), so delete it.
> 
> Signed-off-by: Mark Tinguely <mark.tinguely@oracle.com>
> Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>

Looks good.
Reviewed-by: Joseph Qi <joseph.qi@linux.alibaba.com>

> ---
>  fs/ocfs2/alloc.c | 98 ++++++++++++++++++++++++------------------------
>  fs/ocfs2/alloc.h |  2 -
>  fs/ocfs2/aops.c  | 13 -------
>  fs/ocfs2/aops.h  |  1 -
>  4 files changed, 49 insertions(+), 65 deletions(-)
> 
> diff --git a/fs/ocfs2/alloc.c b/fs/ocfs2/alloc.c
> index cfe9535a27f9..dfcdafc11377 100644
> --- a/fs/ocfs2/alloc.c
> +++ b/fs/ocfs2/alloc.c
> @@ -6847,87 +6847,87 @@ void ocfs2_map_and_dirty_page(struct inode *inode, handle_t *handle,
>  	flush_dcache_folio(folio);
>  }
>  
> -static void ocfs2_zero_cluster_pages(struct inode *inode, loff_t start,
> -				     loff_t end, struct page **pages,
> -				     int numpages, u64 phys, handle_t *handle)
> +static void ocfs2_zero_cluster_folios(struct inode *inode, loff_t start,
> +		loff_t end, struct folio **folios, int numfolios,
> +		u64 phys, handle_t *handle)
>  {
>  	int i;
> -	struct page *page;
>  	unsigned int from, to = PAGE_SIZE;
>  	struct super_block *sb = inode->i_sb;
>  
>  	BUG_ON(!ocfs2_sparse_alloc(OCFS2_SB(sb)));
>  
> -	if (numpages == 0)
> +	if (numfolios == 0)
>  		goto out;
>  
>  	to = PAGE_SIZE;
> -	for(i = 0; i < numpages; i++) {
> -		page = pages[i];
> +	for (i = 0; i < numfolios; i++) {
> +		struct folio *folio = folios[i];
>  
>  		from = start & (PAGE_SIZE - 1);
> -		if ((end >> PAGE_SHIFT) == page->index)
> +		if ((end >> PAGE_SHIFT) == folio->index)
>  			to = end & (PAGE_SIZE - 1);
>  
>  		BUG_ON(from > PAGE_SIZE);
>  		BUG_ON(to > PAGE_SIZE);
>  
> -		ocfs2_map_and_dirty_page(inode, handle, from, to, page, 1,
> +		ocfs2_map_and_dirty_page(inode, handle, from, to, &folio->page, 1,
>  					 &phys);
>  
> -		start = (page->index + 1) << PAGE_SHIFT;
> +		start = (folio->index + 1) << PAGE_SHIFT;
>  	}
>  out:
> -	if (pages)
> -		ocfs2_unlock_and_free_pages(pages, numpages);
> +	if (folios)
> +		ocfs2_unlock_and_free_folios(folios, numfolios);
>  }
>  
> -int ocfs2_grab_pages(struct inode *inode, loff_t start, loff_t end,
> -		     struct page **pages, int *num)
> +static int ocfs2_grab_folios(struct inode *inode, loff_t start, loff_t end,
> +		struct folio **folios, int *num)
>  {
> -	int numpages, ret = 0;
> +	int numfolios, ret = 0;
>  	struct address_space *mapping = inode->i_mapping;
>  	unsigned long index;
>  	loff_t last_page_bytes;
>  
>  	BUG_ON(start > end);
>  
> -	numpages = 0;
> +	numfolios = 0;
>  	last_page_bytes = PAGE_ALIGN(end);
>  	index = start >> PAGE_SHIFT;
>  	do {
> -		pages[numpages] = find_or_create_page(mapping, index, GFP_NOFS);
> -		if (!pages[numpages]) {
> -			ret = -ENOMEM;
> +		folios[numfolios] = __filemap_get_folio(mapping, index,
> +				FGP_LOCK | FGP_ACCESSED | FGP_CREAT, GFP_NOFS);
> +		if (IS_ERR(folios[numfolios])) {
> +			ret = PTR_ERR(folios[numfolios]);
>  			mlog_errno(ret);
>  			goto out;
>  		}
>  
> -		numpages++;
> -		index++;
> +		index = folio_next_index(folios[numfolios]);
> +		numfolios++;
>  	} while (index < (last_page_bytes >> PAGE_SHIFT));
>  
>  out:
>  	if (ret != 0) {
> -		if (pages)
> -			ocfs2_unlock_and_free_pages(pages, numpages);
> -		numpages = 0;
> +		if (folios)
> +			ocfs2_unlock_and_free_folios(folios, numfolios);
> +		numfolios = 0;
>  	}
>  
> -	*num = numpages;
> +	*num = numfolios;
>  
>  	return ret;
>  }
>  
> -static int ocfs2_grab_eof_pages(struct inode *inode, loff_t start, loff_t end,
> -				struct page **pages, int *num)
> +static int ocfs2_grab_eof_folios(struct inode *inode, loff_t start, loff_t end,
> +				struct folio **folios, int *num)
>  {
>  	struct super_block *sb = inode->i_sb;
>  
>  	BUG_ON(start >> OCFS2_SB(sb)->s_clustersize_bits !=
>  	       (end - 1) >> OCFS2_SB(sb)->s_clustersize_bits);
>  
> -	return ocfs2_grab_pages(inode, start, end, pages, num);
> +	return ocfs2_grab_folios(inode, start, end, folios, num);
>  }
>  
>  /*
> @@ -6941,8 +6941,8 @@ static int ocfs2_grab_eof_pages(struct inode *inode, loff_t start, loff_t end,
>  int ocfs2_zero_range_for_truncate(struct inode *inode, handle_t *handle,
>  				  u64 range_start, u64 range_end)
>  {
> -	int ret = 0, numpages;
> -	struct page **pages = NULL;
> +	int ret = 0, numfolios;
> +	struct folio **folios = NULL;
>  	u64 phys;
>  	unsigned int ext_flags;
>  	struct super_block *sb = inode->i_sb;
> @@ -6955,17 +6955,17 @@ int ocfs2_zero_range_for_truncate(struct inode *inode, handle_t *handle,
>  		return 0;
>  
>  	/*
> -	 * Avoid zeroing pages fully beyond current i_size. It is pointless as
> -	 * underlying blocks of those pages should be already zeroed out and
> +	 * Avoid zeroing folios fully beyond current i_size. It is pointless as
> +	 * underlying blocks of those folios should be already zeroed out and
>  	 * page writeback will skip them anyway.
>  	 */
>  	range_end = min_t(u64, range_end, i_size_read(inode));
>  	if (range_start >= range_end)
>  		return 0;
>  
> -	pages = kcalloc(ocfs2_pages_per_cluster(sb),
> -			sizeof(struct page *), GFP_NOFS);
> -	if (pages == NULL) {
> +	folios = kcalloc(ocfs2_pages_per_cluster(sb),
> +			sizeof(struct folio *), GFP_NOFS);
> +	if (folios == NULL) {
>  		ret = -ENOMEM;
>  		mlog_errno(ret);
>  		goto out;
> @@ -6986,18 +6986,18 @@ int ocfs2_zero_range_for_truncate(struct inode *inode, handle_t *handle,
>  	if (phys == 0 || ext_flags & OCFS2_EXT_UNWRITTEN)
>  		goto out;
>  
> -	ret = ocfs2_grab_eof_pages(inode, range_start, range_end, pages,
> -				   &numpages);
> +	ret = ocfs2_grab_eof_folios(inode, range_start, range_end, folios,
> +				   &numfolios);
>  	if (ret) {
>  		mlog_errno(ret);
>  		goto out;
>  	}
>  
> -	ocfs2_zero_cluster_pages(inode, range_start, range_end, pages,
> -				 numpages, phys, handle);
> +	ocfs2_zero_cluster_folios(inode, range_start, range_end, folios,
> +				 numfolios, phys, handle);
>  
>  	/*
> -	 * Initiate writeout of the pages we zero'd here. We don't
> +	 * Initiate writeout of the folios we zero'd here. We don't
>  	 * wait on them - the truncate_inode_pages() call later will
>  	 * do that for us.
>  	 */
> @@ -7007,7 +7007,7 @@ int ocfs2_zero_range_for_truncate(struct inode *inode, handle_t *handle,
>  		mlog_errno(ret);
>  
>  out:
> -	kfree(pages);
> +	kfree(folios);
>  
>  	return ret;
>  }
> @@ -7060,7 +7060,7 @@ void ocfs2_set_inode_data_inline(struct inode *inode, struct ocfs2_dinode *di)
>  int ocfs2_convert_inline_data_to_extents(struct inode *inode,
>  					 struct buffer_head *di_bh)
>  {
> -	int ret, has_data, num_pages = 0;
> +	int ret, has_data, num_folios = 0;
>  	int need_free = 0;
>  	u32 bit_off, num;
>  	handle_t *handle;
> @@ -7069,7 +7069,7 @@ int ocfs2_convert_inline_data_to_extents(struct inode *inode,
>  	struct ocfs2_super *osb = OCFS2_SB(inode->i_sb);
>  	struct ocfs2_dinode *di = (struct ocfs2_dinode *)di_bh->b_data;
>  	struct ocfs2_alloc_context *data_ac = NULL;
> -	struct page *page = NULL;
> +	struct folio *folio = NULL;
>  	struct ocfs2_extent_tree et;
>  	int did_quota = 0;
>  
> @@ -7124,8 +7124,8 @@ int ocfs2_convert_inline_data_to_extents(struct inode *inode,
>  		 */
>  		block = phys = ocfs2_clusters_to_blocks(inode->i_sb, bit_off);
>  
> -		ret = ocfs2_grab_eof_pages(inode, 0, page_end, &page,
> -					   &num_pages);
> +		ret = ocfs2_grab_eof_folios(inode, 0, page_end, &folio,
> +					   &num_folios);
>  		if (ret) {
>  			mlog_errno(ret);
>  			need_free = 1;
> @@ -7136,14 +7136,14 @@ int ocfs2_convert_inline_data_to_extents(struct inode *inode,
>  		 * This should populate the 1st page for us and mark
>  		 * it up to date.
>  		 */
> -		ret = ocfs2_read_inline_data(inode, page, di_bh);
> +		ret = ocfs2_read_inline_data(inode, &folio->page, di_bh);
>  		if (ret) {
>  			mlog_errno(ret);
>  			need_free = 1;
>  			goto out_unlock;
>  		}
>  
> -		ocfs2_map_and_dirty_page(inode, handle, 0, page_end, page, 0,
> +		ocfs2_map_and_dirty_page(inode, handle, 0, page_end, &folio->page, 0,
>  					 &phys);
>  	}
>  
> @@ -7175,8 +7175,8 @@ int ocfs2_convert_inline_data_to_extents(struct inode *inode,
>  	}
>  
>  out_unlock:
> -	if (page)
> -		ocfs2_unlock_and_free_pages(&page, num_pages);
> +	if (folio)
> +		ocfs2_unlock_and_free_folios(&folio, num_folios);
>  
>  out_commit:
>  	if (ret < 0 && did_quota)
> diff --git a/fs/ocfs2/alloc.h b/fs/ocfs2/alloc.h
> index 4af7abaa6e40..6a2aca1a062e 100644
> --- a/fs/ocfs2/alloc.h
> +++ b/fs/ocfs2/alloc.h
> @@ -254,8 +254,6 @@ static inline int ocfs2_is_empty_extent(struct ocfs2_extent_rec *rec)
>  	return !rec->e_leaf_clusters;
>  }
>  
> -int ocfs2_grab_pages(struct inode *inode, loff_t start, loff_t end,
> -		     struct page **pages, int *num);
>  void ocfs2_map_and_dirty_page(struct inode *inode, handle_t *handle,
>  			      unsigned int from, unsigned int to,
>  			      struct page *page, int zero, u64 *phys);
> diff --git a/fs/ocfs2/aops.c b/fs/ocfs2/aops.c
> index 644680ac1414..f1eba968563f 100644
> --- a/fs/ocfs2/aops.c
> +++ b/fs/ocfs2/aops.c
> @@ -783,19 +783,6 @@ void ocfs2_unlock_and_free_folios(struct folio **folios, int num_folios)
>  	}
>  }
>  
> -void ocfs2_unlock_and_free_pages(struct page **pages, int num_pages)
> -{
> -	int i;
> -
> -	for(i = 0; i < num_pages; i++) {
> -		if (pages[i]) {
> -			unlock_page(pages[i]);
> -			mark_page_accessed(pages[i]);
> -			put_page(pages[i]);
> -		}
> -	}
> -}
> -
>  static void ocfs2_unlock_folios(struct ocfs2_write_ctxt *wc)
>  {
>  	int i;
> diff --git a/fs/ocfs2/aops.h b/fs/ocfs2/aops.h
> index 17ca359c6051..cf8d202d9a8b 100644
> --- a/fs/ocfs2/aops.h
> +++ b/fs/ocfs2/aops.h
> @@ -18,7 +18,6 @@ int ocfs2_map_folio_blocks(struct folio *folio, u64 *p_blkno,
>  			  unsigned int to, int new);
>  
>  void ocfs2_unlock_and_free_folios(struct folio **folios, int num_folios);
> -void ocfs2_unlock_and_free_pages(struct page **pages, int num_pages);
>  
>  int walk_page_buffers(	handle_t *handle,
>  			struct buffer_head *head,


  reply	other threads:[~2024-12-14 14:34 UTC|newest]

Thread overview: 51+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-12-05 17:16 [PATCH 00/23] Convert ocfs2 to use folios Matthew Wilcox (Oracle)
2024-12-05 17:16 ` [PATCH 01/23] ocfs2: Handle a symlink read error correctly Matthew Wilcox (Oracle)
2024-12-14 12:03   ` Joseph Qi
2024-12-14 15:20     ` Matthew Wilcox
2024-12-14 15:45       ` Joseph Qi
2024-12-05 17:16 ` [PATCH 02/23] ocfs2: Convert ocfs2_page_mkwrite() to use a folio Matthew Wilcox (Oracle)
2024-12-14 12:20   ` Joseph Qi
2024-12-05 17:16 ` [PATCH 03/23] ocfs2: Convert w_target_page to w_target_folio Matthew Wilcox (Oracle)
2024-12-14 12:29   ` Joseph Qi
2024-12-05 17:16 ` [PATCH 04/23] ocfs2: Use a folio in ocfs2_zero_new_buffers() Matthew Wilcox (Oracle)
2024-12-14 14:01   ` Joseph Qi
2024-12-14 15:32     ` Matthew Wilcox
2024-12-14 15:46       ` Joseph Qi
2024-12-05 17:16 ` [PATCH 05/23] ocfs2: Use a folio in ocfs2_write_begin_inline() Matthew Wilcox (Oracle)
2024-12-14 14:04   ` Joseph Qi
2024-12-05 17:16 ` [PATCH 06/23] ocfs2: Pass mmap_folio around instead of mmap_page Matthew Wilcox (Oracle)
2024-12-14 14:08   ` Joseph Qi
2024-12-05 17:16 ` [PATCH 07/23] ocfs2: Convert ocfs2_readpage_inline() to take a folio Matthew Wilcox (Oracle)
2024-12-14 14:08   ` Joseph Qi
2024-12-05 17:16 ` [PATCH 08/23] ocfs2: Convert ocfs2_inode_lock_with_page() to ocfs2_inode_lock_with_folio() Matthew Wilcox (Oracle)
2024-12-14 14:10   ` Joseph Qi
2024-12-05 17:16 ` [PATCH 09/23] ocfs2: Convert w_pages to w_folios Matthew Wilcox (Oracle)
2024-12-14 14:15   ` Joseph Qi
2024-12-05 17:16 ` [PATCH 10/23] ocfs2: Convert ocfs2_write_failure() to use a folio Matthew Wilcox (Oracle)
2024-12-14 14:16   ` Joseph Qi
2024-12-05 17:16 ` [PATCH 11/23] ocfs2: Use a folio in ocfs2_write_end_nolock() Matthew Wilcox (Oracle)
2024-12-14 14:18   ` Joseph Qi
2024-12-05 17:16 ` [PATCH 12/23] ocfs2: Use a folio in ocfs2_prepare_page_for_write() Matthew Wilcox (Oracle)
2024-12-14 14:26   ` Joseph Qi
2024-12-05 17:16 ` [PATCH 13/23] ocfs2: Use a folio in ocfs2_map_and_dirty_page() Matthew Wilcox (Oracle)
2024-12-14 14:27   ` Joseph Qi
2024-12-05 17:16 ` [PATCH 14/23] ocfs2: Convert ocfs2_map_page_blocks() to ocfs2_map_folio_blocks() Matthew Wilcox (Oracle)
2024-12-14 14:28   ` Joseph Qi
2024-12-05 17:16 ` [PATCH 15/23] ocfs2: Convert ocfs2_clear_page_regions() to ocfs2_clear_folio_regions() Matthew Wilcox (Oracle)
2024-12-14 14:29   ` Joseph Qi
2024-12-05 17:16 ` [PATCH 16/23] ocfs2: Use an array of folios instead of an array of pages Matthew Wilcox (Oracle)
2024-12-14 14:34   ` Joseph Qi [this message]
2024-12-05 17:16 ` [PATCH 17/23] ocfs2: Convert ocfs2_duplicate_clusters_by_page() to use a folio Matthew Wilcox (Oracle)
2024-12-14 14:36   ` Joseph Qi
2024-12-05 17:16 ` [PATCH 18/23] ocfs2: Convert ocfs2_map_and_dirty_page() to ocfs2_map_and_dirty_folio() Matthew Wilcox (Oracle)
2024-12-14 14:36   ` Joseph Qi
2024-12-05 17:16 ` [PATCH 19/23] ocfs2: Convert ocfs2_read_inline_data() to take a folio Matthew Wilcox (Oracle)
2024-12-14 14:39   ` Joseph Qi
2024-12-05 17:16 ` [PATCH 20/23] ocfs2: Use a folio in ocfs2_fast_symlink_read_folio() Matthew Wilcox (Oracle)
2024-12-14 14:43   ` Joseph Qi
2024-12-05 17:16 ` [PATCH 21/23] ocfs2: Remove ocfs2_start_walk_page_trans() prototype Matthew Wilcox (Oracle)
2024-12-14 14:44   ` Joseph Qi
2024-12-05 17:16 ` [PATCH 22/23] ocfs2: Support large folios in ocfs2_zero_cluster_folios() Matthew Wilcox (Oracle)
2024-12-14 14:50   ` Joseph Qi
2024-12-05 17:16 ` [PATCH 23/23] ocfs2: Support large folios in ocfs2_write_zero_page() Matthew Wilcox (Oracle)
2024-12-14 14:51   ` Joseph Qi

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=7ede4cc2-8026-4622-87ae-23d2eec5b4c4@linux.alibaba.com \
    --to=joseph.qi@linux.alibaba.com \
    --cc=akpm@linux-foundation.org \
    --cc=mark.tinguely@oracle.com \
    --cc=ocfs2-devel@lists.linux.dev \
    --cc=willy@infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.