Classification of recyclable spaceThe purpose of garbage collection is to reuse (the amount of space recovered can be written to a valid node), and the lower the value of reuse, the lower the need for recycling. For efficient garbage collection, UBIFS has 2 levels of watermark for recyclable space: The Dead Space waterline, which is the smallest node size (typically the smallest data node):DEAD_WM = ALIGN (MIN_WRITE_SZ, min_io_size);Dark space waterline, which is the maximum node size (typically the largest inode node):DARK_WM = ALIGN (UBIFS_MAX_NODE_SZ, min_io_size); In general, min_io_size (page or subpage) <= dead_wm <= dark_wm. On our system, the waterline of DEAD_WM and DARK_WM is a page size (8K) Free + Dirty < DEAD_WM, when the garbage is considered to be very small, it is generally considered that this leb full, is not worth garbage collection. Free + Dirty < DARK_WM, because the recoverable space is small, the probability of dark_wm being recycled becomes smaller. For efficiency and space saving considerations, this leb is not added to the memory LPT tree. If the recoverable space is less than DARK_WM, the recycling value of this space is small. So there is a conclusion: the larger the node, the greater the space wasted.
Classification of recyclable objectsBecause index node and non-index node are managed differently, garbage collection requires that the 2 classes of objects be differentiated. The management of non-index node is wbuf-flash 2 layer structure, which is relatively simple. Unmap Leb complete the Recycle in Ubifs_garbage_collect_leb (BG GC) or UBIFS_GC_START_COMMIT (commit GC Phase I) stage; index node is managed in Tnc-jo Urnal-flash 4-storey structure, relatively complex. In the Ubifs_garbage_collect_leb (BG GC) or UBIFS_GC_START_COMMIT (commit GC first phase) phase, the preparation is completed in Ubifs_gc_end_commit (commit GC Phase II) stage Unmap LEB completes the collection, and all the garbage-collected index Leb are added to the list idx_gc, and the LEB in this list ubifs_gc_end_commit in unmap phase.
Garbage Collection (
Background Process Stage
)Background Garbage collection is the responsibility of the background thread, which wakes up periodically by the WBUF timer and determines whether a garbage collection is required, if so, to initiate a garbage collection operation. Normally, each garbage collection operation recycles Ubifs_gc_once (5) of Leb. The reclaimed Leb is finally unmap and marked as empty (Bud->start is set to 0) and is re-map when used again. Leb Unmap-map re-mapping process, UBI based on the Wear equalization algorithm to re-map, to achieve PEB wear balance effect. It also avoids the repeated use of a PEB case. Garbage collection when the effective data on the garbage Leb will be transported to the GC Wbuf->lnum for the LEB, Gc_lnum as a fallback for garbage collection purposes Leb, if the GC wbuf->lnum invalid, take Gc_lnum as a GC wbuf-> Lnum, collocated c->gc_lnum Invalid (switch_gc_head). By Gc_lnum, it is ensured that no leb (i.e. GC wbuf->lnum) can be found for the purpose of garbage collection.
Criteria for garbage collection judgment:Check GC watermark Setting Gc_waterline, GC is only performed when the total dirty space Lst.total_dirty > The total size of the volume/gc_waterline, avoiding GC in the case of more free space. Gc_waterline defaults to Ubifs_free_reserve_ratio (5). Also, for index NODE,UBIFS, the recycle of index is to reclaim only dirty space greater than half of the erase block, other index erase blocks may not be reclaimed even if there is dirty space.
garbage collection process: 1) Determine if a commit is required, that is, return-eagain, Trigger commit process 2) has been recycled index Leb and GC has continuously tried Soft_lebs_limit (4) times, return-eagain 3) If the GC has been continuously trying hard_lebs_limit (32) times, Back to-enospc 4) Find DIRTY Leb for recycling (the lookup order is lpt_heap[lprops_dirty_idx], lpt_heap[ Lprops_dirty], lpt_heap[lprops_free],c->uncat_list,lpt in Flash) 5) Read DIRTY Leb node, sorting, sorting, discarding obsolete data and handling data without handling 6) handling data to gc wbuf corresponding LEB (GC LEB), recycling garbage Leb, Here are the details of the index LEB and non-index LEB (see below 7) If the recovered non-index LEB, this GC ends &NBS P 8) If the recycle is index LEB, continue gc 9) has been recycled several times and has not been recycled successfully, stating that each reclaimed block is used for GC itself (because GC needs to always occupy a free leb, Used as the target for handling leb, i.e. GC Leb), and there is no more leb space currently used for GC recycling. Here try to find more dirty leb, because such leb on the effective data, recycling such leb need less space. 10) sync GC wbuf,unmap GC Leb (c->gc_lnum) &NBSp 11) Update LPT tree
handling data, recycling Leb details
Fine Process
:Fully recyclable Leb (free + dirty = = leb_size): Sync, then unmap 1) if not full free leb, write data and index WBUF to the corresponding Flash Leb. After avoiding GC, WBUF again writes obsoleting nodes to Flash. Then update Leb lprops and add this leb to C->frdi_idx_list (index Leb) or c->freeable_list (data leb). 2) unmap recovery leb 3) If C->gc_lnum is not valid, recycle the lnum as C->GC _lnum, and then return to leb_retained. Otherwise, return leb_freed. Non-index LEB: Move and sync again, then unmap 1) Transfer effective node to GC Leb WBUF (C->JHEADS[GCHD].WBUF) & nbsp 2) in order to ensure that the garbage collection node is present in Flash, synchronize data and index LEB WBUF to Flash. After avoiding GC, WBUF obsoleting nodes write to flash 3) Update Leb lprops and add this leb to C->freeable_list (data LEB) 4) If C->gc_lnum is not valid, the reclaimed lnum is used as C->gc_lnum and then returned to leb_retained. Otherwise, synchronize GC Leb wbuf to Flash, then unmap reclaim Leb, and then return to Leb_freed. index LEB: Update Idx_gc->list objects and C->frdi_idx_list objects for use in the end commit GC phase 1) Traverse Index LEB iNdex node, add the index node to the TNC, and the TNC in the corresponding path is set to dirty, commit the time will be re-written to Flash, in the GC to achieve the purpose of handling; 2) Add this LEB to the already GC index linked list idx_gc->list. Since this index LEB has been read to the TNC, it will be read to the index in the TNC at the next commit to write to Flash. But can not immediately unmap this leb, because commit has not happened, if it happens, still need to retain the index Leb for recovery, otherwise, the index LEB has been unmap, but no commit completed, then this index The data on the LEB will be lost. 3) Update Leb lprops and add this leb to C->frdi_idx_list (index Leb) and return to LEB_FREED_IDX.
Garbage Collection
(
Submission Phase
)
The garbage collection in the commit phase, in commit, is divided into 2 parts: Ubifs_gc_start_commit and Ubifs_gc_end_commit. Ubifs_gc_start_commit: Updating Idx_gc->list objects and C->frdi_idx_list objects for use in the end commit GC Phase 1) Unmap freeable_list L EB, update lprops; 2) Find all the frdi_idx_list leb and update to IDX_GC; Ubifs_gc_end_commit:unmap idx_gc Leb Before this stage, the commit is completed, so you can safely unmap all the idx_gc leb; At this point, the Ubifs file system garbage collection process is complete. --eof--
Ubifs core Function--garbage collection