<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="https://devzone.nordicsemi.com/cfs-file/__key/system/syndication/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>FDS garbage collection</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/79667/fds-garbage-collection</link><description>Hello, 
 
 we encounter strange behavior with the garbage collection function (fds_gc()). When calling it in different conditions, the device freezes. We use the following settings for fds: 
 
 First condition that leads to freeze: 
 Calling the garbage</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Mon, 04 Dec 2023 17:06:04 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/79667/fds-garbage-collection" /><item><title>RE: FDS garbage collection</title><link>https://devzone.nordicsemi.com/thread/458807?ContentTypeID=1</link><pubDate>Mon, 04 Dec 2023 17:06:04 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:865debe2-5441-4329-af64-8ed4af73e1e3</guid><dc:creator>vincent_chan</dc:creator><description>&lt;p&gt;Hi, I think I am experiencing the exact issue. Do you find a solution for this issue?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: FDS garbage collection</title><link>https://devzone.nordicsemi.com/thread/330068?ContentTypeID=1</link><pubDate>Fri, 17 Sep 2021 13:37:47 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:87809a18-41d0-4aa6-9325-296ea83e964d</guid><dc:creator>Einar Thorsrud</dc:creator><description>&lt;p&gt;Yes, in that case interrupt priorities should not be a problem.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: FDS garbage collection</title><link>https://devzone.nordicsemi.com/thread/330036?ContentTypeID=1</link><pubDate>Fri, 17 Sep 2021 12:27:57 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:b3fe6329-71c8-4de9-8d63-88ff4c722faa</guid><dc:creator>emb_dev</dc:creator><description>&lt;div&gt;We have the default priorities for SD and priority 6 for our irq handlers, so the requirements are met, right?&lt;/div&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: FDS garbage collection</title><link>https://devzone.nordicsemi.com/thread/330018?ContentTypeID=1</link><pubDate>Fri, 17 Sep 2021 11:51:01 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:adb525ea-3f78-4699-92ad-1e0b86b5df37</guid><dc:creator>Einar Thorsrud</dc:creator><description>&lt;p&gt;That depends on the priority of the interrupt where you make the FDS calls. See &lt;a href="https://devzone.nordicsemi.com/f/nordic-q-a/57067/calling-fds_record_update-in-isr/231362#231362"&gt;this post&lt;/a&gt;.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: FDS garbage collection</title><link>https://devzone.nordicsemi.com/thread/329902?ContentTypeID=1</link><pubDate>Thu, 16 Sep 2021 21:46:53 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:02cf7edd-a9f7-4e56-9a0d-57c262d965a3</guid><dc:creator>emb_dev</dc:creator><description>&lt;p&gt;Hi, Einar! Thanks for the answers.&lt;/p&gt;
