skip to content

In Redis `INFO memory`, what do `used_memory`, `used_memory_rss` and `used_memory_dataset` each measure, and which do you quote for how much data an instance holds?

level: juniorimportance: should knowfreq 40%

answer

  1. three layers, three different numbers
  2. allocator's view against the operating system's
  3. one of them is computed
  4. subtract the bookkeeping from the total

basics

~20 s

In Redis INFO memory, used_memory is all bytes allocated through its allocator, used_memory_rss is the process's resident size as the OS sees it, and used_memory_dataset is used_memory minus overhead. Quote used_memory_dataset for how much data the instance holds.

solid answer

~40 s

`used_memory` is the total number of bytes Redis has allocated through its allocator: keys and values plus everything else it keeps, such as client buffers and the replication backlog. `used_memory_rss` is the resident set size, the memory the operating system sees for the process and the number `top` and `ps` report. `used_memory_dataset` is a subtraction, `used_memory` minus `used_memory_overhead`, so it is what remains after bookkeeping. When someone asks how much data the instance holds, I quote `used_memory_dataset`, and I say it is an in-memory cost that includes allocator and encoding costs, not the byte length of what the application wrote. The other two answer other questions: `used_memory`, less transient replica and AOF buffers, is what Redis compares with `maxmemory`, and `used_memory_rss` is the RAM the host has to supply.

code

plaintext · 5 lines
plaintext
$ redis-cli INFO memory | grep -E '^used_memory(_rss|_overhead|_dataset)?:'
used_memory:3221225472
used_memory_rss:3865470566
used_memory_overhead:536870912
used_memory_dataset:2684354560

go deeper

for a junior

Recall one line each: the allocator's total, the resident size the operating system sees, and the remainder after overhead. Then name used_memory_dataset as the answer to how much data an instance holds.

for a middle

Explain that used_memory_dataset is a subtraction, what lands in used_memory_overhead, and why per-key dictionary cost counts there, so a keyspace of tiny keys can show a large overhead share.

for a senior

Match the number to the question during an incident: a flat dataset under a rising used_memory points at buffers, while a resident size far from the allocated total points at the allocator, the process or swap.

for a principal

Decide which number dashboards and reports standardise on: allocated bytes track the eviction limit, resident size drives host provisioning for peak use, and dataset suits growth planning. Any single headline figure misleads somebody.

