Skip to contentSkip to conversation

f2fs: read contiguous sit entry pages by merging for mount performance

PATCH Superseded Chao Yu 2 participants 4 messages Nov 12, 2013 – Nov 14, 2013

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Chao Yu

author
#0 lore raw

PATCH 2/2 f2fs: read contiguous sit entry pages by merging for mount performance

Previously we read sit entries page one by one, this method lost the chance of reading contiguous page together. So we read pages as contiguous as possible for better mount performance.

---
 fs/f2fs/f2fs.h    |    2 ++
 fs/f2fs/segment.c |   65 ++++++++++++++++++++++++++++++++++++++++++++++++++---
 fs/f2fs/segment.h |    2 ++
 3 files changed, 66 insertions(+), 3 deletions(-)
fs/f2fs/f2fs.h +2 -0
index 0afdcec..bfe9d87 100644
@@ -1113,6 +1113,8 @@ struct page *find_data_page(struct inode *, pgoff_t, bool);
 struct page *get_lock_data_page(struct inode *, pgoff_t);
 struct page *get_new_data_page(struct inode *, struct page *, pgoff_t, bool);
 int f2fs_readpage(struct f2fs_sb_info *, struct page *, block_t, int);
+void f2fs_submit_read_bio(struct f2fs_sb_info *, int);
+void submit_read_page(struct f2fs_sb_info *, struct page *, block_t, int);
 int do_write_data_page(struct page *);
 
 /*
fs/f2fs/segment.c +62 -3

93 lines not on this page · raw message

fs/f2fs/segment.h +2 -0
index 269f690..ad5b9f1 100644
@@ -83,6 +83,8 @@
 	(segno / SIT_ENTRY_PER_BLOCK)
 #define	START_SEGNO(sit_i, segno)		\
 	(SIT_BLOCK_OFFSET(sit_i, segno) * SIT_ENTRY_PER_BLOCK)
+#define SIT_BLK_CNT(sbi)			\
+	((TOTAL_SEGS(sbi) + SIT_ENTRY_PER_BLOCK - 1) / SIT_ENTRY_PER_BLOCK)
 #define f2fs_bitmap_size(nr)			\
 	(BITS_TO_LONGS(nr) * sizeof(unsigned long))
 #define TOTAL_SEGS(sbi)	(SM_I(sbi)->main_segments)
Signature · 1 line
1.7.9.5
#1 lore raw

Hi Yu,

Quoted 15 lines · Chao Yu

Previously we read sit entries page one by one, this method lost the chance of reading contiguous page together. So we read pages as contiguous as possible for better mount performance.

---
 fs/f2fs/f2fs.h    |    2 ++
 fs/f2fs/segment.c |   65 ++++++++++++++++++++++++++++++++++++++++++++++++++---
 fs/f2fs/segment.h |    2 ++
 3 files changed, 66 insertions(+), 3 deletions(-)
fs/f2fs/f2fs.h +0 -0
index 0afdcec..bfe9d87 100644

fs/f2fs/f2fs.h struct page *find_data_page(struct inode *, pgoff_t, bool); · line 1117

Quoted 5 lines
fs/f2fs/f2fs.h +2 -0
@@ -1113,6 +1113,8 @@ struct page *find_data_page(struct inode *, pgoff_t, bool);
 struct page *get_lock_data_page(struct inode *, pgoff_t);
 struct page *get_new_data_page(struct inode *, struct page *, pgoff_t, bool);
 int f2fs_readpage(struct f2fs_sb_info *, struct page *, block_t, int);
+void f2fs_submit_read_bio(struct f2fs_sb_info *, int);
+void submit_read_page(struct f2fs_sb_info *, struct page *, block_t, int);

Better to move these declarations into PATCH 1/2.

Quoted 14 lines
fs/f2fs/f2fs.h +0 -0
 int do_write_data_page(struct page *);
 
 /*
fs/f2fs/segment.c +3 -0
index 86dc289..414c351 100644
@@ -1474,19 +1474,72 @@ static int build_curseg(struct f2fs_sb_info *sbi)
 	return restore_curseg_summaries(sbi);
 }
 
+static int ra_sit_pages(struct f2fs_sb_info *sbi, int start,
+					int nrpages, bool *is_order)
+{

fs/f2fs/segment.c static int build_curseg(struct f2fs_sb_info *sbi) · line 1489

Quoted 10 lines
fs/f2fs/segment.c +10 -0
+	struct address_space *mapping = sbi->meta_inode->i_mapping;
+	struct sit_info *sit_i = SIT_I(sbi);
+	struct page *page;
+	block_t blk_addr;
+	int blkno, readcnt = 0;
+	int sit_blk_cnt = SIT_BLK_CNT(sbi);
+
+	for (blkno = start; blkno < start + nrpages; blkno++) {
+
+		if (blkno >= sit_blk_cnt)

Merge these two judgements:
for (blkno = start; blkno < start + nrpages && blkno < sit_blk_cnt; blkno++)

fs/f2fs/segment.c static int build_curseg(struct f2fs_sb_info *sbi) · line 1493

Quoted 5 lines
fs/f2fs/segment.c +4 -0
+			goto out;
 
+		if ((!f2fs_test_bit(blkno, sit_i->sit_bitmap) ^ !*is_order)) {
+			*is_order = !*is_order;
+			goto out;

'Break' seems more suitable.

Quoted 5 lines
fs/f2fs/segment.c +5 -0
+		}
+
+		blk_addr = sit_i->sit_base_addr + blkno;
+		if (*is_order)
+			blk_addr += sit_i->sit_blocks;

fs/f2fs/segment.c static int build_curseg(struct f2fs_sb_info *sbi) · line 1508

Quoted 10 lines
fs/f2fs/segment.c +10 -0
+repeat:
+		page = grab_cache_page(mapping, blk_addr);
+		if (!page) {
+			cond_resched();
+			goto repeat;
+		}
+		if (PageUptodate(page)) {
+			f2fs_put_page(page, 1);
+			readcnt++;
+			goto out;

Here may be 'Continue'.

fs/f2fs/segment.c static int build_curseg(struct f2fs_sb_info *sbi) · line 1513

Quoted 5 lines
fs/f2fs/segment.c +5 -0
+		}
+
+		submit_read_page(sbi, page, blk_addr, READ_SYNC);
+
+		page_cache_release(page);

Put page here seems not a good idea, otherwise all your work may be in vain.

Quoted 12 lines
fs/f2fs/segment.c +7 -0
+		readcnt++;
+	}
+out:
+	f2fs_submit_read_bio(sbi, READ_SYNC);
+	return readcnt;
+}
+
 static void build_sit_entries(struct f2fs_sb_info *sbi)
 {
 	struct sit_info *sit_i = SIT_I(sbi);
 	struct curseg_info *curseg = CURSEG_I(sbi, CURSEG_COLD_DATA);
 	struct f2fs_summary_block *sum = curseg->sum_blk;

fs/f2fs/segment.c static int build_curseg(struct f2fs_sb_info *sbi) · line 1533

Quoted 10 lines
fs/f2fs/segment.c +7 -2
-	unsigned int start;
+	bool is_order = f2fs_test_bit(0, sit_i->sit_bitmap) ? true : false;
+	int sit_blk_cnt = SIT_BLK_CNT(sbi);
+	int bio_blocks = MAX_BIO_BLOCKS(max_hw_blocks(sbi));
+	unsigned int i, start, end;
+	unsigned int readed, start_blk = 0;
 
-	for (start = 0; start < TOTAL_SEGS(sbi); start++) {
+next:
+	readed = ra_sit_pages(sbi, start_blk, bio_blocks, &is_order);

In fact, you know how many blocks that you want to read(SIT_BLK_CNT(sbi)), so here sit_blk_cnt is more suitable than a MAX one, and it also can make the logic of ra_sit_pages more simple.

Quoted 22 lines
fs/f2fs/segment.c +5 -1
+
+	start = start_blk * sit_i->sents_per_block;
+	end = (start_blk + readed) * sit_i->sents_per_block;
+
+	for (; start < end && start < TOTAL_SEGS(sbi); start++) {
 		struct seg_entry *se = &sit_i->sentries[start];
 		struct f2fs_sit_block *sit_blk;
 		struct f2fs_sit_entry sit;
 		struct page *page;
-		int i;
 
 		mutex_lock(&curseg->curseg_mutex);
fs/f2fs/segment.c +1 -0
 		for (i = 0; i < sits_in_cursum(sum); i++) {
@@ -1497,6 +1550,7 @@ static void build_sit_entries(struct f2fs_sb_info *sbi)
 			}
 		}
 		mutex_unlock(&curseg->curseg_mutex);
+
 		page = get_current_sit_page(sbi, start);
 		sit_blk = (struct f2fs_sit_block *)page_address(page);
 		sit = sit_blk->entries[SIT_ENTRY_OFFSET(sit_i, start)];

fs/f2fs/segment.c got_it: · line 1570

Quoted 8 lines
fs/f2fs/segment.c +5 -0
@@ -1509,6 +1563,11 @@ got_it:
 			e->valid_blocks += se->valid_blocks;
 		}
 	}
+
+	start_blk += readed;
+	if (start_blk >= sit_blk_cnt)
+		return;
+	goto next;

Using do {...} while(start_blk < sit_blk_cnt) rather than the so big upstream goto.

Quoted 16 lines
fs/f2fs/segment.c +0 -0
 }
 
 static void init_free_segmap(struct f2fs_sb_info *sbi)
fs/f2fs/segment.h +2 -0
index 269f690..ad5b9f1 100644
@@ -83,6 +83,8 @@
 	(segno / SIT_ENTRY_PER_BLOCK)
 #define	START_SEGNO(sit_i, segno)		\
 	(SIT_BLOCK_OFFSET(sit_i, segno) * SIT_ENTRY_PER_BLOCK)
+#define SIT_BLK_CNT(sbi)			\
+	((TOTAL_SEGS(sbi) + SIT_ENTRY_PER_BLOCK - 1) / SIT_ENTRY_PER_BLOCK)
 #define f2fs_bitmap_size(nr)			\
 	(BITS_TO_LONGS(nr) * sizeof(unsigned long))
 #define TOTAL_SEGS(sbi)	(SM_I(sbi)->main_segments)
author
#2 lore raw

Hi Gu,

Quoted 20 lines

-----Original Message-----
From: Gu Zheng [mailto:[email protected]]
Sent: Wednesday, November 13, 2013 11:39 AM
To: Chao Yu
Cc: ???; [email protected]; [email protected]; [email protected]; 谭姝
Subject: Re: [f2fs-dev] [PATCH 2/2] f2fs: read contiguous sit entry pages by merging for mount performance

Hi Yu,

Quoted 10 lines · Chao Yu

Previously we read sit entries page one by one, this method lost the chance of reading contiguous page together. So we read pages as contiguous as possible for better mount performance.

---
 fs/f2fs/f2fs.h    |    2 ++
 fs/f2fs/segment.c |   65 ++++++++++++++++++++++++++++++++++++++++++++++++++---
 fs/f2fs/segment.h |    2 ++
 3 files changed, 66 insertions(+), 3 deletions(-)
Quoted 12 lines

fs/f2fs/f2fs.h struct page *find_data_page(struct inode *, pgoff_t, bool); · line 1117

Quoted 10 lines
fs/f2fs/f2fs.h +2 -0
index 0afdcec..bfe9d87 100644
@@ -1113,6 +1113,8 @@ struct page *find_data_page(struct inode *, pgoff_t, bool);
 struct page *get_lock_data_page(struct inode *, pgoff_t);
 struct page *get_new_data_page(struct inode *, struct page *, pgoff_t, bool);
 int f2fs_readpage(struct f2fs_sb_info *, struct page *, block_t, int);
+void f2fs_submit_read_bio(struct f2fs_sb_info *, int);
+void submit_read_page(struct f2fs_sb_info *, struct page *, block_t, int);

Better to move these declarations into PATCH 1/2.

Okay, I will move it to the right place.

Quoted 12 lines
Quoted 12 lines
fs/f2fs/f2fs.h +0 -0
 int do_write_data_page(struct page *);
 
 /*
fs/f2fs/segment.c +0 -0
index 86dc289..414c351 100644
@@ -1474,19 +1474,72 @@ static int build_curseg(struct f2fs_sb_info *sbi)
 	return restore_curseg_summaries(sbi);
 }
 
Quoted 16 lines

fs/f2fs/segment.c static int build_curseg(struct f2fs_sb_info *sbi) · line 1489

Quoted 13 lines
fs/f2fs/segment.c +13 -0
+static int ra_sit_pages(struct f2fs_sb_info *sbi, int start,
+					int nrpages, bool *is_order)
+{
+	struct address_space *mapping = sbi->meta_inode->i_mapping;
+	struct sit_info *sit_i = SIT_I(sbi);
+	struct page *page;
+	block_t blk_addr;
+	int blkno, readcnt = 0;
+	int sit_blk_cnt = SIT_BLK_CNT(sbi);
+
+	for (blkno = start; blkno < start + nrpages; blkno++) {
+
+		if (blkno >= sit_blk_cnt)

Merge these two judgements:
for (blkno = start; blkno < start + nrpages && blkno < sit_blk_cnt; blkno++)

Right, but the line may over 80 characters, if we split this line, it seems not suitable. So how about this?

	int blkno = start, readcnt = 0;
	int sit_blk_cnt = SIT_BLK_CNT(sbi);

	for (; blkno < start + nrpages && blkno < sit_blk_cnt; blkno++) {
Quoted 8 lines

fs/f2fs/segment.c static int build_curseg(struct f2fs_sb_info *sbi) · line 1493

Quoted 6 lines
fs/f2fs/segment.c +4 -0
+			goto out;
 
+		if ((!f2fs_test_bit(blkno, sit_i->sit_bitmap) ^ !*is_order)) {
+			*is_order = !*is_order;
+			goto out;

'Break' seems more suitable.

Yes, you are right.

Quoted 10 lines
Quoted 10 lines
fs/f2fs/segment.c +9 -0
+		}
+
+		blk_addr = sit_i->sit_base_addr + blkno;
+		if (*is_order)
+			blk_addr += sit_i->sit_blocks;
+repeat:
+		page = grab_cache_page(mapping, blk_addr);
+		if (!page) {
+			cond_resched();
Quoted 8 lines

fs/f2fs/segment.c static int build_curseg(struct f2fs_sb_info *sbi) · line 1508

Quoted 6 lines
fs/f2fs/segment.c +6 -0
+			goto repeat;
+		}
+		if (PageUptodate(page)) {
+			f2fs_put_page(page, 1);
+			readcnt++;
+			goto out;

Here may be 'Continue'.

'Out' label could be removed after this modification. It seems more neat.

Quoted 8 lines

fs/f2fs/segment.c static int build_curseg(struct f2fs_sb_info *sbi) · line 1513

Quoted 6 lines
fs/f2fs/segment.c +5 -0
+		}
+
+		submit_read_page(sbi, page, blk_addr, READ_SYNC);
+
+		page_cache_release(page);

Put page here seems not a good idea, otherwise all your work may be in vain.

You mean that pages could be reclaimed by VM when out of memory? IMO, it is designed more like VM read ahead because we should concern memory state of system, and still we have second chance to read these pages.

Could we use mark_page_accessed () to delay VM reclaimed them?

Quoted 20 lines
Quoted 20 lines
fs/f2fs/segment.c +12 -1
+		readcnt++;
+	}
+out:
+	f2fs_submit_read_bio(sbi, READ_SYNC);
+	return readcnt;
+}
+
 static void build_sit_entries(struct f2fs_sb_info *sbi)
 {
 	struct sit_info *sit_i = SIT_I(sbi);
 	struct curseg_info *curseg = CURSEG_I(sbi, CURSEG_COLD_DATA);
 	struct f2fs_summary_block *sum = curseg->sum_blk;
-	unsigned int start;
+	bool is_order = f2fs_test_bit(0, sit_i->sit_bitmap) ? true : false;
+	int sit_blk_cnt = SIT_BLK_CNT(sbi);
+	int bio_blocks = MAX_BIO_BLOCKS(max_hw_blocks(sbi));
+	unsigned int i, start, end;
+	unsigned int readed, start_blk = 0;
 
Quoted 7 lines

fs/f2fs/segment.c static int build_curseg(struct f2fs_sb_info *sbi) · line 1533

Quoted 3 lines
fs/f2fs/segment.c +2 -1
-	for (start = 0; start < TOTAL_SEGS(sbi); start++) {
+next:
+	readed = ra_sit_pages(sbi, start_blk, bio_blocks, &is_order);

In fact, you know how many blocks that you want to read(SIT_BLK_CNT(sbi)), so here sit_blk_cnt is more suitable than a MAX one, and it also can make the logic of ra_sit_pages more simple.

Right.

BTW, I am considering that maybe we should send dynamical cnt which depend on memory state of system more than the logic of ra_sit_pages. May it's the work of anther patch. How do you think?

Quoted 25 lines
Quoted 25 lines
fs/f2fs/segment.c +5 -1
+
+	start = start_blk * sit_i->sents_per_block;
+	end = (start_blk + readed) * sit_i->sents_per_block;
+
+	for (; start < end && start < TOTAL_SEGS(sbi); start++) {
 		struct seg_entry *se = &sit_i->sentries[start];
 		struct f2fs_sit_block *sit_blk;
 		struct f2fs_sit_entry sit;
 		struct page *page;
-		int i;
 
 		mutex_lock(&curseg->curseg_mutex);
fs/f2fs/segment.c +1 -0
 		for (i = 0; i < sits_in_cursum(sum); i++) {
@@ -1497,6 +1550,7 @@ static void build_sit_entries(struct f2fs_sb_info *sbi)
 			}
 		}
 		mutex_unlock(&curseg->curseg_mutex);
+
 		page = get_current_sit_page(sbi, start);
 		sit_blk = (struct f2fs_sit_block *)page_address(page);
 		sit = sit_blk->entries[SIT_ENTRY_OFFSET(sit_i, start)];
@@ -1509,6 +1563,11 @@ got_it:
 			e->valid_blocks += se->valid_blocks;
 		}
Quoted 8 lines

fs/f2fs/segment.c got_it: · line 1570

Quoted 6 lines
fs/f2fs/segment.c +5 -0
 	}
+
+	start_blk += readed;
+	if (start_blk >= sit_blk_cnt)
+		return;
+	goto next;

Using do {...} while(start_blk < sit_blk_cnt) rather than the so big upstream goto.

Yes, you are right.

Quoted 17 lines
Quoted 9 lines
fs/f2fs/segment.c +0 -0
 }
 
 static void init_free_segmap(struct f2fs_sb_info *sbi)
fs/f2fs/segment.h +0 -0
index 269f690..ad5b9f1 100644

fs/f2fs/segment.h line 90

Quoted 8 lines
fs/f2fs/segment.h +2 -0
@@ -83,6 +83,8 @@
 	(segno / SIT_ENTRY_PER_BLOCK)
 #define	START_SEGNO(sit_i, segno)		\
 	(SIT_BLOCK_OFFSET(sit_i, segno) * SIT_ENTRY_PER_BLOCK)
+#define SIT_BLK_CNT(sbi)			\
+	((TOTAL_SEGS(sbi) + SIT_ENTRY_PER_BLOCK - 1) / SIT_ENTRY_PER_BLOCK)
 #define f2fs_bitmap_size(nr)			\
 	(BITS_TO_LONGS(nr) * sizeof(unsigned long))
 #define TOTAL_SEGS(sbi)	(SM_I(sbi)->main_segments)

Thanks!

Regards,
Yu

------------------------------------------------------------------------------
DreamFactory - Open Source REST & JSON Services for HTML5 & Native Apps OAuth, Users, Roles, SQL, NoSQL, BLOB Storage and External API Access Free app hosting. Or install the open source package on any LAMP server. Sign up and see examples for AngularJS, jQuery, Sencha Touch and Native!
http://pubads.g.doubleclick.net/gampad/clk?id=63469471&iu=/4140/ostg.clktrk
_______________________________________________
Linux-f2fs-devel mailing list [email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel

#3 lore raw

Hi Yu,

Quoted 66 lines · Chao Yu

Hi Gu,

Quoted 20 lines

-----Original Message-----
From: Gu Zheng [mailto:[email protected]]
Sent: Wednesday, November 13, 2013 11:39 AM
To: Chao Yu
Cc: ???; [email protected]; [email protected]; [email protected]; 谭姝
Subject: Re: [f2fs-dev] [PATCH 2/2] f2fs: read contiguous sit entry pages by merging for mount performance

Hi Yu,

Quoted 10 lines · Chao Yu

Previously we read sit entries page one by one, this method lost the chance of reading contiguous page together. So we read pages as contiguous as possible for better mount performance.

---
 fs/f2fs/f2fs.h    |    2 ++
 fs/f2fs/segment.c |   65 ++++++++++++++++++++++++++++++++++++++++++++++++++---
 fs/f2fs/segment.h |    2 ++
 3 files changed, 66 insertions(+), 3 deletions(-)
Quoted 12 lines

fs/f2fs/f2fs.h struct page *find_data_page(struct inode *, pgoff_t, bool); · line 1117

Quoted 10 lines
fs/f2fs/f2fs.h +2 -0
index 0afdcec..bfe9d87 100644
@@ -1113,6 +1113,8 @@ struct page *find_data_page(struct inode *, pgoff_t, bool);
 struct page *get_lock_data_page(struct inode *, pgoff_t);
 struct page *get_new_data_page(struct inode *, struct page *, pgoff_t, bool);
 int f2fs_readpage(struct f2fs_sb_info *, struct page *, block_t, int);
+void f2fs_submit_read_bio(struct f2fs_sb_info *, int);
+void submit_read_page(struct f2fs_sb_info *, struct page *, block_t, int);

Better to move these declarations into PATCH 1/2.

Okay, I will move it to the right place.

Quoted 12 lines
Quoted 12 lines
fs/f2fs/f2fs.h +0 -0
 int do_write_data_page(struct page *);
 
 /*
fs/f2fs/segment.c +0 -0
index 86dc289..414c351 100644
@@ -1474,19 +1474,72 @@ static int build_curseg(struct f2fs_sb_info *sbi)
 	return restore_curseg_summaries(sbi);
 }
 
Quoted 16 lines

fs/f2fs/segment.c static int build_curseg(struct f2fs_sb_info *sbi) · line 1489

Quoted 13 lines
fs/f2fs/segment.c +13 -0
+static int ra_sit_pages(struct f2fs_sb_info *sbi, int start,
+					int nrpages, bool *is_order)
+{
+	struct address_space *mapping = sbi->meta_inode->i_mapping;
+	struct sit_info *sit_i = SIT_I(sbi);
+	struct page *page;
+	block_t blk_addr;
+	int blkno, readcnt = 0;
+	int sit_blk_cnt = SIT_BLK_CNT(sbi);
+
+	for (blkno = start; blkno < start + nrpages; blkno++) {
+
+		if (blkno >= sit_blk_cnt)

Merge these two judgements:
for (blkno = start; blkno < start + nrpages && blkno < sit_blk_cnt; blkno++)

Quoted 6 lines

Right, but the line may over 80 characters, if we split this line, it seems not suitable. So how about this?

	int blkno = start, readcnt = 0;
	int sit_blk_cnt = SIT_BLK_CNT(sbi);

	for (; blkno < start + nrpages && blkno < sit_blk_cnt; blkno++) {

More neat!

Quoted 31 lines
Quoted 9 lines

fs/f2fs/segment.c static int build_curseg(struct f2fs_sb_info *sbi) · line 1493

Quoted 7 lines
fs/f2fs/segment.c +4 -0
+			goto out;
 
+		if ((!f2fs_test_bit(blkno, sit_i->sit_bitmap) ^ !*is_order)) {
+			*is_order = !*is_order;
+			goto out;

'Break' seems more suitable.

Yes, you are right.

Quoted 10 lines
Quoted 10 lines
fs/f2fs/segment.c +9 -0
+		}
+
+		blk_addr = sit_i->sit_base_addr + blkno;
+		if (*is_order)
+			blk_addr += sit_i->sit_blocks;
+repeat:
+		page = grab_cache_page(mapping, blk_addr);
+		if (!page) {
+			cond_resched();
Quoted 8 lines

fs/f2fs/segment.c static int build_curseg(struct f2fs_sb_info *sbi) · line 1508

Quoted 6 lines
fs/f2fs/segment.c +6 -0
+			goto repeat;
+		}
+		if (PageUptodate(page)) {
+			f2fs_put_page(page, 1);
+			readcnt++;
+			goto out;

Here may be 'Continue'.

Quoted 2 lines

'Out' label could be removed after this modification. It seems more neat.

Right.

Quoted 10 lines
Quoted 9 lines

fs/f2fs/segment.c static int build_curseg(struct f2fs_sb_info *sbi) · line 1513

Quoted 7 lines
fs/f2fs/segment.c +5 -0
+		}
+
+		submit_read_page(sbi, page, blk_addr, READ_SYNC);
+
+		page_cache_release(page);

Put page here seems not a good idea, otherwise all your work may be in vain.

Quoted 4 lines

You mean that pages could be reclaimed by VM when out of memory? IMO, it is designed more like VM read ahead because we should concern memory state of system, and still we have second chance to read these pages.

Yes, but we can avoid to read the same page secondly, that's a serious waste, if we still reread the page in get_current_sit_page(), all the improvement will disappear.

Quoted 1 line

Could we use mark_page_accessed () to delay VM reclaimed them?

IMO, this is the right way.

Quoted 29 lines
Quoted 21 lines
Quoted 21 lines
fs/f2fs/segment.c +12 -1
+		readcnt++;
+	}
+out:
+	f2fs_submit_read_bio(sbi, READ_SYNC);
+	return readcnt;
+}
+
 static void build_sit_entries(struct f2fs_sb_info *sbi)
 {
 	struct sit_info *sit_i = SIT_I(sbi);
 	struct curseg_info *curseg = CURSEG_I(sbi, CURSEG_COLD_DATA);
 	struct f2fs_summary_block *sum = curseg->sum_blk;
-	unsigned int start;
+	bool is_order = f2fs_test_bit(0, sit_i->sit_bitmap) ? true : false;
+	int sit_blk_cnt = SIT_BLK_CNT(sbi);
+	int bio_blocks = MAX_BIO_BLOCKS(max_hw_blocks(sbi));
+	unsigned int i, start, end;
+	unsigned int readed, start_blk = 0;
 
Quoted 7 lines

fs/f2fs/segment.c static int build_curseg(struct f2fs_sb_info *sbi) · line 1533

Quoted 3 lines
fs/f2fs/segment.c +2 -1
-	for (start = 0; start < TOTAL_SEGS(sbi); start++) {
+next:
+	readed = ra_sit_pages(sbi, start_blk, bio_blocks, &is_order);

In fact, you know how many blocks that you want to read(SIT_BLK_CNT(sbi)), so here sit_blk_cnt is more suitable than a MAX one, and it also can make the logic of ra_sit_pages more simple.

Quoted 5 lines

Right.

BTW, I am considering that maybe we should send dynamical cnt which depend on memory state of system more than the logic of ra_sit_pages. May it's the work of anther patch. How do you think?

Agree. It's the same as the way that I suggested previously, and it can make the contiguous pages reading api more common.

Regards,
Gu

Quoted 62 lines
Quoted 26 lines
Quoted 26 lines
fs/f2fs/segment.c +5 -1
+
+	start = start_blk * sit_i->sents_per_block;
+	end = (start_blk + readed) * sit_i->sents_per_block;
+
+	for (; start < end && start < TOTAL_SEGS(sbi); start++) {
 		struct seg_entry *se = &sit_i->sentries[start];
 		struct f2fs_sit_block *sit_blk;
 		struct f2fs_sit_entry sit;
 		struct page *page;
-		int i;
 
 		mutex_lock(&curseg->curseg_mutex);
fs/f2fs/segment.c +1 -0
 		for (i = 0; i < sits_in_cursum(sum); i++) {
@@ -1497,6 +1550,7 @@ static void build_sit_entries(struct f2fs_sb_info *sbi)
 			}
 		}
 		mutex_unlock(&curseg->curseg_mutex);
+
 		page = get_current_sit_page(sbi, start);
 		sit_blk = (struct f2fs_sit_block *)page_address(page);
 		sit = sit_blk->entries[SIT_ENTRY_OFFSET(sit_i, start)];
@@ -1509,6 +1563,11 @@ got_it:
 			e->valid_blocks += se->valid_blocks;
 		}
Quoted 8 lines

fs/f2fs/segment.c got_it: · line 1570

Quoted 6 lines
fs/f2fs/segment.c +5 -0
 	}
+
+	start_blk += readed;
+	if (start_blk >= sit_blk_cnt)
+		return;
+	goto next;

Using do {...} while(start_blk < sit_blk_cnt) rather than the so big upstream goto.

Yes, you are right.

Quoted 17 lines
Quoted 9 lines
fs/f2fs/segment.c +0 -0
 }
 
 static void init_free_segmap(struct f2fs_sb_info *sbi)
fs/f2fs/segment.h +0 -0
index 269f690..ad5b9f1 100644

fs/f2fs/segment.h line 90

Quoted 8 lines
fs/f2fs/segment.h +2 -0
@@ -83,6 +83,8 @@
 	(segno / SIT_ENTRY_PER_BLOCK)
 #define	START_SEGNO(sit_i, segno)		\
 	(SIT_BLOCK_OFFSET(sit_i, segno) * SIT_ENTRY_PER_BLOCK)
+#define SIT_BLK_CNT(sbi)			\
+	((TOTAL_SEGS(sbi) + SIT_ENTRY_PER_BLOCK - 1) / SIT_ENTRY_PER_BLOCK)
 #define f2fs_bitmap_size(nr)			\
 	(BITS_TO_LONGS(nr) * sizeof(unsigned long))
 #define TOTAL_SEGS(sbi)	(SM_I(sbi)->main_segments)

Thanks!

Regards,
Yu