linux-fsdevel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jaegeuk Kim <jaegeuk.kim@samsung.com>
To: Namjae Jeon <linkinjeon@gmail.com>
Cc: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org,
	linux-f2fs-devel@lists.sourceforge.net
Subject: Re: [PATCH 3/9 v2] f2fs: remove redundant lock_page calls
Date: Wed, 03 Apr 2013 17:12:49 +0900	[thread overview]
Message-ID: <1364976769.4353.11.camel@kjgkr> (raw)
In-Reply-To: <CAKYAXd_rkU5t=OOxjTu0CtKHfrTYkbJuJ2ZFNd=aaRsuToHU7A@mail.gmail.com>

[-- Attachment #1: Type: text/plain, Size: 4444 bytes --]

Hi,

Agreed, and send v2.

Change log from v1:
 o remain read_node_page and remove the lock part

From 04006aecac2882c574fe8a7de926bc52c73a8ad1 Mon Sep 17 00:00:00 2001
From: Jaegeuk Kim <jaegeuk.kim@samsung.com>
Date: Sun, 31 Mar 2013 12:47:20 +0900
Subject: [PATCH] f2fs: remove redundant lock_page calls
Cc: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org,
linux-f2fs-devel@lists.sourceforge.net

In get_node_page, we do not need to call lock_page all the time.

If the node page is cached as uptodate,

1. grab_cache_page locks the page,
2. read_node_page unlocks the page, and
3. lock_page is called for further process.

Let's avoid this.

Signed-off-by: Jaegeuk Kim <jaegeuk.kim@samsung.com>
---
 fs/f2fs/node.c | 44 +++++++++++++++++++++++++++-----------------
 fs/f2fs/node.h |  3 +++
 2 files changed, 30 insertions(+), 17 deletions(-)

diff --git a/fs/f2fs/node.c b/fs/f2fs/node.c
index 10cbee9..e3484b5 100644
--- a/fs/f2fs/node.c
+++ b/fs/f2fs/node.c
@@ -847,6 +847,12 @@ fail:
 	return ERR_PTR(err);
 }
 
+/*
+ * Caller should do after getting the following values.
+ * 0: f2fs_put_page(page, 0)
+ * LOCKED_PAGE: f2fs_put_page(page, 1)
+ * error: nothing
+ */
 static int read_node_page(struct page *page, int type)
 {
 	struct f2fs_sb_info *sbi = F2FS_SB(page->mapping->host->i_sb);
@@ -859,10 +865,8 @@ static int read_node_page(struct page *page, int
type)
 		return -ENOENT;
 	}
 
-	if (PageUptodate(page)) {
-		unlock_page(page);
-		return 0;
-	}
+	if (PageUptodate(page))
+		return LOCKED_PAGE;
 
 	return f2fs_readpage(sbi, page, ni.blk_addr, type);
 }
