优化UBIFS分区磨损均衡的文件尺寸选型咨询
UBIFS重复写入导致Flash磨损不均问题
我需要向一个256 MB的UBIFS分区重复写入8字节的uint64_t计数器数据,担心重复写入会造成Flash磨损不均。查看该分区的ubinfo -a输出,得知最小I/O单元大小为2048字节。因此首次尝试创建一个2048字节的文件进行循环写入——每次写入8字节,写满256次后回到起始位置往复循环。
我编写了测试程序验证,两周后发现:在约18亿次写入后,Current maximum erase counter value(即max_ec计数器)升至约20000,远高于所有擦除块完美均匀磨损的预期值。接下来我计划尝试创建接近逻辑擦除块(Logical Erase Block)大小(124KB)的文件,看是否能改善磨损不均的情况。
目前我有三个方案:
- 尝试不同文件尺寸的对比测试
- 阅读UBIFS驱动代码
- 启用调试选项重建内核,获取更多UBIFS调试日志
是否有更优的解决方案?
测试用C程序
#include<stdio.h> #include<fcntl.h> #include<stdlib.h> #include<unistd.h> #include<sys/stat.h> int main(int argc, char *argv[]){ int fd; char *ptr; uint64_t writeops, filesize, index=0, i; if (argc!=3){ printf("Usage: %s filesize(uint64_t) writeops(uint64_t)\n"); return 1; } // Sanitise args filesize = strtoul(argv[1], &ptr, 10); writeops = strtoul(argv[2], &ptr, 10); if (filesize%8 !=0){ printf("Filesize must be a multiple of 8\n"); return 2; } // Open a file to write fd = open("/mnt/user/magicnumber", O_CREAT|O_RDWR|O_DSYNC|O_LARGEFILE, S_IRUSR|S_IWUSR); // Get file size to be as big as the filesize arg lseek(fd, filesize-1, SEEK_SET); write(fd, '\0', 1); // Begin actual testing for(i=1,index=0; i<=writeops; i++,index+=8){ if (index == filesize){ index = 0; } lseek(fd, index, SEEK_SET); write(fd, (char *)&i, sizeof(i)); } close(fd); return 0; }
内容的提问来源于stack exchange,提问作者Lokesh
相关产品推荐
相关产品推荐