&lt;p&gt;Yes, if deferred logging is disabled, we can see that &lt;span&gt;queue_process() is called&lt;/span&gt;. The stack above is from the paused state after the &amp;quot;freeze&amp;quot;.&lt;/p&gt;
&lt;p&gt;We discovered that fds_gc() causes looping via event reentry in queue_process() (fds.c:1486, nRF5_SDK_17.0.2) if the number of freeable words is less than certain amount (~500). After that loop we got corrupted program flash.&lt;/p&gt;
&lt;p&gt;Moving fds_gc call to the main loop helped. We do have some flash writes in irq handlers, but all of them have priorities &amp;gt; 4. So maybe&amp;nbsp;not all the events allow to call fds_gs()? Now we can call it during FDS_EVT_WRITE,&amp;nbsp;FDS_EVT_DEL_RECORD,&amp;nbsp;FDS_EVT_DEL_FILE and&amp;nbsp;FDS_EVT_GC events.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: FDS garbage collection</title><link>https://devzone.nordicsemi.com/thread/329777?ContentTypeID=1</link><pubDate>Thu, 16 Sep 2021 09:48:17 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:f275bac9-59fe-4683-b015-7db9275883e6</guid><dc:creator>Einar Thorsrud</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
[quote user="emb_dev"]We are running fds_gc() exclusively form fds event handler. Only one event handler is registered by&amp;nbsp;fds_register. Can it be the RC of the issue? Should we move the call to the main loop?[/quote]
&lt;p&gt;No, that should be OK.&lt;/p&gt;
[quote user="emb_dev"]NRF_LOG_ERROR in queue_start never logs anything, so we suggest that&amp;nbsp;&lt;span&gt;queue_process is not launched. Fault handlers are also not called.&lt;/span&gt;[/quote]
&lt;p&gt;To get logs that are queued before the error, but not processed in the main loop you could disable deferred logging. That way logs will be processed and output immediately.&lt;/p&gt;
&lt;p&gt;What can you find by debugging if you pause and check the stack pointer (when testing without optimization). Where is it?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: FDS garbage collection</title><link>https://devzone.nordicsemi.com/thread/329655?ContentTypeID=1</link><pubDate>Wed, 15 Sep 2021 14:38:46 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:f72712ce-7479-42a5-9919-b9909d0df71c</guid><dc:creator>emb_dev</dc:creator><description>&lt;p&gt;We are running fds_gc() exclusively form fds event handler. Only one event handler is registered by&amp;nbsp;fds_register. Can it be the RC of the issue? Should we move the call to the main loop?&lt;/p&gt;
&lt;p&gt;NRF_LOG_ERROR in queue_start never logs anything, so we suggest that&amp;nbsp;&lt;span&gt;queue_process is not launched. Fault handlers are also not called.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Update: stack looks good, no corruption. Seems like fds_gc()&amp;nbsp;triggers some looping :&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;pre class="ui-code" data-mode="text"&gt;page_identify fds.c:222
page_identify fds.c:214
fds_stat fds.c:2172
flash_inspect flash_utils.c:180  &amp;lt;== our handler calling fds_gc, fds_stat
event_send fds.c:109
queue_process fds.c:1487
event_send nrf_fstorage_sd.c:193
nrf_fstorage_sys_evt_handler nrf_fstorage_sd.c:559
nrf_sdh_soc_evts_poll nrf_sdh_soc.c:101
nrf_sdh_evts_poll nrf_sdh.c:358
&amp;lt;signal handler called&amp;gt; 0x00000000ffffffe9
serial_tx nrf_log_backend_uart.c:144
nrf_fprintf_buffer_flush nrf_fprintf.c:56
postfix_process nrf_log_str_formatter.c:150
nrf_log_std_entry_process nrf_log_str_formatter.c:192
...&lt;/pre&gt;&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: FDS garbage collection</title><link>https://devzone.nordicsemi.com/thread/329627?ContentTypeID=1</link><pubDate>Wed, 15 Sep 2021 13:01:00 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:9a17f095-20c5-407f-ba8e-9723c0cb54ba</guid><dc:creator>Einar Thorsrud</dc:creator><description>&lt;p&gt;I see. If you make a debug build and pause execution, what does the call stack look like then? Have you followed the operation further than&amp;nbsp;queue_start()? Does it enter&amp;nbsp;queue_process()? What then? You need to trace this down to where something actually happens (if it looks like a &amp;quot;freeze&amp;quot;, perhaps a busy wait, or perhaps some issue with interrupt priorities causes an event to never happen.&lt;/p&gt;
&lt;p&gt;Do you by any chance make the FDS API calls from a high interrupt priority?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: FDS garbage collection</title><link>https://devzone.nordicsemi.com/thread/329625?ContentTypeID=1</link><pubDate>Wed, 15 Sep 2021 12:53:04 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:45637493-c652-442a-adb1-7a7914214726</guid><dc:creator>emb_dev</dc:creator><description>&lt;p&gt;Hi,&amp;nbsp;&lt;/p&gt;
&lt;p&gt;the device calls fds_gc() and there we added some logs for debugging:&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;ret_code_t fds_gc(void)
{
    fds_op_t * p_op;
    nrf_atfifo_item_put_t iput_ctx;
    NRF_LOG_ERROR(&amp;quot;GC 0&amp;quot;)
    if (!m_flags.initialized)
    {
        return FDS_ERR_NOT_INITIALIZED;
    }
    NRF_LOG_ERROR(&amp;quot;GC 1&amp;quot;)
    p_op = queue_buf_get(&amp;amp;iput_ctx);
    NRF_LOG_ERROR(&amp;quot;GC 2&amp;quot;)
    if (p_op == NULL)
    {
        return FDS_ERR_NO_SPACE_IN_QUEUES;
    }
    NRF_LOG_ERROR(&amp;quot;GC 3&amp;quot;)
    p_op-&amp;gt;op_code = FDS_OP_GC;
    queue_buf_store(&amp;amp;iput_ctx);
    NRF_LOG_ERROR(&amp;quot;GC 4&amp;quot;)
    if (m_gc.state != GC_BEGIN)
    {
        // Resume GC by retrying the last step.
        m_gc.resume = true;
        NRF_LOG_ERROR(&amp;quot;GC 5&amp;quot;)
    }
    NRF_LOG_ERROR(&amp;quot;GC 6&amp;quot;)
    queue_start();
    NRF_LOG_ERROR(&amp;quot;GC 7&amp;quot;)
    return NRF_SUCCESS;
}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;static void queue_start(void)
{
    if (!nrf_atomic_u32_fetch_add(&amp;amp;m_queued_op_cnt, 1))
    {
        NRF_LOG_ERROR(&amp;quot;GC queue&amp;quot;)
        queue_process(NRF_SUCCESS);
    }
}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Then the log output looks like this:&lt;/p&gt;
&lt;div&gt;[00:01:39.000,000] &amp;lt;error&amp;gt; Flash: corruption: 1 valid records: 22 dirty records: 24 largest contig: 2048 freeable words: 6264 used words: 4629&lt;br /&gt; [00:01:39.000,000] &amp;lt;error&amp;gt; Flash: corruption: 1 valid records: 23 dirty records: 24 largest contig: 2048 freeable words: 6264 used words: 4629&lt;br /&gt; [00:01:39.000,000] &amp;lt;error&amp;gt; Flash: corruption: 1 valid records: 23 dirty records: 25 largest contig: 2048 freeable words: 6268 used words: 4629&lt;br /&gt; [00:01:43.000,000] &amp;lt;error&amp;gt; app: GC queue&lt;br /&gt; [00:01:43.000,000] &amp;lt;error&amp;gt; Flash: corruption: 1 valid records: 24 dirty records: 25 largest contig: 2048 freeable words: 6268 used words: 5260&lt;br /&gt; [00:01:43.000,000] &amp;lt;error&amp;gt; app: GC 0&lt;br /&gt; [00:01:43.000,000] &amp;lt;error&amp;gt; app: GC 1&lt;br /&gt; [00:01:43.000,000] &amp;lt;error&amp;gt; app: GC 2&lt;br /&gt; [00:01:43.000,000] &amp;lt;error&amp;gt; app: GC 3&lt;br /&gt; [00:01:43.000,000] &amp;lt;error&amp;gt; app: GC 4&lt;br /&gt; [00:01:43.000,000] &amp;lt;error&amp;gt; app: GC 6&lt;/div&gt;
&lt;div&gt;&lt;/div&gt;
&lt;div&gt;Also the error check does not result in a reboot:&lt;/div&gt;
&lt;div&gt;
&lt;pre&gt;&lt;span&gt;APP_ERROR_CHECK&lt;/span&gt;(&lt;span&gt;fds_gc&lt;/span&gt;());&lt;/pre&gt;
&lt;/div&gt;
&lt;div&gt;&lt;/div&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: FDS garbage collection</title><link>https://devzone.nordicsemi.com/thread/329619?ContentTypeID=1</link><pubDate>Wed, 15 Sep 2021 12:40:55 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:ea8d8234-3ca3-442c-8941-75c8ba3d50eb</guid><dc:creator>Einar Thorsrud</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;Have you done any debugging to see what&amp;nbsp;state the device is in when it &amp;quot;freezes&amp;quot;? That should be the first step in order to understand what has happened.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>