Skip to contentSkip to conversation

f2fs: change the method of calculating the number summary blocks

PATCH Superseded Fan Li 2 participants 3 messages Oct 28, 2013 – Oct 29, 2013

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Fan Li

author
#0 lore raw

PATCH 1/1 f2fs: change the method of calculating the number summary blocks

"There is a HTML error in the previous email, so I send this one.If you already received this before, please ignore it.Sorry for the inconvenience"

This patch change the method of calculating the number of summary blocks in function npages_for_summary_flush.
npages_for_summary_flush uses (SUMMARY_SIZE + 1) as the size of a f2fs_summary while the actual size is just SUMMARY_SIZE.
As a result, occasionally the return value of npages_for_summary_flush will be bigger than the actual number by one, and the checkpoint won't be written contiguously into disk. Besides, struct f2fs_summary can't be split to two pages, so it could take more space than the sum of its size, the current version seems not to take it into account.

---
 fs/f2fs/segment.c |   14 ++++++--------
 1 file changed, 6 insertions(+), 8 deletions(-)
fs/f2fs/segment.c +6 -8
@@ -279,9 +279,8 @@ static void __add_sum_entry(struct f2fs_sb_info *sbi, int type,
  */
 int npages_for_summary_flush(struct f2fs_sb_info *sbi)  {
-	int total_size_bytes = 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++) {
 		if (sbi->ckpt->alloc_type[i] == SSR)
@@ -290,13 +289,12 @@ int npages_for_summary_flush(struct f2fs_sb_info *sbi)
 			valid_sum_count += curseg_blkoff(sbi, i);
 	}
 
-	total_size_bytes = valid_sum_count * (SUMMARY_SIZE + 1)
-			+ sizeof(struct nat_journal) + 2
-			+ sizeof(struct sit_journal) + 2;
-	sum_space = PAGE_CACHE_SIZE - SUM_FOOTER_SIZE;
-	if (total_size_bytes < sum_space)
+	sum_in_page = (PAGE_CACHE_SIZE - 2*SUM_JOURNAL_SIZE - SUM_FOOTER_SIZE)/
+			SUMMARY_SIZE;
+	if (valid_sum_count <= sum_in_page)
 		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 3;
 }

--
1.7.9.5

#1 lore raw

Hi,

2013-10-28 (월), 08:54 +0000, Fan Li:

Quoted 7 lines

"There is a HTML error in the previous email, so I send this one.If you already received this before, please ignore it.Sorry for the inconvenience"

This patch change the method of calculating the number of summary blocks in function npages_for_summary_flush.
npages_for_summary_flush uses (SUMMARY_SIZE + 1) as the size of a f2fs_summary while the actual size is just SUMMARY_SIZE.
As a result, occasionally the return value of npages_for_summary_flush will be bigger than the actual number by one, and the checkpoint won't be written contiguously into disk. Besides, struct f2fs_summary can't be split to two pages, so it could take more space than the sum of its size, the current version seems not to take it into account.

Again. Please write a description not to exceed 80 columns.

Quoted 19 lines
---
 fs/f2fs/segment.c |   14 ++++++--------
 1 file changed, 6 insertions(+), 8 deletions(-)
fs/f2fs/segment.c +1 -2
@@ -279,9 +279,8 @@ static void __add_sum_entry(struct f2fs_sb_info *sbi, int type,
  */
 int npages_for_summary_flush(struct f2fs_sb_info *sbi)  {
-	int total_size_bytes = 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++) {
 		if (sbi->ckpt->alloc_type[i] == SSR)

fs/f2fs/segment.c int npages_for_summary_flush(struct f2fs_sb_info *sbi) · line 292

Quoted 9 lines
fs/f2fs/segment.c +1 -5
@@ -290,13 +289,12 @@ int npages_for_summary_flush(struct f2fs_sb_info *sbi)
 			valid_sum_count += curseg_blkoff(sbi, i);
 	}
 
-	total_size_bytes = valid_sum_count * (SUMMARY_SIZE + 1)
-			+ sizeof(struct nat_journal) + 2
-			+ sizeof(struct sit_journal) + 2;
-	sum_space = PAGE_CACHE_SIZE - SUM_FOOTER_SIZE;
-	if (total_size_bytes < sum_space)
+	sum_in_page = (PAGE_CACHE_SIZE - 2*SUM_JOURNAL_SIZE - SUM_FOOTER_SIZE)/

sum_in_page = (PAGE_CACHE_SIZE - 2 * SUM_JOURNAL_SIZE -
SUM_FOOTER_SIZE) / SUMMARY_SIZE;

Coding style.

fs/f2fs/segment.c int npages_for_summary_flush(struct f2fs_sb_info *sbi) · line 297

Quoted 6 lines
fs/f2fs/segment.c +4 -1
+			SUMMARY_SIZE;
+	if (valid_sum_count <= sum_in_page)
 		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)

ditto.

Quoted 5 lines
fs/f2fs/segment.c +0 -1
 		return 2;
 	return 3;
 }
--

1.7.9.5

Signature · 7 lines
Jaegeuk Kim
Samsung

--
To unsubscribe from this list: send the line "unsubscribe linux-fsdevel" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
author
#2 lore raw
Quoted 11 lines

Hi,

2013-10-28 (월), 08:54 +0000, Fan Li:

Quoted 1 line

"There is a HTML error in the previous email, so I send this one.If you

already received this before, please ignore it.Sorry for the inconvenience"

Quoted 2 lines

This patch change the method of calculating the number of summary blocks

in function npages_for_summary_flush.

Quoted 1 line

npages_for_summary_flush uses (SUMMARY_SIZE + 1) as the size of a

f2fs_summary while the actual size is just SUMMARY_SIZE.

Quoted 1 line

As a result, occasionally the return value of npages_for_summary_flush will

Quoted 9 lines

be bigger than the actual number by one, and the checkpoint won't be written contiguously into disk.

Quoted 1 line

Besides, struct f2fs_summary can't be split to two pages, so it could take

more space than the sum of its size, the current version seems not to take it into account.

Quoted 1 line

Again. Please write a description not to exceed 80 columns.

Sorry, didn't know. here's the short version:
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.

---
 fs/f2fs/segment.c |   14 ++++++--------
 1 file changed, 6 insertions(+), 8 deletions(-)
fs/f2fs/segment.c +6 -8
index 487af61..e40cdc4 100644
@@ -279,9 +279,8 @@ static void __add_sum_entry(struct f2fs_sb_info *sbi, int type,
  */
 int npages_for_summary_flush(struct f2fs_sb_info *sbi)
 {
-	int total_size_bytes = 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++) {
 		if (sbi->ckpt->alloc_type[i] == SSR)
@@ -290,13 +289,12 @@ int npages_for_summary_flush(struct f2fs_sb_info *sbi)
 			valid_sum_count += curseg_blkoff(sbi, i);
 	}
 
-	total_size_bytes = valid_sum_count * (SUMMARY_SIZE + 1)
-			+ sizeof(struct nat_journal) + 2
-			+ sizeof(struct sit_journal) + 2;
-	sum_space = PAGE_CACHE_SIZE - SUM_FOOTER_SIZE;
-	if (total_size_bytes < sum_space)
+	sum_in_page = (PAGE_CACHE_SIZE - 2 * SUM_JOURNAL_SIZE -
+			SUM_FOOTER_SIZE) / SUMMARY_SIZE;
+	if (valid_sum_count <= sum_in_page)
 		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 3;
 }
Signature · 1 line
1.7.9.5