From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B63C143F0B9 for ; Wed, 12 Aug 2026 12:20:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786537215; cv=none; b=QwwwNjv+zUSU1gW6N84A9WPvncy9kQGAI5QsOoBSf4i6p8spuXDNSVcGCX7tiMcWE8iAp9SOf6vY1u6SWzCPziFe4KOFvaWmsJjLZ4bftmwHS1AAM1z54UNZgOof714BROxy/r//v9YHjkyqcqUCM7XK+kOwTtHYHX7D/7xPSMs= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786537215; c=relaxed/simple; bh=9ws1VShoNxtXE/BLulxRYr+8/nIc0mzSxEFntkeoumw=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=acjL7l2nLZp2PxawkU1nv4/QJuJr2GJs1fkSeJYa6vtSd50J10yJNi3s1nBzE9JqNl4Dx1yeijuX9J52HrYMGxR0fvLr/ngxfCv+Uo+a33UAD1AWanTmMoBdD8RH8ZiPXugJyJu97Rtmm3zpmqckrpxwnUwUfuK+datrUoze58o= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Vl6MVA8V; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="Vl6MVA8V" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 85E1B1F000E9; Wed, 12 Aug 2026 12:20:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1786537214; bh=kBvtiGkOJWWQsGUHGWeWsAhMq9zLGNVvWwsNlkdT6+Y=; h=From:To:Cc:Subject:Date; b=Vl6MVA8V4rP5BNPA6BSnX4PUSVXEA2ZH/pEYHkZvAWh4F/dHuFLZhw7SBZ0oEdHma cTE2dGzm+B/Wt92LqAqLwUv+fyjHHjC28/hjLdTrNz8d9zrXVNV8u4pR1IZs88xRJn GwAx22UevfMeHMwhyEnqrfhDdOBwnswWqNaBC6FVFs8qx3f9ZK8TDaXOKcnL70o2rs dXEJYi5NUdnSIAcFd//A9bnfRn6YlpFD6TIBUOZqq0Mhog21ULWYD0Cm1IE6uWLAH4 osxaJBOrnRyKCOvDfSjev+TqIpGoTIaaih9ZBXHbsB3NuQOJnVVzFf76nCjUoa5vci KNnZoZt7YeMOQ== From: Chao Yu To: jaegeuk@kernel.org Cc: linux-f2fs-devel@lists.sourceforge.net, linux-kernel@vger.kernel.org, Chao Yu Subject: [PATCH 1/2] f2fs: cleanup w/ f2fs_need_rand_{blk,seg,seg_blk} Date: Wed, 12 Aug 2026 12:20:07 +0000 Message-ID: <20260812122008.281434-1-chao@kernel.org> X-Mailer: git-send-email 2.55.0.679.g6767b8d81c-goog Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit No logic changes. Signed-off-by: Chao Yu --- fs/f2fs/f2fs.h | 13 +++++++++++-- fs/f2fs/gc.c | 2 +- fs/f2fs/segment.c | 8 ++++---- fs/f2fs/super.c | 4 ++-- 4 files changed, 18 insertions(+), 9 deletions(-) diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h index 5e4242e37238..069fe6537160 100644 --- a/fs/f2fs/f2fs.h +++ b/fs/f2fs/f2fs.h @@ -4146,10 +4146,19 @@ static inline struct inode *fio_inode(struct f2fs_io_info *fio) #define MIN_FRAGMENT_SIZE 1 #define MAX_FRAGMENT_SIZE 512 +static inline bool f2fs_need_rand_blk(struct f2fs_sb_info *sbi) +{ + return F2FS_OPTION(sbi).fs_mode == FS_MODE_FRAGMENT_BLK; +} + static inline bool f2fs_need_rand_seg(struct f2fs_sb_info *sbi) { - return F2FS_OPTION(sbi).fs_mode == FS_MODE_FRAGMENT_SEG || - F2FS_OPTION(sbi).fs_mode == FS_MODE_FRAGMENT_BLK; + return F2FS_OPTION(sbi).fs_mode == FS_MODE_FRAGMENT_SEG; +} + +static inline bool f2fs_need_rand_seg_blk(struct f2fs_sb_info *sbi) +{ + return f2fs_need_rand_blk(sbi) || f2fs_need_rand_seg(sbi); } /* diff --git a/fs/f2fs/gc.c b/fs/f2fs/gc.c index 2f97a7a98517..e6758adc5da1 100644 --- a/fs/f2fs/gc.c +++ b/fs/f2fs/gc.c @@ -310,7 +310,7 @@ static void select_policy(struct f2fs_sb_info *sbi, int gc_type, p->max_search = sbi->max_victim_search; /* let's select beginning hot/small space first. */ - if (f2fs_need_rand_seg(sbi)) { + if (f2fs_need_rand_seg_blk(sbi)) { p->offset = get_random_u32_below(MAIN_SECS(sbi) * SEGS_PER_SEC(sbi)); SIT_I(sbi)->last_victim[p->gc_mode] = p->offset; diff --git a/fs/f2fs/segment.c b/fs/f2fs/segment.c index e202b583a5db..9e0b6776341c 100644 --- a/fs/f2fs/segment.c +++ b/fs/f2fs/segment.c @@ -3055,7 +3055,7 @@ static unsigned int __get_next_segno(struct f2fs_sb_info *sbi, int type) sanity_check_seg_type(sbi, seg_type); if (__is_large_section(sbi)) { - if (f2fs_need_rand_seg(sbi)) { + if (f2fs_need_rand_seg_blk(sbi)) { unsigned int hint = GET_SEC_FROM_SEG(sbi, curseg->segno); if (GET_SEC_FROM_SEG(sbi, curseg->segno + 1) != hint) @@ -3064,7 +3064,7 @@ static unsigned int __get_next_segno(struct f2fs_sb_info *sbi, int type) GET_SEG_FROM_SEC(sbi, hint + 1) - 1); } return curseg->segno; - } else if (f2fs_need_rand_seg(sbi)) { + } else if (f2fs_need_rand_seg_blk(sbi)) { return get_random_u32_below(MAIN_SECS(sbi) * SEGS_PER_SEC(sbi)); } @@ -3120,7 +3120,7 @@ static int new_curseg(struct f2fs_sb_info *sbi, int type, bool new_sec) curseg->next_segno = segno; reset_curseg(sbi, type, 1); curseg->alloc_type = LFS; - if (F2FS_OPTION(sbi).fs_mode == FS_MODE_FRAGMENT_BLK) + if (f2fs_need_rand_blk(sbi)) curseg->fragment_remained_chunk = get_random_u32_inclusive(1, sbi->max_fragment_chunk); return 0; @@ -3939,7 +3939,7 @@ int f2fs_allocate_data_block(struct f2fs_sb_info *sbi, struct folio *folio, curseg->next_blkoff = f2fs_find_next_ssr_block(sbi, curseg); } else { curseg->next_blkoff++; - if (F2FS_OPTION(sbi).fs_mode == FS_MODE_FRAGMENT_BLK) + if (f2fs_need_rand_blk(sbi)) f2fs_randomize_chunk(sbi, curseg); } if (curseg->next_blkoff >= f2fs_usable_blks_in_seg(sbi, curseg->segno)) diff --git a/fs/f2fs/super.c b/fs/f2fs/super.c index fa4a7a7288d5..8dd656a7d3dc 100644 --- a/fs/f2fs/super.c +++ b/fs/f2fs/super.c @@ -2457,9 +2457,9 @@ static int f2fs_show_options(struct seq_file *seq, struct dentry *root) seq_puts(seq, "adaptive"); else if (F2FS_OPTION(sbi).fs_mode == FS_MODE_LFS) seq_puts(seq, "lfs"); - else if (F2FS_OPTION(sbi).fs_mode == FS_MODE_FRAGMENT_SEG) + else if (f2fs_need_rand_seg(sbi)) seq_puts(seq, "fragment:segment"); - else if (F2FS_OPTION(sbi).fs_mode == FS_MODE_FRAGMENT_BLK) + else if (f2fs_need_rand_blk(sbi)) seq_puts(seq, "fragment:block"); seq_printf(seq, ",active_logs=%u", F2FS_OPTION(sbi).active_logs); if (test_opt(sbi, RESERVE_ROOT) || test_opt(sbi, RESERVE_NODE)) -- 2.49.0