Enhancement: shorten umount time
authorJaegeuk Kim <jaegeuk.kim@samsung.com>
Mon, 29 Oct 2012 22:35:21 +0000 (07:35 +0900)
committerJaegeuk Kim <jaegeuk.kim@samsung.com>
Mon, 26 Nov 2012 10:45:59 +0000 (19:45 +0900)
When f2fs is unmounted cleanly, it stores active summmary blocks of nodes in the
checkpoint pack in order to avoid reconstruct all of them at the later mount
time. Previously, mkfs didn't prepare that, which is why the initial mount time
is so huge.

Signed-off-by: Jaegeuk Kim <jaegeuk.kim@samsung.com>
mkfs/f2fs_format.c
mkfs/f2fs_format.h

index 84796c1..ff52c23 100644 (file)
@@ -807,7 +807,8 @@ static int8_t f2fs_write_check_point_pack(void)
                        ((le32_to_cpu(ckp->free_segment_count) + 6 -
                        le32_to_cpu(ckp->overprov_segment_count)) *
                         f2fs_params.blks_per_seg));
-       ckp->cp_pack_total_block_count = cpu_to_le32(5);
+       ckp->cp_pack_total_block_count = cpu_to_le32(8);
+       ckp->ckpt_flags |= CP_UMOUNT_FLAG;
        ckp->cp_pack_start_sum = cpu_to_le32(1);
        ckp->valid_node_count = cpu_to_le32(1);
        ckp->valid_inode_count = cpu_to_le32(1);
@@ -840,6 +841,7 @@ static int8_t f2fs_write_check_point_pack(void)
        }
 
        /* 2. Prepare and write Segment summary for data blocks */
+       memset(sum, 0, sizeof(struct f2fs_summary_block));
        SET_SUM_TYPE((&sum->footer), SUM_TYPE_DATA);
 
        sum->entries[0].nid = super_block.root_ino;
@@ -854,6 +856,7 @@ static int8_t f2fs_write_check_point_pack(void)
 
        /* 3. Fill segment summary for data block to zero. */
        memset(sum, 0, sizeof(struct f2fs_summary_block));
