<?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>Flash update during garbage collection</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/87586/flash-update-during-garbage-collection</link><description>Hello, 
 I am performing garbage collection. During the garbage collection an event could be fired (from the softdevice) that causes updating of records. 
 My question is: 
 Will updating the record cause failure to the update process or failure to the</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Thu, 05 May 2022 13:53:43 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/87586/flash-update-during-garbage-collection" /><item><title>RE: Flash update during garbage collection</title><link>https://devzone.nordicsemi.com/thread/366508?ContentTypeID=1</link><pubDate>Thu, 05 May 2022 13:53:43 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:33c3bb75-bdd6-4dea-b524-631323086a0e</guid><dc:creator>Edvin</dc:creator><description>&lt;p&gt;Hello Thomas,&lt;/p&gt;
&lt;p&gt;If you are using the softdevice, then your fds will use fstorage with the softdevice backend, so the softdevice will handle all reads and writes, and hence, it should be taken care of.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;In addition, fds itself has a queue, so calling fds_gc() will not immediately start the garbage collection, but it will put that task in the queue:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;ret_code_t fds_gc(void)
{
    fds_op_t * p_op;
    nrf_atfifo_item_put_t iput_ctx;

    if (!m_flags.initialized)
    {
        return FDS_ERR_NOT_INITIALIZED;
    }

    p_op = queue_buf_get(&amp;amp;iput_ctx);
    if (p_op == NULL)
    {
        return FDS_ERR_NO_SPACE_IN_QUEUES;
    }

    p_op-&amp;gt;op_code = FDS_OP_GC;

    queue_buf_store(&amp;amp;iput_ctx);

    if (m_gc.state != GC_BEGIN)
    {
        // Resume GC by retrying the last step.
        m_gc.resume = true;
    }

    queue_start();

    return NRF_SUCCESS;
}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;And as you can see, in the end it will start the queue. Similarly, when you write or update a record, it will not be executed immediately, but put on top of the queue, so that if you want to write something while a GC is ongoing, it will add that operation to the queue, and then resume the queue, in which it will finish the GC first.&lt;/p&gt;
&lt;p&gt;The only cases where operations are not queued is when they return FDS_ERR_NO_SPACE_IN_QUEUE, in which case you can increase FDS_OP_QUEUE_SIZE. For more info, see the &lt;a href="https://infocenter.nordicsemi.com/topic/sdk_nrf5_v17.1.0/lib_fds_functionality.html?cp=8_1_3_16_1_3#lib_fds_functionality_cfg"&gt;Configuration section of the FDS documentation&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;I hope that cleared up some things.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Best regards,&lt;/p&gt;
&lt;p&gt;Edvin&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>