From patchwork Wed Sep 23 04:56:51 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Biggers X-Patchwork-Id: 7247641 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 BCCF29F372 for ; Wed, 23 Sep 2015 04:58:12 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id D166C206F3 for ; Wed, 23 Sep 2015 04:58:11 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id D3E79206EC for ; Wed, 23 Sep 2015 04:58:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751164AbbIWE5o (ORCPT ); Wed, 23 Sep 2015 00:57:44 -0400 Received: from mail-io0-f173.google.com ([209.85.223.173]:34758 "EHLO mail-io0-f173.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750844AbbIWE5o (ORCPT ); Wed, 23 Sep 2015 00:57:44 -0400 Received: by iofb144 with SMTP id b144so34554295iof.1; Tue, 22 Sep 2015 21:57:43 -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=tTSgPEFA4MrUGcomFEvfsym+WdmyB1r//GsmzhyVQHw=; b=UOIFXLzHF7MJBWsn513dfQfKX2Yn8oZ03gR6Z4SiY5IGEa+wlJmiU9zYA1v9xZLJ0+ CMtDxxfVoK4Rmv2TLmNVfa7+SClp9V4RjcqRzbUTjK5VVehT2xRUzP4IzJp2VUVSZHyw +0riq6YP3F5oGuEOfnc5M4DcYliHvDdU0zCAg4PJ7GYuT1elsf9yZ9cnIiMYicapTW4v OwhPDh8GON1eZSCsPiaYpQcZJXdwcfM8noIMyhAs+gdoL1nvG7HBzi9bJ8bDvvC2k0Yi 2/jcrcrfB/lApHQKdei9JDyLzZRffeNIjuoXGYq5xhyo8bkp+2jMu+Tw4Ew42yqFbzsf 4giw== X-Received: by 10.107.134.220 with SMTP id q89mr36952928ioi.90.1442984263165; Tue, 22 Sep 2015 21:57:43 -0700 (PDT) Received: from zyxyz.corp.code42.com (c-75-72-182-251.hsd1.mn.comcast.net. [75.72.182.251]) by smtp.gmail.com with ESMTPSA id 92sm2833955ioq.3.2015.09.22.21.57.42 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 22 Sep 2015 21:57:42 -0700 (PDT) From: Eric Biggers To: linux-fsdevel@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Eric Biggers Subject: [PATCH] dcache: Deduplicate code that sets up dentry_hashtable Date: Tue, 22 Sep 2015 23:56:51 -0500 Message-Id: <1442984211-25611-1-git-send-email-ebiggers3@gmail.com> X-Mailer: git-send-email 2.4.3 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, RP_MATCHES_RCVD, T_DKIM_INVALID, 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 Make both dcache_init_early() and dcache_init() call a new helper function, dcache_alloc_hashtable(). Also address a small inefficiency by moving the table length calculation outside of the loop condition. gcc apparently doesn't do that because it assumes that the memory pointed to by 'dentry_hashtable' might alias 'd_hash_shift'. Signed-off-by: Eric Biggers --- fs/dcache.c | 48 +++++++++++++++++++----------------------------- 1 file changed, 19 insertions(+), 29 deletions(-) diff --git a/fs/dcache.c b/fs/dcache.c index 5c33aeb..7cfe848 100644 --- a/fs/dcache.c +++ b/fs/dcache.c @@ -3380,35 +3380,39 @@ static int __init set_dhash_entries(char *str) } __setup("dhash_entries=", set_dhash_entries); -static void __init dcache_init_early(void) +static void __init dcache_alloc_hashtable(int flags) { - unsigned int loop; - - /* If hashes are distributed across NUMA nodes, defer - * hash allocation until vmalloc space is available. - */ - if (hashdist) - return; + unsigned int num_entries; + unsigned int i; dentry_hashtable = alloc_large_system_hash("Dentry cache", sizeof(struct hlist_bl_head), dhash_entries, 13, - HASH_EARLY, + flags, &d_hash_shift, &d_hash_mask, 0, 0); - for (loop = 0; loop < (1U << d_hash_shift); loop++) - INIT_HLIST_BL_HEAD(dentry_hashtable + loop); + num_entries = 1U << d_hash_shift; + + for (i = 0; i < num_entries; i++) + INIT_HLIST_BL_HEAD(&dentry_hashtable[i]); } -static void __init dcache_init(void) +static void __init dcache_init_early(void) { - unsigned int loop; + /* If hashes are distributed across NUMA nodes, defer + * hash allocation until vmalloc space is available. + */ + if (!hashdist) + dcache_alloc_hashtable(HASH_EARLY); +} +static void __init dcache_init(void) +{ /* * A constructor could be added for stable state like the lists, * but it is probably not worth it because of the cache nature @@ -3418,22 +3422,8 @@ static void __init dcache_init(void) SLAB_RECLAIM_ACCOUNT|SLAB_PANIC|SLAB_MEM_SPREAD); /* Hash may have been set up in dcache_init_early */ - if (!hashdist) - return; - - dentry_hashtable = - alloc_large_system_hash("Dentry cache", - sizeof(struct hlist_bl_head), - dhash_entries, - 13, - 0, - &d_hash_shift, - &d_hash_mask, - 0, - 0); - - for (loop = 0; loop < (1U << d_hash_shift); loop++) - INIT_HLIST_BL_HEAD(dentry_hashtable + loop); + if (hashdist) + dcache_alloc_hashtable(0); } /* SLAB cache for __getname() consumers */