Commit 10622d7a authored by Ell's avatar Ell

buffer: remove cloned tiles with lower probability when trimming cache

A set of n cloned tiles is counted only once toward the total cache
size, so each inidividual tile can be thought of as contributing
only 1/n of its size to the total cache size.  On the other hand,
the cost of stroing a tile is independent of the number of clones
it has.

When trimming the cache, remove an unstored tile with n cached
clones with a probability of 1/n, instead of 1, to avoid saturating
the swap queue with cloned tiles, causing stalls.
parent bf6dd78e
......@@ -512,8 +512,8 @@ gegl_tile_handler_cache_has_tile (GeglTileHandlerCache *cache,
static gboolean
gegl_tile_handler_cache_trim (GeglTileHandlerCache *cache)
{
GList *link;
GList *link;
static guint counter;
cache = NULL;
link = NULL;
......@@ -575,6 +575,21 @@ gegl_tile_handler_cache_trim (GeglTileHandlerCache *cache)
if (tile->ref_count > 1)
continue;
/* a set of cloned tiles is only counted once toward the total cache
* size, so the entire set has to be removed from the cache in order
* to reclaim the memory of a single tile. in other words, in a set
* of n cloned tiles, we can assume that each individual tile
* contributes only 1/n of its size to the total cache size. on the
* other hand, storing a cloned tile is as expensive as storing an
* uncloned tile. therefore, if the tile needs to be stored, we only
* remove it with a probability of 1/n.
*/
if (gegl_tile_needs_store (tile) &&
counter++ % *gegl_tile_n_cached_clones (tile))
{
continue;
}
break;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment