Database Autonomy Service (DAS) includes the memory fragmentation ratio as a factor in its inspection and scoring feature for Redis instances. This topic explains what memory fragmentation is, what causes it, how to measure it, and when to act.
How memory fragmentation works
Memory fragmentation occurs when free memory exists but is split into small, non-contiguous segments. Even if total free memory exceeds N bytes, the operating system cannot fulfill a request for a contiguous N-byte block—those scattered segments are memory fragments.
In Tair (Redis OSS-Compatible), memory fragments do not reduce the available memory allocated to your instance and do not incur additional fees.
For example, if a Tair (Redis OSS-Compatible) instance has 1 GB of capacity with 700 MB in use, the remaining 300 MB (1 GB − 700 MB) stays available even if the memory fragmentation ratio reaches 2—meaning the data physically occupies 2 GB of system memory.
What causes memory fragmentation
Memory fragmentation has two root causes.
Memory allocator behavior (internal)
Redis supports multiple memory allocators: libc, jemalloc, and tcmalloc. jemalloc is the default. Rather than allocating exactly the amount of memory an application requests, jemalloc rounds up to the nearest power-of-two boundary—8 bytes, 16 bytes, 32 bytes, 2 KB, 4 KB, and so on. The gap between the requested amount and the allocated amount becomes a fragment.
Key-value pair churn (external)
When key-value pairs are modified or deleted, the memory they occupied is released or resized. Because allocated blocks rarely match the new data size exactly, gaps accumulate over time.
Check the memory fragmentation ratio
Run the following command in DAS to view memory usage details:
INFO memory
The output includes:
# Memory
used_memory:350458970752
used_memory_human:326.39G
used_memory_rss:349066919936
used_memory_rss_human:325.09G
…
mem_fragmentation_ratio:1.00
| Field | Description |
|---|---|
used_memory |
Memory Redis requested to store data |
used_memory_rss |
Physical memory the operating system allocated to Redis, including fragment overhead |
mem_fragmentation_ratio |
Current memory fragmentation ratio |
The ratio is calculated as:
mem_fragmentation_ratio = used_memory_rss / used_memory
Interpret the ratio
| Ratio | Status | Recommended action |
|---|---|---|
| 1.0–1.5 | Normal | No action needed |
| > 1.5 | High | Fragmented memory exceeds half the used memory—investigate and take corrective action |