Skip to contentSkip to conversation

f2fs: introduce f2fs_cache_node_page() to add page into node_inode cache

PATCH In review Chao Yu 2 participants 5 messages Dec 9, 2013 – Dec 10, 2013

Subsystems (2)
lore
Share & tools
lore

Chao Yu

author
#0 lore raw

PATCH v3 3/3 f2fs: introduce f2fs_cache_node_page() to add page into node_inode cache

This patch introduces f2fs_cache_node_page(), in this function, page which is readed ahead will be copy to node_inode's mapping cache.
It will avoid rereading these node pages.

change log:
o check validity of page by searching NAT suggested by Jaegeuk Kim.
o add 'unlikely' for compiler optimization suggested by Jaegeuk Kim.

---
 fs/f2fs/node.c |   39 ++++++++++++++++++++++++++++++++++++++-
 1 file changed, 38 insertions(+), 1 deletion(-)
fs/f2fs/node.c +38 -1
index 099f06f..4c6da98 100644
@@ -1600,13 +1600,46 @@ static int ra_sum_pages(struct f2fs_sb_info *sbi, struct list_head *pages,
 	return 0;
 }
 
+/*
+ * f2fs_cache_node_page() check validaty of input page by searching NAT.
+ * Then, it will copy updated data of vaild page to node_inode cache.
+ */
+void f2fs_cache_node_page(struct f2fs_sb_info *sbi, struct page *page,
+						nid_t nid, block_t blkaddr)
+{
+	struct address_space *mapping = sbi->node_inode->i_mapping;
+	struct page *npage;
+	struct node_info ni;
+
+	get_node_info(sbi, nid, &ni);
+
+	if (ni.blk_addr != blkaddr)
+		return;
+
+	npage = grab_cache_page(mapping, nid);
+	if (unlikely(!npage))
+		return;
+
+	if (PageUptodate(npage)) {
+		f2fs_put_page(npage, 1);
+		return;
+	}
+
+	memcpy(page_address(npage), page_address(page), PAGE_CACHE_SIZE);
+
+	SetPageUptodate(npage);
+	f2fs_put_page(npage, 1);
+
+	return;
+}
+
 int restore_node_summary(struct f2fs_sb_info *sbi,
 			unsigned int segno, struct f2fs_summary_block *sum)
 {
 	struct f2fs_node *rn;
 	struct f2fs_summary *sum_entry;
 	struct page *page, *tmp;
-	block_t addr;
+	block_t addr, blkaddr;
 	int bio_blocks = MAX_BIO_BLOCKS(max_hw_blocks(sbi));
 	int i, last_offset, nrpages, err = 0;
 	LIST_HEAD(page_list);
@@ -1624,6 +1657,7 @@ int restore_node_summary(struct f2fs_sb_info *sbi,
 		if (err)
 			return err;
 
+		blkaddr = addr;
 		list_for_each_entry_safe(page, tmp, &page_list, lru) {
 
 			lock_page(page);
@@ -1633,6 +1667,8 @@ int restore_node_summary(struct f2fs_sb_info *sbi,
 				sum_entry->version = 0;
 				sum_entry->ofs_in_node = 0;
 				sum_entry++;
+				f2fs_cache_node_page(sbi, page,
+					le32_to_cpu(rn->footer.nid), blkaddr);
 			} else {
 				err = -EIO;
 			}
@@ -1640,6 +1676,7 @@ int restore_node_summary(struct f2fs_sb_info *sbi,
 			list_del(&page->lru);
 			unlock_page(page);
 			__free_pages(page, 0);
+			blkaddr++;
 		}
 	}
 	return err;
Signature · 1 line
1.7.9.5
#1 lore raw

Hi,

Sorry for the noise.
Once I tested this patch, I recognized that I made a mistake:

f2fs_fill_super()
1. build_segment_manager()

    -> restore_node_summary()
       -> NULL pointer exception, due to no NAT cache.

2. build_node_manager()

So, we should not call get_node_info() prior to build_node_manager(). And, it's not easy to change the order of build_*_manager simply.

Let's consider in more details.
Thanks,

2013-12-09 (월), 13:35 +0800, Chao Yu:

Quoted 91 lines

This patch introduces f2fs_cache_node_page(), in this function, page which is readed ahead will be copy to node_inode's mapping cache.
It will avoid rereading these node pages.

change log:
o check validity of page by searching NAT suggested by Jaegeuk Kim.
o add 'unlikely' for compiler optimization suggested by Jaegeuk Kim.

---
 fs/f2fs/node.c |   39 ++++++++++++++++++++++++++++++++++++++-
 1 file changed, 38 insertions(+), 1 deletion(-)
fs/f2fs/node.c +38 -1
index 099f06f..4c6da98 100644
@@ -1600,13 +1600,46 @@ static int ra_sum_pages(struct f2fs_sb_info *sbi, struct list_head *pages,
 	return 0;
 }
 
+/*
+ * f2fs_cache_node_page() check validaty of input page by searching NAT.
+ * Then, it will copy updated data of vaild page to node_inode cache.
+ */
+void f2fs_cache_node_page(struct f2fs_sb_info *sbi, struct page *page,
+						nid_t nid, block_t blkaddr)
+{
+	struct address_space *mapping = sbi->node_inode->i_mapping;
+	struct page *npage;
+	struct node_info ni;
+
+	get_node_info(sbi, nid, &ni);
+
+	if (ni.blk_addr != blkaddr)
+		return;
+
+	npage = grab_cache_page(mapping, nid);
+	if (unlikely(!npage))
+		return;
+
+	if (PageUptodate(npage)) {
+		f2fs_put_page(npage, 1);
+		return;
+	}
+
+	memcpy(page_address(npage), page_address(page), PAGE_CACHE_SIZE);
+
+	SetPageUptodate(npage);
+	f2fs_put_page(npage, 1);
+
+	return;
+}
+
 int restore_node_summary(struct f2fs_sb_info *sbi,
 			unsigned int segno, struct f2fs_summary_block *sum)
 {
 	struct f2fs_node *rn;
 	struct f2fs_summary *sum_entry;
 	struct page *page, *tmp;
-	block_t addr;
+	block_t addr, blkaddr;
 	int bio_blocks = MAX_BIO_BLOCKS(max_hw_blocks(sbi));
 	int i, last_offset, nrpages, err = 0;
 	LIST_HEAD(page_list);
@@ -1624,6 +1657,7 @@ int restore_node_summary(struct f2fs_sb_info *sbi,
 		if (err)
 			return err;
 
+		blkaddr = addr;
 		list_for_each_entry_safe(page, tmp, &page_list, lru) {
 
 			lock_page(page);
@@ -1633,6 +1667,8 @@ int restore_node_summary(struct f2fs_sb_info *sbi,
 				sum_entry->version = 0;
 				sum_entry->ofs_in_node = 0;
 				sum_entry++;
+				f2fs_cache_node_page(sbi, page,
+					le32_to_cpu(rn->footer.nid), blkaddr);
 			} else {
 				err = -EIO;
 			}
@@ -1640,6 +1676,7 @@ int restore_node_summary(struct f2fs_sb_info *sbi,
 			list_del(&page->lru);
 			unlock_page(page);
 			__free_pages(page, 0);
+			blkaddr++;
 		}
 	}
 	return err;
Signature · 7 lines
Jaegeuk Kim
Samsung

--
To unsubscribe from this list: send the line "unsubscribe linux-fsdevel" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
author
#2 lore raw

Hi,

Quoted 12 lines

-----Original Message-----
From: Jaegeuk Kim [mailto:[email protected]]
Sent: Monday, December 09, 2013 4:01 PM
To: Chao Yu
Cc: [email protected]; [email protected]; [email protected]
Subject: Re: [f2fs-dev] [PATCH 3/3 V3] f2fs: introduce f2fs_cache_node_page() to add page into node_inode cache

Hi,

Sorry for the noise.
Once I tested this patch, I recognized that I made a mistake:

Quoted 8 lines

f2fs_fill_super()
1. build_segment_manager()

    -> restore_node_summary()
       -> NULL pointer exception, due to no NAT cache.

2. build_node_manager()

So, we should not call get_node_info() prior to build_node_manager(). And, it's not easy to change the order of build_*_manager simply.

Oh, sound bad. And sorry for my carelessness.
Let's reconsider this patch in details.

Quoted 92 lines

Let's consider in more details.
Thanks,

2013-12-09 (월), 13:35 +0800, Chao Yu:

Quoted 87 lines

This patch introduces f2fs_cache_node_page(), in this function, page which is readed ahead will be copy to node_inode's mapping cache.
It will avoid rereading these node pages.

change log:
o check validity of page by searching NAT suggested by Jaegeuk Kim.
o add 'unlikely' for compiler optimization suggested by Jaegeuk Kim.

---
 fs/f2fs/node.c |   39 ++++++++++++++++++++++++++++++++++++++-
 1 file changed, 38 insertions(+), 1 deletion(-)
fs/f2fs/node.c +37 -1
index 099f06f..4c6da98 100644
@@ -1600,13 +1600,46 @@ static int ra_sum_pages(struct f2fs_sb_info *sbi, struct list_head *pages,
 	return 0;
 }
 
+/*
+ * f2fs_cache_node_page() check validaty of input page by searching NAT.
+ * Then, it will copy updated data of vaild page to node_inode cache.
+ */
+void f2fs_cache_node_page(struct f2fs_sb_info *sbi, struct page *page,
+						nid_t nid, block_t blkaddr)
+{
+	struct address_space *mapping = sbi->node_inode->i_mapping;
+	struct page *npage;
+	struct node_info ni;
+
+	get_node_info(sbi, nid, &ni);
+
+	if (ni.blk_addr != blkaddr)
+		return;
+
+	npage = grab_cache_page(mapping, nid);
+	if (unlikely(!npage))
+		return;
+
+	if (PageUptodate(npage)) {
+		f2fs_put_page(npage, 1);
+		return;
+	}
+
+	memcpy(page_address(npage), page_address(page), PAGE_CACHE_SIZE);
+
+	SetPageUptodate(npage);
+	f2fs_put_page(npage, 1);
+
+	return;
+}
+
 int restore_node_summary(struct f2fs_sb_info *sbi,
 			unsigned int segno, struct f2fs_summary_block *sum)
 {
 	struct f2fs_node *rn;
 	struct f2fs_summary *sum_entry;
 	struct page *page, *tmp;
-	block_t addr;
+	block_t addr, blkaddr;
 	int bio_blocks = MAX_BIO_BLOCKS(max_hw_blocks(sbi));
 	int i, last_offset, nrpages, err = 0;
 	LIST_HEAD(page_list);
@@ -1624,6 +1657,7 @@ int restore_node_summary(struct f2fs_sb_info *sbi,
 		if (err)
 			return err;
 
+		blkaddr = addr;
 		list_for_each_entry_safe(page, tmp, &page_list, lru) {
 
 			lock_page(page);
@@ -1633,6 +1667,8 @@ int restore_node_summary(struct f2fs_sb_info *sbi,
 				sum_entry->version = 0;
 				sum_entry->ofs_in_node = 0;
 				sum_entry++;
+				f2fs_cache_node_page(sbi, page,
+					le32_to_cpu(rn->footer.nid), blkaddr);
 			} else {
 				err = -EIO;
 			}
@@ -1640,6 +1676,7 @@ int restore_node_summary(struct f2fs_sb_info *sbi,
 			list_del(&page->lru);
 			unlock_page(page);
 			__free_pages(page, 0);
Quoted 8 lines

fs/f2fs/node.c int restore_node_summary(struct f2fs_sb_info *sbi, · line 1682

Quoted 4 lines
fs/f2fs/node.c +1 -0
+			blkaddr++;
 		}
 	}
 	return err;

--
Jaegeuk Kim
Samsung

------------------------------------------------------------------------------
Sponsored by Intel(R) XDK
Develop, test and display web and hybrid apps with a single code base. Download it for free now!
http://pubads.g.doubleclick.net/gampad/clk?id=111408631&iu=/4140/ostg.clktrk
_______________________________________________
Linux-f2fs-devel mailing list [email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel

author
#3 lore raw
In reply to Jaegeuk Kim

Hi,

Quoted 14 lines

-----Original Message-----
From: Jaegeuk Kim [mailto:[email protected]]
Sent: Monday, December 09, 2013 4:01 PM
To: Chao Yu
Cc: [email protected]; [email protected]; [email protected]
Subject: Re: [f2fs-dev] [PATCH 3/3 V3] f2fs: introduce f2fs_cache_node_page() to add page into node_inode cache

Hi,

Sorry for the noise.
Once I tested this patch, I recognized that I made a mistake:

f2fs_fill_super()
1. build_segment_manager()

Quoted 8 lines
    -> restore_node_summary()
       -> NULL pointer exception, due to no NAT cache.

2. build_node_manager()

So, we should not call get_node_info() prior to build_node_manager(). And, it's not easy to change the order of build_*_manager simply.

Let's consider in more details.

Before we call restore_node_summary(), we have read HOT_DATA Summary. It means already we got the NAT cache in curseg. Although we could not call get_node_info() directly, we still could use NAT cache in HOT_DATA curseg.

So how about using this cache to verify validity of page like this?

f2fs_cache_node_page()

	if(!looup_nat_curseg_cache())
		return;
	grab_cache_page();
	memcpy();
	SetPageUptodate();
	f2fs_put_page();
Quoted 90 lines

Thanks,

2013-12-09 (월), 13:35 +0800, Chao Yu:

Quoted 87 lines

This patch introduces f2fs_cache_node_page(), in this function, page which is readed ahead will be copy to node_inode's mapping cache.
It will avoid rereading these node pages.

change log:
o check validity of page by searching NAT suggested by Jaegeuk Kim.
o add 'unlikely' for compiler optimization suggested by Jaegeuk Kim.

---
 fs/f2fs/node.c |   39 ++++++++++++++++++++++++++++++++++++++-
 1 file changed, 38 insertions(+), 1 deletion(-)
fs/f2fs/node.c +37 -1
index 099f06f..4c6da98 100644
@@ -1600,13 +1600,46 @@ static int ra_sum_pages(struct f2fs_sb_info *sbi, struct list_head *pages,
 	return 0;
 }
 
+/*
+ * f2fs_cache_node_page() check validaty of input page by searching NAT.
+ * Then, it will copy updated data of vaild page to node_inode cache.
+ */
+void f2fs_cache_node_page(struct f2fs_sb_info *sbi, struct page *page,
+						nid_t nid, block_t blkaddr)
+{
+	struct address_space *mapping = sbi->node_inode->i_mapping;
+	struct page *npage;
+	struct node_info ni;
+
+	get_node_info(sbi, nid, &ni);
+
+	if (ni.blk_addr != blkaddr)
+		return;
+
+	npage = grab_cache_page(mapping, nid);
+	if (unlikely(!npage))
+		return;
+
+	if (PageUptodate(npage)) {
+		f2fs_put_page(npage, 1);
+		return;
+	}
+
+	memcpy(page_address(npage), page_address(page), PAGE_CACHE_SIZE);
+
+	SetPageUptodate(npage);
+	f2fs_put_page(npage, 1);
+
+	return;
+}
+
 int restore_node_summary(struct f2fs_sb_info *sbi,
 			unsigned int segno, struct f2fs_summary_block *sum)
 {
 	struct f2fs_node *rn;
 	struct f2fs_summary *sum_entry;
 	struct page *page, *tmp;
-	block_t addr;
+	block_t addr, blkaddr;
 	int bio_blocks = MAX_BIO_BLOCKS(max_hw_blocks(sbi));
 	int i, last_offset, nrpages, err = 0;
 	LIST_HEAD(page_list);
@@ -1624,6 +1657,7 @@ int restore_node_summary(struct f2fs_sb_info *sbi,
 		if (err)
 			return err;
 
+		blkaddr = addr;
 		list_for_each_entry_safe(page, tmp, &page_list, lru) {
 
 			lock_page(page);
@@ -1633,6 +1667,8 @@ int restore_node_summary(struct f2fs_sb_info *sbi,
 				sum_entry->version = 0;
 				sum_entry->ofs_in_node = 0;
 				sum_entry++;
+				f2fs_cache_node_page(sbi, page,
+					le32_to_cpu(rn->footer.nid), blkaddr);
 			} else {
 				err = -EIO;
 			}
@@ -1640,6 +1676,7 @@ int restore_node_summary(struct f2fs_sb_info *sbi,
 			list_del(&page->lru);
 			unlock_page(page);
 			__free_pages(page, 0);
Quoted 8 lines

fs/f2fs/node.c int restore_node_summary(struct f2fs_sb_info *sbi, · line 1682

Quoted 4 lines
fs/f2fs/node.c +1 -0
+			blkaddr++;
 		}
 	}
 	return err;

--
Jaegeuk Kim
Samsung

--
To unsubscribe from this list: send the line "unsubscribe linux-fsdevel" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

author
#4 lore raw
Quoted 37 lines

-----Original Message-----
From: Chao Yu [mailto:[email protected]]
Sent: Tuesday, December 10, 2013 9:52 AM
To: [email protected]
Cc: [email protected]; [email protected]; [email protected]
Subject: Re: [f2fs-dev] [PATCH 3/3 V3] f2fs: introduce f2fs_cache_node_page() to add page into node_inode cache

Hi,

Quoted 14 lines

-----Original Message-----
From: Jaegeuk Kim [mailto:[email protected]]
Sent: Monday, December 09, 2013 4:01 PM
To: Chao Yu
Cc: [email protected]; [email protected]; [email protected]
Subject: Re: [f2fs-dev] [PATCH 3/3 V3] f2fs: introduce f2fs_cache_node_page() to add page into node_inode cache

Hi,

Sorry for the noise.
Once I tested this patch, I recognized that I made a mistake:

f2fs_fill_super()
1. build_segment_manager()

Quoted 8 lines
    -> restore_node_summary()
       -> NULL pointer exception, due to no NAT cache.

2. build_node_manager()

So, we should not call get_node_info() prior to build_node_manager(). And, it's not easy to change the order of build_*_manager simply.

Let's consider in more details.

Before we call restore_node_summary(), we have read HOT_DATA Summary. It means already we got the NAT cache in curseg. Although we could not call get_node_info() directly, we still could use NAT cache in HOT_DATA curseg.

Quoted 5 lines

So how about using this cache to verify validity of page like this?

f2fs_cache_node_page()

	if(!looup_nat_curseg_cache())
		return;

Code of verification is missed here.
if (curseg cache blk_addr != current blkaddr)

	return;
Quoted 105 lines
	grab_cache_page();
	memcpy();
	SetPageUptodate();
	f2fs_put_page();
Quoted 90 lines

Thanks,

2013-12-09 (월), 13:35 +0800, Chao Yu:

Quoted 87 lines

This patch introduces f2fs_cache_node_page(), in this function, page which is readed ahead will be copy to node_inode's mapping cache.
It will avoid rereading these node pages.

change log:
o check validity of page by searching NAT suggested by Jaegeuk Kim.
o add 'unlikely' for compiler optimization suggested by Jaegeuk Kim.

---
 fs/f2fs/node.c |   39 ++++++++++++++++++++++++++++++++++++++-
 1 file changed, 38 insertions(+), 1 deletion(-)
fs/f2fs/node.c +37 -1
index 099f06f..4c6da98 100644
@@ -1600,13 +1600,46 @@ static int ra_sum_pages(struct f2fs_sb_info *sbi, struct list_head *pages,
 	return 0;
 }
 
+/*
+ * f2fs_cache_node_page() check validaty of input page by searching NAT.
+ * Then, it will copy updated data of vaild page to node_inode cache.
+ */
+void f2fs_cache_node_page(struct f2fs_sb_info *sbi, struct page *page,
+						nid_t nid, block_t blkaddr)
+{
+	struct address_space *mapping = sbi->node_inode->i_mapping;
+	struct page *npage;
+	struct node_info ni;
+
+	get_node_info(sbi, nid, &ni);
+
+	if (ni.blk_addr != blkaddr)
+		return;
+
+	npage = grab_cache_page(mapping, nid);
+	if (unlikely(!npage))
+		return;
+
+	if (PageUptodate(npage)) {
+		f2fs_put_page(npage, 1);
+		return;
+	}
+
+	memcpy(page_address(npage), page_address(page), PAGE_CACHE_SIZE);
+
+	SetPageUptodate(npage);
+	f2fs_put_page(npage, 1);
+
+	return;
+}
+
 int restore_node_summary(struct f2fs_sb_info *sbi,
 			unsigned int segno, struct f2fs_summary_block *sum)
 {
 	struct f2fs_node *rn;
 	struct f2fs_summary *sum_entry;
 	struct page *page, *tmp;
-	block_t addr;
+	block_t addr, blkaddr;
 	int bio_blocks = MAX_BIO_BLOCKS(max_hw_blocks(sbi));
 	int i, last_offset, nrpages, err = 0;
 	LIST_HEAD(page_list);
@@ -1624,6 +1657,7 @@ int restore_node_summary(struct f2fs_sb_info *sbi,
 		if (err)
 			return err;
 
+		blkaddr = addr;
 		list_for_each_entry_safe(page, tmp, &page_list, lru) {
 
 			lock_page(page);
@@ -1633,6 +1667,8 @@ int restore_node_summary(struct f2fs_sb_info *sbi,
 				sum_entry->version = 0;
 				sum_entry->ofs_in_node = 0;
 				sum_entry++;
+				f2fs_cache_node_page(sbi, page,
+					le32_to_cpu(rn->footer.nid), blkaddr);
 			} else {
 				err = -EIO;
 			}
@@ -1640,6 +1676,7 @@ int restore_node_summary(struct f2fs_sb_info *sbi,
 			list_del(&page->lru);
 			unlock_page(page);
 			__free_pages(page, 0);
Quoted 8 lines

fs/f2fs/node.c int restore_node_summary(struct f2fs_sb_info *sbi, · line 1682

Quoted 4 lines
fs/f2fs/node.c +1 -0
+			blkaddr++;
 		}
 	}
 	return err;

--
Jaegeuk Kim
Samsung

Quoted 9 lines

------------------------------------------------------------------------------
Sponsored by Intel(R) XDK
Develop, test and display web and hybrid apps with a single code base. Download it for free now!
http://pubads.g.doubleclick.net/gampad/clk?id=111408631&iu=/4140/ostg.clktrk
_______________________________________________
Linux-f2fs-devel mailing list [email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel

------------------------------------------------------------------------------
Sponsored by Intel(R) XDK
Develop, test and display web and hybrid apps with a single code base. Download it for free now!
http://pubads.g.doubleclick.net/gampad/clk?id=111408631&iu=/4140/ostg.clktrk
_______________________________________________
Linux-f2fs-devel mailing list [email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel