Received: by 2002:a05:6359:c8b:b0:c7:702f:21d4 with SMTP id go11csp3256122rwb; Mon, 19 Sep 2022 18:12:06 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6NAq73CfShxgq4u3mDLKEg50slBO2aDCC7fmGWtC4pZSwN70FQxTZqTEgnjz6IASRpUyRJ X-Received: by 2002:a17:906:9bce:b0:770:2600:2cef with SMTP id de14-20020a1709069bce00b0077026002cefmr14288797ejc.611.1663636326008; Mon, 19 Sep 2022 18:12:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1663636326; cv=none; d=google.com; s=arc-20160816; b=PurBt3R0w5Qr/e4PMU6QGEImV1u7k5p63/WU/uGzHlCeRXS6HVqaPz0NrzZ52JZVuo Mj9I0kjkvLju7lCoISs38DPJXvmkpUDfNFU7BekSN+YNIgrGGtT/9ErDUbpB15yCnPHL K/XShWgAXGNR3cTD9oD5O2WvxzbcbZr5fkp3sIOIVYbyTx6T3HxFFdx+jIb8l22mh7Qk 1YKJag7SE2xU5SB+sv3a0AYnRao/620SA44w3FpS80H5m0D1BZBr29gy33x3smM5DyV6 z5TOa2XRWH9ej0VPZ/kXHn9YXFO3tXvRPK3jqCXfctLVR+XgXLwwdPUNEKxWqk+raYIA Lr7g== 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:cc:to:from:date:dkim-signature; bh=ToPfnxF2NxQ2HGUaHBvaCuziGYRm0Sf9SFgkXvvGB3Q=; b=MP7cN5ZLoKgRv7/3zAnZRgCRrgACSu6VJ1NX0EtliTfzh7MRSeV+KTpUFIuQNw+h3J tyzosTIOhGtYyMieip09ilx9MRRFzOjyuC3JAu3Nn/eubE7Uh67+FLEl2rRcu5fQVF0+ DnTwGr3NNOHRn5EOmgc95+ZXevVfMuypIv3YjW9C6H/Ci9Hi/VTG6YsCuI/anM4cS54t PHM80wlm5ahq7310/uQXqxv5feGmM0SGyyKL2k+CIHf63ZkDu5i0YYb/tWOTUeD+p/Sw euv+OlaPbyjA8vFXt/QsMg00wAiTDAoEPzjqOii0tflQGbML/VKZAnhRPycs78ljYlXD euUQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=Je46AiyU; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id ne18-20020a1709077b9200b0073155c0e7cesi28895770ejc.677.2022.09.19.18.11.40; Mon, 19 Sep 2022 18:12:05 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=Je46AiyU; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 S229619AbiITAu7 (ORCPT + 99 others); Mon, 19 Sep 2022 20:50:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53996 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229471AbiITAu5 (ORCPT ); Mon, 19 Sep 2022 20:50:57 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C709A3A4A3 for ; Mon, 19 Sep 2022 17:50:55 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 6144061C15 for ; Tue, 20 Sep 2022 00:50:55 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 94D37C433D6; Tue, 20 Sep 2022 00:50:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1663635054; bh=yOberSEUqwdenP4n+exju7j3AQ6fgojCHFFpQfJqfKk=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=Je46AiyUGmzY04wq9Golwz6HFn+OrAQtxFRzSKNyTFGArWtb7ykqgHE7oIGhNFS2G 4Unv8apLY8M+VxzCmLlw8sT0TVljgLcZ5NQG6JuzUGeOwh8cgazsinaxP7jiFKnNOP ACh2b6ffK2p1tVTVqn8zhyKkPIHIS78EyaQxVkQdV3eDZ0u3RZBH4yCKHoknUg7z1x sh679JxGCwq+blNutBoUwu8svYvi68eZbhhqVuL3fBlmDALkUCHQSu/2G/ipxUKLPD 0vcW3bYsUrhKrwpOaRrGnDUGfnm23p+P3sgLbwIxMylQCs9e9TVRQdaDoOZ2wC23J3 qWmwYh5sUdc8w== Date: Mon, 19 Sep 2022 17:50:52 -0700 From: Jaegeuk Kim To: Wu Bo Cc: chao@kernel.org, linux-f2fs-devel@lists.sourceforge.net, linux-kernel@vger.kernel.org, Philippe De Muyter Subject: Re: [PATCH 1/1] f2fs: fix to check space of current segment journal Message-ID: References: <20220914040423.539-1-bo.wu@vivo.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20220914040423.539-1-bo.wu@vivo.com> X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 09/14, Wu Bo wrote: > As Philippe De Muyter reported: > https://lore.kernel.org/linux-f2fs-devel/20220913224908.GA25100@172.21.0.10/T/#u > > The warning log showed that when finding a new space for nat the journal > space turned out to be full. This because the journal_rwsem is not > locked before the journal space checking. The journal space may become > full just after we check it. > > Reported-by: Philippe De Muyter > Signed-off-by: Wu Bo > --- > fs/f2fs/node.c | 6 +++--- > fs/f2fs/segment.c | 10 +++++----- > 2 files changed, 8 insertions(+), 8 deletions(-) > > diff --git a/fs/f2fs/node.c b/fs/f2fs/node.c > index e06a0c478b39..971d8b9ccdf1 100644 > --- a/fs/f2fs/node.c > +++ b/fs/f2fs/node.c > @@ -2995,13 +2995,13 @@ static int __flush_nat_entry_set(struct f2fs_sb_info *sbi, > * #1, flush nat entries to journal in current hot data summary block. > * #2, flush nat entries to nat page. > */ > + down_write(&curseg->journal_rwsem); > if ((cpc->reason & CP_UMOUNT) || > !__has_cursum_space(journal, set->entry_cnt, NAT_JOURNAL)) I think this is for NAT which was covered by nat_tree_lock. So, we don't need this under journal_rwsem. > to_journal = false; > > - if (to_journal) { > - down_write(&curseg->journal_rwsem); > - } else { > + if (!to_journal) { > + up_write(&curseg->journal_rwsem); > page = get_next_nat_page(sbi, start_nid); > if (IS_ERR(page)) > return PTR_ERR(page); > diff --git a/fs/f2fs/segment.c b/fs/f2fs/segment.c > index 0de21f82d7bc..d545032d2f6f 100644 > --- a/fs/f2fs/segment.c > +++ b/fs/f2fs/segment.c > @@ -3914,13 +3914,13 @@ int f2fs_lookup_journal_in_cursum(struct f2fs_journal *journal, int type, > if (le32_to_cpu(nid_in_journal(journal, i)) == val) > return i; > } > - if (alloc && __has_cursum_space(journal, 1, NAT_JOURNAL)) > + if (alloc) > return update_nats_in_cursum(journal, 1); > } else if (type == SIT_JOURNAL) { > for (i = 0; i < sits_in_cursum(journal); i++) > if (le32_to_cpu(segno_in_journal(journal, i)) == val) > return i; > - if (alloc && __has_cursum_space(journal, 1, SIT_JOURNAL)) > + if (alloc) > return update_sits_in_cursum(journal, 1); > } > return -1; > @@ -4085,13 +4085,13 @@ void f2fs_flush_sit_entries(struct f2fs_sb_info *sbi, struct cp_control *cpc) > (unsigned long)MAIN_SEGS(sbi)); > unsigned int segno = start_segno; > > + down_write(&curseg->journal_rwsem); > if (to_journal && > !__has_cursum_space(journal, ses->entry_cnt, SIT_JOURNAL)) > to_journal = false; > > - if (to_journal) { > - down_write(&curseg->journal_rwsem); > - } else { > + if (!to_journal) { > + up_write(&curseg->journal_rwsem); > page = get_next_sit_page(sbi, start_segno); > raw_sit = page_address(page); > } > -- > 2.36.1