diff mbox series

[f2fs-dev,v2,1/8] f2fs: convert f2fs_write_begin() to use folio

Message ID 20240820034654.698236-1-chao@kernel.org (mailing list archive)
State Accepted
Commit f13c7184e62e44013f3db2a9dd9b9f51ee7fdb7d
Headers show
Series [f2fs-dev,v2,1/8] f2fs: convert f2fs_write_begin() to use folio | expand

Commit Message

Chao Yu Aug. 20, 2024, 3:46 a.m. UTC
Convert to use folio, so that we can get rid of 'page->index' to
prepare for removal of 'index' field in structure page [1].

[1] https://lore.kernel.org/all/Zp8fgUSIBGQ1TN0D@casper.infradead.org/

Cc: Matthew Wilcox <willy@infradead.org>
Signed-off-by: Chao Yu <chao@kernel.org>
---
v2:
- fix compile error.
 fs/f2fs/data.c | 44 +++++++++++++++++++++++---------------------
 1 file changed, 23 insertions(+), 21 deletions(-)

Comments

Li Zetao Aug. 20, 2024, 4:38 a.m. UTC | #1
Hi,

在 2024/8/20 11:46, Chao Yu 写道:
> Convert to use folio, so that we can get rid of 'page->index' to
> prepare for removal of 'index' field in structure page [1].
> 
> [1] https://lore.kernel.org/all/Zp8fgUSIBGQ1TN0D@casper.infradead.org/
> 
> Cc: Matthew Wilcox <willy@infradead.org>
> Signed-off-by: Chao Yu <chao@kernel.org>
> ---
> v2:
> - fix compile error.
>   fs/f2fs/data.c | 44 +++++++++++++++++++++++---------------------
>   1 file changed, 23 insertions(+), 21 deletions(-)
> 
> diff --git a/fs/f2fs/data.c b/fs/f2fs/data.c
> index 0655fddfc4ba..85ac05c3655a 100644
> --- a/fs/f2fs/data.c
> +++ b/fs/f2fs/data.c
> @@ -3378,11 +3378,11 @@ void f2fs_write_failed(struct inode *inode, loff_t to)
>   }
>   
>   static int prepare_write_begin(struct f2fs_sb_info *sbi,
> -			struct page *page, loff_t pos, unsigned len,
> +			struct folio *folio, loff_t pos, unsigned int len,
>   			block_t *blk_addr, bool *node_changed)
>   {
> -	struct inode *inode = page->mapping->host;
> -	pgoff_t index = page->index;
> +	struct inode *inode = folio->mapping->host;
> +	pgoff_t index = folio->index;
>   	struct dnode_of_data dn;
>   	struct page *ipage;
>   	bool locked = false;
> @@ -3419,13 +3419,13 @@ static int prepare_write_begin(struct f2fs_sb_info *sbi,
>   
>   	if (f2fs_has_inline_data(inode)) {
>   		if (pos + len <= MAX_INLINE_DATA(inode)) {
> -			f2fs_do_read_inline_data(page_folio(page), ipage);
> +			f2fs_do_read_inline_data(folio, ipage);
>   			set_inode_flag(inode, FI_DATA_EXIST);
>   			if (inode->i_nlink)
>   				set_page_private_inline(ipage);
>   			goto out;
>   		}
> -		err = f2fs_convert_inline_page(&dn, page);
> +		err = f2fs_convert_inline_page(&dn, folio_page(folio, 0));
>   		if (err || dn.data_blkaddr != NULL_ADDR)
>   			goto out;
>   	}
> @@ -3518,12 +3518,12 @@ static int __reserve_data_block(struct inode *inode, pgoff_t index,
>   }
>   
>   static int prepare_atomic_write_begin(struct f2fs_sb_info *sbi,
> -			struct page *page, loff_t pos, unsigned int len,
> +			struct folio *folio, loff_t pos, unsigned int len,
>   			block_t *blk_addr, bool *node_changed, bool *use_cow)
>   {
> -	struct inode *inode = page->mapping->host;
> +	struct inode *inode = folio->mapping->host;
>   	struct inode *cow_inode = F2FS_I(inode)->cow_inode;
> -	pgoff_t index = page->index;
> +	pgoff_t index = folio->index;
>   	int err = 0;
>   	block_t ori_blk_addr = NULL_ADDR;
>   
> @@ -3566,6 +3566,7 @@ static int f2fs_write_begin(struct file *file, struct address_space *mapping,
>   	struct inode *inode = mapping->host;
>   	struct f2fs_sb_info *sbi = F2FS_I_SB(inode);
>   	struct page *page = NULL;
> +	struct folio *folio;
>   	pgoff_t index = ((unsigned long long) pos) >> PAGE_SHIFT;
>   	bool need_balance = false;
>   	bool use_cow = false;
> @@ -3625,22 +3626,23 @@ static int f2fs_write_begin(struct file *file, struct address_space *mapping,
>   	/* TODO: cluster can be compressed due to race with .writepage */
>   
>   	*pagep = page;
> +	folio = page_folio(page);
>   
>   	if (f2fs_is_atomic_file(inode))
> -		err = prepare_atomic_write_begin(sbi, page, pos, len,
> +		err = prepare_atomic_write_begin(sbi, folio, pos, len,
>   					&blkaddr, &need_balance, &use_cow);
>   	else
> -		err = prepare_write_begin(sbi, page, pos, len,
> +		err = prepare_write_begin(sbi, folio, pos, len,
>   					&blkaddr, &need_balance);
>   	if (err)
>   		goto fail;
>   
>   	if (need_balance && !IS_NOQUOTA(inode) &&
>   			has_not_enough_free_secs(sbi, 0, 0)) {
> -		unlock_page(page);
> +		folio_unlock(folio);
>   		f2fs_balance_fs(sbi, true);
> -		lock_page(page);
> -		if (page->mapping != mapping) {
> +		folio_lock(folio);
> +		if (folio->mapping != mapping) {
>   			/* The page got truncated from under us */
>   			f2fs_put_page(page, 1);
>   			goto repeat;
> @@ -3649,18 +3651,18 @@ static int f2fs_write_begin(struct file *file, struct address_space *mapping,
>   
>   	f2fs_wait_on_page_writeback(page, DATA, false, true);
>   
> -	if (len == PAGE_SIZE || PageUptodate(page))
> +	if (len == PAGE_SIZE || folio_test_uptodate(folio))
>   		return 0;
>   
>   	if (!(pos & (PAGE_SIZE - 1)) && (pos + len) >= i_size_read(inode) &&
>   	    !f2fs_verity_in_progress(inode)) {
> -		zero_user_segment(page, len, PAGE_SIZE);
> +		folio_zero_segment(folio, len, folio_size(folio));
>   		return 0;
>   	}
>   
>   	if (blkaddr == NEW_ADDR) {
> -		zero_user_segment(page, 0, PAGE_SIZE);
> -		SetPageUptodate(page);
> +		folio_zero_segment(folio, 0, folio_size(folio));
> +		folio_mark_uptodate(folio);
>   	} else {
>   		if (!f2fs_is_valid_blkaddr(sbi, blkaddr,
>   				DATA_GENERIC_ENHANCE_READ)) {
> @@ -3669,16 +3671,16 @@ static int f2fs_write_begin(struct file *file, struct address_space *mapping,
>   		}
>   		err = f2fs_submit_page_read(use_cow ?
>   				F2FS_I(inode)->cow_inode : inode,
> -				page_folio(page), blkaddr, 0, true);
> +				folio, blkaddr, 0, true);
>   		if (err)
>   			goto fail;
>   
> -		lock_page(page);
> -		if (unlikely(page->mapping != mapping)) {
> +		folio_lock(folio);
> +		if (unlikely(folio->mapping != mapping)) {
>   			f2fs_put_page(page, 1);
>   			goto repeat;
>   		}
> -		if (unlikely(!PageUptodate(page))) {
> +		if (unlikely(!folio_test_uptodate(folio))) {
>   			err = -EIO;
>   			goto fail;
>   		}I want to apply your patch set for testing, but there is a conflict on 
the master branch of linux-next. Maybe it depends on a certain 
pre-patch. Please let me know, thank you.

   Applying: f2fs: convert f2fs_write_begin() to use folio
   error: patch failed: fs/f2fs/data.c:3566
   error: fs/f2fs/data.c: patch does not apply
   Patch failed at 0001 f2fs: convert f2fs_write_begin() to use folio

Thanks,
Li Zetao.
Chao Yu Aug. 20, 2024, 6:58 a.m. UTC | #2
On 2024/8/20 12:38, Li Zetao wrote:
>> I want to apply your patch set for testing, but there is a conflict on 
> the master branch of linux-next. Maybe it depends on a certain pre-patch. Please let me know, thank you.
> 
>    Applying: f2fs: convert f2fs_write_begin() to use folio
>    error: patch failed: fs/f2fs/data.c:3566
>    error: fs/f2fs/data.c: patch does not apply
>    Patch failed at 0001 f2fs: convert f2fs_write_begin() to use folio

We should apply this patchset on top of dev-test branch?

https://git.kernel.org/pub/scm/linux/kernel/git/jaegeuk/f2fs.git/log/?h=dev-test

Thanks,

> 
> Thanks,
> Li Zetao.
Chao Yu Aug. 21, 2024, 7:31 a.m. UTC | #3
On 2024/8/20 14:58, Chao Yu wrote:
> On 2024/8/20 12:38, Li Zetao wrote:
>>> I want to apply your patch set for testing, but there is a conflict on 
>> the master branch of linux-next. Maybe it depends on a certain pre-patch. Please let me know, thank you.
>>
>>    Applying: f2fs: convert f2fs_write_begin() to use folio
>>    error: patch failed: fs/f2fs/data.c:3566
>>    error: fs/f2fs/data.c: patch does not apply
>>    Patch failed at 0001 f2fs: convert f2fs_write_begin() to use folio
> 
> We should apply this patchset on top of dev-test branch?
> 
> https://git.kernel.org/pub/scm/linux/kernel/git/jaegeuk/f2fs.git/log/?h=dev-test

Oh, I missed one patch...

Can you please check

https://git.kernel.org/pub/scm/linux/kernel/git/chao/linux.git/log/?h=folio

Thanks,

> 
> Thanks,
> 
>>
>> Thanks,
>> Li Zetao.
> 
> 
> 
> _______________________________________________
> Linux-f2fs-devel mailing list
> Linux-f2fs-devel@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
patchwork-bot+f2fs--- via Linux-f2fs-devel Aug. 30, 2024, 8:51 p.m. UTC | #4
Hello:

This series was applied to jaegeuk/f2fs.git (dev)
by Jaegeuk Kim <jaegeuk@kernel.org>:

On Tue, 20 Aug 2024 11:46:47 +0800 you wrote:
> Convert to use folio, so that we can get rid of 'page->index' to
> prepare for removal of 'index' field in structure page [1].
> 
> [1] https://lore.kernel.org/all/Zp8fgUSIBGQ1TN0D@casper.infradead.org/
> 
> Cc: Matthew Wilcox <willy@infradead.org>
> Signed-off-by: Chao Yu <chao@kernel.org>
> 
> [...]

Here is the summary with links:
  - [f2fs-dev,v2,1/8] f2fs: convert f2fs_write_begin() to use folio
    https://git.kernel.org/jaegeuk/f2fs/c/f13c7184e62e
  - [f2fs-dev,v2,2/8] f2fs: convert f2fs_write_end() to use folio
    https://git.kernel.org/jaegeuk/f2fs/c/357dd8479f8b
  - [f2fs-dev,v2,3/8] f2fs: convert f2fs_set_compressed_page() to use folio
    https://git.kernel.org/jaegeuk/f2fs/c/4713b14f107a
  - [f2fs-dev,v2,4/8] f2fs: convert f2fs_do_write_data_page() to use folio
    https://git.kernel.org/jaegeuk/f2fs/c/609c7375350a
  - [f2fs-dev,v2,5/8] f2fs: convert f2fs_write_data_page() to use folio
    https://git.kernel.org/jaegeuk/f2fs/c/75428dcd4d2e
  - [f2fs-dev,v2,6/8] f2fs: convert __write_node_page() to use folio
    https://git.kernel.org/jaegeuk/f2fs/c/62b691af1a66
  - [f2fs-dev,v2,7/8] f2fs: convert read_node_page() to use folio
    https://git.kernel.org/jaegeuk/f2fs/c/e381d92a035a
  - [f2fs-dev,v2,8/8] f2fs: get rid of page->index
    https://git.kernel.org/jaegeuk/f2fs/c/c6f1758f7a68

You are awesome, thank you!
diff mbox series

Patch

diff --git a/fs/f2fs/data.c b/fs/f2fs/data.c
index 0655fddfc4ba..85ac05c3655a 100644
--- a/fs/f2fs/data.c
+++ b/fs/f2fs/data.c
@@ -3378,11 +3378,11 @@  void f2fs_write_failed(struct inode *inode, loff_t to)
 }
 
 static int prepare_write_begin(struct f2fs_sb_info *sbi,
-			struct page *page, loff_t pos, unsigned len,
+			struct folio *folio, loff_t pos, unsigned int len,
 			block_t *blk_addr, bool *node_changed)
 {
-	struct inode *inode = page->mapping->host;
-	pgoff_t index = page->index;
+	struct inode *inode = folio->mapping->host;
+	pgoff_t index = folio->index;
 	struct dnode_of_data dn;
 	struct page *ipage;
 	bool locked = false;
@@ -3419,13 +3419,13 @@  static int prepare_write_begin(struct f2fs_sb_info *sbi,
 
 	if (f2fs_has_inline_data(inode)) {
 		if (pos + len <= MAX_INLINE_DATA(inode)) {
-			f2fs_do_read_inline_data(page_folio(page), ipage);
+			f2fs_do_read_inline_data(folio, ipage);
 			set_inode_flag(inode, FI_DATA_EXIST);
 			if (inode->i_nlink)
 				set_page_private_inline(ipage);
 			goto out;
 		}
-		err = f2fs_convert_inline_page(&dn, page);
+		err = f2fs_convert_inline_page(&dn, folio_page(folio, 0));
 		if (err || dn.data_blkaddr != NULL_ADDR)
 			goto out;
 	}
@@ -3518,12 +3518,12 @@  static int __reserve_data_block(struct inode *inode, pgoff_t index,
 }
 
 static int prepare_atomic_write_begin(struct f2fs_sb_info *sbi,
-			struct page *page, loff_t pos, unsigned int len,
+			struct folio *folio, loff_t pos, unsigned int len,
 			block_t *blk_addr, bool *node_changed, bool *use_cow)
 {
-	struct inode *inode = page->mapping->host;
+	struct inode *inode = folio->mapping->host;
 	struct inode *cow_inode = F2FS_I(inode)->cow_inode;
-	pgoff_t index = page->index;
+	pgoff_t index = folio->index;
 	int err = 0;
 	block_t ori_blk_addr = NULL_ADDR;
 
@@ -3566,6 +3566,7 @@  static int f2fs_write_begin(struct file *file, struct address_space *mapping,
 	struct inode *inode = mapping->host;
 	struct f2fs_sb_info *sbi = F2FS_I_SB(inode);
 	struct page *page = NULL;
+	struct folio *folio;
 	pgoff_t index = ((unsigned long long) pos) >> PAGE_SHIFT;
 	bool need_balance = false;
 	bool use_cow = false;
@@ -3625,22 +3626,23 @@  static int f2fs_write_begin(struct file *file, struct address_space *mapping,
 	/* TODO: cluster can be compressed due to race with .writepage */
 
 	*pagep = page;
+	folio = page_folio(page);
 
 	if (f2fs_is_atomic_file(inode))
-		err = prepare_atomic_write_begin(sbi, page, pos, len,
+		err = prepare_atomic_write_begin(sbi, folio, pos, len,
 					&blkaddr, &need_balance, &use_cow);
 	else
-		err = prepare_write_begin(sbi, page, pos, len,
+		err = prepare_write_begin(sbi, folio, pos, len,
 					&blkaddr, &need_balance);
 	if (err)
 		goto fail;
 
 	if (need_balance && !IS_NOQUOTA(inode) &&
 			has_not_enough_free_secs(sbi, 0, 0)) {
-		unlock_page(page);
+		folio_unlock(folio);
 		f2fs_balance_fs(sbi, true);
-		lock_page(page);
-		if (page->mapping != mapping) {
+		folio_lock(folio);
+		if (folio->mapping != mapping) {
 			/* The page got truncated from under us */
 			f2fs_put_page(page, 1);
 			goto repeat;
@@ -3649,18 +3651,18 @@  static int f2fs_write_begin(struct file *file, struct address_space *mapping,
 
 	f2fs_wait_on_page_writeback(page, DATA, false, true);
 
-	if (len == PAGE_SIZE || PageUptodate(page))
+	if (len == PAGE_SIZE || folio_test_uptodate(folio))
 		return 0;
 
 	if (!(pos & (PAGE_SIZE - 1)) && (pos + len) >= i_size_read(inode) &&
 	    !f2fs_verity_in_progress(inode)) {
-		zero_user_segment(page, len, PAGE_SIZE);
+		folio_zero_segment(folio, len, folio_size(folio));
 		return 0;
 	}
 
 	if (blkaddr == NEW_ADDR) {
-		zero_user_segment(page, 0, PAGE_SIZE);
-		SetPageUptodate(page);
+		folio_zero_segment(folio, 0, folio_size(folio));
+		folio_mark_uptodate(folio);
 	} else {
 		if (!f2fs_is_valid_blkaddr(sbi, blkaddr,
 				DATA_GENERIC_ENHANCE_READ)) {
@@ -3669,16 +3671,16 @@  static int f2fs_write_begin(struct file *file, struct address_space *mapping,
 		}
 		err = f2fs_submit_page_read(use_cow ?
 				F2FS_I(inode)->cow_inode : inode,
-				page_folio(page), blkaddr, 0, true);
+				folio, blkaddr, 0, true);
 		if (err)
 			goto fail;
 
-		lock_page(page);
-		if (unlikely(page->mapping != mapping)) {
+		folio_lock(folio);
+		if (unlikely(folio->mapping != mapping)) {
 			f2fs_put_page(page, 1);
 			goto repeat;
 		}
-		if (unlikely(!PageUptodate(page))) {
+		if (unlikely(!folio_test_uptodate(folio))) {
 			err = -EIO;
 			goto fail;
 		}