<?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>Detect Almost Full FDS to Perform Garbage Collection</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/47084/detect-almost-full-fds-to-perform-garbage-collection</link><description>I would like to perform FDS garbage collection only when it is close to being full. I can read the fds_stat to see the number of words used and the words freeable but what is the maximum number for this if I have 8 virtual pages, each 1kb in size. Is</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Fri, 10 May 2019 17:56:52 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/47084/detect-almost-full-fds-to-perform-garbage-collection" /><item><title>RE: Detect Almost Full FDS to Perform Garbage Collection</title><link>https://devzone.nordicsemi.com/thread/186476?ContentTypeID=1</link><pubDate>Fri, 10 May 2019 17:56:52 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:1328e0de-0d3a-4c56-ac32-6c7e42011e1f</guid><dc:creator>Matt22</dc:creator><description>&lt;p&gt;Thank you, one thing that I noticed is that i should only use the words_used, this includes the freeable words, and the first FDS page is used for garbage collection so I am using this to detect when we are 90% full.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;#define GC_NUM_BYTES ((FDS_VIRTUAL_PAGES-1) * FDS_VIRTUAL_PAGE_SIZE)*.9

if (stats.corruption || stats.words_used &amp;gt; GC_NUM_BYTES) {
garbage_collect();
}&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Detect Almost Full FDS to Perform Garbage Collection</title><link>https://devzone.nordicsemi.com/thread/186333?ContentTypeID=1</link><pubDate>Fri, 10 May 2019 09:08:30 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:1589ba30-4246-4177-8699-3ced25c9f147</guid><dc:creator>Jared</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;The FDS module use records_stat() which is defined as:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;// Retrieve statistics about dirty records on a page.
static void records_stat(uint16_t   page,
                         uint16_t * p_valid_records,
                         uint16_t * p_dirty_records,
                         uint16_t * p_freeable_words,
                         bool     * p_corruption)
{
    fds_header_t const *       p_header   = (fds_header_t*)(m_pages[page].p_addr + FDS_PAGE_TAG_SIZE);
    uint32_t     const * const p_page_end = (m_pages[page].p_addr + FDS_PAGE_SIZE);

    while (header_has_next(p_header, p_page_end))
    {
        switch (header_check(p_header, p_page_end))
        {
            case FDS_HEADER_DIRTY:
                *p_dirty_records  += 1;
                *p_freeable_words += FDS_HEADER_SIZE + p_header-&amp;gt;length_words;
                p_header = header_jump(p_header);
                break;

            case FDS_HEADER_VALID:
                *p_valid_records += 1;
                p_header = header_jump(p_header);
                break;

            case FDS_HEADER_CORRUPT:
            {
                *p_dirty_records  += 1;
                *p_freeable_words += (p_page_end - (uint32_t*)p_header);
                *p_corruption      = true;
                // We can&amp;#39;t continue on this page.
                return;
            }

            default:
                break;
        }
    }
}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Which shows that the freeable words is defined as:&amp;nbsp;*p_freeable_words += FDS_HEADER_SIZE + p_header-&amp;gt;length_words;&lt;/p&gt;
&lt;p&gt;FDS_HEADER_SIZE includes the CRC(&lt;a href="https://infocenter.nordicsemi.com/index.jsp?topic=%2Fcom.nordic.infocenter.sdk5.v15.3.0%2Flib_fds_format.html&amp;amp;cp=5_0_3_55_2"&gt;see storage format&lt;/a&gt;).&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Best regards&lt;/p&gt;
&lt;p&gt;Jared&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>