Received: by 2002:a05:6a10:1287:0:0:0:0 with SMTP id d7csp967972pxv; Thu, 22 Jul 2021 17:41:40 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwaHjyITOxjywP9hRwaOuE6MDp4pV0dg4pam9x9QiWB3vpYtnIW73m+6Gkbe7jGNkNlFxbs X-Received: by 2002:a17:906:a0a:: with SMTP id w10mr2340621ejf.416.1627000899918; Thu, 22 Jul 2021 17:41:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1627000899; cv=none; d=google.com; s=arc-20160816; b=Dbx0VdOJrzAdaBjr08hHBu8fpwvZDuOh6heKhAzys57tCrGbtUMbjGah6Q5cWba28N q+UHANX2k/frO41//zNmxOiotn796Yun5gAenujDKORPIFQhdGyo8SCXYynrCiBHjDb2 r7w1IZ2D6LPu7XLnTvmEx+/1lc5ceJ22yhQZ9nOTeZ5fhA2N0Sr2MDMuOWttRuQgXA39 LrBIX1ewFyaQoOG7pvMagLX6LHETY+ByvP40YTuxnTXDCyBXecwEfJmmebe+dPBsaCPP cdL3tpW3m4jRwIQL3HHOG62vb2pgfBLvOCvIma8uHmAXWU1+EE8G69EZ7SjubOJnqXxp L81g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :in-reply-to:mime-version:user-agent:date:message-id:from:references :to:subject:dkim-signature; bh=U42Bfn8YbMnv0Q6fcrQdXLSWJlV3du1+/2468fvjrDs=; b=QrdqbBbqIrfX+d1GaXmZkQjVbBImw3x3VECyqDLI1qPU7VNm0QXgMdIFM9bR7EJ8Id QbwLzUtsDOKkooADKvqT6tA7PaFOsKJh3JGYvSdSyeEnou7laolTB93znQakl4xjbZUd kO612YYexynI0LdQHnvOnZzk8XBFNiUTjl1lU430CYNK3IuazCFCHkYn8HvHCARrRgmm XeCDSfYWV9qDp6KuvSxWO7JIEBxC2bjALlbdPNluqul9OiFGUFIt8O0GljspQMvAUCMp JwKaWnq131OLD6b4EoWlB0SM0REqJ8IVcCIJyrFThaKLpHfl31sXYaPIvGz2p7xDWSPs D5UQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=QWMyIIVx; 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 rs4si2884486ejb.138.2021.07.22.17.41.15; Thu, 22 Jul 2021 17:41:39 -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=QWMyIIVx; 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 S232840AbhGVX63 (ORCPT + 99 others); Thu, 22 Jul 2021 19:58:29 -0400 Received: from mail.kernel.org ([198.145.29.99]:47266 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232730AbhGVX63 (ORCPT ); Thu, 22 Jul 2021 19:58:29 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 0F4DF60EB0; Fri, 23 Jul 2021 00:39:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1627000743; bh=w6d0ememMNzqQ4orGdbf+c+bf4YvhmCQiSDhVd0wOPE=; h=Subject:To:References:From:Date:In-Reply-To:From; b=QWMyIIVxshyVup1WnAZgZ+tsIDbD9ynjCil6HSJLnp5sXmjLV/W1GLbr+L0jJOyd5 NHoHRGdW3skI+hVTQVAt0KqeeMOkjhtFnkUNx4HoEYwgI6//6l/DEeV/0YAWAiVYR9 A9VG8/q5Jf/F4M+XVr5q3a+UoLFwrkmbeKA8KVwNGfNbettttcTOKgchm3JJDBLafP ys4B+8TYNWpgl4+m9K7dJ0kC8rDe35UnK/clOBk9qoBkqViXj6M29Ekw1hrOg8Yau3 3pwAGAea7v4K9i8HaEP8HxkLQKHB9ZTkmuT4Jb7xakyCYKk8PEpRMWr4I23plB0rD1 PGFDGQb0l4NEw== Subject: Re: [f2fs-dev] [PATCH v2] f2fs: don't sleep while grabing nat_tree_lock To: Jaegeuk Kim , linux-kernel@vger.kernel.org, linux-f2fs-devel@lists.sourceforge.net References: <20210722014149.525166-1-jaegeuk@kernel.org> From: Chao Yu Message-ID: Date: Fri, 23 Jul 2021 08:39:03 +0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.12.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2021/7/23 1:44, Jaegeuk Kim wrote: > 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. Write lock of nat_tree_lock is held from many places, how about just retrying unlock/lock only if checkpoint() is flushing nat blocks? --- fs/f2fs/f2fs.h | 1 + fs/f2fs/node.c | 8 ++++++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h index ad8f99d7235f..05f41a15fda4 100644 --- a/fs/f2fs/f2fs.h +++ b/fs/f2fs/f2fs.h @@ -877,6 +877,7 @@ struct f2fs_nm_info { spinlock_t nat_list_lock; /* protect clean nat entry list */ unsigned int nat_cnt[MAX_NAT_STATE]; /* the # of cached nat entries */ unsigned int nat_blocks; /* # of nat blocks */ + bool flushing_nat; /* indicate checkpoint() is flushing nat blocks */ /* free node ids management */ struct radix_tree_root free_nid_root;/* root of the free_nid cache */ diff --git a/fs/f2fs/node.c b/fs/f2fs/node.c index c60ba4179bb2..2caa171a68f8 100644 --- a/fs/f2fs/node.c +++ b/fs/f2fs/node.c @@ -569,7 +569,7 @@ int f2fs_get_node_info(struct f2fs_sb_info *sbi, nid_t nid, * 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)) { + if (!down_read_trylock(&curseg->journal_rwsem) && nm_i->flushing_nat) { up_read(&nm_i->nat_tree_lock); goto retry; } @@ -2981,6 +2981,8 @@ int f2fs_flush_nat_entries(struct f2fs_sb_info *sbi, struct cp_control *cpc) LIST_HEAD(sets); int err = 0; + nm_i->flushing_nat = true; + /* * during unmount, let's flush nat_bits before checking * nat_cnt[DIRTY_NAT]. @@ -2992,7 +2994,7 @@ int f2fs_flush_nat_entries(struct f2fs_sb_info *sbi, struct cp_control *cpc) } if (!nm_i->nat_cnt[DIRTY_NAT]) - return 0; + goto out; down_write(&nm_i->nat_tree_lock); @@ -3026,6 +3028,8 @@ int f2fs_flush_nat_entries(struct f2fs_sb_info *sbi, struct cp_control *cpc) up_write(&nm_i->nat_tree_lock); /* Allow dirty nats by node block allocation in write_begin */ +out: + nm_i->flushing_nat = false; return err; } -- 2.22.1