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@xxxxxxxxx> --- 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 -- To unsubscribe from this list: send the line "unsubscribe linux-fsdevel" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html