Skip to content

Intelligent garbage collection control (GC)

Latest

Choose a tag to compare

@idyll5988 idyll5988 released this 18 Jun 06:55
· 1 commit to main since this release
b95a045

核心功能模块

  1. ​智能垃圾回收控制 (smart_gc_control)​​
    ​脏段阈值检测​:监控 F2FS 的 dirty_segments 值
    ≥ 150,000:启用激进模式​(GC 强度翻倍)
    ≥ 50,000:启用增强模式​(中级 GC 强度)
    ≥ 200:触发标准 GC

​动态调整策略​:
亮屏状态:
系统负载 ≤ 25:高效 GC(级别 2)
系统负载 > 25:低功耗 GC(级别 1)

灭屏状态:后台 GC(gc_idle=1)

​停止 GC 条件​:
脏段 < 200(安全阈值)
总清理量 ≥ 1500 段(或激进模式 3000 段)
超时 10 分钟
90 秒无进展或连续 10 次检测无变化

  1. ​系统状态感知​
    ​电池状态检测​:
    放电状态:延长检测间隔至 10 分钟
    充电/满电状态:5 分钟检测间隔

​屏幕状态检测​:
亮屏时优先性能
灭屏时启用后台 GC 节省功耗

​系统负载监控​:
负载 ≤ 15 时提升 GC 级别
负载 > 25 时降级 GC

  1. ​分区监控 (monitor_data_partition)​​
    专一监控 /data 分区
    关键指标:
    bashbash复制bash复制空闲段: cat /sys/fs/f2fs/[device]/free_segments
    脏段: cat /sys/fs/f2fs/[device]/dirty_segments

触发 GC 的条件:
脏段 ≥ 80,000:强制 GC
脏段 ≥ 200:标准 GC

  1. ​资源优化机制​
    ​日志管理​:
    自动轮转超过 1MB 的日志
    保留最近 100 条记录

Core functional modules

  1. ​Smart garbage collection control (smart_gc_control)​​
    ​Dirty segment threshold detection: monitor the dirty_segments value of F2FS
    ≥ 150,000: enable aggressive mode (GC intensity doubled)
    ≥ 50,000: enable enhanced mode (medium GC intensity)
    ≥ 200: trigger standard GC

​Dynamic adjustment strategy:
Screen on state:
System load ≤ 25: efficient GC (level 2)
System load > 25: low power GC (level 1)

Screen off state: background GC (gc_idle=1)

​Stop GC conditions:
Dirty segments < 200 (safety threshold)
Total cleanup ≥ 1500 segments (or 3000 segments in aggressive mode)
Timeout 10 minutes
No progress for 90 seconds or no change for 10 consecutive tests

  1. ​System status perception​
    ​Battery status detection​:
    Discharge status: Extend the detection interval to 10 minutes
    Charge/full charge status: 5 minutes detection interval

​Screen status detection​:
Prioritize performance when the screen is on
Enable background GC to save power when the screen is off

​System load monitoring​:
Increase GC level when load ≤ 15
Degrade GC when load > 25

  1. ​Partition monitoring (monitor_data_partition)​​
    Monitor the /data partition exclusively
    Key indicators:
    bashbash copybash copy free segment: cat /sys/fs/f2fs/[device]/free_segments
    Dirty segment: cat /sys/fs/f2fs/[device]/dirty_segments

Conditions for triggering GC:
Dirty segment ≥ 80,000: forced GC
Dirty segment ≥ 200: standard GC

  1. ​Resource optimization mechanism​
    ​Log management​:
    Automatically rotate more than 1MB Keep the latest 100 records

5E542A646B78A68587E48F5859248F75