Skip to contentSkip to conversation

f2fs-dev: support multi-device direct IO

PATCH Superseded sunqiuyang 2 participants 2 messages Jan 4, 2019 – Jan 7, 2019

Subsystems (2)

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

sunqiuyang

author
#0 lore raw

PATCH v2 1/2 f2fs-dev: support multi-device direct IO

From: Qiuyang Sun <[email protected]>

Changelog v1 ==> v2:
1. Modify the definition of update_device_state(), and call it in direct write;
2. Move some local variables into branches where they are used.

---
 fs/f2fs/data.c    | 25 ++++++++++++++++++++++++-
 fs/f2fs/f2fs.h    |  3 +--
 fs/f2fs/segment.c | 11 +++++------
 3 files changed, 30 insertions(+), 9 deletions(-)
fs/f2fs/data.c +24 -1
index e5cd3fd..010300c 100644
@@ -1076,6 +1076,7 @@ int f2fs_map_blocks(struct inode *inode, struct f2fs_map_blocks *map,
 	struct extent_info ei = {0,0,0};
 	block_t blkaddr;
 	unsigned int start_pgofs;
+	block_t end_blk;
 
 	if (!maxblocks)
 		return 0;
@@ -1207,8 +1208,17 @@ int f2fs_map_blocks(struct inode *inode, struct f2fs_map_blocks *map,
 
 		map->m_pblk = blkaddr;
 		map->m_len = 1;
+
+		if (sbi->s_ndevs && blkaddr != NEW_ADDR &&
+							blkaddr != NULL_ADDR) {
+			int devi;
+
+			devi = f2fs_target_device_index(sbi, blkaddr);
+			end_blk = FDEV(devi).end_blk;
+		}
 	} else if ((map->m_pblk != NEW_ADDR &&
-			blkaddr == (map->m_pblk + ofs)) ||
+			blkaddr == (map->m_pblk + ofs) &&
+			(!sbi->s_ndevs || blkaddr <= end_blk)) ||
 			(map->m_pblk == NEW_ADDR && blkaddr == NEW_ADDR) ||
 			flag == F2FS_GET_BLOCK_PRE_DIO) {
 		ofs++;
@@ -1322,6 +1332,7 @@ static int __get_data_block(struct inode *inode, sector_t iblock,
 {
 	struct f2fs_map_blocks map;
 	int err;
+	struct f2fs_sb_info *sbi = F2FS_I_SB(inode);
 
 	map.m_lblk = iblock;
 	map.m_len = bh->b_size >> inode->i_blkbits;
@@ -1333,6 +1344,18 @@ static int __get_data_block(struct inode *inode, sector_t iblock,
 	err = f2fs_map_blocks(inode, &map, create, flag);
 	if (!err) {
 		map_bh(bh, inode->i_sb, map.m_pblk);
+		if (sbi->s_ndevs) {
+			int devi;
+
+			devi = f2fs_target_device_index(sbi, map.m_pblk);
+			if (devi) {
+				bh->b_bdev = FDEV(devi).bdev;
+				bh->b_blocknr -= FDEV(devi).start_blk;
+			}
+			if (may_write)
+				update_device_state(sbi, inode->i_ino,
+								map.m_pblk);
+		}
 		bh->b_state = (bh->b_state & ~F2FS_MAP_FLAGS) | map.m_flags;
 		bh->b_size = (u64)map.m_len << inode->i_blkbits;
 	}
fs/f2fs/f2fs.h +1 -2
index eeede26..659e1e0 100644
@@ -3056,6 +3056,7 @@ int f2fs_lookup_journal_in_cursum(struct f2fs_journal *journal, int type,
 int f2fs_rw_hint_to_seg_type(enum rw_hint hint);
 enum rw_hint f2fs_io_type_to_rw_hint(struct f2fs_sb_info *sbi,
 			enum page_type type, enum temp_type temp);
+void update_device_state(struct f2fs_sb_info *sbi, nid_t ino, block_t blkaddr);
 
 /*
  * checkpoint.c
@@ -3595,8 +3596,6 @@ static inline bool f2fs_force_buffered_io(struct inode *inode,
 
 	if (f2fs_post_read_required(inode))
 		return true;
-	if (sbi->s_ndevs)
-		return true;
 	/*
 	 * for blkzoned device, fallback direct IO to buffered IO, so
 	 * all IOs can be serialized by log-structured write.
fs/f2fs/segment.c +5 -6
index a361d61..eec5db1 100644
@@ -3050,18 +3050,17 @@ void f2fs_allocate_data_block(struct f2fs_sb_info *sbi, struct page *page,
 	up_read(&SM_I(sbi)->curseg_lock);
 }
 
-static void update_device_state(struct f2fs_io_info *fio)
+void update_device_state(struct f2fs_sb_info *sbi, nid_t ino, block_t blkaddr)
 {
-	struct f2fs_sb_info *sbi = fio->sbi;
 	unsigned int devidx;
 
 	if (!sbi->s_ndevs)
 		return;
 
-	devidx = f2fs_target_device_index(sbi, fio->new_blkaddr);
+	devidx = f2fs_target_device_index(sbi, blkaddr);
 
 	/* update device state for fsync */
-	f2fs_set_dirty_device(sbi, fio->ino, devidx, FLUSH_INO);
+	f2fs_set_dirty_device(sbi, ino, devidx, FLUSH_INO);
 
 	/* update device state for checkpoint */
 	if (!f2fs_test_bit(devidx, (char *)&sbi->dirty_device)) {
@@ -3092,7 +3091,7 @@ static void do_write_page(struct f2fs_summary *sum, struct f2fs_io_info *fio)
 		goto reallocate;
 	}
 
-	update_device_state(fio);
+	update_device_state(fio->sbi, fio->ino, fio->new_blkaddr);
 
 	if (keep_order)
 		up_read(&fio->sbi->io_order_lock);
@@ -3168,7 +3167,7 @@ int f2fs_inplace_write_data(struct f2fs_io_info *fio)
 	else
 		err = f2fs_submit_page_bio(fio);
 	if (!err)
-		update_device_state(fio);
+		update_device_state(fio->sbi, fio->ino, fio->new_blkaddr);
 
 	f2fs_update_iostat(fio->sbi, fio->io_type, F2FS_BLKSIZE);
 
Signature · 1 line
1.8.3.1
#1 lore raw
Quoted 54 lines · sunqiuyang

From: Qiuyang Sun <[email protected]>

Changelog v1 ==> v2:
1. Modify the definition of update_device_state(), and call it in direct write;
2. Move some local variables into branches where they are used.

---
 fs/f2fs/data.c    | 25 ++++++++++++++++++++++++-
 fs/f2fs/f2fs.h    |  3 +--
 fs/f2fs/segment.c | 11 +++++------
 3 files changed, 30 insertions(+), 9 deletions(-)
fs/f2fs/data.c +12 -1
index e5cd3fd..010300c 100644
@@ -1076,6 +1076,7 @@ int f2fs_map_blocks(struct inode *inode, struct f2fs_map_blocks *map,
 	struct extent_info ei = {0,0,0};
 	block_t blkaddr;
 	unsigned int start_pgofs;
+	block_t end_blk;
 
 	if (!maxblocks)
 		return 0;
@@ -1207,8 +1208,17 @@ int f2fs_map_blocks(struct inode *inode, struct f2fs_map_blocks *map,
 
 		map->m_pblk = blkaddr;
 		map->m_len = 1;
+
+		if (sbi->s_ndevs && blkaddr != NEW_ADDR &&
+							blkaddr != NULL_ADDR) {
+			int devi;
+
+			devi = f2fs_target_device_index(sbi, blkaddr);
+			end_blk = FDEV(devi).end_blk;
+		}
 	} else if ((map->m_pblk != NEW_ADDR &&
-			blkaddr == (map->m_pblk + ofs)) ||
+			blkaddr == (map->m_pblk + ofs) &&
+			(!sbi->s_ndevs || blkaddr <= end_blk)) ||
 			(map->m_pblk == NEW_ADDR && blkaddr == NEW_ADDR) ||
 			flag == F2FS_GET_BLOCK_PRE_DIO) {
 		ofs++;
@@ -1322,6 +1332,7 @@ static int __get_data_block(struct inode *inode, sector_t iblock,
 {
 	struct f2fs_map_blocks map;
 	int err;
+	struct f2fs_sb_info *sbi = F2FS_I_SB(inode);
 
 	map.m_lblk = iblock;
 	map.m_len = bh->b_size >> inode->i_blkbits;

fs/f2fs/data.c static int __get_data_block(struct inode *inode, sector_t iblock, · line 1347

Quoted 4 lines
fs/f2fs/data.c +1 -0
@@ -1333,6 +1344,18 @@ static int __get_data_block(struct inode *inode, sector_t iblock,
 	err = f2fs_map_blocks(inode, &map, create, flag);
 	if (!err) {
 		map_bh(bh, inode->i_sb, map.m_pblk);
+		if (sbi->s_ndevs) {

struct f2fs_sb_info *sbi = F2FS_I_SB(inode);

No need to get sbi in single device filesystem.

Quoted 19 lines
fs/f2fs/data.c +11 -0
+			int devi;
+
+			devi = f2fs_target_device_index(sbi, map.m_pblk);
+			if (devi) {
+				bh->b_bdev = FDEV(devi).bdev;
+				bh->b_blocknr -= FDEV(devi).start_blk;
+			}
+			if (may_write)
+				update_device_state(sbi, inode->i_ino,
+								map.m_pblk);
+		}
 		bh->b_state = (bh->b_state & ~F2FS_MAP_FLAGS) | map.m_flags;
 		bh->b_size = (u64)map.m_len << inode->i_blkbits;
 	}
fs/f2fs/f2fs.h +0 -0
index eeede26..659e1e0 100644

fs/f2fs/f2fs.h int f2fs_lookup_journal_in_cursum(struct f2fs_journal *journal, int type, · line 3059

Quoted 4 lines
fs/f2fs/f2fs.h +1 -0
@@ -3056,6 +3056,7 @@ int f2fs_lookup_journal_in_cursum(struct f2fs_journal *journal, int type,
 int f2fs_rw_hint_to_seg_type(enum rw_hint hint);
 enum rw_hint f2fs_io_type_to_rw_hint(struct f2fs_sb_info *sbi,
 			enum page_type type, enum temp_type temp);
+void update_device_state(struct f2fs_sb_info *sbi, nid_t ino, block_t blkaddr);

It will be better to rename it to f2fs_update_device_state like other exported function name, otherwise it can pollute global namespace of function in kernel.

Thanks,

Quoted 57 lines
fs/f2fs/f2fs.h +0 -2
 /*
  * checkpoint.c
@@ -3595,8 +3596,6 @@ static inline bool f2fs_force_buffered_io(struct inode *inode,
 
 	if (f2fs_post_read_required(inode))
 		return true;
-	if (sbi->s_ndevs)
-		return true;
 	/*
 	 * for blkzoned device, fallback direct IO to buffered IO, so
 	 * all IOs can be serialized by log-structured write.
fs/f2fs/segment.c +5 -6
index a361d61..eec5db1 100644
@@ -3050,18 +3050,17 @@ void f2fs_allocate_data_block(struct f2fs_sb_info *sbi, struct page *page,
 	up_read(&SM_I(sbi)->curseg_lock);
 }
 
-static void update_device_state(struct f2fs_io_info *fio)
+void update_device_state(struct f2fs_sb_info *sbi, nid_t ino, block_t blkaddr)
 {
-	struct f2fs_sb_info *sbi = fio->sbi;
 	unsigned int devidx;
 
 	if (!sbi->s_ndevs)
 		return;
 
-	devidx = f2fs_target_device_index(sbi, fio->new_blkaddr);
+	devidx = f2fs_target_device_index(sbi, blkaddr);
 
 	/* update device state for fsync */
-	f2fs_set_dirty_device(sbi, fio->ino, devidx, FLUSH_INO);
+	f2fs_set_dirty_device(sbi, ino, devidx, FLUSH_INO);
 
 	/* update device state for checkpoint */
 	if (!f2fs_test_bit(devidx, (char *)&sbi->dirty_device)) {
@@ -3092,7 +3091,7 @@ static void do_write_page(struct f2fs_summary *sum, struct f2fs_io_info *fio)
 		goto reallocate;
 	}
 
-	update_device_state(fio);
+	update_device_state(fio->sbi, fio->ino, fio->new_blkaddr);
 
 	if (keep_order)
 		up_read(&fio->sbi->io_order_lock);
@@ -3168,7 +3167,7 @@ int f2fs_inplace_write_data(struct f2fs_io_info *fio)
 	else
 		err = f2fs_submit_page_bio(fio);
 	if (!err)
-		update_device_state(fio);
+		update_device_state(fio->sbi, fio->ino, fio->new_blkaddr);
 
 	f2fs_update_iostat(fio->sbi, fio->io_type, F2FS_BLKSIZE);