问一下, 我当前节点上有1200个slot,占用的物理内存大概是17.4G, 我把其中的200个slot迁移到其他节点了, 但是,查看redis的物理内存占用,只是少了几百K, 几乎是没有释放,请问,这是啥原因啊? 求大神们指点一下。 谢谢!
https://redis.io/topics/memory-optimization
Memory allocation这一章节
Redis will not always free up (return) memory to the OS when keys are removed. This is not something special about Redis, but it is how most malloc() implementations work. For example if you fill an instance with 5GB worth of data, and then remove the equivalent of 2GB of data, the Resident Set Size (also known as the RSS, which is the number of memory pages consumed by the process) will probably still be around 5GB, even if Redis will claim that the user memory is around 3GB. This happens because the underlying allocator can't easily release the memory. For example often most of the removed keys were allocated in the same pages as the other keys that still exist.
简单说,因为内存交给系统管理,所以删除(迁移走)key时不会很快的释放内存。
要很快释放的话,冻结主节点,让从节点接管,重启原主节点,然后再接管回来。