This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Why are the records getting dirty in fds example

I am trying to use the fds example provided in the sdk16, while viewing the debugging prints I see the following,

<info> app: Initializing fds...
<info> app: Event: FDS_EVT_INIT received (NRF_SUCCESS)
<info> app: Found 1 valid records.
<info> app: Found 41 dirty records (ready to be garbage collected).

Every time I restart the boot count is rightfully incremented and saved back on the flash also displayed in the debugging log. Why are the records getting dirty (and I need to run garbage collector).

Thank you

Parents
  • Hi,

    The purpose of creating a new record and then invalidating the old one is not solely to prevent data loss due to power loss, this is also a more effective way to store data in flash. Flash can only be erased a whole page at a time, meaning that deleting a record and writing a new one back to the same location would require the entire flash page to be erased in between. Erasing a flash page takes a long time, and the flash has a limited number of write/erase cycles (endurance) before it starts to fail. Spreading the writes out over the entire page will provide basic flash wear leveling, increase the lifetime of the flash.

    The maximum data you can store before running garbage collection depends on the number of reserved pages for FDS (FDS_VIRTUAL_PAGES). Note that one of the pages (SWAP page) will be reserved for garbage collection. During garbage collection, valid records are copied to the SWAP page before the DATA page is erased. The old SWAP page is then promoted to a DATA page, while the old DATA page will become the new SWAP page.

    You can call fds_stat() to get statistics about the available flash size. It is not recommended to run garbage collection too often, as this will increase the wear on flash. We recommend calling it only when FDS has filled all available space, or when it is getting close to full.

    Best regards,
    Jørgen

  •   Thank you very much for the details.

    You can call fds_stat() to get statistics about the available flash size

    Running stats yields,

    ================================================
            FLASH STATS (FDS)
    ================================================
    3 pages Available.
    0 open records.
    1 valid records.
    51 dirty records (ready to be garbage collected).
    0 words reserved by fds_reserve().
    472 words written to flash.
    1022 largest number of free contiguous words in the file system.
    459 words that can be reclaimed by garbage.
    0 corrupted records

    From flash_bounds_set() I see flash size as 0x3000,

    flash_size  = (FDS_PHY_PAGES * FDS_PHY_PAGE_SIZE * sizeof(uint32_t))

    = 3 x 1024 x 4 

    = 12kB

    FDS_VIRTUAL_PAGES is 3, where FDS_VIRTUAL_PAGE_SIZE is 1024. As you mentioned one of the page will be used as SWAP page. So we have two pages out of three and by one page we mean we have 1024 WORDS i.e. 4096 bytes. Is this Correct?

    From the stats we see 472 words written to flash. Which leaves us with 2048 - 427 words?

Reply
  •   Thank you very much for the details.

    You can call fds_stat() to get statistics about the available flash size

    Running stats yields,

    ================================================
            FLASH STATS (FDS)
    ================================================
    3 pages Available.
    0 open records.
    1 valid records.
    51 dirty records (ready to be garbage collected).
    0 words reserved by fds_reserve().
    472 words written to flash.
    1022 largest number of free contiguous words in the file system.
    459 words that can be reclaimed by garbage.
    0 corrupted records

    From flash_bounds_set() I see flash size as 0x3000,

    flash_size  = (FDS_PHY_PAGES * FDS_PHY_PAGE_SIZE * sizeof(uint32_t))

    = 3 x 1024 x 4 

    = 12kB

    FDS_VIRTUAL_PAGES is 3, where FDS_VIRTUAL_PAGE_SIZE is 1024. As you mentioned one of the page will be used as SWAP page. So we have two pages out of three and by one page we mean we have 1024 WORDS i.e. 4096 bytes. Is this Correct?

    From the stats we see 472 words written to flash. Which leaves us with 2048 - 427 words?

Children
No Data
Related