## What `INFO memory` reports `INFO` is the Redis command that returns server information as plain `field:value` lines, grouped into sections. `INFO memory` returns only the **memory section**. It holds dozens of fields, and three of them answer most everyday questions: `used_memory`, `used_memory_rss` and `used_memory_dataset`. They look like three views of one number. They are not: each measures a different layer, so they rarely match and they serve different questions. Two terms make the fields readable. An **allocator** is the library that hands memory to Redis, usually jemalloc on Linux builds, and `mem_allocator` names the one in use. **Resident set size (RSS)** is the amount of a process's memory the operating system currently holds in RAM. ## The fields, one by one - **`used_memory`** is the total number of bytes Redis has allocated through its allocator. It covers stored keys and values and everything else the server keeps there, such as client buffers and the replication backlog. Redis keeps this count itself as it allocates and frees, so reading it is cheap and current. - **`used_memory_rss`** is the same process seen from outside: the bytes the operating system shows as resident, the number `top` and `ps` report. It can also contain pages Redis has freed but the allocator has not given back, plus code, shared libraries and stack. Redis refreshes it on a timer, about every 100 milliseconds, because reading it is a relatively slow call. - **`used_memory_overhead`** is the sum of what the server allocates to run and manage itself: startup memory, the replication backlog, replica and client buffers, the AOF buffer, script caches, and the main and expiry dictionaries of each database. - **`used_memory_dataset`** is `used_memory` with `used_memory_overhead` subtracted, and Redis documents the result as the size of the dataset. Nothing measures the stored values directly. The figure is a remainder, and the code floors it at zero if overhead ever exceeds the total. ## How they compare | Field | What it measures | How Redis gets it | Question it answers | |---|---|---|---| | `used_memory` | All bytes from the allocator | Its own running count | How much has Redis allocated? | | `used_memory_rss` | Resident memory of the process | Asked of the operating system on a timer | How much RAM does the process occupy? | | `used_memory_dataset` | Allocated memory left after overhead | `used_memory` minus `used_memory_overhead` | How much data does the instance hold? | ## Which one to quote Match the number to the question being asked: 1. **"How much data does this Redis hold?"** Quote `used_memory_dataset`. `used_memory_dataset_perc` adds its share of net usage, which is `used_memory` minus `used_memory_startup`. 2. **"How close is it to `maxmemory`?"** Read `used_memory`. The eviction check starts from it and takes off transient replica and AOF buffers, which `mem_not_counted_for_evict` reports. It does not use `used_memory_dataset` or `used_memory_rss`. 3. **"How much RAM does the host need for this process?"** Read `used_memory_rss`, because that is what the machine actually supplies. ## What each number does not tell you - **The dataset figure is not what the application wrote.** It includes allocator rounding and the internal structure of each value, so a gigabyte of application strings can cost more than a gigabyte. - **Per-key dictionary cost sits in overhead.** The main dictionary is counted in `used_memory_overhead`, so a keyspace of very many tiny keys can show a large overhead share while its values stay small. - **`MEMORY USAGE` will not add up to it.** That command reports one key's data plus its administrative overheads and samples nested values by default, so a sum over all keys is built differently. - **Resident size is not data.** Redis's memory guide gives the case: fill an instance with 5 GB, remove 2 GB, and RSS will probably stay around 5 GB while Redis reports about 3 GB. The allocator can reuse those chunks for new keys. - **`used_memory_rss` can sit below `used_memory`.** The ideal is only slightly above. When `used_memory` is well above it, part of Redis's memory has been swapped out and significant latency is likely. - **Not every field has a readable twin.** `used_memory_human` and `used_memory_rss_human` exist, but `used_memory_dataset` prints bytes only. ## A worked reading Suppose `INFO memory` shows `used_memory` at 3 GiB, `used_memory_overhead` at 512 MiB, `used_memory_dataset` at 2.5 GiB and `used_memory_rss` at 3.6 GiB. - **Data held:** 2.5 GiB, the number to give anyone who asks how much is stored. - **Room under a limit:** with `maxmemory` at 4 GiB and no large transient buffers, about 1 GiB remains before Redis starts evicting or, under `noeviction`, refusing writes. - **Host memory:** the process occupies 3.6 GiB of RAM, not 2.5 GiB. - **The difference:** the 0.6 GiB between resident and allocated is what `mem_fragmentation_bytes` reports, here a `mem_fragmentation_ratio` of 1.2. Despite the name, it also includes other process overheads. `MEMORY STATS` returns the same accounting as named metrics: `total.allocated`, `overhead.total` and `dataset.bytes`, plus `keys.count` and `keys.bytes-per-key`, which is useful when one instance's numbers need a closer look.

  • If `used_memory` climbs while `used_memory_dataset` stays flat, where is the memory going?
    Into overhead rather than stored data, because `used_memory_dataset` is what is left after `used_memory_overhead` is removed. Likely places are client buffers (`mem_clients_normal`), replication buffers (`mem_total_replication_buffers`) and the AOF buffer (`mem_aof_buffer`). `MEMORY STATS` breaks the same accounting into named metrics, so you can see which one grew before touching any keys.
  • Which number does Redis compare with `maxmemory` when it decides whether to evict?
    `used_memory`, after taking off transient replica and AOF buffers, the amount `mem_not_counted_for_evict` reports. It is not `used_memory_rss`, so a process can show more resident memory than `maxmemory` without any eviction. It is not `used_memory_dataset` either, so a dataset below the limit does not rule out eviction when overhead is large.
  • What does `MEMORY STATS` give you that the `INFO memory` fields do not?
    Mostly the same totals under other names: `total.allocated` is `used_memory`, `overhead.total` is `used_memory_overhead` and `dataset.bytes` is `used_memory_dataset`. It adds `keys.count`, `keys.bytes-per-key` and, for each database, the overhead of its main and expiry dictionaries, which shows how much of the overhead the keyspace itself accounts for.

A rented warehouse: used_memory_rss is the floor area on the lease, used_memory is the area actually in use including offices and aisles, and used_memory_dataset is what remains for the stock on the shelves.

  • used_memory_rss tells you how much data is stored in Redis.
  • used_memory counts only keys and values, with no client or replication memory.
  • Redis compares used_memory_rss with maxmemory to decide when to evict.
  • used_memory_dataset is measured by adding up the values applications wrote.
  • Deleting keys always shrinks used_memory_rss by the same amount.
  • used_memory_rss is always larger than used_memory.