From: OGAWA Hirofumi <hirofumi@mail.parknet.co.jp>
To: akpm@linux-foundation.org
Cc: linux-kernel@vger.kernel.org, hirofumi@mail.parknet.co.jp
Subject: [PATCH 07/21] fat: improve fat_hash()
Date: Wed, 15 Oct 2008 22:57:58 +0900 [thread overview]
Message-ID: <091baa8f3e848f5f6e6722369.ps@mail.parknet.co.jp> (raw)
In-Reply-To: <a36c25243e848f5f6e5622369.ps@mail.parknet.co.jp>
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 <hirofumi@mail.parknet.co.jp>
---
fs/fat/fat.h | 1 -
fs/fat/inode.c | 18 +++++++-----------
2 files changed, 7 insertions(+), 12 deletions(-)
diff -puN fs/fat/fat.h~fat_improve-hash fs/fat/fat.h
--- linux-2.6/fs/fat/fat.h~fat_improve-hash 2008-08-25 03:33:31.000000000 +0900
+++ linux-2.6-hirofumi/fs/fat/fat.h 2008-08-25 03:50:16.000000000 +0900
@@ -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
diff -puN fs/fat/inode.c~fat_improve-hash fs/fat/inode.c
--- linux-2.6/fs/fat/inode.c~fat_improve-hash 2008-08-25 03:33:31.000000000 +0900
+++ linux-2.6-hirofumi/fs/fat/inode.c 2008-08-25 03:50:16.000000000 +0900
@@ -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"
@@ -247,25 +248,21 @@ static void fat_hash_init(struct super_b
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)
@@ -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;
_
next prev parent reply other threads:[~2008-10-15 14:12 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-10-15 13:57 [PATCH 01/21] fat: document additional vfat mount options OGAWA Hirofumi
2008-10-15 13:57 ` [PATCH 02/21] fat: move fs/vfat/* and fs/msdos/* to fs/fat OGAWA Hirofumi
2008-10-15 13:57 ` [PATCH 03/21] fat: split include/msdos_fs.h OGAWA Hirofumi
2008-10-15 13:57 ` [PATCH 04/21] fat: Fix and cleanup timestamp conversion OGAWA Hirofumi
2008-10-15 13:57 ` [PATCH 05/21] fat: use generic_file_llseek() for directory OGAWA Hirofumi
2008-10-15 13:57 ` [PATCH 06/21] fat: cleanup fat_parse_long() error handling OGAWA Hirofumi
2008-10-15 13:57 ` OGAWA Hirofumi [this message]
2008-10-15 13:57 ` [PATCH 08/21] fat: Fix fat_ent_update_ptr() for FAT12 OGAWA Hirofumi
2008-10-15 13:57 ` [PATCH 09/21] fat: use fat_detach() in fat_clear_inode() OGAWA Hirofumi
2008-10-15 13:57 ` [PATCH 10/21] vfat: Fix vfat_find() error path in vfat_lookup() OGAWA Hirofumi
2008-10-15 13:57 ` [PATCH 11/21] fat: Fix/Cleanup dcache handling for vfat OGAWA Hirofumi
2008-10-15 13:57 ` [PATCH 12/21] fat: Kill d_invalidate() in vfat_lookup() OGAWA Hirofumi
2008-10-15 13:57 ` [PATCH 13/21] fat: Cleanup msdos_lookup() OGAWA Hirofumi
2008-10-15 13:58 ` [PATCH 14/21] fat: Cleanup FAT attribute stuff OGAWA Hirofumi
2008-10-15 13:58 ` [PATCH 15/21] fat: Fix ATTR_RO in the case of (~umask & S_WUGO) == 0 OGAWA Hirofumi
2008-10-15 13:58 ` [PATCH 16/21] fat: Fix ATTR_RO for directory OGAWA Hirofumi
2008-10-15 13:58 ` [PATCH 17/21] fat: Fix _fat_bmap() race OGAWA Hirofumi
2008-10-15 13:58 ` [PATCH 18/21] fat: Add printf attribute to fat_fs_panic() OGAWA Hirofumi
2008-10-15 13:58 ` [PATCH 19/21] fat: mmu_private race fix OGAWA Hirofumi
2008-10-15 13:58 ` [PATCH 20/21] fat: ->i_pos " OGAWA Hirofumi
2008-10-15 13:58 ` [PATCH 21/21] fat: i_blocks warning fix OGAWA Hirofumi
2009-03-17 23:33 ` [PATCH 02/21] fat: move fs/vfat/* and fs/msdos/* to fs/fat Pozsar Balazs
2008-10-15 22:07 ` [PATCH 01/21] fat: document additional vfat mount options Andrew Morton
2008-10-15 23:04 ` OGAWA Hirofumi
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=091baa8f3e848f5f6e6722369.ps@mail.parknet.co.jp \
--to=hirofumi@mail.parknet.co.jp \
--cc=akpm@linux-foundation.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
all inboxes | Powered by JetHome®