refactor: 文件系统Open性能优化

优化包括:
1. 提供VnodeLookupFullpath接口,如果路径是规范化的路径,则调用此接口可减少一次vfs_normalizepath接口的调用;
2. fatfs open钩子函数FIL和buffer同时malloc,减少一次malloc调用,同时去除不必要的数据写回;
3. 其他小细节的优化。

Close #I4E0CT

Signed-off-by: Far <yesiyuan2@huawei.com>
This commit is contained in:
Far 2021-10-15 11:59:38 +08:00
parent bda00e6747
commit c1c2be2a87
3 changed files with 10 additions and 11 deletions

View File

@ -606,7 +606,7 @@ int fatfs_open(struct file *filep)
FIL *fp; FIL *fp;
int ret; int ret;
fp = (FIL *)zalloc(sizeof(FIL)); fp = (FIL *)zalloc(sizeof(FIL) + SS(fs));
if (fp == NULL) { if (fp == NULL) {
ret = ENOMEM; ret = ENOMEM;
goto ERROR_EXIT; goto ERROR_EXIT;
@ -630,19 +630,13 @@ int fatfs_open(struct file *filep)
fp->err = 0; fp->err = 0;
fp->sect = 0; fp->sect = 0;
fp->fptr = 0; fp->fptr = 0;
fp->buf = (BYTE*) ff_memalloc(SS(fs)); fp->buf = (BYTE *)fp + sizeof(FIL);
if (fp->buf == NULL) {
ret = ENOMEM;
goto ERROR_UNLOCK;
}
LOS_ListAdd(&finfo->fp_list, &fp->fp_entry); LOS_ListAdd(&finfo->fp_list, &fp->fp_entry);
unlock_fs(fs, FR_OK); unlock_fs(fs, FR_OK);
filep->f_priv = fp; filep->f_priv = fp;
return fatfs_sync(vp->originMount->mountFlags, fs); return 0;
ERROR_UNLOCK:
unlock_fs(fs, FR_OK);
ERROR_FREE: ERROR_FREE:
free(fp); free(fp);
ERROR_EXIT: ERROR_EXIT:
@ -672,7 +666,6 @@ int fatfs_close(struct file *filep)
} }
#endif #endif
LOS_ListDelete(&fp->fp_entry); LOS_ListDelete(&fp->fp_entry);
ff_memfree(fp->buf);
free(fp); free(fp);
filep->f_priv = NULL; filep->f_priv = NULL;
EXIT: EXIT:

View File

@ -163,6 +163,7 @@ int VnodeDevInit(void);
int VnodeAlloc(struct VnodeOps *vop, struct Vnode **vnode); int VnodeAlloc(struct VnodeOps *vop, struct Vnode **vnode);
int VnodeFree(struct Vnode *vnode); int VnodeFree(struct Vnode *vnode);
int VnodeLookup(const char *path, struct Vnode **vnode, uint32_t flags); int VnodeLookup(const char *path, struct Vnode **vnode, uint32_t flags);
int VnodeLookupFullpath(const char *fullpath, struct Vnode **vnode, uint32_t flags);
int VnodeLookupAt(const char *path, struct Vnode **vnode, uint32_t flags, struct Vnode *orgVnode); int VnodeLookupAt(const char *path, struct Vnode **vnode, uint32_t flags, struct Vnode *orgVnode);
int VnodeHold(void); int VnodeHold(void);
int VnodeDrop(void); int VnodeDrop(void);

View File

@ -388,7 +388,7 @@ int VnodeLookupAt(const char *path, struct Vnode **result, uint32_t flags, struc
} }
} }
if (normalizedPath[0] == '/' && normalizedPath[1] == '\0') { if (normalizedPath[1] == '\0' && normalizedPath[0] == '/') {
*result = g_rootVnode; *result = g_rootVnode;
free(normalizedPath); free(normalizedPath);
return LOS_OK; return LOS_OK;
@ -447,6 +447,11 @@ int VnodeLookup(const char *path, struct Vnode **vnode, uint32_t flags)
return VnodeLookupAt(path, vnode, flags, NULL); return VnodeLookupAt(path, vnode, flags, NULL);
} }
int VnodeLookupFullpath(const char *fullpath, struct Vnode **vnode, uint32_t flags)
{
return VnodeLookupAt(fullpath, vnode, flags, g_rootVnode);
}
static void ChangeRootInternal(struct Vnode *rootOld, char *dirname) static void ChangeRootInternal(struct Vnode *rootOld, char *dirname)
{ {
int ret; int ret;