Patent ID: 8429352

Claim:
A method of flushing memory blocks in a memory device in communication with a host, comprising: detecting a quantity of available memory in the memory device, wherein the available memory comprises unwritten capacity in memory blocks; background flushing partially obsolete memory blocks if the quantity of available memory decreases to a background flushing activation threshold, wherein the partially obsolete memory blocks comprise memory blocks having only obsolete data and valid data and background flushing comprises relocating valid data from the partially obsolete memory blocks to the available memory when a host interface is idle; disabling the background flushing if the quantity of available memory increases to a background flushing deactivation threshold, wherein the background flushing activation threshold is less than the background flushing deactivation threshold; overriding disabling of background flushing when a quantity of valid data in a selected partially obsolete memory block is less than an override threshold, wherein the override threshold comprises an average quantity of valid data in the partially obsolete memory blocks during the background flushing; foreground flushing the partially obsolete memory blocks if the quantity of available memory decreases to a foreground flushing activation threshold, wherein foreground flushing comprises after a host write command is received, interleaving host writing operations and flushing operations while the host write command is unfinished, the host writing operations comprising steps of storing data received with the host write command to the available memory and the flushing operations comprising steps of relocating valid data from the partially obsolete memory blocks to the available memory; and disabling the foreground flushing if the quantity of available memory increases to a foreground flushing deactivation threshold, wherein the foreground flushing activation threshold is less than the foreground flushing deactivation threshold.