news 2026/8/29 3:32:18

FlashDB / Easyflash触发GC导致系统卡死的解决方法分享

作者头像

张小明

前端开发工程师

1.2k 24
文章封面图
FlashDB / Easyflash触发GC导致系统卡死的解决方法分享

FlashDB / Easyflash触发GC导致系统卡死的解决方法分享

遇到的问题:启动后单片机打印这样的log

Bootthismcu....[SFUD]Find a Winbond W25Q32BV flash chip.Size is4194304bytes.[SFUD]norflash0 flash device is initialize success.flashDB_myDataSet_construct.OK[D/FAL](fal_flash_init:49)Flash device|norflash0|addr:0x00000000|len:0x00400000|blk_size:0x00001000|initialized finish.[I/FAL]====================FAL partition table====================[I/FAL]|name|flash_dev|offset|length|[I/FAL]-------------------------------------------------------------[I/FAL]|fdb_kvdb1|norflash0|0x00000000|0x00002000|[I/FAL]|fdb_tsdb0|norflash0|0x00002000|0x00040000|[I/FAL]|fdb_tsdb1|norflash0|0x00042000|0x00040000|[I/FAL]=============================================================[I/FAL]Flash AbstractionLayer(V0.5.99)initialize success.[FlashDB][kv][env][fdb_kvdb1](../Core/FlashDB-master/src/fdb_kvdb.c:1801)The oldest addr is @0x00000000[FlashDB][kv][env][fdb_kvdb1](../Core/FlashDB-master/src/fdb_kvdb.c:1817)KVDB size is8192bytes.[FlashDB][kv][env][fdb_kvdb1](../Core/FlashDB-master/src/fdb_kvdb.c:1161)**The remain empty sector is0,GC threshold is1.**[FlashDB][kv][env][fdb_kvdb1](../Core/FlashDB-master/src/fdb_kvdb.c:1130)KV(sch)is garbage NOT need move,collect it.[FlashDB][kv][env][fdb_kvdb1](../Core/FlashDB-master/src/fdb_kvdb.c:1130)KV(chipID_crc32)is garbage NOT need move,collect it.[FlashDB][kv][env][fdb_kvdb1](../Core/FlashDB-master/src/fdb_kvdb.c:1130)KV(user_brightness)is garbage NOT need move,collect it.[FlashDB][kv][env][fdb_kvdb1](../Core/FlashDB-master/src/fdb_kvdb.c:1130)KV(bootCount)is garbage NOT need move,collect it.[FlashDB][kv][env][fdb_kvdb1](../Core/FlashDB-master/src/fdb_kvdb.c:1130)KV(mode_auto)is garbage NOT need move,collect it.[FlashDB][kv][env][fdb_kvdb1](../Core/FlashDB-master/src/fdb_kvdb.c:1130)KV(bootCount)is garbage NOT need move,collect it.[FlashDB][kv][env][fdb_kvdb1](../Core/FlashDB-master/src/fdb_kvdb.c:1130)KV(bootCount)is garbage NOT need move,collect it.[FlashDB][kv][env][fdb_kvdb1](../Core/FlashDB-master/src/fdb_kvdb.c:1130)KV(bootCount)is garbage NOT need move,collect it.[FlashDB][kv][env][fdb_kvdb1](../Core/FlashDB-master/src/fdb_kvdb.c:1130)KV(bootCount)is garbage NOT need move,collect it.[FlashDB][kv][env][fdb_kvdb1](../Core/FlashDB-master/src/fdb_kvdb.c:1130)KV(mode_auto)is garbage NOT need move,collect it.[FlashDB][kv][env][fdb_kvdb1](../Core/FlashDB-master/src/fdb_kvdb.c:1130)KV(mode_auto)is garbage NOT need move,collect it.[FlashDB][kv][env][fdb_kvdb1](../Core/FlashDB-master/src/fdb_kvdb.c:1130)KV(mode_auto)is garbage NOT need move,collect it.[FlashDB][kv][env][fdb_kvdb1](../Core/FlashDB-master/src/fdb_kvdb.c:1130)KV(bootCount)is garbage NOT need move,collect it.[FlashDB][kv][env][fdb_kvdb1](../Core/FlashDB-master/src/fdb_kvdb.c:1130)KV(bootCount)is garbage NOT need move,collect it.[FlashDB][kv][env][fdb_kvdb1](../Core/FlashDB-master/src/fdb_kvdb.c:1130)KV(mode_auto)is garbage NOT need move,collect it.[FlashDB][kv][env][fdb_kvdb1](../Core/FlashDB-master/src/fdb_kvdb.c:1130)KV(bootCount)is garbage NOT need move,collect it.[FlashDB][kv][env][fdb_kvdb1](../Core/FlashDB-master/src/fdb_kvdb.c:1130)KV(bootCount)is garbage NOT need move,collect it.[FlashDB][kv][env][fdb_kvdb1](../Core/FlashDB-master/src/fdb_kvdb.c:1130)KV(mode_auto)is garbage NOT need move,collect it.[FlashDB][kv][env][fdb_kvdb1](../Core/FlashDB-master/src/fdb_kvdb.c:1130)KV(bootCount)is garbage NOT need move,collect it.[FlashDB][kv][env][fdb_kvdb1](../Core/FlashDB-master/src/fdb_kvdb.c:1130)KV(bootCount)is garbage NOT need move,collect it.[FlashDB][kv][env][fdb_kvdb1](../Core/FlashDB-master/src/fdb_kvdb.c:1130)KV(mode_auto)is garbage NOT need move,collect it.[FlashDB][kv][env][fdb_kvdb1](../Core/FlashDB-master/src/fdb_kvdb.c:1130)KV(mode_auto)is garbage NOT need move,collect it.[FlashDB][kv][env][fdb_kvdb1](../Core/FlashDB-master/src/fdb_kvdb.c:1130)KV(bootCount)is garbage NOT need move,collect it.[FlashDB][kv][env][fdb_kvdb1](../Core/FlashDB-master/src/fdb_kvdb.c:1130)KV(mode_auto)is garbage NOT need move,collect it.[FlashDB][kv][env][fdb_kvdb1](../Core/FlashDB-master/src/fdb_kvdb.c:1130)KV(mode_auto)is garbage NOT need move,collect it.[FlashDB][kv][env][fdb_kvdb1](../Core/FlashDB-master/src/fdb_kvdb.c:1130)KV(mode_auto)is garbage NOT need move,collect it.[FlashDB][kv][env][fdb_kvdb1](../Core/FlashDB-master/src/fdb_kvdb.c:1130)KV(mode_auto)is garbage NOT need move,collect it.[FlashDB][kv][env][fdb_kvdb1](../Core/FlashDB-master/src/fdb_kvdb.c:1130)KV(mode_auto)is garbage NOT need move,collect it.[FlashDB][kv][env][fdb_kvdb1](../Core/FlashDB-master/src/fdb_kvdb.c:1130)KV(mode_auto)is garbage NOT need move,collect it.[FlashDB][kv][env][fdb_kvdb1](../Core/FlashDB-master/src/fdb_kvdb.c:1130)KV(mode_auto)is garbage NOT need move,collect it.[FlashDB][kv][env][fdb_kvdb1](../Core/FlashDB-master/src/fdb_kvdb.c:1130)KV(mode_auto)is garbage NOT need move,collect it.[FlashDB][kv][env][fdb_kvdb1](../Core/FlashDB-master/src/fdb_kvdb.c:1130)KV(mode_auto)is garbage NOT need move,collect it.[FlashDB][kv][env][fdb_kvdb1](../Core/FlashDB-master/src/fdb_kvdb.c:1130)KV(mode_auto)is garbage NOT need move,collect it.[FlashDB][kv][env][fdb_kvdb1](../Core/FlashDB-master/src/fdb_kvdb.c:1130)KV(mode_auto)is garbage NOT need move,collect it.[FlashDB][kv][env][fdb_kvdb1](../Core/FlashDB-master/src/fdb_kvdb.c:1130)KV(mode_auto)is garbage NOT need move,collect it.[FlashDB][kv][env][fdb_kvdb1](../Core/FlashDB-master/src/fdb_kvdb.c:1130)KV(mode_auto)is garbage NOT need move,collect it.[FlashDB][kv][env][fdb_kvdb1](../Core/FlashDB-master/src/fdb_kvdb.c:1130)KV(mode_auto)is garbage NOT need move,collect it.[FlashDB][kv][env][fdb_kvdb1](../Core/FlashDB-master/src/fdb_kvdb.c:1130)KV(mode_auto)is garbage NOT need move,collect it.[FlashDB][kv][env][fdb_kvdb1](../Core/FlashDB-master/src/fdb_kvdb.c:1130)KV(mode_auto)is garbage NOT need move,collect it.[FlashDB][kv][env][fdb_kvdb1](../Core/FlashDB-master/src/fdb_kvdb.c:1130)KV(mode_auto)is garbage NOT need move,collect it.[FlashDB][kv][env][fdb_kvdb1](../Core/FlashDB-master/src/fdb_kvdb.c:1130)KV(mode_auto)is garbage NOT need move,collect it.[FlashDB][kv][env][fdb_kvdb1](../Core/FlashDB-master/src/fdb_kvdb.c:1130)KV(mode_auto)is garbage NOT need move,collect it.[FlashDB][kv][env][fdb_kvdb1](../Core/FlashDB-master/src/fdb_kvdb.c:1130)KV(mode_auto)is garbage NOT need move,collect it.[FlashDB][kv][env][fdb_kvdb1](../Core/FlashDB-master/src/fdb_kvdb.c:1130)KV(mode_auto)is garbage NOT need move,collect it.[FlashDB][kv][env][fdb_kvdb1](../Core/FlashDB-master/src/fdb_kvdb.c:1130)KV(mode_auto)is garbage NOT need move,collect it.[FlashDB][kv][env][fdb_kvdb1](../Core/FlashDB-master/src/fdb_kvdb.c:1130)KV(mode_auto)is garbage NOT need move,collect it.[FlashDB][kv][env][fdb_kvdb1](../Core/FlashDB-master/src/fdb_kvdb.c:1130)KV(mode_auto)is garbage NOT

