Received: by 2002:a05:6358:11c7:b0:104:8066:f915 with SMTP id i7csp695423rwl; Fri, 24 Mar 2023 00:12:46 -0700 (PDT) X-Google-Smtp-Source: AK7set/Zhxbx/ujFDSABxWx+8ZD7HGjVhJWw6i+5sVAAT4JKXzYPYQfTO9Bl5suSWaRp/e4dU1i0 X-Received: by 2002:a05:6a20:4694:b0:d9:6a23:f51 with SMTP id el20-20020a056a20469400b000d96a230f51mr1564224pzb.21.1679641966168; Fri, 24 Mar 2023 00:12:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1679641966; cv=none; d=google.com; s=arc-20160816; b=Uvf4q/i14saJOWY5Nwz/BUbGWk3AGhz47tugTl4T+KXuy6C+gr5QHFD3Yw6skulCof McPGnTWEQCNpmN/ruZnDJuyRW0EPzsPlADo9Kwb+uyINYKALxjJ0dkqnXZ8I1ynsDHBt UhHBkZnkz4AXpmMTiMkjNsoNO2VTVNiYYwbiDRCosdNLUuf1bY/MbMuGk43xlGrjlHSd yCuBNtJK+XmWoocT27hcFwqmxa65OkgPEBzEGspUGNvQOggD9HZWfiZ3m5UkX/P2+heX dPDrQqjrDHYnsJsWkKn5+cxASi+URDw1C5vjBXtLkPhqUGWO2SVd1lmS43krJuivC0uF RJZA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=ZETkEfKj2/0zNH33wFebpLM6CNBk0DcgJ8ub7BAvqpE=; b=izI5Vu4aS1cHdnNS/x/8xaawosnOpv9Mq/FPSq2ME3LEbu/FJIzDnn0s7P/NqJS6sT IIOUAMReR5jY9B90drDtpriLXwZNHAm0eQ1XNJrrlXkiaQcNiDUh6vRJmKLZVr7hIA6V q5uffP7+reMJDOGLZLy5jXU8g5VLrX+2U34ypRGg3M1CAzXUtEsMuWt5cIJWoz/kmcxg CJJpdOdG05bba2dKuVe1eY05Km1J+RvMjZTS908AVozjxTYPJXcAeOr7JIGbFCG4WKgA dMh7F8AH7baq45EGseOGxWALBw/hjEqLwmuFDnB3b1kF11LNCj5QtYAB8xo9fBQzC2CT JE1A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=Ifgg7zI5; 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 m10-20020a654c8a000000b00508e498d8f3si20816665pgt.372.2023.03.24.00.12.34; Fri, 24 Mar 2023 00:12:46 -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=Ifgg7zI5; 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 S230021AbjCXHLi (ORCPT + 99 others); Fri, 24 Mar 2023 03:11:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56414 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229522AbjCXHLh (ORCPT ); Fri, 24 Mar 2023 03:11:37 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7C65D25BBA for ; Fri, 24 Mar 2023 00:11:35 -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 ams.source.kernel.org (Postfix) with ESMTPS id 152CDB82178 for ; Fri, 24 Mar 2023 07:11:34 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id A0639C433EF; Fri, 24 Mar 2023 07:11:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1679641892; bh=fd449v8qUAZkDHI6JVneORMPbA4ytiODmJnf767Az2E=; h=From:To:Cc:Subject:Date:From; b=Ifgg7zI5WbqRt/wqU+zoY5M6knul1KM3tbF0F9zWBh/P/F0IUZoA9U0oA8fJLKqe7 XFu7rjzuhLE0JGqH5oTfrqQNn3akT63mR4zyes68LX5vvspHXTFAAE6VTP1+HwX1ai 6o/ZQ7DDwUOX1YVudxWf0iQUWdDZM4wEAUNkPPGqFabR7y9xGIULR1Nq2rd0eKXwP/ OLM3xaXi9QdTa+TQLOwIKvifuaPlCBCQwGHcDNFx1BN3HPmm1x4F3svRGykC/4S1W/ mL682Ozy7WyDe40UAdex1veILvNgqTaN8aVQe/cZaogmNTU4W67Emo6fZbLQ5822I9 l6nWibBrt4IwQ== From: Chao Yu To: jaegeuk@kernel.org Cc: linux-f2fs-devel@lists.sourceforge.net, linux-kernel@vger.kernel.org, Chao Yu Subject: [PATCH] f2fs: fix to trigger a checkpoint in the end of foreground garbage collection Date: Fri, 24 Mar 2023 15:10:28 +0800 Message-Id: <20230324071028.336982-1-chao@kernel.org> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-5.2 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI,SPF_HELO_NONE, SPF_PASS autolearn=unavailable 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 In order to reclaim free blocks in prefree sections before latter use. Fixes: 6f8d4455060d ("f2fs: avoid fi->i_gc_rwsem[WRITE] lock in f2fs_gc") Signed-off-by: Chao Yu --- fs/f2fs/f2fs.h | 1 + fs/f2fs/gc.c | 8 ++++++++ fs/f2fs/segment.c | 1 + 3 files changed, 10 insertions(+) diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h index 53a005b420cf..b1515375cb4c 100644 --- a/fs/f2fs/f2fs.h +++ b/fs/f2fs/f2fs.h @@ -1269,6 +1269,7 @@ struct f2fs_gc_control { unsigned int victim_segno; /* target victim segment number */ int init_gc_type; /* FG_GC or BG_GC */ bool no_bg_gc; /* check the space and stop bg_gc */ + bool reclaim_space; /* trigger checkpoint to reclaim space */ bool should_migrate_blocks; /* should migrate blocks */ bool err_gc_skipped; /* return EAGAIN if GC skipped */ unsigned int nr_free_secs; /* # of free sections to do GC */ diff --git a/fs/f2fs/gc.c b/fs/f2fs/gc.c index 2996d38aa89c..5a451d3d512d 100644 --- a/fs/f2fs/gc.c +++ b/fs/f2fs/gc.c @@ -132,6 +132,7 @@ static int gc_thread_func(void *data) gc_control.init_gc_type = sync_mode ? FG_GC : BG_GC; gc_control.no_bg_gc = foreground; + gc_control.reclaim_space = foreground; gc_control.nr_free_secs = foreground ? 1 : 0; /* if return value is not zero, no victim was selected */ @@ -1880,6 +1881,13 @@ int f2fs_gc(struct f2fs_sb_info *sbi, struct f2fs_gc_control *gc_control) (gc_type == FG_GC) ? sec_freed : 0, 0)) { if (gc_type == FG_GC && sec_freed < gc_control->nr_free_secs) goto go_gc_more; + + /* + * trigger a checkpoint in the end of foreground garbage + * collection. + */ + if (gc_control->reclaim_space) + ret = f2fs_write_checkpoint(sbi, &cpc); goto stop; } diff --git a/fs/f2fs/segment.c b/fs/f2fs/segment.c index 6c11789da884..b62af2ae1685 100644 --- a/fs/f2fs/segment.c +++ b/fs/f2fs/segment.c @@ -421,6 +421,7 @@ void f2fs_balance_fs(struct f2fs_sb_info *sbi, bool need) .victim_segno = NULL_SEGNO, .init_gc_type = BG_GC, .no_bg_gc = true, + .reclaim_space = true, .should_migrate_blocks = false, .err_gc_skipped = false, .nr_free_secs = 1 }; -- 2.25.1