All of lore.kernel.org
 help / color / mirror / Atom feed
From: yalin wang <yalin.wang2010@gmail.com>
To: viro@zeniv.linux.org.uk, linux-fsdevel@vger.kernel.org,
	linux-kernel@vger.kernel.org
Cc: yalin wang <yalin.wang2010@gmail.com>
Subject: [RFC] fs: change bh_lru_install() implementation
Date: Mon, 28 Sep 2015 17:26:03 +0800	[thread overview]
Message-ID: <1443432363-28924-1-git-send-email-yalin.wang2010@gmail.com> (raw)

This patch use swap method to implement bh_lru_install,
it works like this:
swap new and [0] first, update old=[0],
then compare old and [1],
if old != new_bh && old != NULL, swap old and [1],
then start the next compare,
otherwise stop the compare.

Signed-off-by: yalin wang <yalin.wang2010@gmail.com>
---
 fs/buffer.c | 33 ++++++++++++---------------------
 1 file changed, 12 insertions(+), 21 deletions(-)

diff --git a/fs/buffer.c b/fs/buffer.c
index 82283ab..d6769f1 100644
--- a/fs/buffer.c
+++ b/fs/buffer.c
@@ -1287,40 +1287,31 @@ static inline void check_irqs_on(void)
  */
 static void bh_lru_install(struct buffer_head *bh)
 {
-	struct buffer_head *evictee = NULL;
+	struct buffer_head *old = NULL;
 
 	check_irqs_on();
 	bh_lru_lock();
 	if (__this_cpu_read(bh_lrus.bhs[0]) != bh) {
-		struct buffer_head *bhs[BH_LRU_SIZE];
-		int in;
+		struct buffer_head *temp;
 		int out = 0;
 
+		old = __this_cpu_read(bh_lrus.bhs[0]);
 		get_bh(bh);
-		bhs[out++] = bh;
-		for (in = 0; in < BH_LRU_SIZE; in++) {
-			struct buffer_head *bh2 =
-				__this_cpu_read(bh_lrus.bhs[in]);
-
-			if (bh2 == bh) {
-				__brelse(bh2);
+		__this_cpu_write(bh_lrus.bhs[out++], bh);
+		for (; out < BH_LRU_SIZE; out++) {
+			if (old == bh || old == NULL) {
+				break;
 			} else {
-				if (out >= BH_LRU_SIZE) {
-					BUG_ON(evictee != NULL);
-					evictee = bh2;
-				} else {
-					bhs[out++] = bh2;
-				}
+				temp = __this_cpu_read(bh_lrus.bhs[out]);
+				__this_cpu_write(bh_lrus.bhs[out], old);
+				old = temp;
 			}
 		}
-		while (out < BH_LRU_SIZE)
-			bhs[out++] = NULL;
-		memcpy(this_cpu_ptr(&bh_lrus.bhs), bhs, sizeof(bhs));
 	}
 	bh_lru_unlock();
 
-	if (evictee)
-		__brelse(evictee);
+	if (old)
+		__brelse(old);
 }
 
 /*
-- 
1.9.1


                 reply	other threads:[~2015-09-28  9:26 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=1443432363-28924-1-git-send-email-yalin.wang2010@gmail.com \
    --to=yalin.wang2010@gmail.com \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=viro@zeniv.linux.org.uk \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.