Garbage Collection

JFFS2 has a Garbage Collector (GC). The GC is calld directly from JFFS2 or from a background thread called GC thread.

If a user process tries to allocate space for a write and there is not enought free space then it calls the GC to produce the neccesery free space if it is possible.

The GC thread is started at the end of the mount process if the fs is not in readonly mode. GC thread works in the background and begins its operation:

GC selects a jeb (gcblock) to garbage collect. If GC finds unchecked nodes then it checks all the nodes before continues its operation. Valid nodes of the jeb are moved to the currently used jeb (c->nextblock) and the obsolated nodes (and wasted nodes: RWCOMPAT_DELETE, PADDING, etc.) are left back. If GC doesn't find any valid node in the gcblock then moves the jeb to the erase_pending_list list and sets the gcblock pointer to NULL. At each GC call GC moves only one node.

Havasi Ferenc 2005-12-22