From 0d7dc934a732426ea2d06619be4898ab5c4aa160 Mon Sep 17 00:00:00 2001 From: qcloud Date: Fri, 11 Oct 2024 15:41:04 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0inode=E5=9B=9E=E6=94=B6?= =?UTF-8?q?=E6=9C=BA=E5=88=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../fast_fuse/difuse/src/difuse | Bin 0 -> 21800 bytes .../fast_fuse/difuse/src/difuse.c | 50 ++++++++++++++++-- 2 files changed, 45 insertions(+), 5 deletions(-) create mode 100755 eBPF_Supermarket/Filesystem_Subsystem/fast_fuse/difuse/src/difuse diff --git a/eBPF_Supermarket/Filesystem_Subsystem/fast_fuse/difuse/src/difuse b/eBPF_Supermarket/Filesystem_Subsystem/fast_fuse/difuse/src/difuse new file mode 100755 index 0000000000000000000000000000000000000000..dccdfc251680e16be72f3b20f5d1130bb9a1e0d3 GIT binary patch literal 21800 zcmeHPe{@vUoxd|Mf`}xjC?Lw{T9qPW!Y@&ZOn|{hH<2jJR*QBRG6R`1$;6pA5Y*5p z=wUkMG`d>tF1D$=T0HCSNw=;Ws7C`>gJ-P`+S3zvJ!|TZI%%-R2)nV1%znQ2-tWts zN5@E_y`S%od++yt?|tvx%)8$TRIhfsT!Pa$alN3@#;FSNYes#I&VcyE z5^*-ZXN!x)87PmJnBw~t0av9ycOjjq@o}J}H=QzL&{+x=Ou2(gm-Ex_>tJ_8HBE4p<*R1`{ zRA_%PWq*=6`Yh4@bW%sNg;TFy>pAHv*rddi>Y%jleKYc>)K{zZChG<{>2YOVFy;Dg zf*$$hize+(akH+k*f>0<{mGQ$?CN-I)8d6!$0PINvBq@syyhi~=Ph37OC@~sWfQ1f zUVJE~Zn!Z>!_iHccB62&sxsRn-g%l&@^6egvEl5eBTqEl|C5@|8OG%^p0AxwGSqI; zAsI?!kB6Mfl%IkR$tZu^gPg*M9*w@%K(tu;9vJ70!Q5H|r+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@`j6hpBz+!#zE5V#`+3Fmf9}xd=OU)ZSy5AG z{r}<67nNF2(`RUM*%HSOL+>L)dvPqr`<{HRpHrU8Oh1NhnN6SfMVs)}Iwh79`{{a~J-_l=8QaI;vxuSa%vA$WK=^0SA>s!xPex=ex zOk48W@|2wnKH1{>d7q}KN(uVCit@LkD5gRme;h6>CRl&2g{Tb4QnFJk_7qEgcT}mu ykX{(*w?|jt!~N#<=S*PScBP@d+YLp3>R@ucEISn$hlphTWwnx+=}>SK#s30{_&53h literal 0 HcmV?d00001 diff --git a/eBPF_Supermarket/Filesystem_Subsystem/fast_fuse/difuse/src/difuse.c b/eBPF_Supermarket/Filesystem_Subsystem/fast_fuse/difuse/src/difuse.c index f1a6d29a4..61f4d99fe 100644 --- a/eBPF_Supermarket/Filesystem_Subsystem/fast_fuse/difuse/src/difuse.c +++ b/eBPF_Supermarket/Filesystem_Subsystem/fast_fuse/difuse/src/difuse.c @@ -64,6 +64,9 @@ struct dfs_dentry *lru_head = NULL; //LRU 链表头 struct dfs_dentry *lru_tail = NULL; //LRU 链表尾 struct dfs_dentry *hash_table[HASH_SIZE]; //哈希表 +// inode回收队列 +struct dfs_inode *inode_recycle_list = NULL; // inode 回收队列头 + /*缓存管理*/ static unsigned int hash(const char *path) @@ -130,11 +133,35 @@ static void lru_evict() } } +/* 回收 inode 相关函数 */ +static void add_to_inode_recycle_list(struct dfs_inode *inode) +{ + inode->next = inode_recycle_list; + inode_recycle_list = inode; +} + +static struct dfs_inode *get_recycled_inode() +{ + if (inode_recycle_list) + { + struct dfs_inode *inode = inode_recycle_list; + inode_recycle_list = inode->next; + inode->next = NULL; // 复用 inode 时,清除 next 指针 + return inode; + } + return NULL; +} + /*过程函数*/ static struct dfs_inode *new_inode(int size, int dir_cnt) { - struct dfs_inode *inode = (struct dfs_inode *)malloc(sizeof(struct dfs_inode)); - inode->ino = next_ino++; + struct dfs_inode *inode = get_recycled_inode(); // 优先从回收队列中获取 inode + if (!inode) + { + inode = (struct dfs_inode *)malloc(sizeof(struct dfs_inode)); + inode->ino = next_ino++; + } + inode->size = size; inode->dir_cnt = dir_cnt; inode->data_pointer = NULL; @@ -249,6 +276,19 @@ struct dfs_dentry *lookup_or_create_dentry(const char *path, struct dfs_dentry * return dentry; } +static void free_inode(struct dfs_inode *inode) +{ + struct dfs_data *data_block = inode->data_pointer; + while (data_block) + { + struct dfs_data *next = data_block->next; + free(data_block->data); + free(data_block); + data_block = next; + } + add_to_inode_recycle_list(inode); // 将inode添加到回收队列 +} + /*功能函数*/ static int di_unlink(const char *path) @@ -265,7 +305,7 @@ static int di_unlink(const char *path) lru_remove(dentry); unsigned int index = hash(dentry->fname); hash_table[index] = NULL; - free(dentry->inode); + free_inode(dentry->inode); // 释放inode添加到回收队列 free(dentry); return 0; } @@ -325,7 +365,7 @@ static int di_mkdir(const char *path, mode_t mode) return 0; } -static int dfs_create(const char *path, mode_t mode, struct fuse_file_info *fi) +static int di_create(const char *path, mode_t mode, struct fuse_file_info *fi) { (void)mode; (void)fi; @@ -536,7 +576,7 @@ static struct fuse_operations difs_ops = { .read = di_read, .write = di_write, .mkdir = di_mkdir, - .create = dfs_create, + .create = di_create, .utimens = di_utimens, .unlink = di_unlink, .rmdir = di_rmdir,