From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751598AbbIKGmj (ORCPT ); Fri, 11 Sep 2015 02:42:39 -0400 Received: from mailout1.samsung.com ([203.254.224.24]:49358 "EHLO mailout1.samsung.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751243AbbIKGmh (ORCPT ); Fri, 11 Sep 2015 02:42:37 -0400 X-AuditID: cbfee61b-f79d56d0000048c5-fc-55f277dcdbfb From: Chao Yu To: Jaegeuk Kim Cc: linux-f2fs-devel@lists.sourceforge.net, linux-kernel@vger.kernel.org Subject: [PATCH 5/7] f2fs: enhance multithread dio write performance Date: Fri, 11 Sep 2015 14:41:53 +0800 Message-id: <000001d0ec5d$0bbd1880$23374980$@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: AdDsXLPFPYXQtm0hS1G3wzeA07NxHA== Content-language: zh-cn X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFjrDLMWRmVeSWpSXmKPExsVy+t9jAd075Z9CDS6/s7R4sn4Ws8WlRe4W l3fNYXNg9ti0qpPNY/eCz0wenzfJBTBHcdmkpOZklqUW6dslcGVcbvrLXNAvXNH17h9LA+MN /i5GTg4JAROJHVfvskLYYhIX7q1n62Lk4hASWMoo8ezmUiYI5xWjxJYt3YwgVWwCKhLLO/4z gdgiQPahRZfZQWxmAQ+Jxo7vYJOEBVwkdjZvAbNZBFQlrq2YBFbPK2Ap0XbzPSOELSjxY/I9 FoheLYn1O48zQdjyEpvXvGWGuEhBYsfZ14wQu/QkLq7+wwZRIy6x8cgtlgmMArOQjJqFZNQs JKNmIWlZwMiyilEitSC5oDgpPdcoL7Vcrzgxt7g0L10vOT93EyM4jJ9J72A8vMv9EKMAB6MS D6+F6qdQIdbEsuLK3EOMEhzMSiK8BnJAId6UxMqq1KL8+KLSnNTiQ4zSHCxK4ryyK5+FCgmk J5akZqemFqQWwWSZODilGhgj33xjXceScShyI8ufxqA65bayS01Ln5evaXzoxVSjF6S6fipr nDNjU0/RqWOVKvezF1Wqz1f4snBTkuexi/wz377Qc/gqaeASv7PcIFf6QLrEfu4ND9m/Or96 VbTP/5V8xAXHWaprhO7/uRc4eWXD6xehU8zKpxtzf1OZub0vfs+OuQJnd19SYinOSDTUYi4q TgQA1idMLV8CAAA= Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org When dio writes perform concurrently, our performace will be low because of Thread A's allocation of multi continuous blocks will be break 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 which allocated in Thread A being discontinuous. This patch adds writepages mutex lock to make block allocation in dio write atomic to avoid above issues. Test environment: ubuntu os with linux kernel 4.2+, 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=3145KB/s, minb=314KB/s, maxb=411KB/s, mint=39836msec, maxt=52083msec patched: WRITE: io=163840KB, aggrb=10033KB/s, minb=1003KB/s, maxb=1124KB/s, mint=14565msec, maxt=16329msec Signed-off-by: Chao Yu --- fs/f2fs/data.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/fs/f2fs/data.c b/fs/f2fs/data.c index a737ca5..a0a5849 100644 --- a/fs/f2fs/data.c +++ b/fs/f2fs/data.c @@ -1536,7 +1536,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 */ @@ -1555,12 +1557,17 @@ static ssize_t f2fs_direct_IO(struct kiocb *iocb, struct iov_iter *iter, trace_f2fs_direct_IO_enter(inode, offset, count, iov_iter_rw(iter)); - if (iov_iter_rw(iter) == WRITE) + if (rw == WRITE) { + mutex_lock(&sbi->writepages); __allocate_data_blocks(inode, offset, count); + } err = blockdev_direct_IO(iocb, inode, iter, offset, get_data_block_dio); - if (err < 0 && iov_iter_rw(iter) == WRITE) - f2fs_write_failed(mapping, offset + count); + if (rw == WRITE) { + mutex_unlock(&sbi->writepages); + if (err) + f2fs_write_failed(mapping, offset + count); + } trace_f2fs_direct_IO_exit(inode, offset, count, iov_iter_rw(iter), err); -- 2.4.2