@@ -874,6 +878,7 @@ void ra_node_page(struct f2fs_sb_info *sbi, nid_t
nid)
 {
 	struct address_space *mapping = sbi->node_inode->i_mapping;
 	struct page *apage;
+	int err;
 
 	apage = find_get_page(mapping, nid);
 	if (apage && PageUptodate(apage)) {
@@ -886,30 +891,36 @@ void ra_node_page(struct f2fs_sb_info *sbi, nid_t
nid)
 	if (!apage)
 		return;
 
-	if (read_node_page(apage, READA) == 0)
+	err = read_node_page(page, READA);
+	if (err == 0)
 		f2fs_put_page(apage, 0);
+	else if (err == LOCKED_PAGE)
+		f2fs_put_page(apage, 1);
 	return;
 }
 
 struct page *get_node_page(struct f2fs_sb_info *sbi, pgoff_t nid)
 {
-	int err;
-	struct page *page;
 	struct address_space *mapping = sbi->node_inode->i_mapping;
+	struct page *page;
+	int err;
 
 	page = grab_cache_page(mapping, nid);
 	if (!page)
 		return ERR_PTR(-ENOMEM);
 
 	err = read_node_page(page, READ_SYNC);
-	if (err)
-		return ERR_PTR(err);
+	if (err < 0)
+		return ERR_PTR(ret);
+	else if (err == LOCKED_PAGE)
+		goto got_it;
 
 	lock_page(page);
 	if (!PageUptodate(page)) {
 		f2fs_put_page(page, 1);
 		return ERR_PTR(-EIO);
 	}
+got_it:
 	BUG_ON(nid != nid_of_node(page));
 	mark_page_accessed(page);
 	return page;
@@ -923,10 +934,9 @@ struct page *get_node_page_ra(struct page *parent,
int start)
 {
 	struct f2fs_sb_info *sbi = F2FS_SB(parent->mapping->host->i_sb);
 	struct address_space *mapping = sbi->node_inode->i_mapping;
-	int i, end;
-	int err = 0;
-	nid_t nid;
 	struct page *page;
+	int err, i, end;
+	nid_t nid;
 
 	/* First, try getting the desired direct node. */
 	nid = get_nid(parent, start, false);
@@ -936,12 +946,12 @@ struct page *get_node_page_ra(struct page *parent,
int start)
 	page = grab_cache_page(mapping, nid);
 	if (!page)
 		return ERR_PTR(-ENOMEM);
-	else if (PageUptodate(page))
-		goto page_hit;
 
 	err = read_node_page(page, READ_SYNC);
-	if (err)
-		return ERR_PTR(err);
+	if (err < 0)
+		return ERR_PTR(ret);
+	else if (err == LOCKED_PAGE)
+		goto page_hit;
 
 	/* Then, try readahead for siblings of the desired node */
 	end = start + MAX_RA_NODE;
@@ -956,7 +966,7 @@ struct page *get_node_page_ra(struct page *parent,
int start)
 	lock_page(page);
 
 page_hit:
-	if (PageError(page)) {
+	if (!PageUptodate(page)) {
 		f2fs_put_page(page, 1);
 		return ERR_PTR(-EIO);
 	}
diff --git a/fs/f2fs/node.h b/fs/f2fs/node.h
index d009cdf..271a61c 100644
--- a/fs/f2fs/node.h
+++ b/fs/f2fs/node.h
@@ -29,6 +29,9 @@
 /* vector size for gang look-up from nat cache that consists of radix
tree */
 #define NATVEC_SIZE	64
 
+/* return value for read_node_page */
+#define LOCKED_PAGE	1
+
 /*
  * For node information
  */
-- 
1.8.1.3.566.gaa39828




-- 
Jaegeuk Kim
Samsung

[-- Attachment #2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 836 bytes --]

  reply	other threads:[~2013-04-03  8:13 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-04-01  6:55 [PATCH 1/9] f2fs: do not use duplicate names in a macro Jaegeuk Kim
2013-04-01  6:55 ` [PATCH 2/9] f2fs: introduce TOTAL_SECS macro Jaegeuk Kim
2013-04-03  1:17   ` Namjae Jeon
2013-04-01  6:55 ` [PATCH 3/9] f2fs: remove redundant lock_page calls Jaegeuk Kim
2013-04-03  5:58   ` Namjae Jeon
2013-04-03  8:12     ` Jaegeuk Kim [this message]
2013-04-03  8:27       ` [PATCH 3/9 v2] " Namjae Jeon
2013-04-01  6:55 ` [PATCH 4/9] f2fs: allocate new segment aligned with sections Jaegeuk Kim
2013-04-03  6:00   ` Namjae Jeon
2013-04-01  6:55 ` [PATCH 5/9] f2fs: change GC bitmaps to apply the section granularity Jaegeuk Kim
2013-04-03  5:46   ` Namjae Jeon
2013-04-03  8:06     ` [PATCH 5/9 v2] " Jaegeuk Kim
2013-04-03  8:21       ` Namjae Jeon
2013-04-01  6:55 ` [PATCH 6/9] f2fs: check completion of foreground GC Jaegeuk Kim
2013-04-03  5:54   ` Namjae Jeon
2013-04-01  6:55 ` [PATCH 7/9] f2fs: allocate remained free segments in the LFS mode Jaegeuk Kim
2013-04-03  5:59   ` Namjae Jeon
2013-04-01  6:55 ` [PATCH 8/9] f2fs: avoid race for summary information Jaegeuk Kim
2013-04-03  5:54   ` Namjae Jeon
2013-04-01  6:56 ` [PATCH 9/9] f2fs: fix the bitmap consistency of dirty segments Jaegeuk Kim
2013-04-03  1:14   ` Namjae Jeon
2013-04-03  1:15 ` [PATCH 1/9] f2fs: do not use duplicate names in a macro Namjae Jeon

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1364976769.4353.11.camel@kjgkr \
    --to=jaegeuk.kim@samsung.com \
    --cc=linkinjeon@gmail.com \
    --cc=linux-f2fs-devel@lists.sourceforge.net \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).