diff mbox

[RFC] fs: change bh_lru_install() implementation

Message ID 1443432363-28924-1-git-send-email-yalin.wang2010@gmail.com (mailing list archive)
State New, archived
Headers show

Commit Message

yalin wang Sept. 28, 2015, 9:26 a.m. UTC
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 mbox

Patch

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);
 }
 
 /*