When performing big dio writes concurrently, our performace will be low because of Thread A's allocation of multi continuous blocks will be interrupted by Thread B, there are two cases as below: - In Thread B, we may change current segment to a new segment for LFS allocation if we dio write in the beginning of the file. - In Thread B, we may allocate blocks in the middle of Thread A's allocation, which make blocks allocated in Thread A being inconsecutive.
This patch adds writepages mutex lock to make block allocation in dio write being atomic to avoid above issues. Test environment 1: ubuntu os with linux kernel 4.4-rc4, intel i7-3770, 16g memory, 32g kingston sd card. fio --name seqw --ioengine=sync --invalidate=1 --rw=write --directory=/mnt/f2fs --filesize=256m --size=16m --bs=2m --direct=1 --numjobs=10 before: WRITE: io=163840KB, aggrb=5125KB/s, minb=512KB/s, maxb=776KB/s, mint=21105msec, maxt=31967msec patched: WRITE: io=163840KB, aggrb=10424KB/s, minb=1042KB/s, maxb=1172KB/s, mint=13975msec, maxt=15717msec Test environment 2: Note4 eMMC fio --name seqw --ioengine=sync --invalidate=1 --rw=write --directory=/data/test/ --filesize=256m --size=64m --bs=2m --direct=1 --numjobs=16 before: WRITE: io=1024.0MB, aggrb=103583KB/s, minb=6473KB/s, maxb=8806KB/s, mint=7442msec, maxt=10123msec patched: WRITE: io=1024.0MB, aggrb=124860KB/s, minb=7803KB/s, maxb=9315KB/s, mint=7035msec, maxt=8398msec Signed-off-by: Chao Yu <chao2...@samsung.com> --- fs/f2fs/data.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/fs/f2fs/data.c b/fs/f2fs/data.c index 5c43b2d..6b24446 100644 --- a/fs/f2fs/data.c +++ b/fs/f2fs/data.c @@ -1640,7 +1640,9 @@ static ssize_t f2fs_direct_IO(struct kiocb *iocb, struct iov_iter *iter, struct file *file = iocb->ki_filp; struct address_space *mapping = file->f_mapping; struct inode *inode = mapping->host; + struct f2fs_sb_info *sbi = F2FS_I_SB(inode); size_t count = iov_iter_count(iter); + int rw = iov_iter_rw(iter); int err; /* we don't need to use inline_data strictly */ @@ -1655,20 +1657,26 @@ static ssize_t f2fs_direct_IO(struct kiocb *iocb, struct iov_iter *iter, if (err) return err; - trace_f2fs_direct_IO_enter(inode, offset, count, iov_iter_rw(iter)); + trace_f2fs_direct_IO_enter(inode, offset, count, rw); + + if (rw == WRITE) { + bool serialized = (F2FS_BYTES_TO_BLK(count) >= 64); - if (iov_iter_rw(iter) == WRITE) { + if (serialized) + mutex_lock(&sbi->writepages); err = __allocate_data_blocks(inode, offset, count); + if (serialized) + mutex_unlock(&sbi->writepages); if (err) goto out; } err = blockdev_direct_IO(iocb, inode, iter, offset, get_data_block_dio); out: - if (err < 0 && iov_iter_rw(iter) == WRITE) + if (err < 0 && rw == WRITE) f2fs_write_failed(mapping, offset + count); - trace_f2fs_direct_IO_exit(inode, offset, count, iov_iter_rw(iter), err); + trace_f2fs_direct_IO_exit(inode, offset, count, rw, err); return err; } -- 2.6.3 ------------------------------------------------------------------------------ _______________________________________________ Linux-f2fs-devel mailing list Linux-f2fs-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel