* [f2fs-dev] segment allocation cleanups
@ 2022-11-28 9:43 Christoph Hellwig
2022-11-28 9:43 ` [f2fs-dev] [PATCH 1/3] f2fs: remove struct segment_allocation default_salloc_ops Christoph Hellwig
` (3 more replies)
0 siblings, 4 replies; 8+ messages in thread
From: Christoph Hellwig @ 2022-11-28 9:43 UTC (permalink / raw)
To: Jaegeuk Kim, Chao Yu; +Cc: linux-f2fs-devel
Hi Jaegeuk and Chao,
this series cleans up the segment allocation code a bit.
Diffstat
segment.c | 71 ++++++++++++++++++++++++++------------------------------------
segment.h | 6 -----
2 files changed, 30 insertions(+), 47 deletions(-)
_______________________________________________
Linux-f2fs-devel mailing list
Linux-f2fs-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
^ permalink raw reply [flat|nested] 8+ messages in thread
* [f2fs-dev] [PATCH 1/3] f2fs: remove struct segment_allocation default_salloc_ops
2022-11-28 9:43 [f2fs-dev] segment allocation cleanups Christoph Hellwig
@ 2022-11-28 9:43 ` Christoph Hellwig
2022-12-08 13:55 ` Chao Yu
2022-11-28 9:43 ` [f2fs-dev] [PATCH 2/3] f2fs: open code allocate_segment_by_default Christoph Hellwig
` (2 subsequent siblings)
3 siblings, 1 reply; 8+ messages in thread
From: Christoph Hellwig @ 2022-11-28 9:43 UTC (permalink / raw)
To: Jaegeuk Kim, Chao Yu; +Cc: linux-f2fs-devel
There is only single instance of these ops, so remove the indirection
and call allocate_segment_by_default directly.
Signed-off-by: Christoph Hellwig <hch@lst.de>
---
fs/f2fs/segment.c | 11 ++---------
fs/f2fs/segment.h | 6 ------
2 files changed, 2 insertions(+), 15 deletions(-)
diff --git a/fs/f2fs/segment.c b/fs/f2fs/segment.c
index 371d0aa6fc5baf..714f9114d9aac0 100644
--- a/fs/f2fs/segment.c
+++ b/fs/f2fs/segment.c
@@ -2913,7 +2913,7 @@ static void __allocate_new_segment(struct f2fs_sb_info *sbi, int type,
return;
alloc:
old_segno = curseg->segno;
- SIT_I(sbi)->s_ops->allocate_segment(sbi, type, true);
+ allocate_segment_by_default(sbi, type, true);
locate_dirty_segment(sbi, old_segno);
}
@@ -2944,10 +2944,6 @@ void f2fs_allocate_new_segments(struct f2fs_sb_info *sbi)
f2fs_up_read(&SM_I(sbi)->curseg_lock);
}
-static const struct segment_allocation default_salloc_ops = {
- .allocate_segment = allocate_segment_by_default,
-};
-
bool f2fs_exist_trim_candidates(struct f2fs_sb_info *sbi,
struct cp_control *cpc)
{
@@ -3272,7 +3268,7 @@ void f2fs_allocate_data_block(struct f2fs_sb_info *sbi, struct page *page,
get_atssr_segment(sbi, type, se->type,
AT_SSR, se->mtime);
else
- sit_i->s_ops->allocate_segment(sbi, type, false);
+ allocate_segment_by_default(sbi, type, false);
}
/*
* segment dirty status should be updated after segment allocation,
@@ -4258,9 +4254,6 @@ static int build_sit_info(struct f2fs_sb_info *sbi)
return -ENOMEM;
#endif
- /* init SIT information */
- sit_i->s_ops = &default_salloc_ops;
-
sit_i->sit_base_addr = le32_to_cpu(raw_super->sit_blkaddr);
sit_i->sit_blocks = sit_segs << sbi->log_blocks_per_seg;
sit_i->written_valid_blocks = 0;
diff --git a/fs/f2fs/segment.h b/fs/f2fs/segment.h
index 95b2b104da395b..d97afd2496a22c 100644
--- a/fs/f2fs/segment.h
+++ b/fs/f2fs/segment.h
@@ -222,10 +222,6 @@ struct sec_entry {
unsigned int valid_blocks; /* # of valid blocks in a section */
};
-struct segment_allocation {
- void (*allocate_segment)(struct f2fs_sb_info *, int, bool);
-};
-
#define MAX_SKIP_GC_COUNT 16
struct revoke_entry {
@@ -235,8 +231,6 @@ struct revoke_entry {
};
struct sit_info {
- const struct segment_allocation *s_ops;
-
block_t sit_base_addr; /* start block address of SIT area */
block_t sit_blocks; /* # of blocks used by SIT area */
block_t written_valid_blocks; /* # of valid blocks in main area */
--
2.30.2
_______________________________________________
Linux-f2fs-devel mailing list
Linux-f2fs-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [f2fs-dev] [PATCH 2/3] f2fs: open code allocate_segment_by_default
2022-11-28 9:43 [f2fs-dev] segment allocation cleanups Christoph Hellwig
2022-11-28 9:43 ` [f2fs-dev] [PATCH 1/3] f2fs: remove struct segment_allocation default_salloc_ops Christoph Hellwig
@ 2022-11-28 9:43 ` Christoph Hellwig
2022-12-08 14:36 ` Chao Yu
2022-11-28 9:43 ` [f2fs-dev] [PATCH 3/3] f2fs: remove the unused flush argument to change_curseg Christoph Hellwig
2022-11-28 21:14 ` [f2fs-dev] segment allocation cleanups Jaegeuk Kim
3 siblings, 1 reply; 8+ messages in thread
From: Christoph Hellwig @ 2022-11-28 9:43 UTC (permalink / raw)
To: Jaegeuk Kim, Chao Yu; +Cc: linux-f2fs-devel
allocate_segment_by_default has just two callers, which use very
different code pathes inside it based on the force paramter. Just
open code the logic in the two callers using a new helper to decided
if a new segment should be allocated.
Signed-off-by: Christoph Hellwig <hch@lst.de>
---
fs/f2fs/segment.c | 50 +++++++++++++++++++++++------------------------
1 file changed, 24 insertions(+), 26 deletions(-)
diff --git a/fs/f2fs/segment.c b/fs/f2fs/segment.c
index 714f9114d9aac0..2e54df1d3feea5 100644
--- a/fs/f2fs/segment.c
+++ b/fs/f2fs/segment.c
@@ -2836,31 +2836,20 @@ static int get_ssr_segment(struct f2fs_sb_info *sbi, int type,
return 0;
}
-/*
- * flush out current segment and replace it with new segment
- * This function should be returned with success, otherwise BUG
- */
-static void allocate_segment_by_default(struct f2fs_sb_info *sbi,
- int type, bool force)
+static bool need_new_seg(struct f2fs_sb_info *sbi, int type)
{
struct curseg_info *curseg = CURSEG_I(sbi, type);
- if (force)
- new_curseg(sbi, type, true);
- else if (!is_set_ckpt_flags(sbi, CP_CRC_RECOVERY_FLAG) &&
- curseg->seg_type == CURSEG_WARM_NODE)
- new_curseg(sbi, type, false);
- else if (curseg->alloc_type == LFS &&
- is_next_segment_free(sbi, curseg, type) &&
- likely(!is_sbi_flag_set(sbi, SBI_CP_DISABLED)))
- new_curseg(sbi, type, false);
- else if (f2fs_need_SSR(sbi) &&
- get_ssr_segment(sbi, type, SSR, 0))
- change_curseg(sbi, type, true);
- else
- new_curseg(sbi, type, false);
-
- stat_inc_seg_type(sbi, curseg);
+ if (!is_set_ckpt_flags(sbi, CP_CRC_RECOVERY_FLAG) &&
+ curseg->seg_type == CURSEG_WARM_NODE)
+ return true;
+ if (curseg->alloc_type == LFS &&
+ is_next_segment_free(sbi, curseg, type) &&
+ likely(!is_sbi_flag_set(sbi, SBI_CP_DISABLED)))
+ return true;
+ if (!f2fs_need_SSR(sbi) || !get_ssr_segment(sbi, type, SSR, 0))
+ return true;
+ return false;
}
void f2fs_allocate_segment_for_resize(struct f2fs_sb_info *sbi, int type,
@@ -2913,7 +2902,8 @@ static void __allocate_new_segment(struct f2fs_sb_info *sbi, int type,
return;
alloc:
old_segno = curseg->segno;
- allocate_segment_by_default(sbi, type, true);
+ new_curseg(sbi, type, true);
+ stat_inc_seg_type(sbi, curseg);
locate_dirty_segment(sbi, old_segno);
}
@@ -3264,11 +3254,19 @@ void f2fs_allocate_data_block(struct f2fs_sb_info *sbi, struct page *page,
update_sit_entry(sbi, old_blkaddr, -1);
if (!__has_curseg_space(sbi, curseg)) {
- if (from_gc)
+ /*
+ * Flush out current segment and replace it with new segment.
+ */
+ if (from_gc) {
get_atssr_segment(sbi, type, se->type,
AT_SSR, se->mtime);
- else
- allocate_segment_by_default(sbi, type, false);
+ } else {
+ if (need_new_seg(sbi, type))
+ new_curseg(sbi, type, false);
+ else
+ change_curseg(sbi, type, true);
+ stat_inc_seg_type(sbi, curseg);
+ }
}
/*
* segment dirty status should be updated after segment allocation,
--
2.30.2
_______________________________________________
Linux-f2fs-devel mailing list
Linux-f2fs-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [f2fs-dev] [PATCH 3/3] f2fs: remove the unused flush argument to change_curseg
2022-11-28 9:43 [f2fs-dev] segment allocation cleanups Christoph Hellwig
2022-11-28 9:43 ` [f2fs-dev] [PATCH 1/3] f2fs: remove struct segment_allocation default_salloc_ops Christoph Hellwig
2022-11-28 9:43 ` [f2fs-dev] [PATCH 2/3] f2fs: open code allocate_segment_by_default Christoph Hellwig
@ 2022-11-28 9:43 ` Christoph Hellwig
2022-12-08 14:39 ` Chao Yu
2022-11-28 21:14 ` [f2fs-dev] segment allocation cleanups Jaegeuk Kim
3 siblings, 1 reply; 8+ messages in thread
From: Christoph Hellwig @ 2022-11-28 9:43 UTC (permalink / raw)
To: Jaegeuk Kim, Chao Yu; +Cc: linux-f2fs-devel
Signed-off-by: Christoph Hellwig <hch@lst.de>
---
fs/f2fs/segment.c | 16 +++++++---------
1 file changed, 7 insertions(+), 9 deletions(-)
diff --git a/fs/f2fs/segment.c b/fs/f2fs/segment.c
index 2e54df1d3feea5..b3b7ea6559f95e 100644
--- a/fs/f2fs/segment.c
+++ b/fs/f2fs/segment.c
@@ -2643,7 +2643,7 @@ bool f2fs_segment_has_free_slot(struct f2fs_sb_info *sbi, int segno)
* This function always allocates a used segment(from dirty seglist) by SSR
* manner, so it should recover the existing segment information of valid blocks
*/
-static void change_curseg(struct f2fs_sb_info *sbi, int type, bool flush)
+static void change_curseg(struct f2fs_sb_info *sbi, int type)
{
struct dirty_seglist_info *dirty_i = DIRTY_I(sbi);
struct curseg_info *curseg = CURSEG_I(sbi, type);
@@ -2651,9 +2651,7 @@ static void change_curseg(struct f2fs_sb_info *sbi, int type, bool flush)
struct f2fs_summary_block *sum_node;
struct page *sum_page;
- if (flush)
- write_sum_page(sbi, curseg->sum_blk,
- GET_SUM_BLOCK(sbi, curseg->segno));
+ write_sum_page(sbi, curseg->sum_blk, GET_SUM_BLOCK(sbi, curseg->segno));
__set_test_and_inuse(sbi, new_segno);
@@ -2692,7 +2690,7 @@ static void get_atssr_segment(struct f2fs_sb_info *sbi, int type,
struct seg_entry *se = get_seg_entry(sbi, curseg->next_segno);
curseg->seg_type = se->type;
- change_curseg(sbi, type, true);
+ change_curseg(sbi, type);
} else {
/* allocate cold segment by default */
curseg->seg_type = CURSEG_COLD_DATA;
@@ -2867,7 +2865,7 @@ void f2fs_allocate_segment_for_resize(struct f2fs_sb_info *sbi, int type,
goto unlock;
if (f2fs_need_SSR(sbi) && get_ssr_segment(sbi, type, SSR, 0))
- change_curseg(sbi, type, true);
+ change_curseg(sbi, type);
else
new_curseg(sbi, type, true);
@@ -3264,7 +3262,7 @@ void f2fs_allocate_data_block(struct f2fs_sb_info *sbi, struct page *page,
if (need_new_seg(sbi, type))
new_curseg(sbi, type, false);
else
- change_curseg(sbi, type, true);
+ change_curseg(sbi, type);
stat_inc_seg_type(sbi, curseg);
}
}
@@ -3527,7 +3525,7 @@ void f2fs_do_replace_block(struct f2fs_sb_info *sbi, struct f2fs_summary *sum,
/* change the current segment */
if (segno != curseg->segno) {
curseg->next_segno = segno;
- change_curseg(sbi, type, true);
+ change_curseg(sbi, type);
}
curseg->next_blkoff = GET_BLKOFF_FROM_SEG0(sbi, new_blkaddr);
@@ -3555,7 +3553,7 @@ void f2fs_do_replace_block(struct f2fs_sb_info *sbi, struct f2fs_summary *sum,
if (recover_curseg) {
if (old_cursegno != curseg->segno) {
curseg->next_segno = old_cursegno;
- change_curseg(sbi, type, true);
+ change_curseg(sbi, type);
}
curseg->next_blkoff = old_blkoff;
curseg->alloc_type = old_alloc_type;
--
2.30.2
_______________________________________________
Linux-f2fs-devel mailing list
Linux-f2fs-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
^ permalink raw reply related [flat|nested] 8+ messages in thread
* Re: [f2fs-dev] segment allocation cleanups
2022-11-28 9:43 [f2fs-dev] segment allocation cleanups Christoph Hellwig
` (2 preceding siblings ...)
2022-11-28 9:43 ` [f2fs-dev] [PATCH 3/3] f2fs: remove the unused flush argument to change_curseg Christoph Hellwig
@ 2022-11-28 21:14 ` Jaegeuk Kim
3 siblings, 0 replies; 8+ messages in thread
From: Jaegeuk Kim @ 2022-11-28 21:14 UTC (permalink / raw)
To: Christoph Hellwig; +Cc: linux-f2fs-devel
On 11/28, Christoph Hellwig wrote:
> Hi Jaegeuk and Chao,
>
> this series cleans up the segment allocation code a bit.
Thanks, applied for test.
>
> Diffstat
> segment.c | 71 ++++++++++++++++++++++++++------------------------------------
> segment.h | 6 -----
> 2 files changed, 30 insertions(+), 47 deletions(-)
_______________________________________________
Linux-f2fs-devel mailing list
Linux-f2fs-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [f2fs-dev] [PATCH 1/3] f2fs: remove struct segment_allocation default_salloc_ops
2022-11-28 9:43 ` [f2fs-dev] [PATCH 1/3] f2fs: remove struct segment_allocation default_salloc_ops Christoph Hellwig
@ 2022-12-08 13:55 ` Chao Yu
0 siblings, 0 replies; 8+ messages in thread
From: Chao Yu @ 2022-12-08 13:55 UTC (permalink / raw)
To: Christoph Hellwig, Jaegeuk Kim; +Cc: linux-f2fs-devel
On 2022/11/28 17:43, Christoph Hellwig wrote:
> There is only single instance of these ops, so remove the indirection
> and call allocate_segment_by_default directly.
>
> Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Chao Yu <chao@kernel.org>
Thanks,
_______________________________________________
Linux-f2fs-devel mailing list
Linux-f2fs-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [f2fs-dev] [PATCH 2/3] f2fs: open code allocate_segment_by_default
2022-11-28 9:43 ` [f2fs-dev] [PATCH 2/3] f2fs: open code allocate_segment_by_default Christoph Hellwig
@ 2022-12-08 14:36 ` Chao Yu
0 siblings, 0 replies; 8+ messages in thread
From: Chao Yu @ 2022-12-08 14:36 UTC (permalink / raw)
To: Christoph Hellwig, Jaegeuk Kim; +Cc: linux-f2fs-devel
On 2022/11/28 17:43, Christoph Hellwig wrote:
> allocate_segment_by_default has just two callers, which use very
> different code pathes inside it based on the force paramter. Just
> open code the logic in the two callers using a new helper to decided
> if a new segment should be allocated.
>
> Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Chao Yu <chao@kernel.org>
Thanks,
_______________________________________________
Linux-f2fs-devel mailing list
Linux-f2fs-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [f2fs-dev] [PATCH 3/3] f2fs: remove the unused flush argument to change_curseg
2022-11-28 9:43 ` [f2fs-dev] [PATCH 3/3] f2fs: remove the unused flush argument to change_curseg Christoph Hellwig
@ 2022-12-08 14:39 ` Chao Yu
0 siblings, 0 replies; 8+ messages in thread
From: Chao Yu @ 2022-12-08 14:39 UTC (permalink / raw)
To: Christoph Hellwig, Jaegeuk Kim; +Cc: linux-f2fs-devel
On 2022/11/28 17:43, Christoph Hellwig wrote:
> Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Chao Yu <chao@kernel.org>
Thanks,
_______________________________________________
Linux-f2fs-devel mailing list
Linux-f2fs-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2022-12-08 14:40 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-11-28 9:43 [f2fs-dev] segment allocation cleanups Christoph Hellwig
2022-11-28 9:43 ` [f2fs-dev] [PATCH 1/3] f2fs: remove struct segment_allocation default_salloc_ops Christoph Hellwig
2022-12-08 13:55 ` Chao Yu
2022-11-28 9:43 ` [f2fs-dev] [PATCH 2/3] f2fs: open code allocate_segment_by_default Christoph Hellwig
2022-12-08 14:36 ` Chao Yu
2022-11-28 9:43 ` [f2fs-dev] [PATCH 3/3] f2fs: remove the unused flush argument to change_curseg Christoph Hellwig
2022-12-08 14:39 ` Chao Yu
2022-11-28 21:14 ` [f2fs-dev] segment allocation cleanups Jaegeuk Kim
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).