Commit 024e1a49 authored by Stephen Hemminger's avatar Stephen Hemminger Committed by James Morris

tomoyo: improve hash bucket dispersion

When examining the network device name hash, it was discovered that
the low order bits of full_name_hash() are not very well dispersed
across the possible values. When used by filesystem code, this is handled
by folding with the function hash_long().

The only other non-filesystem usage of full_name_hash() at this time
appears to be in TOMOYO. This patch should fix that.

I do not use TOMOYO at this time, so this patch is build tested only.
Signed-off-by: default avatarStephen Hemminger <shemminger@vyatta.com>
Acked-by: default avatarTetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp>
Signed-off-by: default avatarJames Morris <jmorris@namei.org>
parent d6ba4521
...@@ -13,6 +13,8 @@ ...@@ -13,6 +13,8 @@
#include <linux/mount.h> #include <linux/mount.h>
#include <linux/mnt_namespace.h> #include <linux/mnt_namespace.h>
#include <linux/fs_struct.h> #include <linux/fs_struct.h>
#include <linux/hash.h>
#include "common.h" #include "common.h"
#include "realpath.h" #include "realpath.h"
...@@ -263,7 +265,8 @@ static unsigned int tomoyo_quota_for_savename; ...@@ -263,7 +265,8 @@ static unsigned int tomoyo_quota_for_savename;
* table. Frequency of appending strings is very low. So we don't need * table. Frequency of appending strings is very low. So we don't need
* large (e.g. 64k) hash size. 256 will be sufficient. * large (e.g. 64k) hash size. 256 will be sufficient.
*/ */
#define TOMOYO_MAX_HASH 256 #define TOMOYO_HASH_BITS 8
#define TOMOYO_MAX_HASH (1u<<TOMOYO_HASH_BITS)
/* /*
* tomoyo_name_entry is a structure which is used for linking * tomoyo_name_entry is a structure which is used for linking
...@@ -315,6 +318,7 @@ const struct tomoyo_path_info *tomoyo_save_name(const char *name) ...@@ -315,6 +318,7 @@ const struct tomoyo_path_info *tomoyo_save_name(const char *name)
struct tomoyo_free_memory_block_list *fmb; struct tomoyo_free_memory_block_list *fmb;
int len; int len;
char *cp; char *cp;
struct list_head *head;
if (!name) if (!name)
return NULL; return NULL;
...@@ -325,9 +329,10 @@ const struct tomoyo_path_info *tomoyo_save_name(const char *name) ...@@ -325,9 +329,10 @@ const struct tomoyo_path_info *tomoyo_save_name(const char *name)
return NULL; return NULL;
} }
hash = full_name_hash((const unsigned char *) name, len - 1); hash = full_name_hash((const unsigned char *) name, len - 1);
head = &tomoyo_name_list[hash_long(hash, TOMOYO_HASH_BITS)];
mutex_lock(&lock); mutex_lock(&lock);
list_for_each_entry(ptr, &tomoyo_name_list[hash % TOMOYO_MAX_HASH], list_for_each_entry(ptr, head, list) {
list) {
if (hash == ptr->entry.hash && !strcmp(name, ptr->entry.name)) if (hash == ptr->entry.hash && !strcmp(name, ptr->entry.name))
goto out; goto out;
} }
...@@ -365,7 +370,7 @@ const struct tomoyo_path_info *tomoyo_save_name(const char *name) ...@@ -365,7 +370,7 @@ const struct tomoyo_path_info *tomoyo_save_name(const char *name)
tomoyo_fill_path_info(&ptr->entry); tomoyo_fill_path_info(&ptr->entry);
fmb->ptr += len; fmb->ptr += len;
fmb->len -= len; fmb->len -= len;
list_add_tail(&ptr->list, &tomoyo_name_list[hash % TOMOYO_MAX_HASH]); list_add_tail(&ptr->list, head);
if (fmb->len == 0) { if (fmb->len == 0) {
list_del(&fmb->list); list_del(&fmb->list);
kfree(fmb); kfree(fmb);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment