* [PATCH] fsck.f2fs: reduce mem alloc during read sit block
@ 2018-01-29 3:22 Yunlei He
2018-01-31 2:05 ` Jaegeuk Kim
0 siblings, 1 reply; 2+ messages in thread
From: Yunlei He @ 2018-01-29 3:22 UTC (permalink / raw)
To: jaegeuk, yuchao0, linux-f2fs-devel; +Cc: ning.jia, heyunlei
This patch reduce mem alloc during read sit block
Signed-off-by: Yunlei He <heyunlei@huawei.com>
---
fsck/fsck.c | 9 ++++++---
fsck/fsck.h | 4 ++--
fsck/mount.c | 45 ++++++++++++++++++++++++++-------------------
3 files changed, 34 insertions(+), 24 deletions(-)
diff --git a/fsck/fsck.c b/fsck/fsck.c
index 6c1b9a7..d5c18d3 100644
--- a/fsck/fsck.c
+++ b/fsck/fsck.c
@@ -1895,25 +1895,28 @@ static void fix_nat_entries(struct f2fs_sb_info *sbi)
static void flush_curseg_sit_entries(struct f2fs_sb_info *sbi)
{
struct sit_info *sit_i = SIT_I(sbi);
+ struct f2fs_sit_block *sit_blk;
int i;
+ sit_blk = calloc(BLOCK_SZ, 1);
+ ASSERT(sit_blk);
/* update curseg sit entries, since we may change
* a segment type in move_curseg_info
*/
for (i = 0; i < NO_CHECK_TYPE; i++) {
struct curseg_info *curseg = CURSEG_I(sbi, i);
- struct f2fs_sit_block *sit_blk;
struct f2fs_sit_entry *sit;
struct seg_entry *se;
se = get_seg_entry(sbi, curseg->segno);
- sit_blk = get_current_sit_page(sbi, curseg->segno);
+ get_current_sit_page(sbi, curseg->segno, sit_blk);
sit = &sit_blk->entries[SIT_ENTRY_OFFSET(sit_i, curseg->segno)];
sit->vblocks = cpu_to_le16((se->type << SIT_VBLOCKS_SHIFT) |
se->valid_blocks);
rewrite_current_sit_page(sbi, curseg->segno, sit_blk);
- free(sit_blk);
}
+
+ free(sit_blk);
}
static void fix_checkpoint(struct f2fs_sb_info *sbi)
diff --git a/fsck/fsck.h b/fsck/fsck.h
index d635c5a..648c2db 100644
--- a/fsck/fsck.h
+++ b/fsck/fsck.h
@@ -182,8 +182,8 @@ extern void update_nat_blkaddr(struct f2fs_sb_info *, nid_t, nid_t, block_t);
extern void print_raw_sb_info(struct f2fs_super_block *);
extern u32 get_free_segments(struct f2fs_sb_info *);
-extern struct f2fs_sit_block *get_current_sit_page(struct f2fs_sb_info *,
- unsigned int);
+extern void get_current_sit_page(struct f2fs_sb_info *,
+ unsigned int, struct f2fs_sit_block *);
extern void rewrite_current_sit_page(struct f2fs_sb_info *, unsigned int,
struct f2fs_sit_block *);
diff --git a/fsck/mount.c b/fsck/mount.c
index fe0d510..247bc96 100644
--- a/fsck/mount.c
+++ b/fsck/mount.c
@@ -1324,17 +1324,14 @@ static inline void check_seg_range(struct f2fs_sb_info *sbi, unsigned int segno)
ASSERT(segno <= end_segno);
}
-struct f2fs_sit_block *get_current_sit_page(struct f2fs_sb_info *sbi,
- unsigned int segno)
+void get_current_sit_page(struct f2fs_sb_info *sbi,
+ unsigned int segno, struct f2fs_sit_block *sit_blk)
{
struct sit_info *sit_i = SIT_I(sbi);
unsigned int offset = SIT_BLOCK_OFFSET(sit_i, segno);
block_t blk_addr = sit_i->sit_base_addr + offset;
- struct f2fs_sit_block *sit_blk;
int ret;
- sit_blk = calloc(BLOCK_SZ, 1);
- ASSERT(sit_blk);
check_seg_range(sbi, segno);
/* calculate sit block address */
@@ -1343,10 +1340,11 @@ struct f2fs_sit_block *get_current_sit_page(struct f2fs_sb_info *sbi,
ret = dev_read_block(sit_blk, blk_addr);
ASSERT(ret >= 0);
-
- return sit_blk;
}
+void get_current_nat_page(struct f2fs_sb_info *sbi,
+ )
+
void rewrite_current_sit_page(struct f2fs_sb_info *sbi,
unsigned int segno, struct f2fs_sit_block *sit_blk)
{
@@ -1607,22 +1605,24 @@ void build_sit_entries(struct f2fs_sb_info *sbi)
struct sit_info *sit_i = SIT_I(sbi);
struct curseg_info *curseg = CURSEG_I(sbi, CURSEG_COLD_DATA);
struct f2fs_journal *journal = &curseg->sum_blk->journal;
+ struct f2fs_sit_block *sit_blk;
struct seg_entry *se;
struct f2fs_sit_entry sit;
unsigned int i, segno;
+ sit_blk = calloc(BLOCK_SZ, 1);
+ ASSERT(sit_blk);
for (segno = 0; segno < TOTAL_SEGS(sbi); segno++) {
se = &sit_i->sentries[segno];
- struct f2fs_sit_block *sit_blk;
- sit_blk = get_current_sit_page(sbi, segno);
+ get_current_sit_page(sbi, segno, sit_blk);
sit = sit_blk->entries[SIT_ENTRY_OFFSET(sit_i, segno)];
- free(sit_blk);
check_block_count(sbi, segno, &sit);
seg_info_from_raw_sit(se, &sit);
}
+ free(sit_blk);
for (i = 0; i < sits_in_cursum(journal); i++) {
segno = le32_to_cpu(segno_in_journal(journal, i));
se = &sit_i->sentries[segno];
@@ -1714,24 +1714,26 @@ void rewrite_sit_area_bitmap(struct f2fs_sb_info *sbi)
struct f2fs_fsck *fsck = F2FS_FSCK(sbi);
struct curseg_info *curseg = CURSEG_I(sbi, CURSEG_COLD_DATA);
struct sit_info *sit_i = SIT_I(sbi);
+ struct f2fs_sit_block *sit_blk;
unsigned int segno = 0;
struct f2fs_summary_block *sum = curseg->sum_blk;
char *ptr = NULL;
+ sit_blk = calloc(BLOCK_SZ, 1);
+ ASSERT(sit_blk);
/* remove sit journal */
sum->journal.n_sits = 0;
ptr = fsck->main_area_bitmap;
for (segno = 0; segno < TOTAL_SEGS(sbi); segno++) {
- struct f2fs_sit_block *sit_blk;
struct f2fs_sit_entry *sit;
struct seg_entry *se;
u16 valid_blocks = 0;
u16 type;
int i;
- sit_blk = get_current_sit_page(sbi, segno);
+ get_current_sit_page(sbi, segno, sit_blk);
sit = &sit_blk->entries[SIT_ENTRY_OFFSET(sit_i, segno)];
memcpy(sit->valid_map, ptr, SIT_VBLOCK_MAP_SIZE);
@@ -1751,10 +1753,11 @@ void rewrite_sit_area_bitmap(struct f2fs_sb_info *sbi)
sit->vblocks = cpu_to_le16((type << SIT_VBLOCKS_SHIFT) |
valid_blocks);
rewrite_current_sit_page(sbi, segno, sit_blk);
- free(sit_blk);
ptr += SIT_VBLOCK_MAP_SIZE;
}
+
+ free(sit_blk);
}
static int flush_sit_journal_entries(struct f2fs_sb_info *sbi)
@@ -1762,18 +1765,20 @@ static int flush_sit_journal_entries(struct f2fs_sb_info *sbi)
struct curseg_info *curseg = CURSEG_I(sbi, CURSEG_COLD_DATA);
struct f2fs_journal *journal = &curseg->sum_blk->journal;
struct sit_info *sit_i = SIT_I(sbi);
+ struct f2fs_sit_block *sit_blk;
unsigned int segno;
int i;
+ sit_blk = calloc(BLOCK_SZ, 1);
+ ASSERT(sit_blk);
for (i = 0; i < sits_in_cursum(journal); i++) {
- struct f2fs_sit_block *sit_blk;
struct f2fs_sit_entry *sit;
struct seg_entry *se;
segno = segno_in_journal(journal, i);
se = get_seg_entry(sbi, segno);
- sit_blk = get_current_sit_page(sbi, segno);
+ get_current_sit_page(sbi, segno, sit_blk);
sit = &sit_blk->entries[SIT_ENTRY_OFFSET(sit_i, segno)];
memcpy(sit->valid_map, se->cur_valid_map, SIT_VBLOCK_MAP_SIZE);
@@ -1782,9 +1787,9 @@ static int flush_sit_journal_entries(struct f2fs_sb_info *sbi)
sit->mtime = cpu_to_le64(se->mtime);
rewrite_current_sit_page(sbi, segno, sit_blk);
- free(sit_blk);
}
+ free(sit_blk);
journal->n_sits = 0;
return i;
}
@@ -1839,12 +1844,14 @@ void flush_sit_entries(struct f2fs_sb_info *sbi)
{
struct f2fs_checkpoint *cp = F2FS_CKPT(sbi);
struct sit_info *sit_i = SIT_I(sbi);
+ struct f2fs_sit_block *sit_blk;
unsigned int segno = 0;
u32 free_segs = 0;
+ sit_blk = calloc(BLOCK_SZ, 1);
+ ASSERT(sit_blk);
/* update free segments */
for (segno = 0; segno < TOTAL_SEGS(sbi); segno++) {
- struct f2fs_sit_block *sit_blk;
struct f2fs_sit_entry *sit;
struct seg_entry *se;
@@ -1853,19 +1860,19 @@ void flush_sit_entries(struct f2fs_sb_info *sbi)
if (!se->dirty)
continue;
- sit_blk = get_current_sit_page(sbi, segno);
+ get_current_sit_page(sbi, segno, sit_blk);
sit = &sit_blk->entries[SIT_ENTRY_OFFSET(sit_i, segno)];
memcpy(sit->valid_map, se->cur_valid_map, SIT_VBLOCK_MAP_SIZE);
sit->vblocks = cpu_to_le16((se->type << SIT_VBLOCKS_SHIFT) |
se->valid_blocks);
rewrite_current_sit_page(sbi, segno, sit_blk);
- free(sit_blk);
if (se->valid_blocks == 0x0 &&
!IS_CUR_SEGNO(sbi, segno, NO_CHECK_TYPE))
free_segs++;
}
+ free(sit_blk);
set_cp(free_segment_count, free_segs);
}
--
1.9.1
------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
^ permalink raw reply related [flat|nested] 2+ messages in thread* Re: [PATCH] fsck.f2fs: reduce mem alloc during read sit block
2018-01-29 3:22 [PATCH] fsck.f2fs: reduce mem alloc during read sit block Yunlei He
@ 2018-01-31 2:05 ` Jaegeuk Kim
0 siblings, 0 replies; 2+ messages in thread
From: Jaegeuk Kim @ 2018-01-31 2:05 UTC (permalink / raw)
To: Yunlei He; +Cc: ning.jia, linux-f2fs-devel
On 01/29, Yunlei He wrote:
> This patch reduce mem alloc during read sit block
>
> Signed-off-by: Yunlei He <heyunlei@huawei.com>
> ---
> fsck/fsck.c | 9 ++++++---
> fsck/fsck.h | 4 ++--
> fsck/mount.c | 45 ++++++++++++++++++++++++++-------------------
> 3 files changed, 34 insertions(+), 24 deletions(-)
>
> diff --git a/fsck/fsck.c b/fsck/fsck.c
> index 6c1b9a7..d5c18d3 100644
> --- a/fsck/fsck.c
> +++ b/fsck/fsck.c
> @@ -1895,25 +1895,28 @@ static void fix_nat_entries(struct f2fs_sb_info *sbi)
> static void flush_curseg_sit_entries(struct f2fs_sb_info *sbi)
> {
> struct sit_info *sit_i = SIT_I(sbi);
> + struct f2fs_sit_block *sit_blk;
> int i;
>
> + sit_blk = calloc(BLOCK_SZ, 1);
> + ASSERT(sit_blk);
> /* update curseg sit entries, since we may change
> * a segment type in move_curseg_info
> */
> for (i = 0; i < NO_CHECK_TYPE; i++) {
> struct curseg_info *curseg = CURSEG_I(sbi, i);
> - struct f2fs_sit_block *sit_blk;
> struct f2fs_sit_entry *sit;
> struct seg_entry *se;
>
> se = get_seg_entry(sbi, curseg->segno);
> - sit_blk = get_current_sit_page(sbi, curseg->segno);
> + get_current_sit_page(sbi, curseg->segno, sit_blk);
> sit = &sit_blk->entries[SIT_ENTRY_OFFSET(sit_i, curseg->segno)];
> sit->vblocks = cpu_to_le16((se->type << SIT_VBLOCKS_SHIFT) |
> se->valid_blocks);
> rewrite_current_sit_page(sbi, curseg->segno, sit_blk);
> - free(sit_blk);
> }
> +
> + free(sit_blk);
> }
>
> static void fix_checkpoint(struct f2fs_sb_info *sbi)
> diff --git a/fsck/fsck.h b/fsck/fsck.h
> index d635c5a..648c2db 100644
> --- a/fsck/fsck.h
> +++ b/fsck/fsck.h
> @@ -182,8 +182,8 @@ extern void update_nat_blkaddr(struct f2fs_sb_info *, nid_t, nid_t, block_t);
> extern void print_raw_sb_info(struct f2fs_super_block *);
>
> extern u32 get_free_segments(struct f2fs_sb_info *);
> -extern struct f2fs_sit_block *get_current_sit_page(struct f2fs_sb_info *,
> - unsigned int);
> +extern void get_current_sit_page(struct f2fs_sb_info *,
> + unsigned int, struct f2fs_sit_block *);
> extern void rewrite_current_sit_page(struct f2fs_sb_info *, unsigned int,
> struct f2fs_sit_block *);
>
> diff --git a/fsck/mount.c b/fsck/mount.c
> index fe0d510..247bc96 100644
> --- a/fsck/mount.c
> +++ b/fsck/mount.c
> @@ -1324,17 +1324,14 @@ static inline void check_seg_range(struct f2fs_sb_info *sbi, unsigned int segno)
> ASSERT(segno <= end_segno);
> }
>
> -struct f2fs_sit_block *get_current_sit_page(struct f2fs_sb_info *sbi,
> - unsigned int segno)
> +void get_current_sit_page(struct f2fs_sb_info *sbi,
> + unsigned int segno, struct f2fs_sit_block *sit_blk)
> {
> struct sit_info *sit_i = SIT_I(sbi);
> unsigned int offset = SIT_BLOCK_OFFSET(sit_i, segno);
> block_t blk_addr = sit_i->sit_base_addr + offset;
> - struct f2fs_sit_block *sit_blk;
> int ret;
>
> - sit_blk = calloc(BLOCK_SZ, 1);
> - ASSERT(sit_blk);
> check_seg_range(sbi, segno);
>
> /* calculate sit block address */
> @@ -1343,10 +1340,11 @@ struct f2fs_sit_block *get_current_sit_page(struct f2fs_sb_info *sbi,
>
> ret = dev_read_block(sit_blk, blk_addr);
> ASSERT(ret >= 0);
> -
> - return sit_blk;
> }
>
> +void get_current_nat_page(struct f2fs_sb_info *sbi,
> + )
> +
I removed this. :(
> void rewrite_current_sit_page(struct f2fs_sb_info *sbi,
> unsigned int segno, struct f2fs_sit_block *sit_blk)
> {
> @@ -1607,22 +1605,24 @@ void build_sit_entries(struct f2fs_sb_info *sbi)
> struct sit_info *sit_i = SIT_I(sbi);
> struct curseg_info *curseg = CURSEG_I(sbi, CURSEG_COLD_DATA);
> struct f2fs_journal *journal = &curseg->sum_blk->journal;
> + struct f2fs_sit_block *sit_blk;
> struct seg_entry *se;
> struct f2fs_sit_entry sit;
> unsigned int i, segno;
>
> + sit_blk = calloc(BLOCK_SZ, 1);
> + ASSERT(sit_blk);
> for (segno = 0; segno < TOTAL_SEGS(sbi); segno++) {
> se = &sit_i->sentries[segno];
> - struct f2fs_sit_block *sit_blk;
>
> - sit_blk = get_current_sit_page(sbi, segno);
> + get_current_sit_page(sbi, segno, sit_blk);
> sit = sit_blk->entries[SIT_ENTRY_OFFSET(sit_i, segno)];
> - free(sit_blk);
>
> check_block_count(sbi, segno, &sit);
> seg_info_from_raw_sit(se, &sit);
> }
>
> + free(sit_blk);
> for (i = 0; i < sits_in_cursum(journal); i++) {
> segno = le32_to_cpu(segno_in_journal(journal, i));
> se = &sit_i->sentries[segno];
> @@ -1714,24 +1714,26 @@ void rewrite_sit_area_bitmap(struct f2fs_sb_info *sbi)
> struct f2fs_fsck *fsck = F2FS_FSCK(sbi);
> struct curseg_info *curseg = CURSEG_I(sbi, CURSEG_COLD_DATA);
> struct sit_info *sit_i = SIT_I(sbi);
> + struct f2fs_sit_block *sit_blk;
> unsigned int segno = 0;
> struct f2fs_summary_block *sum = curseg->sum_blk;
> char *ptr = NULL;
>
> + sit_blk = calloc(BLOCK_SZ, 1);
> + ASSERT(sit_blk);
> /* remove sit journal */
> sum->journal.n_sits = 0;
>
> ptr = fsck->main_area_bitmap;
>
> for (segno = 0; segno < TOTAL_SEGS(sbi); segno++) {
> - struct f2fs_sit_block *sit_blk;
> struct f2fs_sit_entry *sit;
> struct seg_entry *se;
> u16 valid_blocks = 0;
> u16 type;
> int i;
>
> - sit_blk = get_current_sit_page(sbi, segno);
> + get_current_sit_page(sbi, segno, sit_blk);
> sit = &sit_blk->entries[SIT_ENTRY_OFFSET(sit_i, segno)];
> memcpy(sit->valid_map, ptr, SIT_VBLOCK_MAP_SIZE);
>
> @@ -1751,10 +1753,11 @@ void rewrite_sit_area_bitmap(struct f2fs_sb_info *sbi)
> sit->vblocks = cpu_to_le16((type << SIT_VBLOCKS_SHIFT) |
> valid_blocks);
> rewrite_current_sit_page(sbi, segno, sit_blk);
> - free(sit_blk);
>
> ptr += SIT_VBLOCK_MAP_SIZE;
> }
> +
> + free(sit_blk);
> }
>
> static int flush_sit_journal_entries(struct f2fs_sb_info *sbi)
> @@ -1762,18 +1765,20 @@ static int flush_sit_journal_entries(struct f2fs_sb_info *sbi)
> struct curseg_info *curseg = CURSEG_I(sbi, CURSEG_COLD_DATA);
> struct f2fs_journal *journal = &curseg->sum_blk->journal;
> struct sit_info *sit_i = SIT_I(sbi);
> + struct f2fs_sit_block *sit_blk;
> unsigned int segno;
> int i;
>
> + sit_blk = calloc(BLOCK_SZ, 1);
> + ASSERT(sit_blk);
> for (i = 0; i < sits_in_cursum(journal); i++) {
> - struct f2fs_sit_block *sit_blk;
> struct f2fs_sit_entry *sit;
> struct seg_entry *se;
>
> segno = segno_in_journal(journal, i);
> se = get_seg_entry(sbi, segno);
>
> - sit_blk = get_current_sit_page(sbi, segno);
> + get_current_sit_page(sbi, segno, sit_blk);
> sit = &sit_blk->entries[SIT_ENTRY_OFFSET(sit_i, segno)];
>
> memcpy(sit->valid_map, se->cur_valid_map, SIT_VBLOCK_MAP_SIZE);
> @@ -1782,9 +1787,9 @@ static int flush_sit_journal_entries(struct f2fs_sb_info *sbi)
> sit->mtime = cpu_to_le64(se->mtime);
>
> rewrite_current_sit_page(sbi, segno, sit_blk);
> - free(sit_blk);
> }
>
> + free(sit_blk);
> journal->n_sits = 0;
> return i;
> }
> @@ -1839,12 +1844,14 @@ void flush_sit_entries(struct f2fs_sb_info *sbi)
> {
> struct f2fs_checkpoint *cp = F2FS_CKPT(sbi);
> struct sit_info *sit_i = SIT_I(sbi);
> + struct f2fs_sit_block *sit_blk;
> unsigned int segno = 0;
> u32 free_segs = 0;
>
> + sit_blk = calloc(BLOCK_SZ, 1);
> + ASSERT(sit_blk);
> /* update free segments */
> for (segno = 0; segno < TOTAL_SEGS(sbi); segno++) {
> - struct f2fs_sit_block *sit_blk;
> struct f2fs_sit_entry *sit;
> struct seg_entry *se;
>
> @@ -1853,19 +1860,19 @@ void flush_sit_entries(struct f2fs_sb_info *sbi)
> if (!se->dirty)
> continue;
>
> - sit_blk = get_current_sit_page(sbi, segno);
> + get_current_sit_page(sbi, segno, sit_blk);
> sit = &sit_blk->entries[SIT_ENTRY_OFFSET(sit_i, segno)];
> memcpy(sit->valid_map, se->cur_valid_map, SIT_VBLOCK_MAP_SIZE);
> sit->vblocks = cpu_to_le16((se->type << SIT_VBLOCKS_SHIFT) |
> se->valid_blocks);
> rewrite_current_sit_page(sbi, segno, sit_blk);
> - free(sit_blk);
>
> if (se->valid_blocks == 0x0 &&
> !IS_CUR_SEGNO(sbi, segno, NO_CHECK_TYPE))
> free_segs++;
> }
>
> + free(sit_blk);
> set_cp(free_segment_count, free_segs);
> }
>
> --
> 1.9.1
------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2018-01-31 2:05 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-01-29 3:22 [PATCH] fsck.f2fs: reduce mem alloc during read sit block Yunlei He
2018-01-31 2:05 ` 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).