f2fs: change the method of calculating the number summary blocks

npages_for_summary_flush uses (SUMMARY_SIZE + 1) as the size of a f2fs_summary
while its actual size is  SUMMARY_SIZE. So the result sometimes is bigger than
actual number by one, which causes checkpoint can't be written into disk
contiguously, and sometimes summary blocks can't be compacted like they should.
Besides, when writing summary blocks into pages, if remain space in a page
isn't big enough for one f2fs_summary, it will be left unused, current code
seems not to take it into account.

Signed-off-by: Fan Li <fanofcode.li@samsung.com>
Signed-off-by: Jaegeuk Kim <jaegeuk.kim@samsung.com>
This commit is contained in:
Fan Li 2013-10-29 16:21:47 +08:00 committed by Jaegeuk Kim
parent cc3de6a3ac
commit 9a47938b22

View File

@ -264,9 +264,8 @@ static void __add_sum_entry(struct f2fs_sb_info *sbi, int type,
*/ */
int npages_for_summary_flush(struct f2fs_sb_info *sbi) int npages_for_summary_flush(struct f2fs_sb_info *sbi)
{ {
int total_size_bytes = 0;
int valid_sum_count = 0; int valid_sum_count = 0;
int i, sum_space; int i, sum_in_page;
for (i = CURSEG_HOT_DATA; i <= CURSEG_COLD_DATA; i++) { for (i = CURSEG_HOT_DATA; i <= CURSEG_COLD_DATA; i++) {
if (sbi->ckpt->alloc_type[i] == SSR) if (sbi->ckpt->alloc_type[i] == SSR)
@ -275,13 +274,12 @@ int npages_for_summary_flush(struct f2fs_sb_info *sbi)
valid_sum_count += curseg_blkoff(sbi, i); valid_sum_count += curseg_blkoff(sbi, i);
} }
total_size_bytes = valid_sum_count * (SUMMARY_SIZE + 1) sum_in_page = (PAGE_CACHE_SIZE - 2 * SUM_JOURNAL_SIZE -
+ sizeof(struct nat_journal) + 2 SUM_FOOTER_SIZE) / SUMMARY_SIZE;
+ sizeof(struct sit_journal) + 2; if (valid_sum_count <= sum_in_page)
sum_space = PAGE_CACHE_SIZE - SUM_FOOTER_SIZE;
if (total_size_bytes < sum_space)
return 1; return 1;
else if (total_size_bytes < 2 * sum_space) else if ((valid_sum_count - sum_in_page) <=
(PAGE_CACHE_SIZE - SUM_FOOTER_SIZE) / SUMMARY_SIZE)
return 2; return 2;
return 3; return 3;
} }