Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

Use ilog2() in fs/namespace.c

We can use ilog2() in fs/namespace.c to compute hash_bits and hash_mask at
compile time, not runtime.

[akpm@linux-foundation.org: clean it all up]
Signed-off-by: Eric Dumazet <dada1@cosmosbay.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

authored by

Eric Dumazet and committed by
Linus Torvalds
13f14b4d b41ecbeb

+10 -33
+10 -33
fs/namespace.c
··· 25 25 #include <linux/security.h> 26 26 #include <linux/mount.h> 27 27 #include <linux/ramfs.h> 28 + #include <linux/log2.h> 28 29 #include <asm/uaccess.h> 29 30 #include <asm/unistd.h> 30 31 #include "pnode.h" 31 32 #include "internal.h" 33 + 34 + #define HASH_SHIFT ilog2(PAGE_SIZE / sizeof(struct list_head)) 35 + #define HASH_SIZE (1UL << HASH_SHIFT) 32 36 33 37 /* spinlock for vfsmount related operations, inplace of dcache_lock */ 34 38 __cacheline_aligned_in_smp DEFINE_SPINLOCK(vfsmount_lock); ··· 40 36 static int event; 41 37 42 38 static struct list_head *mount_hashtable __read_mostly; 43 - static int hash_mask __read_mostly, hash_bits __read_mostly; 44 39 static struct kmem_cache *mnt_cache __read_mostly; 45 40 static struct rw_semaphore namespace_sem; 46 41 ··· 51 48 { 52 49 unsigned long tmp = ((unsigned long)mnt / L1_CACHE_BYTES); 53 50 tmp += ((unsigned long)dentry / L1_CACHE_BYTES); 54 - tmp = tmp + (tmp >> hash_bits); 55 - return tmp & hash_mask; 51 + tmp = tmp + (tmp >> HASH_SHIFT); 52 + return tmp & (HASH_SIZE - 1); 56 53 } 57 54 58 55 struct vfsmount *alloc_vfsmnt(const char *name) ··· 1816 1813 1817 1814 void __init mnt_init(void) 1818 1815 { 1819 - struct list_head *d; 1820 - unsigned int nr_hash; 1821 - int i; 1816 + unsigned u; 1822 1817 int err; 1823 1818 1824 1819 init_rwsem(&namespace_sem); ··· 1829 1828 if (!mount_hashtable) 1830 1829 panic("Failed to allocate mount hash table\n"); 1831 1830 1832 - /* 1833 - * Find the power-of-two list-heads that can fit into the allocation.. 1834 - * We don't guarantee that "sizeof(struct list_head)" is necessarily 1835 - * a power-of-two. 1836 - */ 1837 - nr_hash = PAGE_SIZE / sizeof(struct list_head); 1838 - hash_bits = 0; 1839 - do { 1840 - hash_bits++; 1841 - } while ((nr_hash >> hash_bits) != 0); 1842 - hash_bits--; 1831 + printk("Mount-cache hash table entries: %lu\n", HASH_SIZE); 1843 1832 1844 - /* 1845 - * Re-calculate the actual number of entries and the mask 1846 - * from the number of bits we can fit. 1847 - */ 1848 - nr_hash = 1UL << hash_bits; 1849 - hash_mask = nr_hash - 1; 1833 + for (u = 0; u < HASH_SIZE; u++) 1834 + INIT_LIST_HEAD(&mount_hashtable[u]); 1850 1835 1851 - printk("Mount-cache hash table entries: %d\n", nr_hash); 1852 - 1853 - /* And initialize the newly allocated array */ 1854 - d = mount_hashtable; 1855 - i = nr_hash; 1856 - do { 1857 - INIT_LIST_HEAD(d); 1858 - d++; 1859 - i--; 1860 - } while (i); 1861 1836 err = sysfs_init(); 1862 1837 if (err) 1863 1838 printk(KERN_WARNING "%s: sysfs_init error: %d\n",