Skip to content

Commit 211edce

Browse files
committed
Use hash func to boost file creation and lookup
Introduce a hash-based mechanism to speed up file creation and lookup operations. The hash function enables faster access to extent and logical block extent index, improving overall filesystem performance. hash_code = file_hash(file_name); extent index = hash_code / SIMPLEFS_MAX_BLOCKS_PER_EXTENT block index = hash_code % SIMPLEFS_MAX_BLOCKS_PER_EXTENT; Use perf to measure: 1. File Creation (random) Legacy: 259.842753513 seconds time elapsed 23.000247000 seconds user 150.380145000 seconds sys full_name_hash: 222.274028604 seconds time elapsed 20.794966000 seconds user 151.941876000 seconds sys 2. File Listing (random) Legacy: min time: 0.00171 s max time: 0.03799 s avg time: 0.00423332 s tot time: 129.539510 s full_name_hash: min time: 0.00171 s max time: 0.03588 s avg time: 0.00305601 s tot time: 93.514040 s 3. files Removal (Random) Legacy: 106.921706288 seconds time elapsed 16.987883000 seconds user 91.268661000 seconds sys full_name_hash: 86.132655220 seconds time elapsed 19.180209000 seconds user 68.476075000 seconds sys
1 parent d190d31 commit 211edce

File tree

5 files changed

+290
-181
lines changed

5 files changed

+290
-181
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
obj-m += simplefs.o
2-
simplefs-objs := fs.o super.o inode.o file.o dir.o extent.o
2+
simplefs-objs := fs.o super.o inode.o file.o dir.o extent.o hash.o
33

44
KDIR ?= /lib/modules/$(shell uname -r)/build
55

dir.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ static int simplefs_iterate(struct file *dir, struct dir_context *ctx)
8181
continue;
8282
}
8383

84-
for (fi = 0; fi < SIMPLEFS_FILES_PER_BLOCK;) {
84+
for (fi = 0; fi < SIMPLEFS_FILES_PER_BLOCK && dblock->nr_files;) {
8585
if (dblock->files[fi].inode != 0) {
8686
if (offset) {
8787
offset--;

hash.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#include <linux/stringhash.h>
2+
#include <linux/types.h>
3+
#include "simplefs.h"
4+
5+
uint32_t simplefs_hash(struct dentry *dentry)
6+
{
7+
return full_name_hash(dentry, dentry->d_name.name,
8+
strlen(dentry->d_name.name));
9+
}

0 commit comments

Comments
 (0)