-
Notifications
You must be signed in to change notification settings - Fork 5.4k
Memory Configuration
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.
-
maxheap
The
maxheap
value 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.maxheap
is a hard limit. When it’s reached, Redis will terminate with an out-of-memory exception. -
maxmemory
You only need to set
maxmemory
if 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 setmaxmemory
.WARNING: not setting
maxmemory
will cause Redis to terminate with an out-of-memory exception if themaxheap
limit is reached.
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 maxmemory
, the maxheap
setting will be automatically increased if it is smaller than 1.5 * maxmemory
.
The 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 maxheap
or 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 heapdir
setting.
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.
If the maxmemory
setting is specified but maxheap
isn't, 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
Explicitly setting 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 maxmemory-policy
setting.
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 SET
, LPUSH
, and so on, and will continue to reply to read-only commands like GET
.
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:
BGSAVE
and BGREWRITEAOF
. This setting may not be combined with any of the other settings that configure AOF and RDB operations:
persistence-available [(yes)|no]
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.
The 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 INFO
command.
=== REDIS BUG REPORT START: Cut & paste starting from here === [4776] 29 Dec 09:13:11.730 # Redis version: 3.0.504 [4776] 29 Dec 09:13:11.730 # --- EXCEPTION_ACCESS_VIOLATION [4776] 29 Dec 09:13:11.730 # --- STACK TRACE redis-server.exe!LogStackTrace(c:\release\redis\src\win32_interop\win32_stacktrace.cpp:95)(0x0014DFA0, 0x0014FF60, 0x0014DFA0, 0x40124730) redis-server.exe!UnhandledExceptiontHandler(c:\release\redis\src\win32_interop\win32_stacktrace.cpp:185)(0x40028E60, 0x40028E60, 0x0014DFA0, 0x00000010) KERNELBASE.dll!UnhandledExceptionFilter(c:\release\redis\src\win32_interop\win32_stacktrace.cpp:185)(0x00000000, 0x95B02008, 0x00000000, 0x00000000) ntdll.dll!memset(c:\release\redis\src\win32_interop\win32_stacktrace.cpp:185)(0x0014EC30, 0xFEEEFEEE, 0x0014EC30, 0x0014E568) ntdll.dll!_C_specific_handler(c:\release\redis\src\win32_interop\win32_stacktrace.cpp:185)(0x00000000, 0x0014E550, 0x00000000, 0x40000000) ntdll.dll!_chkstk(c:\release\redis\src\win32_interop\win32_stacktrace.cpp:185)(0x0014E550, 0x00000000, 0x9365BC3C, 0x935B0000) ntdll.dll!RtlWalkFrameChain(c:\release\redis\src\win32_interop\win32_stacktrace.cpp:185)(0x0EADE9EA, 0xFE8E3B55, 0x0014F5F8, 0x959D7F3D) ntdll.dll!KiUserExceptionDispatcher(c:\release\redis\src\win32_interop\win32_stacktrace.cpp:185)(0x4008E920, 0x00000030, 0x400DD251, 0x04407040) redis-server.exe!dictGenHashFunction(c:\release\redis\src\dict.c:127)(0x00000030, 0x400DD251, 0x04407040, 0x0014F6B0) redis-server.exe!dictFind(c:\release\redis\src\dict.c:514)(0x0014F5F8, 0x00000001, 0x04407040, 0x04407070) redis-server.exe!getExpire(c:\release\redis\src\db.c:804)(0x0014F6B0, 0x0FBC1A40, 0x064B65A0, 0x064B65A0) redis-server.exe!rdbSaveRio(c:\release\redis\src\rdb.c:693)(0x40150210, 0x01630000, 0x00000005, 0x01A32754) redis-server.exe!rdbSave(c:\release\redis\src\rdb.c:758)(0x01630000, 0x5FD7F6A3, 0x01630000, 0x00000005) redis-server.exe!QForkChildInit(c:\release\redis\src\win32_interop\win32_qfork.cpp:337)(0x00000005, 0x00000000, 0x0057DFA0, 0x00000005) redis-server.exe!QForkStartup(c:\release\redis\src\win32_interop\win32_qfork.cpp:515)(0x00000006, 0x00000000, 0x00000000, 0x00565640) redis-server.exe!main(c:\release\redis\src\win32_interop\win32_qfork.cpp:1240)(0x00000000, 0x00000000, 0x00000000, 0x00000000) redis-server.exe!__tmainCRTStartup(f:\dd\vctools\crt\crtw32\startup\crt0.c:255)(0x00000000, 0x00000000, 0x00000000, 0x00000000) KERNEL32.DLL!BaseThreadInitThunk(f:\dd\vctools\crt\crtw32\startup\crt0.c:255)(0x00000000, 0x00000000, 0x00000000, 0x00000000) ntdll.dll!RtlUserThreadStart(f:\dd\vctools\crt\crtw32\startup\crt0.c:255)(0x00000000, 0x00000000, 0x00000000, 0x00000000) ntdll.dll!RtlUserThreadStart(f:\dd\vctools\crt\crtw32\startup\crt0.c:255)(0x00000000, 0x00000000, 0x00000000, 0x00000000) [4776] 29 Dec 09:13:11.730 # --- INFO OUTPUT
redis_version:3.0.504
redis_git_sha1:00000000
redis_git_dirty:0
redis_build_id:a4f7a6e86f2d60b3
redis_mode:standalone
os:Windows
arch_bits:64
multiplexing_api:WinSock_IOCP
process_id:4776
run_id:f6e90d287241e61ad8cbd212aee43e72ab1bb563
tcp_port:6379
uptime_in_seconds:1616860
uptime_in_days:18
hz:10
lru_clock:15385071
config_file:C:\Program Files\Redis\redis.windows-service.conf
connected_clients:283 client_longest_output_list:1 client_biggest_input_buf:4265607760 blocked_clients:0
used_memory:944 used_memory_human:944B used_memory_rss:307938944 used_memory_peak:551673856 used_memory_peak_human:526.12M used_memory_lua:-32010591232 mem_fragmentation_ratio:326206.50 mem_allocator:jemalloc-3.6.0
loading:0 rdb_changes_since_last_save:248539 rdb_bgsave_in_progress:1 rdb_last_save_time:1609220530 rdb_last_bgsave_status:ok rdb_last_bgsave_time_sec:2 rdb_current_bgsave_time_sec:1609220592 aof_enabled:0 aof_rewrite_in_progress:0 aof_rewrite_scheduled:0 aof_last_rewrite_time_sec:-1 aof_current_rewrite_time_sec:-1 aof_last_bgrewrite_status:ok aof_last_write_status:ok
total_connections_received:2145 total_commands_processed:6532475159 instantaneous_ops_per_sec:22654 total_net_input_bytes:772342079093 total_net_output_bytes:8913770464992 instantaneous_input_kbps:2717.40 instantaneous_output_kbps:26171.58 rejected_connections:0 sync_full:0 sync_partial_ok:0 sync_partial_err:0 expired_keys:158349869 evicted_keys:0 keyspace_hits:2863444947 keyspace_misses:290755433 pubsub_channels:1 pubsub_patterns:0 latest_fork_usec:20866 migrate_cached_sockets:0
role:master connected_slaves:0 master_repl_offset:0 repl_backlog_active:0 repl_backlog_size:1048576 repl_backlog_first_byte_offset:0 repl_backlog_histlen:0
used_cpu_sys:0.08 used_cpu_user:0.06 used_cpu_sys_children:0.00 used_cpu_user_children:0.00
cluster_enabled:0
db0:keys=2,expires=1,avg_ttl=21168130416 db1:keys=323823,expires=323823,avg_ttl=498062 db2:keys=597,expires=597,avg_ttl=660808 db3:keys=1,expires=0,avg_ttl=0 [4776] 29 Dec 09:13:11.730 # === REDIS BUG REPORT END. Make sure to include from START to END. ===
Please report this bug by following the instructions at:
http://github.com/MSOpenTech/redis/wiki/Submitting-an-Issue
Suspect RAM error? Use redis-server --test-memory to verify it.
[3708] 29 Dec 09:13:12.104 # fork operation failed