-/* Try to free one object form the pre-allocated objects free list.
- * This is useful under low mem conditions as by default we take 1 million
- * free objects allocated. On success REDIS_OK is returned, otherwise
- * REDIS_ERR. */
-int tryFreeOneObjectFromFreelist(void) {
- robj *o;
-
- if (server.vm_enabled) pthread_mutex_lock(&server.obj_freelist_mutex);
- if (listLength(server.objfreelist)) {
- listNode *head = listFirst(server.objfreelist);
- o = listNodeValue(head);
- listDelNode(server.objfreelist,head);
- if (server.vm_enabled) pthread_mutex_unlock(&server.obj_freelist_mutex);
- zfree(o);
- return REDIS_OK;
- } else {
- if (server.vm_enabled) pthread_mutex_unlock(&server.obj_freelist_mutex);
- return REDIS_ERR;
- }
-}
-
-/* A fast RSS sampling function.
- *
- * The function is reasonably accurate while fast, since it uses the trick of
- * using the server.fragmentation ratio that is computed every second and
- * is the ratio between the RSS and our zmalloc() count of allocated bytes.
- *
- * So in order to compute the current RSS used we just need to multiply
- * the zmalloc() memory reporting, that is as fast as reading a counter,
- * for the latest estimation of fragmentation.
- *
- * The behavior of this function is also very desirable because it is
- * very responsive to memory changes: while the real RSS is actually measured
- * in pages, the RSS estimation will actually change even if just a few bytes
- * are freed, and this is a good property when the function is used in order
- * to evict keys for Virtual Memory of for 'maxmemory' directive.
- *
- * Note that when the memory reported by zmalloc is smaller than the RSS
- * (that is, fragmentation < 1) this means that something is odd (many pages
- * swapped since the Redis instance is idle) and we consider the fragmentation
- * ratio 1. */
-size_t redisEstimateRSS(void) {
- size_t used = zmalloc_used_memory();
- float maxfrag;
-
- if (server.fragmentation < 1) return used;
- maxfrag = (float)SIZE_MAX / used;
-
- /* If multiplying memory usage reported by zmalloc per fragmentation
- * ratio will lead to an overflow we just return SIZE_MAX. */
- if (maxfrag < server.fragmentation) return SIZE_MAX;
-
- return (size_t)((used * server.fragmentation));
-}
-