From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id CCEB8C433ED for ; Thu, 15 Apr 2021 09:44:00 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id A815661166 for ; Thu, 15 Apr 2021 09:44:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231423AbhDOJoW (ORCPT ); Thu, 15 Apr 2021 05:44:22 -0400 Received: from szxga07-in.huawei.com ([45.249.212.35]:17340 "EHLO szxga07-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232204AbhDOJoR (ORCPT ); Thu, 15 Apr 2021 05:44:17 -0400 Received: from DGGEMS406-HUB.china.huawei.com (unknown [172.30.72.59]) by szxga07-in.huawei.com (SkyGuard) with ESMTP id 4FLZ9V26V1zB1Gr; Thu, 15 Apr 2021 17:41:34 +0800 (CST) Received: from szvp000203569.huawei.com (10.120.216.130) by DGGEMS406-HUB.china.huawei.com (10.3.19.206) with Microsoft SMTP Server id 14.3.498.0; Thu, 15 Apr 2021 17:43:42 +0800 From: Chao Yu To: , , CC: , , Chao Yu Subject: [PATCH] direct-io: use read lock for DIO_LOCKING flag Date: Thu, 15 Apr 2021 17:43:32 +0800 Message-ID: <20210415094332.37231-1-yuchao0@huawei.com> X-Mailer: git-send-email 2.29.2 MIME-Version: 1.0 Content-Transfer-Encoding: 7BIT Content-Type: text/plain; charset=US-ASCII X-Originating-IP: [10.120.216.130] X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org 9902af79c01a ("parallel lookups: actual switch to rwsem") changes inode lock from mutex to rwsem, however, we forgot to adjust lock for DIO_LOCKING flag in do_blockdev_direct_IO(), so let's change to hold read lock to mitigate performance regression in the case of read DIO vs read DIO, meanwhile it still keeps original functionality of avoiding buffered access vs direct access. Signed-off-by: Chao Yu --- fs/direct-io.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/fs/direct-io.c b/fs/direct-io.c index b2e86e739d7a..93ff912f2749 100644 --- a/fs/direct-io.c +++ b/fs/direct-io.c @@ -1166,7 +1166,7 @@ do_blockdev_direct_IO(struct kiocb *iocb, struct inode *inode, dio->flags = flags; if (dio->flags & DIO_LOCKING && iov_iter_rw(iter) == READ) { /* will be released by direct_io_worker */ - inode_lock(inode); + inode_lock_shared(inode); } /* Once we sampled i_size check for reads beyond EOF */ @@ -1316,7 +1316,7 @@ do_blockdev_direct_IO(struct kiocb *iocb, struct inode *inode, * of protecting us from looking up uninitialized blocks. */ if (iov_iter_rw(iter) == READ && (dio->flags & DIO_LOCKING)) - inode_unlock(dio->inode); + inode_unlock_shared(dio->inode); /* * The only time we want to leave bios in flight is when a successful @@ -1341,7 +1341,7 @@ do_blockdev_direct_IO(struct kiocb *iocb, struct inode *inode, fail_dio: if (dio->flags & DIO_LOCKING && iov_iter_rw(iter) == READ) - inode_unlock(inode); + inode_unlock_shared(inode); kmem_cache_free(dio_cache, dio); return retval; -- 2.29.2