把KVDB分区从2个sector更改为4个sector后,问题暂时可以解决,但是不知道是否会再次发生
别人的解决方法:

芯片:SMT32F429
操作系统:RTT 5.0.0
文件系统:littlefs + romfs
flashdb:kvdb + 文件模式 使用
使用场景
分配5个扇区情况
创建一个线程,1秒写入一次当前时间戳至kvdb数据库中
发现如果分配五个扇区,前四个扇区都可以正常读写。
当五个扇区都写满的时候,需要搬运数据到第0扇区去。
日志如下,没有空扇区了。
The remain empty sector is 1, GC threshold is 1.
这个日志已出现,系统就会卡死,看门狗复位
尝试debug调试,总是调到没有使用的函数里面,函数地址
0x00000xx开头。
解决方法
经过不断尝试,ps打印当前线程状态时,发现时间戳保存线程的最大使用率高达81%.一般来说都要控制在75%左右合适。
分析是不是应该堆栈不够导致系统卡死
将该线程从2048改为4096后,不会出现卡死问题了。线程的最大使用率变为51%

分析
flshdb在扇区都满的情况下,会进行Collect操作。这个操作是在当前线程完成的,会增加占用率。
然而这个运行操作并不是会频繁出现的,所以很难判断到是堆栈不够导致的问题。
建议
能否增加一个异步模式来专门执行gc与Collect操作?
就像ulog的异步线程的方式那样。
写入数据库并不要求实时性,只需要确保数据的准确就好了。
异步方式需要一个缓冲区,缓冲区满了才能传入数据,可能导致缓冲区未满时掉电,导致数据缺失了一部分。
但是这个情况,可以添加一个函数,立刻刷新缓冲区。然后给用户使用。 用户自己实现掉电保存与硬件。
所以可以增加一个异步线程的选项,提供用户使用。看用户是选择实时,还是效率。
原作者:用户名由3_15位

