.. SPDX-License-Identifier: GPL-3.0-or-later .. _config-cache-gc-prefetch: Cache GC and prefetch ===================== These two components help maintaining the cache utilization. While garbage collector evicts old and less useful records, prefetch updates expiring records which are frequently accessed. They have in some sense opposite goals, so see the last section of this page to recognize possible clashes. To compare the usefulness of the records, both of them use statistics on accesses to individual records stored in the KRU data structure beside the cache data. In particular, we store exponentially decreasing counters of accesses to the records which are for the purposes of garbage collector divided by the sizes of the records; we multiply them back for use in the prefetch. The higher the value is, the more useful is the record. The reason for the difference in the metrics of GC and prefetch is that GC maintains space as the limited resource, so accesses per byte are used; prefetch on the other hand considers only the access frequency. The exponential decay makes the value halve in 5 hours. .. _config-cache-gc: Garbage collector ----------------- Garbage collector keeps free space in cache for new records by evicting existing ones. The GC process checks in a regular time intervals whether the occupied space exceeded a set threshold. If the threshold is exceeded, the content of the cache is analysed and a set percentage of the occupied space is released. Furthermore, if prefetch is enabled, a higher percentage of the occupied space is considered and scheduled updates are cancelled in this area. In both cases, the records with the lowest frequency of accesses per byte are chosen. The analysis is performed by two linear scans of the whole cache. We assign an integer category number (0--99) to each record according to its access frequency per byte stored in the KRU table; the higher the frequency the lower the category number. In the first pass, the space occupied by individual categories is calculated. In the second pass, we remove all from a computed limit category to higher numbers and cancel prefetch from another limit category to higher ones. Different statistics are computed and logged during the analysis as described in the :ref:`last section ` of this page. If you experience issues with GC analysis being run too often or similar, you probably need to increase the :ref:`cache size `. The options below allow fine-tuning of GC in non-standard cases; usually, it is not needed and not recommended to change them. .. warning:: Misconfiguration of these options may lead to losing all the cached data periodically. If it happens that the cache is filled up completely, kresd will remove all its data as an emergency way how to continue using it. This may be caused by too high time interval, too high utilization threshold, too low release percentage, using dry-run mode or disabling the GC completely. .. option:: cache/garbage-collector/enable: true|false :default: true This allows disabling the GC completely; nothing will ever be removed from cache until it is filled up and cleared. .. option:: cache/garbage-collector/interval: