Received: by 2002:a05:6a10:1287:0:0:0:0 with SMTP id d7csp733866pxv; Thu, 22 Jul 2021 10:46:40 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyEDpa2Mfs/xw3VQQyI+a50lMwLhTbhP/Gh0t8aqfZfmfkwbVcrvvFZmdJMANiz3k+trvL8 X-Received: by 2002:a17:906:fb90:: with SMTP id lr16mr941690ejb.541.1626976000268; Thu, 22 Jul 2021 10:46:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1626976000; cv=none; d=google.com; s=arc-20160816; b=CDuGiHbULguMRlu4HMIZ7Ms683GNPev5fm+/+k6OuIcPaGjmTmih33ywit4LkzSojx H/UFBeJJVI/qnAU/f0V9g9/z50XpJxF/oyuPQYXV80nRldyQ22uB7Mh1HPJMv5jCm8/S dz/ZRb2egN7UwtIQTE14ybvVr2EoLPgOwx88iSsP9SR2LV/BPuyH4DXo7AqwTbtI+mtS VZtlC1aWIckWGmvvdjm5dCv2p8317QtOdJf2DIL97iGgMpNK13vUxxHWdp4JaSMl4t1s hwHapuzJ8oTuGXyEE6Txb+/gkbBgyeAALoJCtTMsPe7MiMMdAAXSgRvgyepKvtU8YswQ bAdg== 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=KSOzutUeRqPDwj7532S0t+cTZriEo1IZe7gia5sDwBo=; b=EDkcGds267CjGiPHBKO+3vFkP3K3SpkcCeaCpMolriXRfQ704sg2qMpVpMbyrcxHr3 EsDpsUThCk7PIEn3+WjEcqo6LUYkOGX01wxJ+5yO2MB/ZNV7gmvw8BGsOAblRH0JcfyZ OeNIGXMPYhnS91rfuDXpagQ/8/gfii4DADqGRpry1iHly3aK2EfDG6DI3lEDowOzNh4n J7o6GZXl35HXZaPdqoEgo9QoYXXDPrIFnbsttFkVotX7fBVlNp0fN5KAxwXg0eniX3Xl BYlK5p8OghbhCGX9QggcqUI45VTl6AOMn7Lfy6Jux9qs5Qh6s9RKB545jm6Xjuxcmwxi ox6A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=u9loRPsv; 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 q12si31154437eds.113.2021.07.22.10.46.15; Thu, 22 Jul 2021 10:46:40 -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=u9loRPsv; 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 S229906AbhGVRD5 (ORCPT + 99 others); Thu, 22 Jul 2021 13:03:57 -0400 Received: from mail.kernel.org ([198.145.29.99]:56346 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229514AbhGVRDy (ORCPT ); Thu, 22 Jul 2021 13:03:54 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id AEB5061001; Thu, 22 Jul 2021 17:44:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1626975869; bh=+1VtaWnpu+/vg0Zu7lXitOvQJPQ5sE29/Tcbn/mDaJw=; h=Date:From:To:Subject:References:In-Reply-To:From; b=u9loRPsvhcfjzmctIAYBGzicMdiPmZqpfANrWNV1BIb+tJZ1mV4+NfLphNTnNOjFw 0fYVzaBKoTyQQdm1nepJPpgg1xgGlAEim3ygYRtMdpm4LC47XBlBlKHkpWkurwviqD iWfDT6PVBKnQz5kIaf5V0fuLFxoV9JQl15oyGAMA0VtnzCoBsjsZWVFqoS/dYDERT7 cE0XlVtO7R9hpOf7hNdIddYQsD9t1tsA/djWeL7ANoy0SEnSlbyvBpWhuB/AwiRPjW Zfe5RBXrWFHJ0ngUsedMe0z6+sQS7Q5shV+pn1bs2Vwc+s0N37xXeNfg68L3eb6imB eTNrgs0SpkPUw== Date: Thu, 22 Jul 2021 10:44:28 -0700 From: Jaegeuk Kim To: linux-kernel@vger.kernel.org, linux-f2fs-devel@lists.sourceforge.net Subject: Re: [PATCH v2] 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: <20210722014149.525166-1-jaegeuk@kernel.org> 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: Jaegeuk Kim --- Change log from v1: - drop rwlock but take retry logic to reduce lock-holding time fs/f2fs/node.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/fs/f2fs/node.c b/fs/f2fs/node.c index 0be9e2d7120e..c60ba4179bb2 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,16 @@ 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. + */ + 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