+       SET_SUM_TYPE((&sum->footer), SUM_TYPE_DATA);
 
        cp_seg_blk_offset += blk_size_bytes;
        if (writetodisk(f2fs_params.fd, sum, cp_seg_blk_offset,
@@ -864,6 +867,7 @@ static int8_t f2fs_write_check_point_pack(void)
 
        /* 4. Fill segment summary for data block to zero. */
        memset(sum, 0, sizeof(struct f2fs_summary_block));
+       SET_SUM_TYPE((&sum->footer), SUM_TYPE_DATA);
 
        /* inode sit for root */
        sum->n_sits = cpu_to_le16(6);
@@ -891,36 +895,13 @@ static int8_t f2fs_write_check_point_pack(void)
                return -1;
        }
 
-       /* 5. cp page2 */
-       cp_seg_blk_offset += blk_size_bytes;
-       if (writetodisk(f2fs_params.fd, ckp, cp_seg_blk_offset,
-                               F2FS_CP_BLOCK_SIZE) < 0) {
-               printf("\n\tError: While writing the ckp to disk!!!\n");
-               return -1;
-       }
-
-       /* 6. cp page 1 of check point pack 2
-        * Initiatialize other checkpoint pack with version zero
-        */
-       ckp->checkpoint_ver = 0;
-
-       crc = f2fs_cal_crc32(F2FS_SUPER_MAGIC, ckp,
-                                       le32_to_cpu(ckp->checksum_offset));
-       *((u_int32_t *)((unsigned char *)ckp +
-                               le32_to_cpu(ckp->checksum_offset))) = crc;
+       /* 5. Prepare and write Segment summary for node blocks */
+       memset(sum, 0, sizeof(struct f2fs_summary_block));
+       SET_SUM_TYPE((&sum->footer), SUM_TYPE_NODE);
 
-       cp_seg_blk_offset = (le32_to_cpu(super_block.start_segment_checkpoint) +
-                               f2fs_params.blks_per_seg) *
-                               blk_size_bytes;
-       if (writetodisk(f2fs_params.fd, ckp,
-                               cp_seg_blk_offset, F2FS_CP_BLOCK_SIZE) < 0) {
-               printf("\n\tError: While writing the ckp to disk!!!\n");
-               return -1;
-       }
+       sum->entries[0].nid = super_block.root_ino;
+       sum->entries[0].ofs_in_node = 0;
 
-       /* 7. */
-       memset(sum, 0, sizeof(struct f2fs_summary_block));
-       SET_SUM_TYPE((&sum->footer), SUM_TYPE_DATA);
        cp_seg_blk_offset += blk_size_bytes;
        if (writetodisk(f2fs_params.fd, sum, cp_seg_blk_offset,
                                sizeof(struct f2fs_summary_block)) < 0) {
@@ -928,8 +909,10 @@ static int8_t f2fs_write_check_point_pack(void)
                return -1;
        }
 
-       /* 8. */
+       /* 6. Fill segment summary for data block to zero. */
        memset(sum, 0, sizeof(struct f2fs_summary_block));
+       SET_SUM_TYPE((&sum->footer), SUM_TYPE_NODE);
+
        cp_seg_blk_offset += blk_size_bytes;
        if (writetodisk(f2fs_params.fd, sum, cp_seg_blk_offset,
                                sizeof(struct f2fs_summary_block)) < 0) {
@@ -937,8 +920,9 @@ static int8_t f2fs_write_check_point_pack(void)
                return -1;
        }
 
-       /* 9. */
+       /* 7. Fill segment summary for data block to zero. */
        memset(sum, 0, sizeof(struct f2fs_summary_block));
+       SET_SUM_TYPE((&sum->footer), SUM_TYPE_NODE);
        cp_seg_blk_offset += blk_size_bytes;
        if (writetodisk(f2fs_params.fd, sum, cp_seg_blk_offset,
                                sizeof(struct f2fs_summary_block)) < 0) {
@@ -946,7 +930,7 @@ static int8_t f2fs_write_check_point_pack(void)
                return -1;
        }
 
-       /* 10. cp page 2 of check point pack 2 */
+       /* 8. cp page2 */
        cp_seg_blk_offset += blk_size_bytes;
        if (writetodisk(f2fs_params.fd, ckp, cp_seg_blk_offset,
                                F2FS_CP_BLOCK_SIZE) < 0) {
@@ -954,6 +938,25 @@ static int8_t f2fs_write_check_point_pack(void)
                return -1;
        }
 
+       /* 9. cp page 1 of check point pack 2
+        * Initiatialize other checkpoint pack with version zero
+        */
+       ckp->checkpoint_ver = 0;
+
+       crc = f2fs_cal_crc32(F2FS_SUPER_MAGIC, ckp,
+                                       le32_to_cpu(ckp->checksum_offset));
+       *((u_int32_t *)((unsigned char *)ckp +
+                               le32_to_cpu(ckp->checksum_offset))) = crc;
+
+       cp_seg_blk_offset = (le32_to_cpu(super_block.start_segment_checkpoint) +
+                               f2fs_params.blks_per_seg) *
+                               blk_size_bytes;
+       if (writetodisk(f2fs_params.fd, ckp,
+                               cp_seg_blk_offset, F2FS_CP_BLOCK_SIZE) < 0) {
+               printf("\n\tError: While writing the ckp to disk!!!\n");
+               return -1;
+       }
+
        free(sum) ;
        free(ckp) ;
        return  0;
index ec49d4d..2ef246d 100644 (file)
@@ -143,6 +143,11 @@ struct f2fs_super_block {
 /*
  * For checkpoint
  */
+#define CP_ERROR_FLAG          0x00000008
+#define CP_COMPACT_SUM_FLAG    0x00000004
+#define CP_ORPHAN_PRESENT_FLAG 0x00000002
+#define CP_UMOUNT_FLAG         0x00000001
+
 struct f2fs_checkpoint {
        __le64 checkpoint_ver;          /* Checkpoint block version number */
        __le64 user_block_count;        /* # of user blocks */