Received: by 2002:a05:6a10:1287:0:0:0:0 with SMTP id d7csp1064855pxv; Thu, 22 Jul 2021 21:28:27 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxCLUpGFwkK3c4AnKzQZqe8Is/4IijLxM1IWmB3HW7z0/fHEH2mTaquyFhvgX5yEIl2fZmT X-Received: by 2002:a05:6602:249a:: with SMTP id g26mr2464862ioe.150.1627014506908; Thu, 22 Jul 2021 21:28:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1627014506; cv=none; d=google.com; s=arc-20160816; b=Q7XSfo3gBLRN7+Rk2rIJX2vORBvdYyA6G6GV3TOoNgXUCK06uh6bbXWEH7nxhIVvHG IXLDFzVsfzFRJyOuCu4Bdj/sZ5ydNF6lok7PWg7sCgHIfuRGulxKdR68mC6lVzHAi8WH 3lld4YSgjaH/dGP+4uY3XqGUpB2OSjj0JZ0UGNJxN9sjWVclrsTqBvVsU2Y+ZiRqjMbv HlXxUWQEgVbTLp7Bvz/Q1wP0HacIIHUEIcpcqxTVXFTkAbdnrASCLope/9JW1/FQhNJW KpV0ZwViGuUuVA7t+kxaQ/2Yv8Q5cId3cpHg/7QqfoO0IikABvUu9vAZkuMVHOAer/QK DOaw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:to:from:date:dkim-signature; bh=xDcAUVCzw82O3btn3TMr+/l/TFQ5VodEzkcyj6On2Fw=; b=zxkGP2ytaL1SXJ4VF4KMI6Kt78gQ1Qnlhyf3znmbhOp7z/m+iRw5756vH1y0Fz1wg1 J3EI2cBteFA8oiDnFrZQaoo+Y+7p41ms8Y0U9HHnUH+z6FsQqEofRHS5eBQZYQZemhMS ThxyMkD51wcgcSLjxOw2pK1vGAO7VZZH7L3gmdco3wSu3D2lZySpBESKtQh7TYooJA9/ 2VMeZKak5ilHY6lL6OFgYjLtEFeB/ziiEkToW+l+fZHW/pyXLzhNhWzM4yOIg1xIU+D4 82L1hlflrZd8Z1cYo+iU3Oo9Z4/5ZudUHWYzMwZ2aaen3ir8UG2O+Ti8CqsSd5RRiZrF R1qA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=Q45twTiT; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id i23si29703901ila.157.2021.07.22.21.28.14; Thu, 22 Jul 2021 21:28:26 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=Q45twTiT; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233612AbhGWDq6 (ORCPT + 99 others); Thu, 22 Jul 2021 23:46:58 -0400 Received: from mail.kernel.org ([198.145.29.99]:46850 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233572AbhGWDq6 (ORCPT ); Thu, 22 Jul 2021 23:46:58 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 05FFF60E8E; Fri, 23 Jul 2021 04:27:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1627014452; bh=4AJtrL5EuFvtcmtmky/U4ejUKlCr3swf/oxZOxyr6aI=; h=Date:From:To:Subject:References:In-Reply-To:From; b=Q45twTiT/2jXymp9Xj6GP2lrkfi801xtC6RkmiTArDxQ67+Gp9RMoRPbOZQL7C9rd TqbYEjczWge6siHnU5wKB9tZCqlY/HLfe4ZObqz4t9OpJWMS9HD+JlU66EQBbO4wZ/ kIBaE47XiEo9I/ohWHflTsIjQEpMOit43qbcBz2lznkLQPWiRfGjIRDqLe50tv7p5t EX3zhbAV601LhsSqkYujoX7ftNErD9srSauXuelFzxFSz9l7CHFZt+wNKHeuGRdkj1 FdXPkMASfobIPCXNcVLwXTrp4W3CrGd5Vu5wwR+jhIX8Ba96JeXBx8xHJ2xAqVTuV3 1gNdn+0nzSc3g== Date: Thu, 22 Jul 2021 21:27:30 -0700 From: Jaegeuk Kim To: linux-kernel@vger.kernel.org, linux-f2fs-devel@lists.sourceforge.net Subject: Re: [f2fs-dev] [PATCH v4] f2fs: don't sleep while grabing nat_tree_lock Message-ID: References: <20210722014149.525166-1-jaegeuk@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This tries to fix priority inversion in the below condition resulting in long checkpoint delay. f2fs_get_node_info() - nat_tree_lock -> sleep to grab journal_rwsem by contention checkpoint - waiting for nat_tree_lock In order to let checkpoint go, let's release nat_tree_lock, if there's a journal_rwsem contention. Signed-off-by: Daeho Jeong Signed-off-by: Jaegeuk Kim --- Change log from v3: - fix wrong condition check fs/f2fs/node.c | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/fs/f2fs/node.c b/fs/f2fs/node.c index 0be9e2d7120e..c945a9730f3c 100644 --- a/fs/f2fs/node.c +++ b/fs/f2fs/node.c @@ -552,7 +552,7 @@ int f2fs_get_node_info(struct f2fs_sb_info *sbi, nid_t nid, int i; ni->nid = nid; - +retry: /* Check nat cache */ down_read(&nm_i->nat_tree_lock); e = __lookup_nat_cache(nm_i, nid); @@ -564,10 +564,19 @@ int f2fs_get_node_info(struct f2fs_sb_info *sbi, nid_t nid, return 0; } - memset(&ne, 0, sizeof(struct f2fs_nat_entry)); + /* + * Check current segment summary by trying to grab journal_rwsem first. + * This sem is on the critical path on the checkpoint requiring the above + * nat_tree_lock. Therefore, we should retry, if we failed to grab here + * while not bothering checkpoint. + */ + if (!rwsem_is_locked(&sbi->cp_global_sem)) { + down_read(&curseg->journal_rwsem); + } else if (!down_read_trylock(&curseg->journal_rwsem)) { + up_read(&nm_i->nat_tree_lock); + goto retry; + } - /* Check current segment summary */ - down_read(&curseg->journal_rwsem); i = f2fs_lookup_journal_in_cursum(journal, NAT_JOURNAL, nid, 0); if (i >= 0) { ne = nat_in_journal(journal, i); -- 2.32.0.432.gabb21c7263-goog