版权声明: 本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若内容造成侵权/违法违规/事实不符,请联系邮箱:809451989@qq.com进行投诉反馈,一经查实,立即删除!
网站建设 2026/8/28 23:10:46

如何用Python快速调用EmotiVoice生成情感语音?

如何用Python快速调用EmotiVoice生成情感语音? 在虚拟助手越来越“懂人心”、游戏NPC开始“真情流露”的今天,传统的文本转语音(TTS)技术早已显得力不从心。那些机械重复、语调平直的合成音,已经无法满足用户对沉浸感和…

作者头像 李华
网站建设 2026/8/26 22:35:54

系统 “清洁 + 体检” 神器!这款卸载工具,强制卸毒瘤

宝子们!谁懂啊~ 公司之前那款监控软件简直是毒瘤本瘤!卸载起来超级费劲,还好同事给我安利了IObit Uninstaller,直接帮我解决了大难题~这款 IObit Uninstaller 的功能真的绝了~ 不仅能强制卸载毒…

作者头像 李华
网站建设 2026/8/27 8:05:01

阅读APP书源配置完整使用指南

阅读APP书源配置完整使用指南 【免费下载链接】Yuedu 📚「阅读」APP 精品书源(网络小说) 项目地址: https://gitcode.com/gh_mirrors/yu/Yuedu 阅读APP作为一款优秀的阅读应用,其核心功能在于通过书源配置为用户提供海量小…

作者头像 李华
网站建设 2026/8/27 17:49:45

GSE宏编译器:解决魔兽世界玩家技能循环难题的终极方案

GSE宏编译器:解决魔兽世界玩家技能循环难题的终极方案 【免费下载链接】GSE-Advanced-Macro-Compiler GSE is an alternative advanced macro editor and engine for World of Warcraft. It uses Travis for UnitTests, Coveralls to report on test coverage and t…

作者头像 李华
网站建设 2026/8/27 1:34:49

UG\NX二次开发 使用ufun获取nx主窗口,并显示标题

文章作者:里海 来源网站:里海NX二次开发3000例专栏 感谢粉丝订阅 感谢 ​ck666667 订阅本专栏。本专栏永久畅读,内容持续更新,知识源源不断,价格也逐渐提升,但已订粉丝不受影响。让我们一起充满激情地进步,不断超越自己。 《里海NX二次开发3000例专栏》是NX二次…

作者头像 李华
网站建设 2026/8/27 15:31:08

17、Linux 网络与内核管理全解析

Linux 网络与内核管理全解析 1. 无线设备与黑客技术 无线设备是未来连接与黑客技术的发展方向。Linux 系统开发了专门的命令用于扫描和连接 Wi - Fi 接入点(AP),这是对这些系统进行黑客攻击的第一步。 无线黑客工具套件 aircrack - ng 套件 :包含 airmon - ng 和 airo…

作者头像 李华