From: Christoph Hellwig <hch@lst.de>
To: Jaegeuk Kim <jaegeuk@kernel.org>, Chao Yu <chao@kernel.org>
Cc: linux-f2fs-devel@lists.sourceforge.net
Subject: [f2fs-dev] [PATCH 7/8] f2fs: refactor next blk selection
Date: Thu, 19 Jan 2023 07:36:24 +0100 [thread overview]
Message-ID: <20230119063625.466485-8-hch@lst.de> (raw)
In-Reply-To: <20230119063625.466485-1-hch@lst.de>
Remove __refresh_next_blkoff by opencoding the SSR vs LFS segment check
in the only caller, and then add helpers for SSR block selection and
blkoff randomization instead.
Signed-off-by: Christoph Hellwig <hch@lst.de>
---
fs/f2fs/segment.c | 48 +++++++++++++++++++++++------------------------
1 file changed, 23 insertions(+), 25 deletions(-)
diff --git a/fs/f2fs/segment.c b/fs/f2fs/segment.c
index f889f623a59fd6..6f588e440c7575 100644
--- a/fs/f2fs/segment.c
+++ b/fs/f2fs/segment.c
@@ -2616,30 +2616,10 @@ static int __next_free_blkoff(struct f2fs_sb_info *sbi,
return __find_rev_next_zero_bit(target_map, sbi->blocks_per_seg, start);
}
-/*
- * If a segment is written by LFS manner, next block offset is just obtained
- * by increasing the current block offset. However, if a segment is written by
- * SSR manner, next block offset obtained by calling __next_free_blkoff
- */
-static void __refresh_next_blkoff(struct f2fs_sb_info *sbi,
- struct curseg_info *seg)
+static int f2fs_find_next_ssr_block(struct f2fs_sb_info *sbi,
+ struct curseg_info *seg)
{
- if (seg->alloc_type == SSR) {
- seg->next_blkoff =
- __next_free_blkoff(sbi, seg->segno,
- seg->next_blkoff + 1);
- } else {
- seg->next_blkoff++;
- if (F2FS_OPTION(sbi).fs_mode == FS_MODE_FRAGMENT_BLK) {
- /* To allocate block chunks in different sizes, use random number */
- if (--seg->fragment_remained_chunk <= 0) {
- seg->fragment_remained_chunk =
- get_random_u32_inclusive(1, sbi->max_fragment_chunk);
- seg->next_blkoff +=
- get_random_u32_inclusive(1, sbi->max_fragment_hole);
- }
- }
- }
+ return __next_free_blkoff(sbi, seg->segno, seg->next_blkoff + 1);
}
bool f2fs_segment_has_free_slot(struct f2fs_sb_info *sbi, int segno)
@@ -3216,6 +3196,19 @@ static int __get_segment_type(struct f2fs_io_info *fio)
return type;
}
+static void f2fs_randomize_chunk(struct f2fs_sb_info *sbi,
+ struct curseg_info *seg)
+{
+ /* To allocate block chunks in different sizes, use random number */
+ if (--seg->fragment_remained_chunk > 0)
+ return;
+
+ seg->fragment_remained_chunk =
+ get_random_u32_inclusive(1, sbi->max_fragment_chunk);
+ seg->next_blkoff +=
+ get_random_u32_inclusive(1, sbi->max_fragment_hole);
+}
+
void f2fs_allocate_data_block(struct f2fs_sb_info *sbi, struct page *page,
block_t old_blkaddr, block_t *new_blkaddr,
struct f2fs_summary *sum, int type,
@@ -3245,8 +3238,13 @@ void f2fs_allocate_data_block(struct f2fs_sb_info *sbi, struct page *page,
f2fs_wait_discard_bio(sbi, *new_blkaddr);
curseg->sum_blk->entries[curseg->next_blkoff] = *sum;
- __refresh_next_blkoff(sbi, curseg);
-
+ if (curseg->alloc_type == SSR) {
+ curseg->next_blkoff = f2fs_find_next_ssr_block(sbi, curseg);
+ } else {
+ curseg->next_blkoff++;
+ if (F2FS_OPTION(sbi).fs_mode == FS_MODE_FRAGMENT_BLK)
+ f2fs_randomize_chunk(sbi, curseg);
+ }
stat_inc_block_count(sbi, curseg);
if (from_gc) {
--
2.39.0
_______________________________________________
Linux-f2fs-devel mailing list
Linux-f2fs-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
next prev parent reply other threads:[~2023-01-19 6:36 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-01-19 6:36 [f2fs-dev] misc f2fs cleanups Christoph Hellwig
2023-01-19 6:36 ` [f2fs-dev] [PATCH 1/8] f2fs: remove __add_sum_entry Christoph Hellwig
2023-01-29 10:29 ` Chao Yu
2023-01-31 19:10 ` patchwork-bot+f2fs
2023-01-19 6:36 ` [f2fs-dev] [PATCH 2/8] f2fs: simplify do_checkpoint Christoph Hellwig
2023-01-29 10:30 ` Chao Yu
2023-01-19 6:36 ` [f2fs-dev] [PATCH 3/8] f2fs: add a f2fs_curseg_valid_blocks helper Christoph Hellwig
2023-01-29 10:34 ` Chao Yu
2023-01-19 6:36 ` [f2fs-dev] [PATCH 4/8] f2fs: factor the read/write tracing logic into a helper Christoph Hellwig
2023-01-29 10:36 ` Chao Yu
2023-01-30 23:00 ` Jaegeuk Kim
2023-01-19 6:36 ` [f2fs-dev] [PATCH 5/8] f2fs: refactor __allocate_new_segment Christoph Hellwig
2023-01-29 10:39 ` Chao Yu
2023-01-19 6:36 ` [f2fs-dev] [PATCH 6/8] f2fs: remove __allocate_new_section Christoph Hellwig
2023-01-29 10:39 ` Chao Yu
2023-01-19 6:36 ` Christoph Hellwig [this message]
2023-01-29 12:20 ` [f2fs-dev] [PATCH 7/8] f2fs: refactor next blk selection Chao Yu
2023-01-19 6:36 ` [f2fs-dev] [PATCH 8/8] f2fs: remove __has_curseg_space Christoph Hellwig
2023-01-29 12:24 ` Chao Yu
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20230119063625.466485-8-hch@lst.de \
--to=hch@lst.de \
--cc=chao@kernel.org \
--cc=jaegeuk@kernel.org \
--cc=linux-f2fs-devel@lists.sourceforge.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).