From patchwork Tue Aug 14 16:24:43 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sasha Levin X-Patchwork-Id: 1321921 Return-Path: X-Original-To: patchwork-linux-nfs@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork1.kernel.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by patchwork1.kernel.org (Postfix) with ESMTP id D2A3D40210 for ; Tue, 14 Aug 2012 16:28:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756722Ab2HNQZ5 (ORCPT ); Tue, 14 Aug 2012 12:25:57 -0400 Received: from mail-bk0-f46.google.com ([209.85.214.46]:39086 "EHLO mail-bk0-f46.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756211Ab2HNQZx (ORCPT ); Tue, 14 Aug 2012 12:25:53 -0400 Received: by mail-bk0-f46.google.com with SMTP id j10so208146bkw.19 for ; Tue, 14 Aug 2012 09:25:52 -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:x-mailer:in-reply-to:references; bh=g6k4Y43RlpktchLCSkGGrufdqWICUAkyxxT6YhfzbS4=; b=y+eeYa8RlR5ZUkuNUvHgI74cHWVIbRMjlkuqe/onhn5oezZRhHlgc21jYaWP/I6PQ0 XzDps5nEfMtaFGyy7tLrCixo+O3vDPPCVVFpzgpSUcTGkxTek2Ar/ddgs6TKQzs8uRwP BUlMckLIM9l10AkDf5vVpOfM56pKIUjcvDw5dfpFD0Lm4Zp09AL2L4PNcLhfU8+mwDtK 3fPG/EeaWgaa9aw62nkBEpa8+3Mmqy0yqJWd86isqb+T0thY344R0whopT3wvOhtaRQs U+4e3ZsSvJfgWn+cTcgb4yRCgT7LntwjTaM53KRZkdC/BU3pvuEwECvSSgfV1go+Es+7 RYHQ== Received: by 10.205.137.8 with SMTP id im8mr6426187bkc.135.1344961552050; Tue, 14 Aug 2012 09:25:52 -0700 (PDT) Received: from localhost.localdomain (95-89-78-76-dynip.superkabel.de. [95.89.78.76]) by mx.google.com with ESMTPS id t23sm1470660bks.4.2012.08.14.09.25.45 (version=TLSv1/SSLv3 cipher=OTHER); Tue, 14 Aug 2012 09:25:51 -0700 (PDT) From: Sasha Levin To: torvalds@linux-foundation.org Cc: tj@kernel.org, akpm@linux-foundation.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, paul.gortmaker@windriver.com, davem@davemloft.net, rostedt@goodmis.org, mingo@elte.hu, ebiederm@xmission.com, aarcange@redhat.com, ericvh@gmail.com, netdev@vger.kernel.org, josh@joshtriplett.org, eric.dumazet@gmail.com, mathieu.desnoyers@efficios.com, axboe@kernel.dk, agk@redhat.com, dm-devel@redhat.com, neilb@suse.de, ccaulfie@redhat.com, teigland@redhat.com, Trond.Myklebust@netapp.com, bfields@fieldses.org, fweisbec@gmail.com, jesse@nicira.com, venkat.x.venkatsubra@oracle.com, ejt@redhat.com, snitzer@redhat.com, edumazet@google.com, linux-nfs@vger.kernel.org, dev@openvswitch.org, rds-devel@oss.oracle.com, lw@cn.fujitsu.com, Sasha Levin Subject: [PATCH 09/16] SUNRPC/cache: use new hashtable implementation Date: Tue, 14 Aug 2012 18:24:43 +0200 Message-Id: <1344961490-4068-10-git-send-email-levinsasha928@gmail.com> X-Mailer: git-send-email 1.7.8.6 In-Reply-To: <1344961490-4068-1-git-send-email-levinsasha928@gmail.com> References: <1344961490-4068-1-git-send-email-levinsasha928@gmail.com> Sender: linux-nfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org Switch cache to use the new hashtable implementation. This reduces the amount of generic unrelated code in the cache implementation. Signed-off-by: Sasha Levin --- net/sunrpc/cache.c | 20 +++++++++----------- 1 files changed, 9 insertions(+), 11 deletions(-) diff --git a/net/sunrpc/cache.c b/net/sunrpc/cache.c index 2afd2a8..2d1f333 100644 --- a/net/sunrpc/cache.c +++ b/net/sunrpc/cache.c @@ -28,6 +28,7 @@ #include #include #include +#include #include #include #include @@ -524,19 +525,18 @@ EXPORT_SYMBOL_GPL(cache_purge); * it to be revisited when cache info is available */ -#define DFR_HASHSIZE (PAGE_SIZE/sizeof(struct list_head)) -#define DFR_HASH(item) ((((long)item)>>4 ^ (((long)item)>>13)) % DFR_HASHSIZE) +#define DFR_HASH_BITS 9 #define DFR_MAX 300 /* ??? */ static DEFINE_SPINLOCK(cache_defer_lock); static LIST_HEAD(cache_defer_list); -static struct hlist_head cache_defer_hash[DFR_HASHSIZE]; +static DEFINE_HASHTABLE(cache_defer_hash, DFR_HASH_BITS) static int cache_defer_cnt; static void __unhash_deferred_req(struct cache_deferred_req *dreq) { - hlist_del_init(&dreq->hash); + hash_del(&dreq->hash); if (!list_empty(&dreq->recent)) { list_del_init(&dreq->recent); cache_defer_cnt--; @@ -545,10 +545,7 @@ static void __unhash_deferred_req(struct cache_deferred_req *dreq) static void __hash_deferred_req(struct cache_deferred_req *dreq, struct cache_head *item) { - int hash = DFR_HASH(item); - - INIT_LIST_HEAD(&dreq->recent); - hlist_add_head(&dreq->hash, &cache_defer_hash[hash]); + hash_add(cache_defer_hash, &dreq->hash, (unsigned long)item); } static void setup_deferral(struct cache_deferred_req *dreq, @@ -600,7 +597,7 @@ static void cache_wait_req(struct cache_req *req, struct cache_head *item) * to clean up */ spin_lock(&cache_defer_lock); - if (!hlist_unhashed(&sleeper.handle.hash)) { + if (hash_hashed(&sleeper.handle.hash)) { __unhash_deferred_req(&sleeper.handle); spin_unlock(&cache_defer_lock); } else { @@ -671,12 +668,11 @@ static void cache_revisit_request(struct cache_head *item) struct cache_deferred_req *dreq; struct list_head pending; struct hlist_node *lp, *tmp; - int hash = DFR_HASH(item); INIT_LIST_HEAD(&pending); spin_lock(&cache_defer_lock); - hlist_for_each_entry_safe(dreq, lp, tmp, &cache_defer_hash[hash], hash) + hash_for_each_possible_safe(cache_defer_hash, dreq, lp, tmp, hash, (unsigned long)item) if (dreq->item == item) { __unhash_deferred_req(dreq); list_add(&dreq->recent, &pending); @@ -1636,6 +1632,8 @@ static int create_cache_proc_entries(struct cache_detail *cd, struct net *net) void __init cache_initialize(void) { INIT_DELAYED_WORK_DEFERRABLE(&cache_cleaner, do_cache_clean); + + hash_init(cache_defer_hash); } int cache_register_net(struct cache_detail *cd, struct net *net)