The following documentation applies to Redis on Windows 2.8.x, for 3.0.x please follow this link.
The UNIX version of Redis relies on the system call fork() to perform point-in-time snapshots of the heap. In addition to the AOF and RDB backup mechanism, the master-slave synchronization and clustering features are also dependent on fork(). Windows doesn't have a fork() API, so in order to simulate this behavior the Redis heap is placed in a memory mapped file that can be shared between the main Redis process and a child process.
Memory Configuration Settings
maxheapvalue represents the underlying memory and memory mapped file storage for the Redis heap, which includes what reported by Redis as memory usage + fragmentation + internal data structures.
maxheapis a hard limit. When it’s reached, Redis will terminate with an out-of-memory exception.
You only need to set
maxmemoryif you want Redis to limit the size of the data, either by evicting old keys or preventing additional writes when the limit is reached. Otherwise, it’s not required that you set
WARNING: not setting
maxmemorywill cause Redis to terminate with an out-of-memory exception if the
maxheaplimit is reached.
MaxMemory and MaxHeap constrains
The Redis heap must be larger than the value specified by the
maxmemory setting, as the heap allocator has its own memory requirements and fragmentation of the heap is inevitable. If only the
maxmemory setting is specified,
maxheap will be set at
1.5 * maxmemory. If the
maxheap setting is specified along with
maxheap setting will be automatically increased if it is smaller than
1.5 * maxmemory.
maxheap setting controls the maximum size of the memory mapped file, as well as the total usable space for the Redis heap. Running Redis without either
maxmemory will result in a memory mapped file being created that is equal to the size of physical memory.
There must be enough disk space available for the page file in order for Redis to launch.
The default configuration places the memory mapped file in the local appdata directory. If you wish to move this file to another directory or to another local disk, use the
System Paging File Size Requirements
During fork() operations additional commit charge is also put on the system paging file, corresponding to the number of memory pages that get modified (for example, by clients modifying the data set) while the fork() operation is in progress. In the worst case scenario, the total page file commit will max out at around:
(size of physical memory) + (2 * size of maxheap)
For instance, on a machine with 8GB of physical RAM, the max page file commit, with the default maxheap size, will be:
(8GB) + (2 * 8GB) = 24GB
The default page file sizing of Windows will allow for this without having to reconfigure the system. Larger heap sizes are possible, but the maximum page file size will have to be increased accordingly.
maxmemory setting is specified but
maxheap will be set at
1.5 * maxmemory. On a machine with 16GB of physical RAM, the max page file commit, with a
maxmemory set to 8GB, will be:
(16GB) + (2 * (1.5 * 8GB) = 40GB
Preventing Redis from running out-of-memory
maxmemory will prevent Redis from using more memory than the specified amount of bytes. When the memory limit is reached Redis will try to remove keys according to the eviction policy selected by the
If Redis can't remove keys according to the policy, or if the policy is set to 'noeviction', Redis will start to reply with errors to commands that would use more memory, like
LPUSH, and so on, and will continue to reply to read-only commands like
This option is usually useful when using Redis as an LRU cache, or to set a hard memory limit for an instance (using the 'noeviction' policy).
WARNING: If you have slaves attached to an instance with
maxmemory on, the size of the output buffers needed to feed the slaves are subtracted from the used memory count, so that network problems / resyncs will not trigger a loop where keys are evicted, and in turn the output buffer of slaves is full with DELs of keys evicted triggering the deletion of more keys, and so forth until the database is completely emptied.
In short... if you have slaves attached it is suggested that you set a lower limit for
maxmemory so that there is some free RAM on the system for slave output buffers (but this is not needed if the policy is 'noeviction').
If Redis is to be used without any kind of asynchronous persistence, then the fork() mechanism used by the background AOF/RDB persistence is unneccessary. As an optimization, all persistence can be turned off in the Windows version of Redis. This will disable the creation of the memory mapped heap file, redirect heap allocations to the system heap allocator, and disable commands that would otherwise cause fork() operations:
BGREWRITEAOF. This setting may not be combined with any of the other settings that configure AOF and RDB operations:
Since Redis uses a memory mapped file to allocate the heap memory, the
Working Set memory usage showed by the Windows Task Manager or by other tools such as ProcessExplorer will not always be accurate.
For example, right after a background save of the RDB or the AOF files, the working set value may drop significantly.
In order to check the correct amount of memory used by the redis-server to store the data, use the
INFO client command.
INFO command shows only the memory used to store the redis data, not the extra memory used by the Windows process for its own requirements. That extra amount of memory not reported by the
INFO command can be calculated subtracting the
Peak Working Set reported by the Windows Task Manager and the
used_memory_peak reported by the