BUG/MINOR: memory: Set objects size for pools in the per-thread cache

When a memory pool is created, it may be allocated from a static array. This
happens for "most common" pools, allocated first. Objects of these pools may
also be cached in a pool cache. Of course, to not cache too much entries, we
track the number of cached objects and the total size of the cache.

But the objects size of each pool in the cache (ie, pool_cache[tid][idx].size,
where tid is the thread-id and idx is the index of the pool) was never set. So
the total size of the cache was never limited. Now when a pool is created, if
these objects may be cached, we set the corresponding objects size in the pool
cache.

This patch must be backported to 2.0 and 1.9.

(cherry picked from commit 2f6d3c0d65f09c342612d1b69198e23773fb7520)
Signed-off-by: Christopher Faulet <cfaulet@haproxy.com>
diff --git a/src/memory.c b/src/memory.c
index 6331c84..edacb00 100644
--- a/src/memory.c
+++ b/src/memory.c
@@ -66,6 +66,7 @@
 	struct pool_head *entry;
 	struct list *start;
 	unsigned int align;
+	int thr, idx;
 
 	/* We need to store a (void *) at the end of the chunks. Since we know
 	 * that the malloc() function will never return such a small size,
@@ -131,6 +132,13 @@
 		pool->size = size;
 		pool->flags = flags;
 		LIST_ADDQ(start, &pool->list);
+
+		/* update per-thread pool cache if necessary */
+		idx = pool_get_index(pool);
+		if (idx >= 0) {
+			for (thr = 0; thr < MAX_THREADS; thr++)
+				pool_cache[thr][idx].size = size;
+		}
 	}
 	pool->users++;
 #ifndef CONFIG_HAP_LOCKLESS_POOLS