In-depth analysis of Redis memory fragmentation

Let’s look at a question first. Assuming that the Redis instance has saved 5GB of data, and now 2GB of data is deleted, will the memory occupied by the Redis process be reduced?

The answer is: it may still take up about 5GB of memory, even though the Redis data only takes up about 3GB.

If the maxmemory parameter is not set, Redis will not trigger the memory elimination strategy to delete data.

Redis will continue to allocate memory for newly written data. Failure to allocate it will cause the application to report an error, but of course, it will not cause downtime.

Note:To set the maxmemory parameter, execute the command CONFIG SET maxmemory 100mb, or set maxmemory 100mb in the redis.conf configuration file.

You can confirm that the data has been deleted, and use the top command to view it. Why does it still take up so much memory?

Where does the freed memory go?

When we use the top command to check the system usage, we will find that the memory is still high, and Redis has not really released the memory.

Where did all the memory go? At this time, we need to use the info memory command to obtain Redis memory-related indicators.

Website

Tags: Analysis Redis