Received: by 2002:a05:6a10:1287:0:0:0:0 with SMTP id d7csp1020467pxv; Thu, 22 Jul 2021 19:36:58 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwdDCFuEBOl1b5wnpSlqsyu4L6b+8A6oNWUMBQ2y2O/IxTo0k+ncKIB0n+pxeoNrIR4lplV X-Received: by 2002:a92:cb06:: with SMTP id s6mr2041963ilo.87.1627007818357; Thu, 22 Jul 2021 19:36:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1627007818; cv=none; d=google.com; s=arc-20160816; b=ZfPDHDaaLPR7rONCie/Au/HLzRJjzlIu9KRHT3tyhWyFWjREbUrMDRlfl7j4JwIqRs pjK/i6jrS4T9qkMxbq/NezTJSVOQRJEX3CPIumysEMRcTSlk3JIvi8QSYjO0U8dchAB8 PdfoLDuD8pbo2xPiHSkQLXVGMA6uKqUIJmQIMGzZ8DD74nYPeVZmI59622B9nEB+q7ck MHLbjabILKoqiChCOyoEBARBCd8XyvsdOrW0lH/YHlGjUFyw2AArUAScAnGYbaCMu9im hSroI4ojWTkNCiIeu8FmTkBynXi1e3MmmOVLwqU2gjBgkQet9quoZazZuUED2HIw9wIT BcPg== 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=3RsNRhoc4leQnQJYVhz9WAQj9eatICq7xn8tNbB2LDs=; b=D5m6hlxQd5KLO1N3KJ15GLyEacl3lIIZJhRE2pussfJRZReiJfHAGQCJd0M0xCyGXm IAZZJnIOfXuHMeHR7q8fmFmMUjFBcoaolThGWDi0+de+zNRD+oc2aDJ/eCBAltSgXriS do1uVwAHBVIobJefNPnyC1gbCI5l+ANWjlBC00CJmzJX7aEYUq0uYNj3XVNnwxx3xf3Q sHHFbcdyRmbUQA+DpSnUB1Mk0mwPTKinivT5ItLpsTXHznRmT7aW8IFfu2BRFEDRA4Cw iGwBjkE9E3N6Z3U9ghYri5TEPju9O5H6pj8NetQUnqfeoO5rxYpC63P2Djh3Xo92Iqrg T7Jw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=YnRvh2lb; 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 a1si27813654iow.19.2021.07.22.19.36.47; Thu, 22 Jul 2021 19:36:58 -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=YnRvh2lb; 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 S233216AbhGWBzY (ORCPT + 99 others); Thu, 22 Jul 2021 21:55:24 -0400 Received: from mail.kernel.org ([198.145.29.99]:41420 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231663AbhGWBzY (ORCPT ); Thu, 22 Jul 2021 21:55:24 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 3263D60EBE; Fri, 23 Jul 2021 02:35:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1627007758; bh=/Mwrac25+uC81BGpDWykRwtoURQdfGp5sL5q4DXj/l0=; h=Date:From:To:Subject:References:In-Reply-To:From; b=YnRvh2lbNgYSQOdHwmOSjNxugVvcHBoIbv6a0ZZ+gW9aJrFU1qeiv2QZFqx/XauPA 6kJixcenGQri9j7ONCZGaGBkYEnpxsFVUBR5vzCBVXlqrXiv0McEPar+FmtNUMU4Tf /9Ae+BqLuk/gm06lL/rNegJy6srSACvlxKaX4+D9JEufxYPH9Wpyc3Gnpqsu9RcaUo PZPfJ+/6UfpT+UZy4zqZMO11FWboir9YIcx2IkKn5wCgJtipLcwG6vfMrGl+6s7+co j0SxnogBm+6qvuK8aJ1kk+q9OOwImWWmX4Vjx+tdwn1UQRDuCFiO3qu1vYLOXf/oBC pA/3c//xEptyA== Date: Thu, 22 Jul 2021 19:35:56 -0700 From: Jaegeuk Kim To: linux-kernel@vger.kernel.org, linux-f2fs-devel@lists.sourceforge.net Subject: Re: [PATCH v3] 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 v2: - don't bother checkpoint 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..b26642daa3d2 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