MINOR: pools: evict excess objects using pool_evict_from_local_cache()

Till now we could only evict oldest objects from all local caches using
pool_evict_from_local_caches() until the cache size was satisfying again,
but there was no way to evict excess objects from a single cache, which
is the reason why pool_put_to_cache() used to refrain from putting into
the local cache and would directly write to the shared cache, resulting
in massive writes when caches were full.

Let's add this new function now. It will stop once the number of objects
in the local cache is no higher than 16+total/8 or the cache size is no
more than 75% full, just like before.

For now the function is not used.
diff --git a/src/pool.c b/src/pool.c
index 487e0da..8ccb0c0 100644
--- a/src/pool.c
+++ b/src/pool.c
@@ -186,6 +186,30 @@
 
 #ifdef CONFIG_HAP_POOLS
 
+/* Evicts some of the oldest objects from one local cache, until its number of
+ * objects is no more than 16+1/8 of the total number of locally cached objects
+ * or the total size of the local cache is no more than 75% of its maximum (i.e.
+ * we don't want a single cache to use all the cache for itself). For this, the
+ * list is scanned in reverse.
+ */
+void pool_evict_from_local_cache(struct pool_head *pool)
+{
+	struct pool_cache_head *ph = &pool->cache[tid];
+	struct pool_cache_item *item;
+	struct pool_head *pool;
+
+	while (ph->count >= 16 + pool_cache_count / 8 &&
+	       pool_cache_bytes > CONFIG_HAP_POOL_CACHE_SIZE * 3 / 4) {
+		item = LIST_NEXT(&ph->list, typeof(item), by_pool);
+		ph->count--;
+		pool_cache_bytes -= pool->size;
+		pool_cache_count--;
+		LIST_DEL(&item->by_pool);
+		LIST_DEL(&item->by_lru);
+		pool_put_to_shared_cache(pool, item);
+	}
+}
+
 /* Evicts some of the oldest objects from the local cache, pushing them to the
  * global pool.
  */