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

Detect Almost Full FDS to Perform Garbage Collection

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 there overhead such as CRC that is not included in these stats or can I just add these two numbers together and get the 8kb in complete size I have allocated?

  • Hi,

    The FDS module use records_stat() which is defined as:

    // 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->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't continue on this page.
                    return;
                }
    
                default:
                    break;
            }
        }
    }

    Which shows that the freeable words is defined as: *p_freeable_words += FDS_HEADER_SIZE + p_header->length_words;

    FDS_HEADER_SIZE includes the CRC(see storage format). 

    Best regards

    Jared 

  • 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.

    #define GC_NUM_BYTES ((FDS_VIRTUAL_PAGES-1) * FDS_VIRTUAL_PAGE_SIZE)*.9
    
    if (stats.corruption || stats.words_used > GC_NUM_BYTES) {
    garbage_collect();
    }

Related