From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932332AbbI1J0Z (ORCPT ); Mon, 28 Sep 2015 05:26:25 -0400 Received: from mail-pa0-f50.google.com ([209.85.220.50]:33753 "EHLO mail-pa0-f50.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932098AbbI1J0X (ORCPT ); Mon, 28 Sep 2015 05:26:23 -0400 From: yalin wang To: viro@zeniv.linux.org.uk, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org Cc: yalin wang Subject: [RFC] fs: change bh_lru_install() implementation Date: Mon, 28 Sep 2015 17:26:03 +0800 Message-Id: <1443432363-28924-1-git-send-email-yalin.wang2010@gmail.com> X-Mailer: git-send-email 1.9.1 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 --- 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