Received: by 2002:a05:7412:8d10:b0:f3:1519:9f41 with SMTP id bj16csp4286366rdb; Mon, 11 Dec 2023 14:48:35 -0800 (PST) X-Google-Smtp-Source: AGHT+IFMXGvGPXpljMGUcdBn63fF6rC1kdeiJ3LWCz3NbwQqVRYW4BPNz4oy4BopMs7aEfULpBLE X-Received: by 2002:a17:903:1206:b0:1d0:7d9a:3bca with SMTP id l6-20020a170903120600b001d07d9a3bcamr6525231plh.52.1702334915693; Mon, 11 Dec 2023 14:48:35 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702334915; cv=none; d=google.com; s=arc-20160816; b=YmTyyatuWfFBBsplYTDyEXD7q5a098iV7uZLArNLpJ6eVOuxLpiI0g3CcL1oXQL4F3 0dJ3oFVt6e53IldTbwUYvorcTuKDdU47AZT4uKd5B1vimVZf1t94Q4VKhgAEqrGHwHfv oIqgznVwcUJg1PCZX9nZ0NGalp1KzewKux3pKK7es9k6i5V17UnPw/J7ApiwFx7QzQ10 5pFPO/EXjfkm5sTbsnU5/v3ympQlBYjpE0nJ0dpzIwwlxLl4d2lmpYXYjPwEyadQyDr2 0hBKT5slvrLjzGQ5oadVrWFgYtWIHM1LQTeQR9+0k1qaLb1utmxEdXcxM5i+L1mN+9PL JoSg== 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=UbHdz3I7p00C/04trgrJWlXNUG3QkB/8qEyuJ25b/+0=; fh=QkmKqaC9l6H2vgX4LhceBKmzQ6ofqCyO72v5dpq4Ybs=; b=dZT5ABaC752Dp8n6qwzxFRs89ICL/OXwTIpDLDlHRmiEdj7vk5VmxfH2fIESxIe1d0 gWhbARWqF0bN5v0iYGB5os9/I7zHHcnaBLiwMa5my7QdwUFl5m+ubap0Foao0Xr75bI5 lE3TYVCcwwaiy3l27inxyPE2lOLL6Cjq4BtwFhVbuFWVlkk8yc3NI3/soLbRM/M3P8f0 c/z6Pin+qvMh+m4GU+rPV2c42HPvkmbzRH3gIcySryFm/rD+QDvLH/TQrDORQIWpNONj hTgm0jfxOzCsaSeFuh2PUn5zK/u+yIDZIzc6vHkIxyHRjdDlr2UoOL97asHBfOwRCchw RDog== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=S34qGgIX; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 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 snail.vger.email (snail.vger.email. [23.128.96.37]) by mx.google.com with ESMTPS id f11-20020a170902e98b00b001cf8d316dfcsi6677809plb.236.2023.12.11.14.48.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 Dec 2023 14:48:35 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) client-ip=23.128.96.37; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=S34qGgIX; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id 7C17D80A9911; Mon, 11 Dec 2023 14:48:34 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235097AbjLKWsZ (ORCPT + 99 others); Mon, 11 Dec 2023 17:48:25 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51614 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235058AbjLKWsL (ORCPT ); Mon, 11 Dec 2023 17:48:11 -0500 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 57870F1 for ; Mon, 11 Dec 2023 14:47:46 -0800 (PST) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0F5A4C433C8; Mon, 11 Dec 2023 22:47:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1702334866; bh=34tnQX9ctCBczkyhWp459H2RBzFpA5vSI+uY7xIEEhs=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=S34qGgIX+VOjSl98nrnGR6MzsYZbUiNVAeKCJ4TrF1uISKJo36bMCBAnzoOzmMGr7 oZBhmXvFJjCPIF31qM0WRkPrZBRd9EoXcdtWX4Mt9gQ7TGkBFwzT2eVR3MnZaVgq/4 YOfemhdPwNmj+9FyecWIQ9/R7tb7AKsn4V67Q9dYC8ZcIOxT4v7GuOMKHvYe++sPjw wF3SugfP0GUB58TxxivrkSYlst/FPKtBY/frIq1hx7PIcL+wmnLgqHQkKlg1d1Mext xLjYgMbzs2sCKz05QdN1lyNOOPrPlG/7FWoeiNbfgLMI9/u/qPEESUxtnJYCTyuj1i RwVzFJkNe1rgA== Date: Mon, 11 Dec 2023 14:47:44 -0800 From: Jaegeuk Kim To: Yonggil Song Cc: "chao@kernel.org" , "linux-f2fs-devel@lists.sourceforge.net" , "linux-kernel@vger.kernel.org" , Seokhwan Kim , Daejun Park , Siwoo Jung Subject: Re: [PATCH v2] f2fs: New victim selection for GC Message-ID: References: <20231208090444epcms2p33884216391931d04c1771dfb51a08a44@epcms2p3> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20231208090444epcms2p33884216391931d04c1771dfb51a08a44@epcms2p3> X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE 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 X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Mon, 11 Dec 2023 14:48:34 -0800 (PST) On 12/08, Yonggil Song wrote: > Overview > ======== > > This patch introduces a new way to preference data sections when selecting > GC victims. Migration of data blocks causes invalidation of node blocks. > Therefore, in situations where GC is frequent, selecting data blocks as > victims can reduce unnecessary block migration by invalidating node blocks. > For exceptional situations where free sections are insufficient, node blocks > are selected as victims instead of data blocks to get extra free sections. > > Problem > ======= > > If the total amount of nodes is larger than the size of one section, nodes > occupy multiple sections, and node victims are often selected because the > gc cost is lowered by data block migration in GC. Since moving the data > section causes frequent node victim selection, victim threshing occurs in > the node section. This results in an increase in WAF. > > Experiment > ========== > > Test environment is as follows. > > System info > - 3.6GHz, 16 core CPU > - 36GiB Memory > Device info > - a conventional null_blk with 228MiB > - a sequential null_blk with 4068 zones of 8MiB > Format > - mkfs.f2fs -c -m -Z 8 -o 3.89 > Mount > - mount > Fio script > - fio --rw=randwrite --bs=4k --ba=4k --filesize=31187m --norandommap --overwrite=1 --name=job1 --filename=./mnt/sustain --io_size=128g > WAF calculation > - (IOs on conv. null_blk + IOs on seq. null_blk) / random write IOs > > Conclusion > ========== > > This experiment showed that the WAF was reduced by 29% (18.75 -> 13.3) when > the data section was selected first when selecting GC victims. This was > achieved by reducing the migration of the node blocks by 69.4% > (253,131,743 blks -> 77,463,278 blks). It is possible to achieve low WAF > performance with the GC victim selection method in environments where the > section size is relatively small. > > Signed-off-by: Yonggil Song > --- > fs/f2fs/f2fs.h | 1 + > fs/f2fs/gc.c | 98 ++++++++++++++++++++++++++++++++++++++------------ > 2 files changed, 77 insertions(+), 22 deletions(-) > > diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h > index 9043cedfa12b..578d57f6022f 100644 > --- a/fs/f2fs/f2fs.h > +++ b/fs/f2fs/f2fs.h > @@ -1649,6 +1649,7 @@ struct f2fs_sb_info { > struct f2fs_mount_info mount_opt; /* mount options */ > > /* for cleaning operations */ > + bool need_node_clean; /* need to clean dirty nodes */ > struct f2fs_rwsem gc_lock; /* > * semaphore for GC, avoid > * race between GC and GC or CP > diff --git a/fs/f2fs/gc.c b/fs/f2fs/gc.c > index f550cdeaa663..682dcf0de59e 100644 > --- a/fs/f2fs/gc.c > +++ b/fs/f2fs/gc.c > @@ -368,6 +368,14 @@ static inline unsigned int get_gc_cost(struct f2fs_sb_info *sbi, > if (p->alloc_mode == SSR) > return get_seg_entry(sbi, segno)->ckpt_valid_blocks; > > + /* > + * If we don't need to clean dirty nodes, > + * we just skip node victims. > + */ > + if (IS_NODESEG(get_seg_entry(sbi, segno)->type) && > + !sbi->need_node_clean) > + return get_max_cost(sbi, p); How about differentiating the gc cost between data vs. node by adding some weights? By default, data is preferred, while node is better in the worst case? > + > /* alloc_mode == LFS */ > if (p->gc_mode == GC_GREEDY) > return get_valid_blocks(sbi, segno, true); > @@ -557,6 +565,14 @@ static void atgc_lookup_victim(struct f2fs_sb_info *sbi, > if (ve->mtime >= max_mtime || ve->mtime < min_mtime) > goto skip; > > + /* > + * If we don't need to clean dirty nodes, > + * we just skip node victims. > + */ > + if (IS_NODESEG(get_seg_entry(sbi, ve->segno)->type) && > + !sbi->need_node_clean) > + goto skip; > + > /* age = 10000 * x% * 60 */ > age = div64_u64(accu * (max_mtime - ve->mtime), total_time) * > age_weight; > @@ -913,7 +929,21 @@ int f2fs_get_victim(struct f2fs_sb_info *sbi, unsigned int *result, > goto retry; > } > > + > if (p.min_segno != NULL_SEGNO) { > + if (sbi->need_node_clean && > + IS_DATASEG(get_seg_entry(sbi, p.min_segno)->type)) { > + /* > + * we need to clean node sections. > + * but, data victim cost is the lowest. > + * if free sections are enough, stop cleaning node victim. > + * if not, it goes on by GCing data victims. > + */ > + if (has_enough_free_secs(sbi, prefree_segments(sbi), 0)) { > + p.min_segno = NULL_SEGNO; > + goto out; > + } > + } > got_it: > *result = (p.min_segno / p.ofs_unit) * p.ofs_unit; > got_result: > @@ -1830,8 +1860,27 @@ int f2fs_gc(struct f2fs_sb_info *sbi, struct f2fs_gc_control *gc_control) > goto stop; > } > > + __get_secs_required(sbi, NULL, &upper_secs, NULL); > + > + /* > + * Write checkpoint to reclaim prefree segments. > + * We need more three extra sections for writer's data/node/dentry. > + */ > + if (free_sections(sbi) <= upper_secs + NR_GC_CHECKPOINT_SECS) { > + sbi->need_node_clean = true; > + > + if (prefree_segments(sbi)) { > + stat_inc_cp_call_count(sbi, TOTAL_CALL); > + ret = f2fs_write_checkpoint(sbi, &cpc); > + if (ret) > + goto stop; > + /* Reset due to checkpoint */ > + sec_freed = 0; > + } > + } > + > /* Let's run FG_GC, if we don't have enough space. */ > - if (has_not_enough_free_secs(sbi, 0, 0)) { > + if (gc_type == BG_GC && has_not_enough_free_secs(sbi, 0, 0)) { > gc_type = FG_GC; > > /* > @@ -1858,10 +1907,22 @@ int f2fs_gc(struct f2fs_sb_info *sbi, struct f2fs_gc_control *gc_control) > ret = __get_victim(sbi, &segno, gc_type); > if (ret) { > /* allow to search victim from sections has pinned data */ > - if (ret == -ENODATA && gc_type == FG_GC && > - f2fs_pinned_section_exists(DIRTY_I(sbi))) { > - f2fs_unpin_all_sections(sbi, false); > - goto retry; > + if (ret == -ENODATA && gc_type == FG_GC) { > + if (f2fs_pinned_section_exists(DIRTY_I(sbi))) { > + f2fs_unpin_all_sections(sbi, false); > + goto retry; > + } > + /* > + * If we have no more data victims, let's start to > + * clean dirty nodes. > + */ > + if (!sbi->need_node_clean) { > + sbi->need_node_clean = true; > + goto retry; > + } > + /* node cleaning is over */ > + else if (sbi->need_node_clean) > + goto stop; > } > goto stop; > } > @@ -1882,7 +1943,13 @@ int f2fs_gc(struct f2fs_sb_info *sbi, struct f2fs_gc_control *gc_control) > if (!gc_control->no_bg_gc && > total_sec_freed < gc_control->nr_free_secs) > goto go_gc_more; > - goto stop; > + /* > + * If the need_node_clean flag is set > + * even though there are enough free > + * sections, node cleaning will continue. > + */ > + if (!sbi->need_node_clean) > + goto stop; > } > if (sbi->skipped_gc_rwsem) > skipped_round++; > @@ -1897,21 +1964,6 @@ int f2fs_gc(struct f2fs_sb_info *sbi, struct f2fs_gc_control *gc_control) > goto stop; > } > > - __get_secs_required(sbi, NULL, &upper_secs, NULL); > - > - /* > - * Write checkpoint to reclaim prefree segments. > - * We need more three extra sections for writer's data/node/dentry. > - */ > - if (free_sections(sbi) <= upper_secs + NR_GC_CHECKPOINT_SECS && > - prefree_segments(sbi)) { > - stat_inc_cp_call_count(sbi, TOTAL_CALL); > - ret = f2fs_write_checkpoint(sbi, &cpc); > - if (ret) > - goto stop; > - /* Reset due to checkpoint */ > - sec_freed = 0; > - } > go_gc_more: > segno = NULL_SEGNO; > goto gc_more; > @@ -1920,8 +1972,10 @@ int f2fs_gc(struct f2fs_sb_info *sbi, struct f2fs_gc_control *gc_control) > SIT_I(sbi)->last_victim[ALLOC_NEXT] = 0; > SIT_I(sbi)->last_victim[FLUSH_DEVICE] = gc_control->victim_segno; > > - if (gc_type == FG_GC) > + if (gc_type == FG_GC) { > f2fs_unpin_all_sections(sbi, true); > + sbi->need_node_clean = false; > + } > > trace_f2fs_gc_end(sbi->sb, ret, total_freed, total_sec_freed, > get_pages(sbi, F2FS_DIRTY_NODES), > -- > 2.34.1