ucfs文件系统效率提升探索

ucfs文件系统:各函数操作流程:

新建文件流程(4K内容)
函数实际作用flash耗时作用目的
fsopen读目录表(第一次)0.7ms判断文件是否已打开
读目录表(第二次)0.7ms判断文件是否存在
写目录表4+49+15ms写文件名创建时间
fswrite读sec1(fat表)0.7ms读fat表(查找空闲簇)
写sec1(fat表)4+49+15ms写fat表(写首簇)
写数据(大于sec41)4+49+15写数据
读目录表(第三次)0.7ms读目录表
写目录表4+49+15更新文件属性(大小,修改时间)
fsclose创建一个内容为4KB以内的文件所需要的时间综合243~270ms 太慢了!

1.fsopen中第一次读目录表可以省去,判断目录是否已打开可以通过已打开文件结构体判断,这里应该是为了更加安全先检测目录是否存在了。

2.fswrite中当一次写入数据量大于一簇时,那么在读取fat表计算空闲簇  并写入fat表后  写数据的语句会循环执行直到数据全部写入,最后写目录表更新文件大小和时间;而多次调用fswrite写入数据就会多次读写fat表和目录表,产生较多的擦写次数造成读写效率下降,因此应用层调用写文件时尽量一次写入尽可能多的数据避免多次调用fswrite函数。

3.根据嵌入式设备实际情况写文件的数据量大都是小数据,不会超过1K字节,因此fswrite效率并不高,为了提高写文件效率可以创建缓冲机制(耗费内存):将fat表和目录表读到内存,每次修改不写入flash, 单位时间内的多次写同一文件(不超过一簇)的也缓冲到内存,直到单位时间耗尽或者缓冲区满 或者fsclose被调用才写入flash,代码修改比较复杂,其最终结果待实际检验。

实验结果:

1.实验得出写大数据(4K整数倍),文件系统效率提高微小,缓冲区每次都被填满,所以必须写入磁盘,因此写大数据时缓冲机制只在读写fat表和目录表时发挥作用,读写数据时不起作用。

2.多次写入少量数据(小于一扇区数据量),文件系统效率提升随fswrite的调用次数逐步提升,因为少量数据先写进缓冲区,等缓冲满才写入磁盘,因此多次写小数据是缓冲机制的作用就会越来越大。

3.注意:文件系统的簇必须和存储设备的读写块(或整数倍)一至,且数据区的起始扇区必须是存储设备的某一bloc的起始地址。

µC/FS µC/FS is a compact, reliable, high-performance file system. It offers full-featured file and directory access with flexible device and volume management including support for partitions. Source Code: µC/FS is provided in ANSI-C source to licensees. The source code is written to an exacting coding standard that emphasizes cleanness and readability. Moreover, extensive comments pepper the code to elucidate its logic and describe global variables and functions. Where appropriate, the code directly references standards and supporting documents. Device Drivers: Device drivers are available for most common media including SD/MMC cards, NAND flash, NOR flash. Each of these is written with a clear, layered structure so that it can easily be ported to your hardware. The device driver structure is simple—basically just initialization, read and write functions—so that µC/FS can easily be ported to a new medium. Devices and Volumes: Multiple media can be accessed simultaneously, including multiple instances of the same type of medium (since all drivers are re-entrant). DOS partitions are supported, so more than one volume can be located on a device. In addition, the logical device driver allows a single volume to span several (typically identical) devices, such as a bank of flash chips. FAT: All standard FAT variants and features are supported including FAT12/FAT16/FAT32 and long file names, which encompasses Unicode file names. Files can be up to 4-GB and volumes up to 8-TB (the standard maximum). An optional journaling module provides total power fail-safety to the FAT system driver. Application Programming Interface (API): µC/FS provides two APIs for file and directory access. A proprietary API with parallel argument placement and meaningful return error codes is provided, with functions like FSFile_Wr(), FSFile_Rd() and FSFile_PosSet(). Alternatively, a standard POSIX-like API is provided, including functions like fs_fwrite(), fs_fread() and fs_fsetpos
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值