Skip to contentSkip to conversation

some optimization & code cleanup

PATCH New Haicheng Li 1 participant 4 messages Jun 13, 2013

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

cover some optimization & code cleanup

Fix some issues found by code review.

Haicheng Li (3):
f2fs: remove unnecessary parameter "offset" from __add_sum_entry()
f2fs: make locate_dirty_segment() as static
f2fs: optimize do_write_data_page()

 fs/f2fs/data.c    |    5 +++--
 fs/f2fs/f2fs.h    |    1 -
 fs/f2fs/segment.c |   12 ++++++------
 3 files changed, 9 insertions(+), 9 deletions(-)
Signature · 1 line
1.7.9.5
#1 lore raw

PATCH 1/3 f2fs: remove unnecessary parameter "offset" from __add_sum_entry()

We can get the value directly from pointer "curseg".

---
 fs/f2fs/segment.c |   10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
fs/f2fs/segment.c +5 -5
index be668ff..77f31c0 100644
@@ -255,11 +255,11 @@ void invalidate_blocks(struct f2fs_sb_info *sbi, block_t addr)
  * This function should be resided under the curseg_mutex lock
  */
 static void __add_sum_entry(struct f2fs_sb_info *sbi, int type,
-		struct f2fs_summary *sum, unsigned short offset)
+					struct f2fs_summary *sum)
 {
 	struct curseg_info *curseg = CURSEG_I(sbi, type);
 	void *addr = curseg->sum_blk;
-	addr += offset * sizeof(struct f2fs_summary);
+	addr += curseg->next_blkoff * sizeof(struct f2fs_summary);
 	memcpy(addr, sum, sizeof(struct f2fs_summary));
 	return;
 }
@@ -845,7 +845,7 @@ static void do_write_page(struct f2fs_sb_info *sbi, struct page *page,
 	 * because, this function updates a summary entry in the
 	 * current summary block.
 	 */
-	__add_sum_entry(sbi, type, sum, curseg->next_blkoff);
+	__add_sum_entry(sbi, type, sum);
 
 	mutex_lock(&sit_i->sentry_lock);
 	__refresh_next_blkoff(sbi, curseg);
@@ -946,7 +946,7 @@ void recover_data_page(struct f2fs_sb_info *sbi,
 
 	curseg->next_blkoff = GET_SEGOFF_FROM_SEG0(sbi, new_blkaddr) &
 					(sbi->blocks_per_seg - 1);
-	__add_sum_entry(sbi, type, sum, curseg->next_blkoff);
+	__add_sum_entry(sbi, type, sum);
 
 	refresh_sit_entry(sbi, old_blkaddr, new_blkaddr);
 
@@ -983,7 +983,7 @@ void rewrite_node_page(struct f2fs_sb_info *sbi,
 	}
 	curseg->next_blkoff = GET_SEGOFF_FROM_SEG0(sbi, new_blkaddr) &
 					(sbi->blocks_per_seg - 1);
-	__add_sum_entry(sbi, type, sum, curseg->next_blkoff);
+	__add_sum_entry(sbi, type, sum);
 
 	/* change the current log to the next block addr in advance */
 	if (next_segno != segno) {
Signature · 1 line
1.7.9.5
#2 lore raw

PATCH 2/3 f2fs: make locate_dirty_segment() as static

In reply to Haicheng Li

It's used only locally and could be static.

---
 fs/f2fs/f2fs.h    |    1 -
 fs/f2fs/segment.c |    2 +-
 2 files changed, 1 insertion(+), 2 deletions(-)
fs/f2fs/f2fs.h +0 -1
index a05aa65..3e7cb33 100644
@@ -996,7 +996,6 @@ void destroy_node_manager_caches(void);
  */
 void f2fs_balance_fs(struct f2fs_sb_info *);
 void invalidate_blocks(struct f2fs_sb_info *, block_t);
-void locate_dirty_segment(struct f2fs_sb_info *, unsigned int);
 void clear_prefree_segments(struct f2fs_sb_info *);
 int npages_for_summary_flush(struct f2fs_sb_info *);
 void allocate_new_segments(struct f2fs_sb_info *);
fs/f2fs/segment.c +1 -1
index 77f31c0..b15debc 100644
@@ -94,7 +94,7 @@ static void __remove_dirty_segment(struct f2fs_sb_info *sbi, unsigned int segno,
  * Adding dirty entry into seglist is not critical operation.
  * If a given segment is one of current working segments, it won't be added.
  */
-void locate_dirty_segment(struct f2fs_sb_info *sbi, unsigned int segno)
+static void locate_dirty_segment(struct f2fs_sb_info *sbi, unsigned int segno)
 {
 	struct dirty_seglist_info *dirty_i = DIRTY_I(sbi);
 	unsigned short valid_blocks;
Signature · 9 lines
1.7.9.5


------------------------------------------------------------------------------
This SF.net email is sponsored by Windows:

Build for Windows Store.

http://p.sf.net/sfu/windows-dev2dev
#3 lore raw

PATCH 3/3 f2fs: optimize do_write_data_page()

In reply to Haicheng Li

Since "need_inplace_update() == true" is a very rare case, using unlikely() to give compiler a chance to optimize the code.

---
 fs/f2fs/data.c |    5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
fs/f2fs/data.c +3 -2
index 5b145fc..6d4a743 100644
@@ -497,8 +497,9 @@ int do_write_data_page(struct page *page)
 	 * If current allocation needs SSR,
 	 * it had better in-place writes for updated data.
 	 */
-	if (old_blk_addr != NEW_ADDR && !is_cold_data(page) &&
-				need_inplace_update(inode)) {
+	if (unlikely(old_blk_addr != NEW_ADDR &&
+			!is_cold_data(page) &&
+			need_inplace_update(inode))) {
 		rewrite_data_page(F2FS_SB(inode->i_sb), page,
 						old_blk_addr);
 	} else {
Signature · 1 line
1.7.9.5