Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754941AbbGPKSx (ORCPT ); Thu, 16 Jul 2015 06:18:53 -0400 Received: from mailout3.samsung.com ([203.254.224.33]:40536 "EHLO mailout3.samsung.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753892AbbGPKSw (ORCPT ); Thu, 16 Jul 2015 06:18:52 -0400 X-AuditID: cbfee61a-f79516d000006302-54-55a7850b60bb From: Chao Yu To: Jaegeuk Kim Cc: linux-kernel@vger.kernel.org, linux-f2fs-devel@lists.sourceforge.net Subject: [PATCH 1/2] f2fs: reduce region of cp_rwsem covered in f2fs_do_collapse Date: Thu, 16 Jul 2015 18:18:11 +0800 Message-id: <018d01d0bfb0$cf828090$6e8781b0$@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: AdC/sIOvWi7vyjJLRLCBPanTr2jzsQ== Content-language: zh-cn X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFjrGLMWRmVeSWpSXmKPExsVy+t9jQV3u1uWhBtfv8lo8WT+L2eLSIneL y7vmsDkwe2xa1cnmsXvBZyaPz5vkApijuGxSUnMyy1KL9O0SuDK+zVrDXtDLX3FrtXoD413u LkZODgkBE4ktK3ezQdhiEhfurQeyuTiEBKYzSvz/0sUC4bxilFhwcBcLSBWbgIrE8o7/TCC2 CJB9aNFl9i5GDg5mAQ+JXcdKQcLCAgES6/+tAitnEVCVuP58FdgCXgFLicWzXzBD2IISPybf A6thFtCSWL/zOBOELS+xec1bZoiDFCR2nH3NCDJeREBP4uARU4gScYmNR26xTGAUmIVk0iwk k2YhmTQLScsCRpZVjKKpBckFxUnpuYZ6xYm5xaV56XrJ+bmbGMGh+0xqB+PKBotDjAIcjEo8 vBy/l4UKsSaWFVfmHmKU4GBWEuF96rk8VIg3JbGyKrUoP76oNCe1+BCjNAeLkjjvyXyfUCGB 9MSS1OzU1ILUIpgsEwenVAPjjlrZgxe48rvVEnnWrWqMW+2/d1dNed/5lfMvNU94u0b5x/9I SdbvjoKXy64sX8kaJP4lMbnialHmtGm3Z2/Z/5+7dsnryw/a558qSzV/vX9GyLps/RqFtHns woWrZ8RV6DWlvFRTFJ8j/cdhUuOfx8aG4ScvXNn6ZuHkltBX77Y+zLReXfSuSImlOCPRUIu5 qDgRAFKpaJxZAgAA Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2113 Lines: 70 In f2fs_do_collapse, region cp_rwsem covered is large, since it will be held until all blocks are left shifted, so if we try to collapse small area at the beginning of large file, checkpoint who want to grab writer's lock of cp_rwsem will be delayed for long time. In order to avoid this condition, altering to lock/unlock cp_rwsem each shift operation. Signed-off-by: Chao Yu --- fs/f2fs/file.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/fs/f2fs/file.c b/fs/f2fs/file.c index 963cee0..852535f 100644 --- a/fs/f2fs/file.c +++ b/fs/f2fs/file.c @@ -800,11 +800,11 @@ static int f2fs_do_collapse(struct inode *inode, pgoff_t start, pgoff_t end) pgoff_t nrpages = (i_size_read(inode) + PAGE_SIZE - 1) / PAGE_SIZE; int ret = 0; - f2fs_lock_op(sbi); - for (; end < nrpages; start++, end++) { block_t new_addr, old_addr; + f2fs_lock_op(sbi); + set_new_dnode(&dn, inode, NULL, NULL, 0); ret = get_dnode_of_data(&dn, end, LOOKUP_NODE_RA); if (ret && ret != -ENOENT) { @@ -820,13 +820,16 @@ static int f2fs_do_collapse(struct inode *inode, pgoff_t start, pgoff_t end) if (new_addr == NULL_ADDR) { set_new_dnode(&dn, inode, NULL, NULL, 0); ret = get_dnode_of_data(&dn, start, LOOKUP_NODE_RA); - if (ret && ret != -ENOENT) + if (ret && ret != -ENOENT) { goto out; - else if (ret == -ENOENT) + } else if (ret == -ENOENT) { + f2fs_unlock_op(sbi); continue; + } if (dn.data_blkaddr == NULL_ADDR) { f2fs_put_dnode(&dn); + f2fs_unlock_op(sbi); continue; } else { truncate_data_blocks_range(&dn, 1); @@ -865,8 +868,9 @@ static int f2fs_do_collapse(struct inode *inode, pgoff_t start, pgoff_t end) f2fs_put_dnode(&dn); } + f2fs_unlock_op(sbi); } - ret = 0; + return 0; out: f2fs_unlock_op(sbi); return ret; -- 2.4.2 -- 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/