From patchwork Mon Sep 28 06:52:51 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: yalin wang X-Patchwork-Id: 7275571 Return-Path: X-Original-To: patchwork-linux-fsdevel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 56FF5BEEA4 for ; Mon, 28 Sep 2015 06:53:20 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 5359B207B0 for ; Mon, 28 Sep 2015 06:53:19 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 361A0207AF for ; Mon, 28 Sep 2015 06:53:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753741AbbI1Gw7 (ORCPT ); Mon, 28 Sep 2015 02:52:59 -0400 Received: from mail-pa0-f49.google.com ([209.85.220.49]:32855 "EHLO mail-pa0-f49.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750843AbbI1Gw6 (ORCPT ); Mon, 28 Sep 2015 02:52:58 -0400 Received: by pacex6 with SMTP id ex6so165788514pac.0; Sun, 27 Sep 2015 23:52:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=content-type:mime-version:subject:from:in-reply-to:date:cc :content-transfer-encoding:message-id:references:to; bh=g978IKkkrVE+o1ZIFK3goQm0LSOrW80fynLXaQAZl8s=; b=CN2fVnuw2pQ+RA5P4p/R5fejAC757XZJW+VW5HUYFzs90RPoTJA3rKhoN1kAAkNgB/ sSsjoE5kcS2LqL0soUHvXEoc2K6vGAeQx4aIEMpaz3eeA0K1T2Hci/1iAML8vf471Neq P3QLN+naMQq9PmkJJ6u2YkGurvJ9dxZOwCgD18U0gwGiOt0IdJ70AnZXVb2Dny/f4jPY DmGxlXaGlv0qPSLetp3b4P5A4dmazRYUj8GyIqSEDlYEwBVv1esgOSJzg8rpHYfI9VZ3 CgrAl5EtofQ+TP8Oorw54fYVTe4CVKuDSrUllLenoUbIZONCrnpM6qCZ0iP29+i1GUsy yBrw== X-Received: by 10.66.240.37 with SMTP id vx5mr24633005pac.76.1443423177521; Sun, 27 Sep 2015 23:52:57 -0700 (PDT) Received: from [17.87.20.169] ([17.87.20.169]) by smtp.gmail.com with ESMTPSA id dk2sm17188441pbd.57.2015.09.27.23.52.55 (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Sun, 27 Sep 2015 23:52:57 -0700 (PDT) Mime-Version: 1.0 (Mac OS X Mail 9.0 \(3094\)) Subject: Re: [PATCH] fs/buffer: simplify the code flow of LRU management algorithm From: yalin wang In-Reply-To: <20150928053639.GA10349@dhcp-128-25.nay.redhat.com> Date: Mon, 28 Sep 2015 14:52:51 +0800 Cc: Al Viro , linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, Minfei Huang Message-Id: <28690A54-7E8A-4170-9A86-CB077E4F112D@gmail.com> References: <1441872579-31595-1-git-send-email-mhuang@redhat.com> <20150928053639.GA10349@dhcp-128-25.nay.redhat.com> To: Minfei Huang X-Mailer: Apple Mail (2.3094) 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=unavailable 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 why not change like this: more simple to understand and have better performance . am i understanding correctly ? > On Sep 28, 2015, at 13:36, Minfei Huang wrote: > > Ping, Could you someone help to review this patch? > > Thanks > Minfei > > On 09/10/15 at 04:09pm, Minfei Huang wrote: >> From: Minfei Huang >> >> There is a buffer_head lru list cache in local cpu to accelerate the >> speed. The LRU management algorithm is simple enough in >> bh_lru_install(). >> >> There are three situtaions we should deal with. >> 1) All/part of the lru cache is NULL. >> 2) The new buffer_head hitts the lru cache. >> 3) The new buffer_head does hit the lru cache. >> >> We put the new buffer_head at the head of lru cache, then copy the >> buffer_head from the original lru cache, and drop the spare. >> >> Signed-off-by: Minfei Huang >> --- >> fs/buffer.c | 32 ++++++++++++++++++++------------ >> 1 file changed, 20 insertions(+), 12 deletions(-) >> >> diff --git a/fs/buffer.c b/fs/buffer.c >> index 1cf7a53..2139574 100644 >> --- a/fs/buffer.c >> +++ b/fs/buffer.c >> @@ -1287,8 +1287,6 @@ static inline void check_irqs_on(void) >> */ >> static void bh_lru_install(struct buffer_head *bh) >> { >> - struct buffer_head *evictee = NULL; >> - >> check_irqs_on(); >> bh_lru_lock(); >> if (__this_cpu_read(bh_lrus.bhs[0]) != bh) { >> @@ -1302,25 +1300,35 @@ static void bh_lru_install(struct buffer_head *bh) >> struct buffer_head *bh2 = >> __this_cpu_read(bh_lrus.bhs[in]); >> >> - if (bh2 == bh) { >> + if (bh2 == NULL) { >> + /* Rest value in bh_lrus.bhs always is NULL */ >> + break; >> + } else if (bh2 == bh) { >> __brelse(bh2); >> } else { >> - if (out >= BH_LRU_SIZE) { >> - BUG_ON(evictee != NULL); >> - evictee = bh2; >> + if (out == BH_LRU_SIZE) { >> + /* >> + * this condition will be happened, >> + * only if none of entry in >> + * bh_lrus.bhs hits the new bh, >> + * so the last bh should be released. >> + */ >> + BUG_ON(in != BH_LRU_SIZE - 1); >> + __brelse(bh2); >> + break; >> } else { >> bhs[out++] = bh2; >> } >> } >> } >> - while (out < BH_LRU_SIZE) >> - bhs[out++] = NULL; >> - memcpy(this_cpu_ptr(&bh_lrus.bhs), bhs, sizeof(bhs)); >> + /* >> + * it is fine that the value out may be smaller than >> + * BH_LRU_SIZE. The rest of the value in bh_lrus.bhs is NULL. >> + */ >> + memcpy(this_cpu_ptr(&bh_lrus.bhs), bhs, >> + sizeof(struct buffer_head *) * out); >> } >> bh_lru_unlock(); >> - >> - if (evictee) >> - __brelse(evictee); >> } >> >> /* >> -- >> 2.1.0 >> >> -- >> To unsubscribe from this list: send the line "unsubscribe linux-kernel" in >> the body of a message to majordomo@vger.kernel.org >> More majordomo info at http://vger.kernel.org/majordomo-info.html >> Please read the FAQ at http://www.tux.org/lkml/ > -- > To unsubscribe from this list: send the line "unsubscribe linux-kernel" in > the body of a message to majordomo@vger.kernel.org > More majordomo info at http://vger.kernel.org/majordomo-info.html > Please read the FAQ at http://www.tux.org/lkml/ --- To unsubscribe from this list: send the line "unsubscribe linux-fsdevel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html 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); } /*