Skip to content

Commit b928f62

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;
1 parent d7e0c9b commit b928f62

File tree

8 files changed

+341
-238
lines changed

8 files changed

+341
-238
lines changed

Makefile

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
obj-m += simplefs.o
2-
simplefs-objs := fs.o super.o inode.o file.o dir.o extent.o
3-
2+
simplefs-objs := fs.o super.o inode.o file.o dir.o extent.o symlink.o hash.o
43
KDIR ?= /lib/modules/$(shell uname -r)/build
54

65
MKFS = mkfs.simplefs

bitmap.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,11 @@ static inline uint32_t get_free_blocks(struct super_block *sb, uint32_t len)
4848
struct simplefs_sb_info *sbi = SIMPLEFS_SB(sb);
4949
uint32_t ret = get_first_free_bits(sbi->bfree_bitmap, sbi->nr_blocks, len);
5050
uint32_t i;
51+
struct buffer_head *bh;
5152
if (!ret) /* No enough free blocks */
5253
return 0;
5354

5455
sbi->nr_free_blocks -= len;
55-
struct buffer_head *bh;
5656
for (i = 0; i < len; i++) {
5757
bh = sb_bread(sb, ret + i);
5858
if (!bh) {

dir.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,10 @@ static int simplefs_iterate(struct file *dir, struct dir_context *ctx)
6262
for (; remained_nr_files && ei < SIMPLEFS_MAX_EXTENTS; ei++) {
6363
if (eblock->extents[ei].ee_start == 0)
6464
continue;
65-
65+
int ei_nr = eblock->extents[ei].nr_files;
6666
/* Iterate over blocks in one extent */
67-
for (bi = 0; bi < eblock->extents[ei].ee_len && remained_nr_files;
67+
for (bi = 0;
68+
bi < eblock->extents[ei].ee_len && remained_nr_files && ei_nr;
6869
bi++) {
6970
bh2 = sb_bread(sb, eblock->extents[ei].ee_start + bi);
7071
if (!bh2) {
@@ -80,12 +81,13 @@ static int simplefs_iterate(struct file *dir, struct dir_context *ctx)
8081
continue;
8182
}
8283

83-
for (fi = 0; fi < SIMPLEFS_FILES_PER_BLOCK;) {
84+
for (fi = 0; fi < SIMPLEFS_FILES_PER_BLOCK && dblock->nr_files;) {
8485
if (dblock->files[fi].inode != 0) {
8586
if (offset) {
8687
offset--;
8788
} else {
8889
remained_nr_files--;
90+
ei_nr--;
8991
if (!dir_emit(ctx, dblock->files[fi].filename,
9092
SIMPLEFS_FILENAME_LEN,
9193
dblock->files[fi].inode, DT_UNKNOWN)) {

hash.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#include <linux/types.h>
2+
#include "simplefs.h"
3+
4+
uint64_t fnv1a_64(const char *str)
5+
{
6+
uint64_t h = 0xcbf29ce484222325ULL;
7+
while (*str) {
8+
h ^= (unsigned char) (*str++);
9+
h *= 0x100000001b3ULL;
10+
}
11+
return h;
12+
}

0 commit comments

Comments
 (0)