• Jin Xu's avatar
    f2fs: optimize gc for better performance · a26b7c8a
    Jin Xu authored
    This patch improves the gc efficiency by optimizing the victim
    selection policy. With this optimization, the random re-write
    performance could increase up to 20%.
    
    For f2fs, when disk is in shortage of free spaces, gc will selects
    dirty segments and moves valid blocks around for making more space
    available. The gc cost of a segment is determined by the valid blocks
    in the segment. The less the valid blocks, the higher the efficiency.
    The ideal victim segment is the one that has the most garbage blocks.
    
    Currently, it searches up to 20 dirty segments for a victim segment.
    The selected victim is not likely the best victim for gc when there
    are much more dirty segments. Why not searching more dirty segments
    for a better victim? The cost of searching dirty segments is
    negligible in comparison to moving blocks.
    
    In this patch, it enlarges the MAX_VICTIM_SEARCH to 4096 to make
    the search more aggressively for a possible better victim. Since
    it also applies to victim selection for SSR, it will likely improve
    the SSR efficiency as well.
    
    The test case is simple. It creates as many files until the disk full.
    The size for each file is 32KB. Then it writes as many as 100000
    records of 4KB size to random offsets of random files in sync mode.
    The testing was done on a 2GB partition of a SDHC card. Let's see the
    test result of f2fs without and with the patch.
    
    ---------------------------------------
    2GB partition, SDHC
    create 52023 files of size 32768 bytes
    random re-write 100000 records of 4KB
    ---------------------------------------
    | file creation (s) | rewrite time (s) | gc count | gc garbage blocks |
    [no patch]  341         4227             1174          174840
    [patched]   324         2958             645           106682
    
    It's obvious that, with the patch, f2fs finishes the test in 20+% less
    time than without the patch. And internally it does much less gc with
    higher efficiency than before.
    
    Since the performance improvement is related to gc, it might not be so
    obvious for other tests that do not trigger gc as often as this one (
    This is because f2fs selects dirty segments for SSR use most of the
    time when free space is in shortage). The well-known iozone test tool
    was not used for benchmarking the patch becuase it seems do not have
    a test case that performs random re-write on a full disk.
    
    This patch is the revised version based on the suggestion from
    Jaegeuk Kim.
    Signed-off-by: default avatarJin Xu <jinuxstyle@gmail.com>
    [Jaegeuk Kim: suggested simpler solution]
    Reviewed-by: default avatarJaegeuk Kim <jaegeuk.kim@samsung.com>
    Signed-off-by: default avatarJaegeuk Kim <jaegeuk.kim@samsung.com>
    a26b7c8a
segment.h 19.2 KB