From patchwork Mon Sep 28 09:26:03 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: yalin wang X-Patchwork-Id: 7276051 Return-Path: X-Original-To: patchwork-linux-fsdevel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 3A1B19F36A for ; Mon, 28 Sep 2015 09:26:41 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 58F78206EA for ; Mon, 28 Sep 2015 09:26:40 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 700F9206DB for ; Mon, 28 Sep 2015 09:26:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932268AbbI1J0Y (ORCPT ); Mon, 28 Sep 2015 05:26:24 -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 Received: by pacex6 with SMTP id ex6so169655368pac.0; Mon, 28 Sep 2015 02:26:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id; bh=OFeh4mCVB2KBx4wek7103+TgRj2PjSkemPsZZpS6cyw=; b=nqih5q/kFLTjVq1ayv5VOfKs+lbXcZxsHHZw4Sm4xKCCMnlvVE3Sm92/QGhml8UABE /R26P4tL5pq4J/jEEVM2pYzlA3J0YWdZTHIQ4u7lqrKQoYFLUAFllK/j+1ReD36Z1kQ9 nX31Q8A5/JzpDH2Ovm+xoQ1nAC1IplLmVxofAXvBGuQYdC/L59HqZjpvIIuote6AmTKi 4Sh9WN+m39QVZfplNiLEMv4UMR8UHerst84wUDw+HPBKE/pdBCn3oWON1lgLYBkZn6iW WaMpmJ7QVYDCch0G5IlpdOi8ac/mmIR4GO8+F+4W5xey4DF9hegkj9/aKeba/EZ2Eas/ rlhQ== X-Received: by 10.68.220.132 with SMTP id pw4mr25315401pbc.149.1443432383384; Mon, 28 Sep 2015 02:26:23 -0700 (PDT) Received: from ubuntu.localdomain ([17.87.20.100]) by smtp.googlemail.com with ESMTPSA id y5sm18107715pbt.77.2015.09.28.02.26.21 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 28 Sep 2015 02:26:22 -0700 (PDT) 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-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org X-Spam-Status: No, score=-6.8 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, T_DKIM_INVALID, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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); } /*