Skip to content

Commit

Permalink
fat: improve fat_hash()
Browse files Browse the repository at this point in the history
fat_hash() is using the algorithm known as bad. Instead of it, this
uses hash_32(). The following is the summary of test.

old hash:
	hash func (1000 times): 33489 cycles
	total inodes in hash table: 70926
	largest bucket contains: 696
	smallest bucket contains: 54

new hash:
	hash func (1000 times): 33129 cycles
	total inodes in hash table: 70926
	largest bucket contains: 315
	smallest bucket contains: 236

Signed-off-by: OGAWA Hirofumi <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
  • Loading branch information
OGAWAHirofumi authored and torvalds committed Nov 6, 2008
1 parent 52e9d9f commit d3dfa82
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 12 deletions.
1 change: 0 additions & 1 deletion fs/fat/fat.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ struct fat_mount_options {

#define FAT_HASH_BITS 8
#define FAT_HASH_SIZE (1UL << FAT_HASH_BITS)
#define FAT_HASH_MASK (FAT_HASH_SIZE-1)

/*
* MS-DOS file system in-core superblock data
Expand Down
18 changes: 7 additions & 11 deletions fs/fat/inode.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include <linux/uio.h>
#include <linux/writeback.h>
#include <linux/log2.h>
#include <linux/hash.h>
#include <asm/unaligned.h>
#include "fat.h"

Expand Down Expand Up @@ -247,25 +248,21 @@ static void fat_hash_init(struct super_block *sb)
INIT_HLIST_HEAD(&sbi->inode_hashtable[i]);
}

static inline unsigned long fat_hash(struct super_block *sb, loff_t i_pos)
static inline unsigned long fat_hash(loff_t i_pos)
{
unsigned long tmp = (unsigned long)i_pos | (unsigned long) sb;
tmp = tmp + (tmp >> FAT_HASH_BITS) + (tmp >> FAT_HASH_BITS * 2);
return tmp & FAT_HASH_MASK;
return hash_32(i_pos, FAT_HASH_BITS);
}

void fat_attach(struct inode *inode, loff_t i_pos)
{
struct super_block *sb = inode->i_sb;
struct msdos_sb_info *sbi = MSDOS_SB(sb);
struct msdos_sb_info *sbi = MSDOS_SB(inode->i_sb);
struct hlist_head *head = sbi->inode_hashtable + fat_hash(i_pos);

spin_lock(&sbi->inode_hash_lock);
MSDOS_I(inode)->i_pos = i_pos;
hlist_add_head(&MSDOS_I(inode)->i_fat_hash,
sbi->inode_hashtable + fat_hash(sb, i_pos));
hlist_add_head(&MSDOS_I(inode)->i_fat_hash, head);
spin_unlock(&sbi->inode_hash_lock);
}

EXPORT_SYMBOL_GPL(fat_attach);

void fat_detach(struct inode *inode)
Expand All @@ -276,13 +273,12 @@ void fat_detach(struct inode *inode)
hlist_del_init(&MSDOS_I(inode)->i_fat_hash);
spin_unlock(&sbi->inode_hash_lock);
}

EXPORT_SYMBOL_GPL(fat_detach);

struct inode *fat_iget(struct super_block *sb, loff_t i_pos)
{
struct msdos_sb_info *sbi = MSDOS_SB(sb);
struct hlist_head *head = sbi->inode_hashtable + fat_hash(sb, i_pos);
struct hlist_head *head = sbi->inode_hashtable + fat_hash(i_pos);
struct hlist_node *_p;
struct msdos_inode_info *i;
struct inode *inode = NULL;
Expand Down

0 comments on commit d3dfa82

Please sign in to comment.