f2fs: get rid of buffer_head use
Chao Yu
maintainerPATCH v2 1/1 f2fs: get rid of buffer_head use
Convert to use folio and related functionality.
---
v2:
- convert to use folio rather than page suggested by Matthew.
fs/f2fs/data.c | 1 - fs/f2fs/f2fs.h | 7 +++- fs/f2fs/file.c | 1 - fs/f2fs/inode.c | 1 - fs/f2fs/super.c | 94 +++++++++++++++++++++++++++++-------------------- 5 files changed, 62 insertions(+), 42 deletions(-)
fs/f2fs/data.c +0 -1
@@ -7,7 +7,6 @@*/ #include <linux/fs.h> #include <linux/f2fs_fs.h> -#include <linux/buffer_head.h> #include <linux/sched/mm.h> #include <linux/mpage.h> #include <linux/writeback.h>
fs/f2fs/f2fs.h +6 -1
@@ -11,7 +11,6 @@#include <linux/uio.h> #include <linux/types.h> #include <linux/page-flags.h> -#include <linux/buffer_head.h> #include <linux/slab.h> #include <linux/crc32.h> #include <linux/magic.h>
@@ -1990,6 +1989,12 @@ static inline struct f2fs_super_block *F2FS_RAW_SUPER(struct f2fs_sb_info *sbi)return (struct f2fs_super_block *)(sbi->raw_super); } +static inline struct f2fs_super_block *F2FS_SUPER_BLOCK (struct folio *folio) +{ +return (struct f2fs_super_block *)(page_address (folio_page (folio,0 )) + +F2FS_SUPER_OFFSET ); +} +static inline struct f2fs_checkpoint *F2FS_CKPT (struct f2fs_sb_info *sbi) {return (struct f2fs_checkpoint *)(sbi->ckpt);
fs/f2fs/file.c +0 -1
@@ -8,7 +8,6 @@#include <linux/fs.h> #include <linux/f2fs_fs.h> #include <linux/stat.h> -#include <linux/buffer_head.h> #include <linux/writeback.h> #include <linux/blkdev.h> #include <linux/falloc.h>
fs/f2fs/inode.c +0 -1
@@ -7,7 +7,6 @@*/ #include <linux/fs.h> #include <linux/f2fs_fs.h> -#include <linux/buffer_head.h> #include <linux/writeback.h> #include <linux/sched/mm.h> #include <linux/lz4.h>
fs/f2fs/super.c +56 -38
181 lines not on this page · raw message
Signature · 1 line
2.40.1
fs/f2fs/f2fs.h static inline struct f2fs_super_block *F2FS_RAW_SUPER(struct f2fs_sb_info *sbi) · line 1996
Quoted 9 lines · Chao Yu
fs/f2fs/f2fs.h +5
-0@@ -1990,6 +1989,12 @@ static inline struct f2fs_super_block *F2FS_RAW_SUPER(struct f2fs_sb_info *sbi)return (struct f2fs_super_block *)(sbi->raw_super); } +static inline struct f2fs_super_block *F2FS_SUPER_BLOCK (struct folio *folio) +{ +return (struct f2fs_super_block *)(page_address (folio_page (folio,0 )) + +F2FS_SUPER_OFFSET ); +}
This assumes that the superblock is in the first page of the folio. That's not necessarily guaranteed; let's say you have a 64KiB folio that covers the start of the bdev.
I don't quite know how to write this because f2fs defines its block size in terms of PAGE_SIZE, which just seems like nonsense to me. If you format a filesystem on a 16KiB PAGE_SIZE machine and then try to mount it on a machine with a 4KiB PAGE_SIZE, it's going to go horribly wrong.
You'd need to pass in something that indicates whether you're trying to access the first or second superblock; there's no way to tell from the folio which one it is.
Quoted 22 lines
fs/f2fs/super.c +13
-7+static int __f2fs_commit_super (struct f2fs_sb_info *sbi,struct folio *folio, +bool update) { -lock_buffer (bh); -if (super) -memcpy (bh->b_data +F2FS_SUPER_OFFSET , super,sizeof (*super)); -set_buffer_dirty (bh); -unlock_buffer (bh); - +struct bio *bio;/* it's rare case, we can do fua all the time */ -return __sync_dirty_buffer (bh,REQ_SYNC |REQ_PREFLUSH |REQ_FUA ); +blk_opf_t opf =REQ_OP_WRITE |REQ_SYNC |REQ_PREFLUSH |REQ_FUA ; +int ret; + +folio_lock (folio); +folio_wait_writeback (folio); +if (update) +memcpy (F2FS_SUPER_BLOCK (folio),F2FS_RAW_SUPER (sbi), +sizeof (struct f2fs_super_block )); +folio_mark_dirty (folio); +folio_clear_dirty_for_io (folio);
fs/f2fs/super.c loff_t max_file_blocks(struct inode *inode) · line 3359
Quoted 10 lines
fs/f2fs/super.c +10
-0+folio_start_writeback (folio); +folio_unlock (folio); + + bio =bio_alloc (sbi->sb->s_bdev,1 , opf,GFP_NOFS ); + +/* it doesn't need to set crypto context for superblock update */ + bio->bi_iter.bi_sector =SECTOR_FROM_BLOCK (folio_index (folio)); + +if (!bio_add_folio (bio, folio,PAGE_SIZE ,0 )) +f2fs_bug_on (sbi,1 );
Better make that folio_size(folio) to support bs>PS.
Chao Yu
maintainerQuoted 5 lines · Matthew Wilcox
Quoted 4 lines · Chao Yu
fs/f2fs/f2fs.h +0
-0@@ -1990,6 +1989,12 @@ static inline struct f2fs_super_block *F2FS_RAW_SUPER(struct f2fs_sb_info *sbi)return (struct f2fs_super_block *)(sbi->raw_super); }
Quoted 9 lines
fs/f2fs/f2fs.h static inline struct f2fs_super_block *F2FS_RAW_SUPER(struct f2fs_sb_info *sbi) · line 1996
Quoted 5 lines
fs/f2fs/f2fs.h +5
-0+static inline struct f2fs_super_block *F2FS_SUPER_BLOCK (struct folio *folio) +{ +return (struct f2fs_super_block *)(page_address (folio_page (folio,0 )) + +F2FS_SUPER_OFFSET ); +}This assumes that the superblock is in the first page of the folio. That's not necessarily guaranteed; let's say you have a 64KiB folio that covers the start of the bdev.
Oh, I missed to add large folio support in this version.
For the case: page size is 4KiB, and folio size is 64KiB, read_mapping_folio(mapping, 0, NULL) and read_mapping_folio(mapping, 1, NULL) will return the same #0 folio, right?
Quoted 5 lines
I don't quite know how to write this because f2fs defines its block size in terms of
PAGE_SIZE, which just seems like nonsense to me. If you format a filesystem on a 16KiBPAGE_SIZEmachine and then try to mount it on a machine with a 4KiBPAGE_SIZE, it's going to go horribly wrong.
f2fs will check on-disk block size w/ PAGE_SIZE in sanity_check_raw_super() as below:
/* only support block_size equals to PAGE_SIZE */
if (le32_to_cpu(raw_super->log_blocksize) != F2FS_BLKSIZE_BITS) {
f2fs_info(sbi, "Invalid log_blocksize (%u), supports only %u",
le32_to_cpu(raw_super->log_blocksize),
F2FS_BLKSIZE_BITS);
return -EFSCORRUPTED;
}Quoted 31 lines
You'd need to pass in something that indicates whether you're trying to access the first or second superblock; there's no way to tell from the folio which one it is.
Quoted 26 lines
fs/f2fs/super.c +17
-7+static int __f2fs_commit_super (struct f2fs_sb_info *sbi,struct folio *folio, +bool update) { -lock_buffer (bh); -if (super) -memcpy (bh->b_data +F2FS_SUPER_OFFSET , super,sizeof (*super)); -set_buffer_dirty (bh); -unlock_buffer (bh); - +struct bio *bio;/* it's rare case, we can do fua all the time */ -return __sync_dirty_buffer (bh,REQ_SYNC |REQ_PREFLUSH |REQ_FUA ); +blk_opf_t opf =REQ_OP_WRITE |REQ_SYNC |REQ_PREFLUSH |REQ_FUA ; +int ret; + +folio_lock (folio); +folio_wait_writeback (folio); +if (update) +memcpy (F2FS_SUPER_BLOCK (folio),F2FS_RAW_SUPER (sbi), +sizeof (struct f2fs_super_block )); +folio_mark_dirty (folio); +folio_clear_dirty_for_io (folio); +folio_start_writeback (folio); +folio_unlock (folio); + + bio =bio_alloc (sbi->sb->s_bdev,1 , opf,GFP_NOFS );
Quoted 8 lines
fs/f2fs/super.c loff_t max_file_blocks(struct inode *inode) · line 3359
Quoted 6 lines
fs/f2fs/super.c +6
-0+ +/* it doesn't need to set crypto context for superblock update */ + bio->bi_iter.bi_sector =SECTOR_FROM_BLOCK (folio_index (folio)); + +if (!bio_add_folio (bio, folio,PAGE_SIZE ,0 )) +f2fs_bug_on (sbi,1 );Better make that
folio_size(folio)to support bs>PS.
Looks better, will update.
Thanks,
Quoted 1 line
Quoted 15 lines · Chao Yu
Quoted 13 lines · Matthew Wilcox
fs/f2fs/f2fs.h static inline struct f2fs_super_block *F2FS_RAW_SUPER(struct f2fs_sb_info *sbi) · line 1995
Quoted 8 lines · Chao Yu
fs/f2fs/f2fs.h +5
-0@@ -1990,6 +1989,12 @@ static inline struct f2fs_super_block *F2FS_RAW_SUPER(struct f2fs_sb_info *sbi)return (struct f2fs_super_block *)(sbi->raw_super); } +static inline struct f2fs_super_block *F2FS_SUPER_BLOCK (struct folio *folio) +{ +return (struct f2fs_super_block *)(page_address (folio_page (folio,0 )) + +F2FS_SUPER_OFFSET ); +}This assumes that the superblock is in the first page of the folio. That's not necessarily guaranteed; let's say you have a 64KiB folio that covers the start of the bdev.
Quoted 5 lines
Oh, I missed to add large folio support in this version.
For the case: page size is 4KiB, and folio size is 64KiB,
read_mapping_folio(mapping, 0, NULL)andread_mapping_folio(mapping, 1, NULL)will return the same #0 folio, right?
That's right. If you want to pass a page into F2FS_SUPER_BLOCK, that would be fine. Assuming you're not trying to support fs blocksize != PAGE_SIZE.