Re: [PATCH 05/16] f2fs: add checkpoint operations

2012-10-15 Thread NeilBrown
On Sat, 13 Oct 2012 00:49:06 +0900 Jaegeuk Kim  wrote:

> 2012-10-11 (목), 09:24 +1100, NeilBrown:
> > On Fri, 05 Oct 2012 20:59:29 +0900 김재극  wrote:
> > 
> > > +static void do_checkpoint(struct f2fs_sb_info *sbi, bool is_umount)
> > > +{
> > > + struct f2fs_checkpoint *ckpt = F2FS_CKPT(sbi);
> > > + nid_t last_nid = 0;
> > > + int nat_upd_blkoff[3];
> > > + block_t start_blk;
> > > + struct page *cp_page;
> > > + unsigned int data_sum_blocks, orphan_blocks;
> > > + void *kaddr;
> > > + __u32 crc32 = 0;
> > > + int i;
> > > +
> > > + /* Flush all the NAT/SIT pages */
> > > + while (get_pages(sbi, F2FS_DIRTY_META))
> > > + sync_meta_pages(sbi, META, LONG_MAX);
> > > +
> > > + next_free_nid(sbi, _nid);
> > > +
> > > + /*
> > > +  * modify checkpoint
> > > +  * version number is already updated
> > > +  */
> > > + ckpt->elapsed_time = cpu_to_le64(get_mtime(sbi));
> > > + ckpt->valid_block_count = cpu_to_le64(valid_user_blocks(sbi));
> > > + ckpt->free_segment_count = cpu_to_le32(free_segments(sbi));
> > > + for (i = 0; i < 3; i++) {
> > > + ckpt->cur_node_segno[i] =
> > > + cpu_to_le32(curseg_segno(sbi, i + CURSEG_HOT_NODE));
> > > + ckpt->cur_node_blkoff[i] =
> > > + cpu_to_le16(curseg_blkoff(sbi, i + CURSEG_HOT_NODE));
> > > + nat_upd_blkoff[i] = NM_I(sbi)->nat_upd_blkoff[i];
> > > + ckpt->nat_upd_blkoff[i] = cpu_to_le16(nat_upd_blkoff[i]);
> > > + ckpt->alloc_type[i + CURSEG_HOT_NODE] =
> > > + curseg_alloc_type(sbi, i + CURSEG_HOT_NODE);
> > > + }
> > > + for (i = 0; i < 3; i++) {
> > > + ckpt->cur_data_segno[i] =
> > > + cpu_to_le32(curseg_segno(sbi, i + CURSEG_HOT_DATA));
> > > + ckpt->cur_data_blkoff[i] =
> > > + cpu_to_le16(curseg_blkoff(sbi, i + CURSEG_HOT_DATA));
> > > + ckpt->alloc_type[i + CURSEG_HOT_DATA] =
> > > + curseg_alloc_type(sbi, i + CURSEG_HOT_DATA);
> > > + }
> > > +
> > > + ckpt->valid_node_count = cpu_to_le32(valid_node_count(sbi));
> > > + ckpt->valid_inode_count = cpu_to_le32(valid_inode_count(sbi));
> > > + ckpt->next_free_nid = cpu_to_le32(last_nid);
> > > +
> > > + /* 2 cp  + n data seg summary + orphan inode blocks */
> > > + data_sum_blocks = npages_for_summary_flush(sbi);
> > > + if (data_sum_blocks < 3)
> > > + ckpt->ckpt_flags |= CP_COMPACT_SUM_FLAG;
> > > + else
> > > + ckpt->ckpt_flags &= (~CP_COMPACT_SUM_FLAG);
> > > +
> > > + orphan_blocks = (sbi->n_orphans + F2FS_ORPHANS_PER_BLOCK - 1)
> > > + / F2FS_ORPHANS_PER_BLOCK;
> > > + ckpt->cp_pack_start_sum = 1 + orphan_blocks;
> > > + ckpt->cp_pack_total_block_count = 2 + data_sum_blocks + orphan_blocks;
> > 
> > This looks a bit weird to me, though I might be misunderstanding something.
> > 
> > data_sum_blocks is either 1, 2, or 3.
> > "3" actually means "at least 3".
> > 
> > If it is 3, you choose not to set CP_COMPACT_SUM_FLAG.  In that case the NAT
> > and SIT journal entries go into SSA blocks, not into the checkpoint at all.
> > So in that case, zero blocks of the checkpoint are used for journalling.  
> > Yet
> > you still add data_sum_blocks (==3) to the cp_pack_total_block_count (and
> > later to the start block).
> > Is that really what you want to do?  Leave 3 empty blocks?
> > 
> > I would suggest changing npages_for_summary_flush to return 0 if the number
> > of blocks needed would be more than three, and set CP_COMPACT_SUM_FLAG only
> > when data_sum_blocks > 0.
> > 
> > I don't know if you would need to make a corresponding change to the 
> > recovery
> > code, I haven't fully examined that yet.
> 
> Ok, let me explain about CP_COMPACT_SUM_FLAG.
> Let's assume that there are some journal entries and data summaries.
> Note that this scenario is not from the umount procedure.
> 
> Basically f2fs writes three data summary blocks for current active logs
> inside the checkpoint pack.
> And NAT and SIT journal entries are stored in hot and cold data summary
> blocks.
> So, if the CP_COMPACT_SUM_FLAG is not set, f2fs writes the checkpoint
> pack like this.
> 
> [CP 0]
> [Orphan blocks]
> [Hot sum block w/ NAT journal]
> [Warm sum block]
> [Cold sum block w/ SIT journal]
> [CP 0']
> 
> But, if the CP_COMPACT_SUM_FLAG is set, the checkpoint pack consists of
> 1 or 2 summary blocks as follows.
> 
> [CP 0]
> [Orphan blocks]
> [summary entries w/ NAT and SIT journal]
> [CP 0']
> 
> or,
> 
> [CP 0]
> [Orphan blocks]
> [summary entries]
> [summary entries w/ NAT and SIT journal]
> [CP 0']
> 
> So, I think it needs no change.
> Any idea?
> Thanks,

I see.  I missed the fact that the current data summary blocks are always
written to the checkpoint area - I assumed they were being written back to
the SSA.

So it makes sense now and you are right - no change needed.

Thanks,
NeilBrown


> 
> > 
> > Regards,
> > NeilBrown
> 



signature.asc
Description: PGP signature


Re: [PATCH 05/16] f2fs: add checkpoint operations

2012-10-15 Thread NeilBrown
On Sat, 13 Oct 2012 00:49:06 +0900 Jaegeuk Kim jaegeuk@gmail.com wrote:

 2012-10-11 (목), 09:24 +1100, NeilBrown:
  On Fri, 05 Oct 2012 20:59:29 +0900 김재극 jaegeuk@samsung.com wrote:
  
   +static void do_checkpoint(struct f2fs_sb_info *sbi, bool is_umount)
   +{
   + struct f2fs_checkpoint *ckpt = F2FS_CKPT(sbi);
   + nid_t last_nid = 0;
   + int nat_upd_blkoff[3];
   + block_t start_blk;
   + struct page *cp_page;
   + unsigned int data_sum_blocks, orphan_blocks;
   + void *kaddr;
   + __u32 crc32 = 0;
   + int i;
   +
   + /* Flush all the NAT/SIT pages */
   + while (get_pages(sbi, F2FS_DIRTY_META))
   + sync_meta_pages(sbi, META, LONG_MAX);
   +
   + next_free_nid(sbi, last_nid);
   +
   + /*
   +  * modify checkpoint
   +  * version number is already updated
   +  */
   + ckpt-elapsed_time = cpu_to_le64(get_mtime(sbi));
   + ckpt-valid_block_count = cpu_to_le64(valid_user_blocks(sbi));
   + ckpt-free_segment_count = cpu_to_le32(free_segments(sbi));
   + for (i = 0; i  3; i++) {
   + ckpt-cur_node_segno[i] =
   + cpu_to_le32(curseg_segno(sbi, i + CURSEG_HOT_NODE));
   + ckpt-cur_node_blkoff[i] =
   + cpu_to_le16(curseg_blkoff(sbi, i + CURSEG_HOT_NODE));
   + nat_upd_blkoff[i] = NM_I(sbi)-nat_upd_blkoff[i];
   + ckpt-nat_upd_blkoff[i] = cpu_to_le16(nat_upd_blkoff[i]);
   + ckpt-alloc_type[i + CURSEG_HOT_NODE] =
   + curseg_alloc_type(sbi, i + CURSEG_HOT_NODE);
   + }
   + for (i = 0; i  3; i++) {
   + ckpt-cur_data_segno[i] =
   + cpu_to_le32(curseg_segno(sbi, i + CURSEG_HOT_DATA));
   + ckpt-cur_data_blkoff[i] =
   + cpu_to_le16(curseg_blkoff(sbi, i + CURSEG_HOT_DATA));
   + ckpt-alloc_type[i + CURSEG_HOT_DATA] =
   + curseg_alloc_type(sbi, i + CURSEG_HOT_DATA);
   + }
   +
   + ckpt-valid_node_count = cpu_to_le32(valid_node_count(sbi));
   + ckpt-valid_inode_count = cpu_to_le32(valid_inode_count(sbi));
   + ckpt-next_free_nid = cpu_to_le32(last_nid);
   +
   + /* 2 cp  + n data seg summary + orphan inode blocks */
   + data_sum_blocks = npages_for_summary_flush(sbi);
   + if (data_sum_blocks  3)
   + ckpt-ckpt_flags |= CP_COMPACT_SUM_FLAG;
   + else
   + ckpt-ckpt_flags = (~CP_COMPACT_SUM_FLAG);
   +
   + orphan_blocks = (sbi-n_orphans + F2FS_ORPHANS_PER_BLOCK - 1)
   + / F2FS_ORPHANS_PER_BLOCK;
   + ckpt-cp_pack_start_sum = 1 + orphan_blocks;
   + ckpt-cp_pack_total_block_count = 2 + data_sum_blocks + orphan_blocks;
  
  This looks a bit weird to me, though I might be misunderstanding something.
  
  data_sum_blocks is either 1, 2, or 3.
  3 actually means at least 3.
  
  If it is 3, you choose not to set CP_COMPACT_SUM_FLAG.  In that case the NAT
  and SIT journal entries go into SSA blocks, not into the checkpoint at all.
  So in that case, zero blocks of the checkpoint are used for journalling.  
  Yet
  you still add data_sum_blocks (==3) to the cp_pack_total_block_count (and
  later to the start block).
  Is that really what you want to do?  Leave 3 empty blocks?
  
  I would suggest changing npages_for_summary_flush to return 0 if the number
  of blocks needed would be more than three, and set CP_COMPACT_SUM_FLAG only
  when data_sum_blocks  0.
  
  I don't know if you would need to make a corresponding change to the 
  recovery
  code, I haven't fully examined that yet.
 
 Ok, let me explain about CP_COMPACT_SUM_FLAG.
 Let's assume that there are some journal entries and data summaries.
 Note that this scenario is not from the umount procedure.
 
 Basically f2fs writes three data summary blocks for current active logs
 inside the checkpoint pack.
 And NAT and SIT journal entries are stored in hot and cold data summary
 blocks.
 So, if the CP_COMPACT_SUM_FLAG is not set, f2fs writes the checkpoint
 pack like this.
 
 [CP 0]
 [Orphan blocks]
 [Hot sum block w/ NAT journal]
 [Warm sum block]
 [Cold sum block w/ SIT journal]
 [CP 0']
 
 But, if the CP_COMPACT_SUM_FLAG is set, the checkpoint pack consists of
 1 or 2 summary blocks as follows.
 
 [CP 0]
 [Orphan blocks]
 [summary entries w/ NAT and SIT journal]
 [CP 0']
 
 or,
 
 [CP 0]
 [Orphan blocks]
 [summary entries]
 [summary entries w/ NAT and SIT journal]
 [CP 0']
 
 So, I think it needs no change.
 Any idea?
 Thanks,

I see.  I missed the fact that the current data summary blocks are always
written to the checkpoint area - I assumed they were being written back to
the SSA.

So it makes sense now and you are right - no change needed.

Thanks,
NeilBrown


 
  
  Regards,
  NeilBrown
 



signature.asc
Description: PGP signature


Re: [PATCH 05/16] f2fs: add checkpoint operations

2012-10-12 Thread Jaegeuk Kim
2012-10-11 (목), 09:24 +1100, NeilBrown:
> On Fri, 05 Oct 2012 20:59:29 +0900 김재극  wrote:
> 
> > +static void do_checkpoint(struct f2fs_sb_info *sbi, bool is_umount)
> > +{
> > +   struct f2fs_checkpoint *ckpt = F2FS_CKPT(sbi);
> > +   nid_t last_nid = 0;
> > +   int nat_upd_blkoff[3];
> > +   block_t start_blk;
> > +   struct page *cp_page;
> > +   unsigned int data_sum_blocks, orphan_blocks;
> > +   void *kaddr;
> > +   __u32 crc32 = 0;
> > +   int i;
> > +
> > +   /* Flush all the NAT/SIT pages */
> > +   while (get_pages(sbi, F2FS_DIRTY_META))
> > +   sync_meta_pages(sbi, META, LONG_MAX);
> > +
> > +   next_free_nid(sbi, _nid);
> > +
> > +   /*
> > +* modify checkpoint
> > +* version number is already updated
> > +*/
> > +   ckpt->elapsed_time = cpu_to_le64(get_mtime(sbi));
> > +   ckpt->valid_block_count = cpu_to_le64(valid_user_blocks(sbi));
> > +   ckpt->free_segment_count = cpu_to_le32(free_segments(sbi));
> > +   for (i = 0; i < 3; i++) {
> > +   ckpt->cur_node_segno[i] =
> > +   cpu_to_le32(curseg_segno(sbi, i + CURSEG_HOT_NODE));
> > +   ckpt->cur_node_blkoff[i] =
> > +   cpu_to_le16(curseg_blkoff(sbi, i + CURSEG_HOT_NODE));
> > +   nat_upd_blkoff[i] = NM_I(sbi)->nat_upd_blkoff[i];
> > +   ckpt->nat_upd_blkoff[i] = cpu_to_le16(nat_upd_blkoff[i]);
> > +   ckpt->alloc_type[i + CURSEG_HOT_NODE] =
> > +   curseg_alloc_type(sbi, i + CURSEG_HOT_NODE);
> > +   }
> > +   for (i = 0; i < 3; i++) {
> > +   ckpt->cur_data_segno[i] =
> > +   cpu_to_le32(curseg_segno(sbi, i + CURSEG_HOT_DATA));
> > +   ckpt->cur_data_blkoff[i] =
> > +   cpu_to_le16(curseg_blkoff(sbi, i + CURSEG_HOT_DATA));
> > +   ckpt->alloc_type[i + CURSEG_HOT_DATA] =
> > +   curseg_alloc_type(sbi, i + CURSEG_HOT_DATA);
> > +   }
> > +
> > +   ckpt->valid_node_count = cpu_to_le32(valid_node_count(sbi));
> > +   ckpt->valid_inode_count = cpu_to_le32(valid_inode_count(sbi));
> > +   ckpt->next_free_nid = cpu_to_le32(last_nid);
> > +
> > +   /* 2 cp  + n data seg summary + orphan inode blocks */
> > +   data_sum_blocks = npages_for_summary_flush(sbi);
> > +   if (data_sum_blocks < 3)
> > +   ckpt->ckpt_flags |= CP_COMPACT_SUM_FLAG;
> > +   else
> > +   ckpt->ckpt_flags &= (~CP_COMPACT_SUM_FLAG);
> > +
> > +   orphan_blocks = (sbi->n_orphans + F2FS_ORPHANS_PER_BLOCK - 1)
> > +   / F2FS_ORPHANS_PER_BLOCK;
> > +   ckpt->cp_pack_start_sum = 1 + orphan_blocks;
> > +   ckpt->cp_pack_total_block_count = 2 + data_sum_blocks + orphan_blocks;
> 
> This looks a bit weird to me, though I might be misunderstanding something.
> 
> data_sum_blocks is either 1, 2, or 3.
> "3" actually means "at least 3".
> 
> If it is 3, you choose not to set CP_COMPACT_SUM_FLAG.  In that case the NAT
> and SIT journal entries go into SSA blocks, not into the checkpoint at all.
> So in that case, zero blocks of the checkpoint are used for journalling.  Yet
> you still add data_sum_blocks (==3) to the cp_pack_total_block_count (and
> later to the start block).
> Is that really what you want to do?  Leave 3 empty blocks?
> 
> I would suggest changing npages_for_summary_flush to return 0 if the number
> of blocks needed would be more than three, and set CP_COMPACT_SUM_FLAG only
> when data_sum_blocks > 0.
> 
> I don't know if you would need to make a corresponding change to the recovery
> code, I haven't fully examined that yet.

Ok, let me explain about CP_COMPACT_SUM_FLAG.
Let's assume that there are some journal entries and data summaries.
Note that this scenario is not from the umount procedure.

Basically f2fs writes three data summary blocks for current active logs
inside the checkpoint pack.
And NAT and SIT journal entries are stored in hot and cold data summary
blocks.
So, if the CP_COMPACT_SUM_FLAG is not set, f2fs writes the checkpoint
pack like this.

[CP 0]
[Orphan blocks]
[Hot sum block w/ NAT journal]
[Warm sum block]
[Cold sum block w/ SIT journal]
[CP 0']

But, if the CP_COMPACT_SUM_FLAG is set, the checkpoint pack consists of
1 or 2 summary blocks as follows.

[CP 0]
[Orphan blocks]
[summary entries w/ NAT and SIT journal]
[CP 0']

or,

[CP 0]
[Orphan blocks]
[summary entries]
[summary entries w/ NAT and SIT journal]
[CP 0']

So, I think it needs no change.
Any idea?
Thanks,

> 
> Regards,
> NeilBrown

-- 
Jaegeuk Kim
Samsung

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH 05/16] f2fs: add checkpoint operations

2012-10-12 Thread Jaegeuk Kim
2012-10-11 (목), 09:24 +1100, NeilBrown:
 On Fri, 05 Oct 2012 20:59:29 +0900 김재극 jaegeuk@samsung.com wrote:
 
  +static void do_checkpoint(struct f2fs_sb_info *sbi, bool is_umount)
  +{
  +   struct f2fs_checkpoint *ckpt = F2FS_CKPT(sbi);
  +   nid_t last_nid = 0;
  +   int nat_upd_blkoff[3];
  +   block_t start_blk;
  +   struct page *cp_page;
  +   unsigned int data_sum_blocks, orphan_blocks;
  +   void *kaddr;
  +   __u32 crc32 = 0;
  +   int i;
  +
  +   /* Flush all the NAT/SIT pages */
  +   while (get_pages(sbi, F2FS_DIRTY_META))
  +   sync_meta_pages(sbi, META, LONG_MAX);
  +
  +   next_free_nid(sbi, last_nid);
  +
  +   /*
  +* modify checkpoint
  +* version number is already updated
  +*/
  +   ckpt-elapsed_time = cpu_to_le64(get_mtime(sbi));
  +   ckpt-valid_block_count = cpu_to_le64(valid_user_blocks(sbi));
  +   ckpt-free_segment_count = cpu_to_le32(free_segments(sbi));
  +   for (i = 0; i  3; i++) {
  +   ckpt-cur_node_segno[i] =
  +   cpu_to_le32(curseg_segno(sbi, i + CURSEG_HOT_NODE));
  +   ckpt-cur_node_blkoff[i] =
  +   cpu_to_le16(curseg_blkoff(sbi, i + CURSEG_HOT_NODE));
  +   nat_upd_blkoff[i] = NM_I(sbi)-nat_upd_blkoff[i];
  +   ckpt-nat_upd_blkoff[i] = cpu_to_le16(nat_upd_blkoff[i]);
  +   ckpt-alloc_type[i + CURSEG_HOT_NODE] =
  +   curseg_alloc_type(sbi, i + CURSEG_HOT_NODE);
  +   }
  +   for (i = 0; i  3; i++) {
  +   ckpt-cur_data_segno[i] =
  +   cpu_to_le32(curseg_segno(sbi, i + CURSEG_HOT_DATA));
  +   ckpt-cur_data_blkoff[i] =
  +   cpu_to_le16(curseg_blkoff(sbi, i + CURSEG_HOT_DATA));
  +   ckpt-alloc_type[i + CURSEG_HOT_DATA] =
  +   curseg_alloc_type(sbi, i + CURSEG_HOT_DATA);
  +   }
  +
  +   ckpt-valid_node_count = cpu_to_le32(valid_node_count(sbi));
  +   ckpt-valid_inode_count = cpu_to_le32(valid_inode_count(sbi));
  +   ckpt-next_free_nid = cpu_to_le32(last_nid);
  +
  +   /* 2 cp  + n data seg summary + orphan inode blocks */
  +   data_sum_blocks = npages_for_summary_flush(sbi);
  +   if (data_sum_blocks  3)
  +   ckpt-ckpt_flags |= CP_COMPACT_SUM_FLAG;
  +   else
  +   ckpt-ckpt_flags = (~CP_COMPACT_SUM_FLAG);
  +
  +   orphan_blocks = (sbi-n_orphans + F2FS_ORPHANS_PER_BLOCK - 1)
  +   / F2FS_ORPHANS_PER_BLOCK;
  +   ckpt-cp_pack_start_sum = 1 + orphan_blocks;
  +   ckpt-cp_pack_total_block_count = 2 + data_sum_blocks + orphan_blocks;
 
 This looks a bit weird to me, though I might be misunderstanding something.
 
 data_sum_blocks is either 1, 2, or 3.
 3 actually means at least 3.
 
 If it is 3, you choose not to set CP_COMPACT_SUM_FLAG.  In that case the NAT
 and SIT journal entries go into SSA blocks, not into the checkpoint at all.
 So in that case, zero blocks of the checkpoint are used for journalling.  Yet
 you still add data_sum_blocks (==3) to the cp_pack_total_block_count (and
 later to the start block).
 Is that really what you want to do?  Leave 3 empty blocks?
 
 I would suggest changing npages_for_summary_flush to return 0 if the number
 of blocks needed would be more than three, and set CP_COMPACT_SUM_FLAG only
 when data_sum_blocks  0.
 
 I don't know if you would need to make a corresponding change to the recovery
 code, I haven't fully examined that yet.

Ok, let me explain about CP_COMPACT_SUM_FLAG.
Let's assume that there are some journal entries and data summaries.
Note that this scenario is not from the umount procedure.

Basically f2fs writes three data summary blocks for current active logs
inside the checkpoint pack.
And NAT and SIT journal entries are stored in hot and cold data summary
blocks.
So, if the CP_COMPACT_SUM_FLAG is not set, f2fs writes the checkpoint
pack like this.

[CP 0]
[Orphan blocks]
[Hot sum block w/ NAT journal]
[Warm sum block]
[Cold sum block w/ SIT journal]
[CP 0']

But, if the CP_COMPACT_SUM_FLAG is set, the checkpoint pack consists of
1 or 2 summary blocks as follows.

[CP 0]
[Orphan blocks]
[summary entries w/ NAT and SIT journal]
[CP 0']

or,

[CP 0]
[Orphan blocks]
[summary entries]
[summary entries w/ NAT and SIT journal]
[CP 0']

So, I think it needs no change.
Any idea?
Thanks,

 
 Regards,
 NeilBrown

-- 
Jaegeuk Kim
Samsung

--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH 05/16] f2fs: add checkpoint operations

2012-10-10 Thread NeilBrown
On Fri, 05 Oct 2012 20:59:29 +0900 김재극  wrote:

> +static void do_checkpoint(struct f2fs_sb_info *sbi, bool is_umount)
> +{
> + struct f2fs_checkpoint *ckpt = F2FS_CKPT(sbi);
> + nid_t last_nid = 0;
> + int nat_upd_blkoff[3];
> + block_t start_blk;
> + struct page *cp_page;
> + unsigned int data_sum_blocks, orphan_blocks;
> + void *kaddr;
> + __u32 crc32 = 0;
> + int i;
> +
> + /* Flush all the NAT/SIT pages */
> + while (get_pages(sbi, F2FS_DIRTY_META))
> + sync_meta_pages(sbi, META, LONG_MAX);
> +
> + next_free_nid(sbi, _nid);
> +
> + /*
> +  * modify checkpoint
> +  * version number is already updated
> +  */
> + ckpt->elapsed_time = cpu_to_le64(get_mtime(sbi));
> + ckpt->valid_block_count = cpu_to_le64(valid_user_blocks(sbi));
> + ckpt->free_segment_count = cpu_to_le32(free_segments(sbi));
> + for (i = 0; i < 3; i++) {
> + ckpt->cur_node_segno[i] =
> + cpu_to_le32(curseg_segno(sbi, i + CURSEG_HOT_NODE));
> + ckpt->cur_node_blkoff[i] =
> + cpu_to_le16(curseg_blkoff(sbi, i + CURSEG_HOT_NODE));
> + nat_upd_blkoff[i] = NM_I(sbi)->nat_upd_blkoff[i];
> + ckpt->nat_upd_blkoff[i] = cpu_to_le16(nat_upd_blkoff[i]);
> + ckpt->alloc_type[i + CURSEG_HOT_NODE] =
> + curseg_alloc_type(sbi, i + CURSEG_HOT_NODE);
> + }
> + for (i = 0; i < 3; i++) {
> + ckpt->cur_data_segno[i] =
> + cpu_to_le32(curseg_segno(sbi, i + CURSEG_HOT_DATA));
> + ckpt->cur_data_blkoff[i] =
> + cpu_to_le16(curseg_blkoff(sbi, i + CURSEG_HOT_DATA));
> + ckpt->alloc_type[i + CURSEG_HOT_DATA] =
> + curseg_alloc_type(sbi, i + CURSEG_HOT_DATA);
> + }
> +
> + ckpt->valid_node_count = cpu_to_le32(valid_node_count(sbi));
> + ckpt->valid_inode_count = cpu_to_le32(valid_inode_count(sbi));
> + ckpt->next_free_nid = cpu_to_le32(last_nid);
> +
> + /* 2 cp  + n data seg summary + orphan inode blocks */
> + data_sum_blocks = npages_for_summary_flush(sbi);
> + if (data_sum_blocks < 3)
> + ckpt->ckpt_flags |= CP_COMPACT_SUM_FLAG;
> + else
> + ckpt->ckpt_flags &= (~CP_COMPACT_SUM_FLAG);
> +
> + orphan_blocks = (sbi->n_orphans + F2FS_ORPHANS_PER_BLOCK - 1)
> + / F2FS_ORPHANS_PER_BLOCK;
> + ckpt->cp_pack_start_sum = 1 + orphan_blocks;
> + ckpt->cp_pack_total_block_count = 2 + data_sum_blocks + orphan_blocks;

This looks a bit weird to me, though I might be misunderstanding something.

data_sum_blocks is either 1, 2, or 3.
"3" actually means "at least 3".

If it is 3, you choose not to set CP_COMPACT_SUM_FLAG.  In that case the NAT
and SIT journal entries go into SSA blocks, not into the checkpoint at all.
So in that case, zero blocks of the checkpoint are used for journalling.  Yet
you still add data_sum_blocks (==3) to the cp_pack_total_block_count (and
later to the start block).
Is that really what you want to do?  Leave 3 empty blocks?

I would suggest changing npages_for_summary_flush to return 0 if the number
of blocks needed would be more than three, and set CP_COMPACT_SUM_FLAG only
when data_sum_blocks > 0.

I don't know if you would need to make a corresponding change to the recovery
code, I haven't fully examined that yet.

Regards,
NeilBrown


signature.asc
Description: PGP signature


Re: [PATCH 05/16] f2fs: add checkpoint operations

2012-10-10 Thread NeilBrown
On Fri, 05 Oct 2012 20:59:29 +0900 김재극 jaegeuk@samsung.com wrote:

 +static void do_checkpoint(struct f2fs_sb_info *sbi, bool is_umount)
 +{
 + struct f2fs_checkpoint *ckpt = F2FS_CKPT(sbi);
 + nid_t last_nid = 0;
 + int nat_upd_blkoff[3];
 + block_t start_blk;
 + struct page *cp_page;
 + unsigned int data_sum_blocks, orphan_blocks;
 + void *kaddr;
 + __u32 crc32 = 0;
 + int i;
 +
 + /* Flush all the NAT/SIT pages */
 + while (get_pages(sbi, F2FS_DIRTY_META))
 + sync_meta_pages(sbi, META, LONG_MAX);
 +
 + next_free_nid(sbi, last_nid);
 +
 + /*
 +  * modify checkpoint
 +  * version number is already updated
 +  */
 + ckpt-elapsed_time = cpu_to_le64(get_mtime(sbi));
 + ckpt-valid_block_count = cpu_to_le64(valid_user_blocks(sbi));
 + ckpt-free_segment_count = cpu_to_le32(free_segments(sbi));
 + for (i = 0; i  3; i++) {
 + ckpt-cur_node_segno[i] =
 + cpu_to_le32(curseg_segno(sbi, i + CURSEG_HOT_NODE));
 + ckpt-cur_node_blkoff[i] =
 + cpu_to_le16(curseg_blkoff(sbi, i + CURSEG_HOT_NODE));
 + nat_upd_blkoff[i] = NM_I(sbi)-nat_upd_blkoff[i];
 + ckpt-nat_upd_blkoff[i] = cpu_to_le16(nat_upd_blkoff[i]);
 + ckpt-alloc_type[i + CURSEG_HOT_NODE] =
 + curseg_alloc_type(sbi, i + CURSEG_HOT_NODE);
 + }
 + for (i = 0; i  3; i++) {
 + ckpt-cur_data_segno[i] =
 + cpu_to_le32(curseg_segno(sbi, i + CURSEG_HOT_DATA));
 + ckpt-cur_data_blkoff[i] =
 + cpu_to_le16(curseg_blkoff(sbi, i + CURSEG_HOT_DATA));
 + ckpt-alloc_type[i + CURSEG_HOT_DATA] =
 + curseg_alloc_type(sbi, i + CURSEG_HOT_DATA);
 + }
 +
 + ckpt-valid_node_count = cpu_to_le32(valid_node_count(sbi));
 + ckpt-valid_inode_count = cpu_to_le32(valid_inode_count(sbi));
 + ckpt-next_free_nid = cpu_to_le32(last_nid);
 +
 + /* 2 cp  + n data seg summary + orphan inode blocks */
 + data_sum_blocks = npages_for_summary_flush(sbi);
 + if (data_sum_blocks  3)
 + ckpt-ckpt_flags |= CP_COMPACT_SUM_FLAG;
 + else
 + ckpt-ckpt_flags = (~CP_COMPACT_SUM_FLAG);
 +
 + orphan_blocks = (sbi-n_orphans + F2FS_ORPHANS_PER_BLOCK - 1)
 + / F2FS_ORPHANS_PER_BLOCK;
 + ckpt-cp_pack_start_sum = 1 + orphan_blocks;
 + ckpt-cp_pack_total_block_count = 2 + data_sum_blocks + orphan_blocks;

This looks a bit weird to me, though I might be misunderstanding something.

data_sum_blocks is either 1, 2, or 3.
3 actually means at least 3.

If it is 3, you choose not to set CP_COMPACT_SUM_FLAG.  In that case the NAT
and SIT journal entries go into SSA blocks, not into the checkpoint at all.
So in that case, zero blocks of the checkpoint are used for journalling.  Yet
you still add data_sum_blocks (==3) to the cp_pack_total_block_count (and
later to the start block).
Is that really what you want to do?  Leave 3 empty blocks?

I would suggest changing npages_for_summary_flush to return 0 if the number
of blocks needed would be more than three, and set CP_COMPACT_SUM_FLAG only
when data_sum_blocks  0.

I don't know if you would need to make a corresponding change to the recovery
code, I haven't fully examined that yet.

Regards,
NeilBrown


signature.asc
Description: PGP signature


[PATCH 05/16] f2fs: add checkpoint operations

2012-10-05 Thread 김재극
This adds functions required by the checkpoint operations.

Basically, f2fs adopts a roll-back model with checkpoint blocks written in the
CP area. The checkpoint procedure includes as follows.

- write_checkpoint()
1. block_operations() freezes VFS calls.
2. submit cached bios.
3. flush_nat_entries() writes NAT pages updated by dirty NAT entries.
4. flush_sit_entries() writes SIT pages updated by dirty SIT entries.
5. do_checkpoint() writes,
  - checkpoint block (#0)
  - orphan inode blocks
  - summary blocks made by active logs
  - checkpoint block (copy of #0)
6. unblock_opeations()

In order to provide an address space for meta pages, f2fs_sb_info has a special
inode, namely meta_inode. This patch also adds the address space operations for
meta_inode.

Signed-off-by: Chul Lee 
Signed-off-by: Jaegeuk Kim 
---
 fs/f2fs/checkpoint.c |  791 ++
 1 file changed, 791 insertions(+)
 create mode 100644 fs/f2fs/checkpoint.c

diff --git a/fs/f2fs/checkpoint.c b/fs/f2fs/checkpoint.c
new file mode 100644
index 000..2186b82
--- /dev/null
+++ b/fs/f2fs/checkpoint.c
@@ -0,0 +1,791 @@
+/**
+ * fs/f2fs/checkpoint.c
+ *
+ * Copyright (c) 2012 Samsung Electronics Co., Ltd.
+ * http://www.samsung.com/
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include "f2fs.h"
+#include "node.h"
+#include "segment.h"
+
+static struct kmem_cache *orphan_entry_slab;
+static struct kmem_cache *inode_entry_slab;
+
+/**
+ * We guarantee no failure on the returned page.
+ */
+struct page *grab_meta_page(struct f2fs_sb_info *sbi, pgoff_t index)
+{
+   struct address_space *mapping = sbi->meta_inode->i_mapping;
+   struct page *page = NULL;
+repeat:
+   page = grab_cache_page(mapping, index);
+   if (!page) {
+   cond_resched();
+   goto repeat;
+   }
+
+   /* We wait writeback only inside grab_meta_page() */
+   wait_on_page_writeback(page);
+   SetPageUptodate(page);
+   return page;
+}
+
+/**
+ * We guarantee no failure on the returned page.
+ */
+struct page *get_meta_page(struct f2fs_sb_info *sbi, pgoff_t index)
+{
+   struct address_space *mapping = sbi->meta_inode->i_mapping;
+   struct page *page;
+repeat:
+   page = grab_cache_page(mapping, index);
+   if (!page) {
+   cond_resched();
+   goto repeat;
+   }
+   if (f2fs_readpage(sbi, page, index, READ_SYNC)) {
+   f2fs_put_page(page, 1);
+   goto repeat;
+   }
+   mark_page_accessed(page);
+
+   /* We do not allow returning an errorneous page */
+   return page;
+}
+
+static int f2fs_write_meta_page(struct page *page,
+   struct writeback_control *wbc)
+{
+   struct inode *inode = page->mapping->host;
+   struct f2fs_sb_info *sbi = F2FS_SB(inode->i_sb);
+   int err;
+
+   wait_on_page_writeback(page);
+
+   err = write_meta_page(sbi, page, wbc);
+   if (err) {
+   wbc->pages_skipped++;
+   set_page_dirty(page);
+   }
+
+   dec_page_count(sbi, F2FS_DIRTY_META);
+
+   /* In this case, we should not unlock this page */
+   if (err != AOP_WRITEPAGE_ACTIVATE)
+   unlock_page(page);
+   return err;
+}
+
+static int f2fs_write_meta_pages(struct address_space *mapping,
+   struct writeback_control *wbc)
+{
+   struct f2fs_sb_info *sbi = F2FS_SB(mapping->host->i_sb);
+   struct block_device *bdev = sbi->sb->s_bdev;
+   long written;
+
+   if (wbc->for_kupdate)
+   return 0;
+
+   if (get_pages(sbi, F2FS_DIRTY_META) == 0)
+   return 0;
+
+   /* if mounting is failed, skip writing node pages */
+   mutex_lock(>cp_mutex);
+   written = sync_meta_pages(sbi, META, bio_get_nr_vecs(bdev));
+   mutex_unlock(>cp_mutex);
+   wbc->nr_to_write -= written;
+   return 0;
+}
+
+long sync_meta_pages(struct f2fs_sb_info *sbi, enum page_type type,
+   long nr_to_write)
+{
+   struct address_space *mapping = sbi->meta_inode->i_mapping;
+   pgoff_t index = 0, end = LONG_MAX;
+   struct pagevec pvec;
+   long nwritten = 0;
+   struct writeback_control wbc = {
+   .for_reclaim = 0,
+   };
+
+   pagevec_init(, 0);
+
+   while (index <= end) {
+   int i, nr_pages;
+   nr_pages = pagevec_lookup_tag(, mapping, ,
+   PAGECACHE_TAG_DIRTY,
+   min(end - index, (pgoff_t)PAGEVEC_SIZE-1) + 1);
+   if (nr_pages == 0)
+   break;
+
+   for (i = 0; i < nr_pages; i++) {
+   

[PATCH 05/16] f2fs: add checkpoint operations

2012-10-05 Thread 김재극
This adds functions required by the checkpoint operations.

Basically, f2fs adopts a roll-back model with checkpoint blocks written in the
CP area. The checkpoint procedure includes as follows.

- write_checkpoint()
1. block_operations() freezes VFS calls.
2. submit cached bios.
3. flush_nat_entries() writes NAT pages updated by dirty NAT entries.
4. flush_sit_entries() writes SIT pages updated by dirty SIT entries.
5. do_checkpoint() writes,
  - checkpoint block (#0)
  - orphan inode blocks
  - summary blocks made by active logs
  - checkpoint block (copy of #0)
6. unblock_opeations()

In order to provide an address space for meta pages, f2fs_sb_info has a special
inode, namely meta_inode. This patch also adds the address space operations for
meta_inode.

Signed-off-by: Chul Lee chur@samsung.com
Signed-off-by: Jaegeuk Kim jaegeuk@samsung.com
---
 fs/f2fs/checkpoint.c |  791 ++
 1 file changed, 791 insertions(+)
 create mode 100644 fs/f2fs/checkpoint.c

diff --git a/fs/f2fs/checkpoint.c b/fs/f2fs/checkpoint.c
new file mode 100644
index 000..2186b82
--- /dev/null
+++ b/fs/f2fs/checkpoint.c
@@ -0,0 +1,791 @@
+/**
+ * fs/f2fs/checkpoint.c
+ *
+ * Copyright (c) 2012 Samsung Electronics Co., Ltd.
+ * http://www.samsung.com/
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+#include linux/fs.h
+#include linux/bio.h
+#include linux/mpage.h
+#include linux/writeback.h
+#include linux/blkdev.h
+#include linux/f2fs_fs.h
+#include linux/pagevec.h
+#include linux/swap.h
+
+#include f2fs.h
+#include node.h
+#include segment.h
+
+static struct kmem_cache *orphan_entry_slab;
+static struct kmem_cache *inode_entry_slab;
+
+/**
+ * We guarantee no failure on the returned page.
+ */
+struct page *grab_meta_page(struct f2fs_sb_info *sbi, pgoff_t index)
+{
+   struct address_space *mapping = sbi-meta_inode-i_mapping;
+   struct page *page = NULL;
+repeat:
+   page = grab_cache_page(mapping, index);
+   if (!page) {
+   cond_resched();
+   goto repeat;
+   }
+
+   /* We wait writeback only inside grab_meta_page() */
+   wait_on_page_writeback(page);
+   SetPageUptodate(page);
+   return page;
+}
+
+/**
+ * We guarantee no failure on the returned page.
+ */
+struct page *get_meta_page(struct f2fs_sb_info *sbi, pgoff_t index)
+{
+   struct address_space *mapping = sbi-meta_inode-i_mapping;
+   struct page *page;
+repeat:
+   page = grab_cache_page(mapping, index);
+   if (!page) {
+   cond_resched();
+   goto repeat;
+   }
+   if (f2fs_readpage(sbi, page, index, READ_SYNC)) {
+   f2fs_put_page(page, 1);
+   goto repeat;
+   }
+   mark_page_accessed(page);
+
+   /* We do not allow returning an errorneous page */
+   return page;
+}
+
+static int f2fs_write_meta_page(struct page *page,
+   struct writeback_control *wbc)
+{
+   struct inode *inode = page-mapping-host;
+   struct f2fs_sb_info *sbi = F2FS_SB(inode-i_sb);
+   int err;
+
+   wait_on_page_writeback(page);
+
+   err = write_meta_page(sbi, page, wbc);
+   if (err) {
+   wbc-pages_skipped++;
+   set_page_dirty(page);
+   }
+
+   dec_page_count(sbi, F2FS_DIRTY_META);
+
+   /* In this case, we should not unlock this page */
+   if (err != AOP_WRITEPAGE_ACTIVATE)
+   unlock_page(page);
+   return err;
+}
+
+static int f2fs_write_meta_pages(struct address_space *mapping,
+   struct writeback_control *wbc)
+{
+   struct f2fs_sb_info *sbi = F2FS_SB(mapping-host-i_sb);
+   struct block_device *bdev = sbi-sb-s_bdev;
+   long written;
+
+   if (wbc-for_kupdate)
+   return 0;
+
+   if (get_pages(sbi, F2FS_DIRTY_META) == 0)
+   return 0;
+
+   /* if mounting is failed, skip writing node pages */
+   mutex_lock(sbi-cp_mutex);
+   written = sync_meta_pages(sbi, META, bio_get_nr_vecs(bdev));
+   mutex_unlock(sbi-cp_mutex);
+   wbc-nr_to_write -= written;
+   return 0;
+}
+
+long sync_meta_pages(struct f2fs_sb_info *sbi, enum page_type type,
+   long nr_to_write)
+{
+   struct address_space *mapping = sbi-meta_inode-i_mapping;
+   pgoff_t index = 0, end = LONG_MAX;
+   struct pagevec pvec;
+   long nwritten = 0;
+   struct writeback_control wbc = {
+   .for_reclaim = 0,
+   };
+
+   pagevec_init(pvec, 0);
+
+   while (index = end) {
+   int i, nr_pages;
+   nr_pages = pagevec_lookup_tag(pvec, mapping, index,
+   PAGECACHE_TAG_DIRTY,
+   min(end - index,