Skip to contentSkip to conversation

f2fs: initialize both two copies of NAT and SIT area

PATCH In review Yunlei He 2 participants 4 messages Jul 23, 2015 – Jul 24, 2015

lore
Share & tools
lore

Yunlei He

author
#0 lore raw

PATCH 1/1 f2fs: initialize both two copies of NAT and SIT area

In the process of formatting, we zero out only one copy of NAT and SIT area, but we use both of them when the filesystem is sucessfully mounted. So I change the code to initialize both of two copies in mkfs.

---
 mkfs/f2fs_format.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
mkfs/f2fs_format.c +3 -3
index f879bca..b2b3549 100644
@@ -389,7 +389,7 @@ static int f2fs_init_sit_area(void)
 	sit_seg_addr *= blk_size;
 
 	DBG(1, "\tFilling sit area at offset 0x%08"PRIx64"\n", sit_seg_addr);
-	for (index = 0; index < (get_sb(segment_count_sit) / 2); index++) {
+	for (index = 0; index < get_sb(segment_count_sit); index++) {
 		if (dev_fill(zero_buf, sit_seg_addr, seg_size)) {
 			MSG(1, "\tError: While zeroing out the sit area \
 					on disk!!!\n");
@@ -423,14 +423,14 @@ static int f2fs_init_nat_area(void)
 	nat_seg_addr *= blk_size;
 
 	DBG(1, "\tFilling nat area at offset 0x%08"PRIx64"\n", nat_seg_addr);
-	for (index = 0; index < get_sb(segment_count_nat) / 2; index++) {
+	for (index = 0; index < get_sb(segment_count_nat); index++) {
 		if (dev_fill(nat_buf, nat_seg_addr, seg_size)) {
 			MSG(1, "\tError: While zeroing out the nat area \
 					on disk!!!\n");
 			free(nat_buf);
 			return -1;
 		}
-		nat_seg_addr = nat_seg_addr + (2 * seg_size);
+		nat_seg_addr = nat_seg_addr + seg_size;
 	}
 
 	free(nat_buf);
Signature · 4 lines
1.9.1


------------------------------------------------------------------------------
#1 lore raw

Hi Yunlei,

Quoted 3 lines · Yunlei He

In the process of formatting, we zero out only one copy of NAT and SIT area, but we use both of them when the filesystem is sucessfully mounted. So I change the code to initialize both of two copies in mkfs.

After mounted, the other set will be filled with all valid entries by f2fs. Is there a bug?

Thanks,

Quoted 38 lines
---
 mkfs/f2fs_format.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
mkfs/f2fs_format.c +3 -3
index f879bca..b2b3549 100644
@@ -389,7 +389,7 @@ static int f2fs_init_sit_area(void)
 	sit_seg_addr *= blk_size;
 
 	DBG(1, "\tFilling sit area at offset 0x%08"PRIx64"\n", sit_seg_addr);
-	for (index = 0; index < (get_sb(segment_count_sit) / 2); index++) {
+	for (index = 0; index < get_sb(segment_count_sit); index++) {
 		if (dev_fill(zero_buf, sit_seg_addr, seg_size)) {
 			MSG(1, "\tError: While zeroing out the sit area \
 					on disk!!!\n");
@@ -423,14 +423,14 @@ static int f2fs_init_nat_area(void)
 	nat_seg_addr *= blk_size;
 
 	DBG(1, "\tFilling nat area at offset 0x%08"PRIx64"\n", nat_seg_addr);
-	for (index = 0; index < get_sb(segment_count_nat) / 2; index++) {
+	for (index = 0; index < get_sb(segment_count_nat); index++) {
 		if (dev_fill(nat_buf, nat_seg_addr, seg_size)) {
 			MSG(1, "\tError: While zeroing out the nat area \
 					on disk!!!\n");
 			free(nat_buf);
 			return -1;
 		}
-		nat_seg_addr = nat_seg_addr + (2 * seg_size);
+		nat_seg_addr = nat_seg_addr + seg_size;
 	}
 
 	free(nat_buf);
Signature · 1 line
1.9.1

------------------------------------------------------------------------------

author
#2 lore raw

Hi Jaegeuk

Quoted 12 lines · Jaegeuk Kim

Hi Yunlei,

Quoted 3 lines · Yunlei He

In the process of formatting, we zero out only one copy of NAT and SIT area, but we use both of them when the filesystem is sucessfully mounted. So I change the code to initialize both of two copies in mkfs.

After mounted, the other set will be filled with all valid entries by f2fs. Is there a bug?

Thanks,

I think f2fs write nat and sit in two place alternately.

In function flush_sit_entries, f2fs chooses journal in curseg f2fs_summary_block firstly, if no enough space, then it flush entries to sit pages, which wait for write back. Pages are got by get_next_sit_page function:

1714 src_off = current_sit_addr(sbi, start);
1715 dst_off = next_sit_addr(sbi, src_off);
1716

1717     /* get current sit block page without lock */
1718     src_page = get_meta_page(sbi, src_off);
1719     dst_page = grab_meta_page(sbi, dst_off);
1722     src_addr = page_address(src_page);
1723     dst_addr = page_address(dst_page);
1724     memcpy(dst_addr, src_addr, PAGE_CACHE_SIZE);

I also make a test on my pc

SIT info on my f2fs partition is as below, SIT(1): 1280 ~ 2816 (4k unit, total 6 MB 3 segments) SIT(2): 2817 ~ 4352 (4k unit, total 6 MB 3 segments)

I touch 2000 empty files to make sure dirty sit entries are flushed to sit pages

[ 5870.324921]  flush to sit ~~~hyl fs/f2fs/segment.c:1875
[ 5870.324921]  src_off = 4198~~~hyl fs/f2fs/segment.c:1715
[ 5870.324921]  dst_off = 2662~~~hyl fs/f2fs/segment.c:1717

then I delete all the file and touch again

[ 5613.634439]  flush to sit ~~~hyl fs/f2fs/segment.c:1875
[ 5613.634439]  src_off = 2662~~~hyl fs/f2fs/segment.c:1715
[ 5613.634439]  dst_off = 4198~~~hyl fs/f2fs/segment.c:1717

We can see f2fs use both copies of NAT and SIT, so why we zero out just one copy ?

Quoted 35 lines
Quoted 35 lines
---
  mkfs/f2fs_format.c | 6 +++---
  1 file changed, 3 insertions(+), 3 deletions(-)
mkfs/f2fs_format.c +3 -3
index f879bca..b2b3549 100644
@@ -389,7 +389,7 @@ static int f2fs_init_sit_area(void)
  	sit_seg_addr *= blk_size;
 
  	DBG(1, "\tFilling sit area at offset 0x%08"PRIx64"\n", sit_seg_addr);
-	for (index = 0; index < (get_sb(segment_count_sit) / 2); index++) {
+	for (index = 0; index < get_sb(segment_count_sit); index++) {
  		if (dev_fill(zero_buf, sit_seg_addr, seg_size)) {
  			MSG(1, "\tError: While zeroing out the sit area \
  					on disk!!!\n");
@@ -423,14 +423,14 @@ static int f2fs_init_nat_area(void)
  	nat_seg_addr *= blk_size;
 
  	DBG(1, "\tFilling nat area at offset 0x%08"PRIx64"\n", nat_seg_addr);
-	for (index = 0; index < get_sb(segment_count_nat) / 2; index++) {
+	for (index = 0; index < get_sb(segment_count_nat); index++) {
  		if (dev_fill(nat_buf, nat_seg_addr, seg_size)) {
  			MSG(1, "\tError: While zeroing out the nat area \
  					on disk!!!\n");
  			free(nat_buf);
  			return -1;
  		}
-		nat_seg_addr = nat_seg_addr + (2 * seg_size);
+		nat_seg_addr = nat_seg_addr + seg_size;
  	}
 
Quoted 6 lines
Quoted 3 lines
mkfs/f2fs_format.c +0 -1
  	free(nat_buf);
--

1.9.1

.

------------------------------------------------------------------------------

#3 lore raw

Hi Yunlei,

Quoted 9 lines · He YunLei

Hi Jaegeuk

Quoted 7 lines · Jaegeuk Kim

Hi Yunlei,

Quoted 3 lines · Yunlei He

In the process of formatting, we zero out only one copy of NAT and SIT area, but we use both of them when the filesystem is sucessfully mounted. So I change the code to initialize both of two copies in mkfs.

Quoted 7 lines
Quoted 5 lines

After mounted, the other set will be filled with all valid entries by f2fs. Is there a bug?

Thanks,

I think f2fs write nat and sit in two place alternately.

Yup.

Quoted 10 lines

In function flush_sit_entries, f2fs chooses journal in curseg f2fs_summary_block firstly, if no enough space, then it flush entries to sit pages, which wait for write back. Pages are got by get_next_sit_page function:

1714 src_off = current_sit_addr(sbi, start);
1715 dst_off = next_sit_addr(sbi, src_off);
1716
1717 /* get current sit block page without lock */
1718 src_page = get_meta_page(sbi, src_off);

The src_page is filled with zeros written by mkfs.f2fs.

Quoted 5 lines

1719 dst_page = grab_meta_page(sbi, dst_off);

1722     src_addr = page_address(src_page);
1723     dst_addr = page_address(dst_page);
1724     memcpy(dst_addr, src_addr, PAGE_CACHE_SIZE);

So, the next set, dst_page, is copied from src_page and then new entries will be updated into the dst_page.

Therefore, we don't need to zero out the dst_page by mkfs.f2fs.

Thanks,

Quoted 13 lines

I also make a test on my pc

SIT info on my f2fs partition is as below, SIT(1): 1280 ~ 2816 (4k unit, total 6 MB 3 segments) SIT(2): 2817 ~ 4352 (4k unit, total 6 MB 3 segments)

I touch 2000 empty files to make sure dirty sit entries are flushed to sit pages

[ 5870.324921]  flush to sit ~~~hyl fs/f2fs/segment.c:1875
[ 5870.324921]  src_off = 4198~~~hyl fs/f2fs/segment.c:1715
[ 5870.324921]  dst_off = 2662~~~hyl fs/f2fs/segment.c:1717
Quoted 50 lines

then I delete all the file and touch again

[ 5613.634439]  flush to sit ~~~hyl fs/f2fs/segment.c:1875
[ 5613.634439]  src_off = 2662~~~hyl fs/f2fs/segment.c:1715
[ 5613.634439]  dst_off = 4198~~~hyl fs/f2fs/segment.c:1717

We can see f2fs use both copies of NAT and SIT, so why we zero out just one copy ?

Quoted 41 lines
Quoted 37 lines
---
 mkfs/f2fs_format.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
mkfs/f2fs_format.c +3 -4
index f879bca..b2b3549 100644
@@ -389,7 +389,7 @@ static int f2fs_init_sit_area(void)
 	sit_seg_addr *= blk_size;
 
 	DBG(1, "\tFilling sit area at offset 0x%08"PRIx64"\n", sit_seg_addr);
-	for (index = 0; index < (get_sb(segment_count_sit) / 2); index++) {
+	for (index = 0; index < get_sb(segment_count_sit); index++) {
 		if (dev_fill(zero_buf, sit_seg_addr, seg_size)) {
 			MSG(1, "\tError: While zeroing out the sit area \
 					on disk!!!\n");
@@ -423,14 +423,14 @@ static int f2fs_init_nat_area(void)
 	nat_seg_addr *= blk_size;
 
 	DBG(1, "\tFilling nat area at offset 0x%08"PRIx64"\n", nat_seg_addr);
-	for (index = 0; index < get_sb(segment_count_nat) / 2; index++) {
+	for (index = 0; index < get_sb(segment_count_nat); index++) {
 		if (dev_fill(nat_buf, nat_seg_addr, seg_size)) {
 			MSG(1, "\tError: While zeroing out the nat area \
 					on disk!!!\n");
 			free(nat_buf);
 			return -1;
 		}
-		nat_seg_addr = nat_seg_addr + (2 * seg_size);
+		nat_seg_addr = nat_seg_addr + seg_size;
 	}
 
 	free(nat_buf);
--
Quoted 1 line

1.9.1

.

------------------------------------------------------------------------------