From: Eric Biggers <ebiggers3@gmail.com>
To: linux-fsdevel@vger.kernel.org
Cc: linux-kernel@vger.kernel.org, Eric Biggers <ebiggers3@gmail.com>
Subject: [PATCH] dcache: Deduplicate code that sets up dentry_hashtable
Date: Tue, 22 Sep 2015 23:56:51 -0500 [thread overview]
Message-ID: <1442984211-25611-1-git-send-email-ebiggers3@gmail.com> (raw)
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 <ebiggers3@gmail.com>
---
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 */
--
2.4.3
reply other threads:[~2015-09-23 4:57 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1442984211-25611-1-git-send-email-ebiggers3@gmail.com \
--to=ebiggers3@gmail.com \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).