Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751584AbbL1KFU (ORCPT ); Mon, 28 Dec 2015 05:05:20 -0500 Received: from mailout1.samsung.com ([203.254.224.24]:58248 "EHLO mailout1.samsung.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750983AbbL1KFR (ORCPT ); Mon, 28 Dec 2015 05:05:17 -0500 X-AuditID: cbfee61a-f79266d000003652-f6-5681095bc2e3 From: Chao Yu To: Jaegeuk Kim Cc: linux-f2fs-devel@lists.sourceforge.net, linux-kernel@vger.kernel.org Subject: [RFC PATCH 1/2] f2fs: enhance multithread dio write performance Date: Mon, 28 Dec 2015 18:04:35 +0800 Message-id: <006d01d14157$3f76de50$be649af0$@samsung.com> MIME-version: 1.0 Content-type: text/plain; charset=us-ascii Content-transfer-encoding: 7bit X-Mailer: Microsoft Outlook 14.0 Thread-index: AdFBVx6qJJGPh8ZuQ7m1dn3Z5B1mGg== Content-language: zh-cn X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFjrFLMWRmVeSWpSXmKPExsVy+t9jAd1ozsYwg+bZihZP1s9itri0yN3i 8q45bA7MHptWdbJ57F7wmcnj8ya5AOYoLpuU1JzMstQifbsEroyDb5cxFayWqJi69SNrA2OH SBcjJ4eEgInE/td72CFsMYkL99azgdhCAksZJV4s5Oxi5AKyXzFK/Pj5EizBJqAisbzjPxOI LQJkH1p0GayZWcBDorHjO2sXIweHMJC9eYseSJhFQFWiqekHI4jNK2Ap8fzxLlYIW1Dix+R7 LBCtWhLrdx5ngrDlJTavecsMcY+CxI6zrxkhVulJnNnwDWqVuMTGI7dYJjAKzEIyahaSUbOQ jJqFpGUBI8sqRonUguSC4qT0XMO81HK94sTc4tK8dL3k/NxNjOAQfia1g/HgLvdDjAIcjEo8 vB1NDWFCrIllxZW5hxglOJiVRHhN3wCFeFMSK6tSi/Lji0pzUosPMUpzsCiJ89ZeigwTEkhP LEnNTk0tSC2CyTJxcEo1MEbJJ1xq2fCJeyHv9wlyObbG/l5X/7+rTLWyu6tufmXBBk//nhQe /Q13fQVMzT9udevSCP2yI97nuv8dRsn/t+Utzwc+nM3ad9d+eVjtno5bc4K0Amdv6F/6u+Qw W1zgkceTbjb2ftzMvplbjy2g1bNH7YbivhBlnbNbNzctiuRP+CavfXhTjRJLcUaioRZzUXEi ALo0t41dAgAA Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 3272 Lines: 93 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 --- 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 -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/