FDS_EVT_GC results in NRF_SUCCESS but with remaining freeable words

Hello, 

We have nRF52832 in production on a custom board. Recently, we created a new functionality with the aim to handle flash more efficiently, and to avoid the case where peer manager will not have enough space and it will erase bonds. So, every time before saving any kind of record, words_used + new record size is checked that is less than the determined limit and then saving in flash is allowed. We also call two times a day the fds_gc, as long as there is no BLE connection at the time. 

The problem is that from many clients devices we receive logs that we have set in order to track gc behaviour. This kind of log is set after FDS_EVT_GC and if this event returns NRF_SUCCESS. In this case we call fds_stat to witness the result of garbage collector, but unfortunately, it returns the same number of freeable words at every gc call. We have this log from many users for days, and we do not know why this happens, and why it doesn't delete all freeable words but still returns nrf_success? 
When I say the same number I mean same number again and again for each user, e.g. one user has 1458, another 2012, etc. 

Why does this happen?
How can we solve this problem? 

Thank you in advance.

Dimitra

  • Hi,

    DimitraN said:
    Is there a way that I have knowledge that gc has been already called from peer manager and so I do not call it again while it is running ? 

    I don't think that is possible with the peer manager. 

    DimitraN said:
    Is there a way that I have knowledge that gc has been already called from peer manager and so I do not call it again while it is running ? 
    Or perhaps this happens if GC is called while there is another active action in flash like writing/updating a record? 

    Essentially you should only call the garbage collection once the filesystem is full to minimize flash wear. 

    Another plausible reason for the GC skipping pages is if the record is already open when the garbage collection is started.

    From the documentation for freeable words:

        * The actual amount of space freed by garbage collection might be less than this value if
        * records are open while garbage collection is run.

    DimitraN said:
    Finally, could you explain me more about CRC? Why should I set it enabled or disabled? and now that it was reproduced should I enable CRC16_ENABLED again?

    It's an extra added layer to enable integrity of data to ensure that the data hasn't been corrupted. While we debug this issue, you can have it disabled. 

    regards

    Jared 

  • Hello, 

    Another plausible reason for the GC skipping pages is if the record is already open when the garbage collection is started.

    Usually the number of freeable left is a lot larger than a record, but it is close to the size of a virtual page which is 2048 words. 
    I found this at fds.h at function fds_record_close

    * Closing a record allows garbage collection to run on the virtual page in which the record is
    * stored (if no other records remain open on that page).

    I think I found what the problem was! 
    After a reset (or a power-up) I call some function to retrieve data from flash to set some variables. There we didn't close one record so the GC would not run on its page. 
    Probably this happens to clients that leave the device for a long time without charge and it eventually turns off.
    Also I had a call of GC right after updating another record, which probably make them run simultaneously or at least GC might run before finishing the update and maybe this causes the problem again. 
    I have confirmed at least twice that this error has not occured after correcting the above . 

    Thank you very much for your help! 

    Regards, 
    Dimitra 

  • Hi Nordic Team,

    I will continue on this thread because I have similar issue, but my problem is that I can not clear FDS with GC. Problem is that some users can not connect anymore to the device because it constantly returning this warning after successful pair:

    <info> app: Connected
    <info> app: Data len is set to 0xF4(244)
    <info> app: Passkey: 188154
    <info> app: BLE_GAP_EVT_LESC_DHKEY_REQUEST
    <info> nrf_ble_lesc: Calling sd_ble_gap_lesc_dhkey_reply on conn_handle: 0
    <warning> peer_manager_handler: Flash storage is full
    <info> peer_manager_handler: Attempting to clean flash.
    <info> peer_manager_handler: Connection secured: role: Peripheral, conn_handle: 0, procedure: Bonding
    <info> app: Link secured. Role: 1. conn_handle: 0, Procedure: 1
    <info> app: BLE_GAP_EVT_AUTH_STATUS: status=0x0 bond=0x1 lv4: 1 kdist_own:0x3 kdist_peer:0x2
    <warning> peer_manager_handler: Flash garbage collection failed with error Unknown error code.
    <info> peer_manager_handler: Attempting to clean flash.
    <warning> peer_manager_handler: Flash garbage collection failed with error Unknown error code.
    <info> peer_manager_handler: Attempting to clean flash.

    If i try to disconnect and connect again then I am in the loop of this warning again:

    <info> app: Disconnected
    <info> app: Connected
    <info> peer_manager_handler: Connection security failed: role: Peripheral, conn_handle: 0x0, procedure: Encryption, error: 4102
    <warning> peer_manager_handler: Disconnecting conn_handle 0.
    <info> app: Disconnected
    <info> app: Connected
    <info> peer_manager_handler: Connection security failed: role: Peripheral, conn_handle: 0x0, procedure: Encryption, error: 4102
    <warning> peer_manager_handler: Disconnecting conn_handle 0.
    <info> app: Disconnected
    <info> app: Connected
    <info> peer_manager_handler: Connection security failed: role: Peripheral, conn_handle: 0x0, procedure: Encryption, error: 4102
    <warning> peer_manager_handler: Disconnecting conn_handle 0.
    <info> app: Disconnected
    <warning> peer_manager_handler: Flash garbage collection failed with error Unknown error code.
    <info> peer_manager_handler: Attempting to clean flash.
    <warning> peer_manager_handler: Flash garbage collection failed with error Unknown error code.
    <info> peer_manager_handler: Attempting to clean flash.
    <warning> peer_manager_handler: Flash garbage collection failed with error Unknown error code.
    <info> peer_manager_handler: Attempting to clean flash.

    I tried to debug ant check the FDS statistics and got this output:

    <info> app: Flash usage statistics:
    <info> app: Pages available: 3
    <info> app: Open records: 0
    <info> app: Valid records: 0
    <info> app: Dirty records: 92
    <info> app: Words reserved: 0
    <info> app: Words used: 2048

    Do you maybe have an Idea what is happening here?

    Regards.


    Seba

Related