Memory Management & Memory Mapping · Caches, Virtual Memory, and the Page Cache · Practice Question
How to Check a q Process's Memory Usage From the Command Line
Question
How can you check how much memory a kdb+ process is using from the operating system command line, without connecting to the process itself?
Solution
# Find the q process ID
ps aux | grep "q "
# Check memory for a specific PID (replace 12345 with actual PID)
ps -p 12345 -o pid,rss,vsz,comm
# Live view with memory columns
top -p 12345
# Detailed breakdown from the kernel (Linux only)
cat /proc/12345/status | grep -E "VmRSS|VmHWM|VmSize|VmPeak"Reading the output:
USER PID %CPU %MEM VSZ RSS COMMAND
ubuntu 12345 15.2 8.3 4200000 1376256 q
RSS (Resident Set Size) — physical RAM currently used, in KB
VSZ (Virtual Size) — total virtual address space, in KB (includes mapped files)Explanation
ps aux | grep "q " lists all running processes. The columns to focus on for memory are:
- RSS — Resident Set Size: the portion of the process's memory that is currently held in physical RAM. This is the most useful number for day-to-day monitoring because it reflects actual RAM consumption.
- VSZ — Virtual Size: the full virtual address space the process has mapped, including memory-mapped files (HDB columns, log files) that may not currently be in RAM. kdb+ uses extensive memory mapping, so VSZ is routinely several times larger than RSS and does not directly indicate RAM pressure.
- %MEM — RSS as a percentage of total system RAM.
/proc/PID/status (Linux) provides a finer breakdown:
VmPeak: 8200000 kB — peak virtual memory ever used by this process
VmSize: 4200000 kB — current virtual memory
VmRSS: 1376256 kB — current physical RAM in useVmPeak is the largest the process's virtual address space has been. For the largest amount of physical RAM it has held, look at VmHWM ("high water mark") in the same file.
Relating OS metrics to .Q.w[] output:
.Q.w[] field | OS equivalent |
|---|---|
used | bytes currently in use by q objects in its heap |
heap | the heap q has obtained from the OS — part of RSS once touched |
peak | the largest heap has been (q's high-water mark; not the same as VmPeak, which is virtual memory) |
mmap | memory currently mapped from files — part of VSZ |
mphy | total physical RAM on the machine |
The OS view and .Q.w[] see the same physical reality but report it differently. RSS includes q's heap plus mapped files currently paged in; .Q.w[]`used shows only what q has actively allocated in its heap. When memory-mapped HDB columns are hot, RSS can exceed heap significantly — the extra RSS is the mapped data, not heap allocation.
Quick one-liner to watch memory live:
watch -n 2 'ps -p 12345 -o pid,rss,vsz --no-headers | awk "{print \"RSS:\", $2/1024, \"MB | VSZ:\", $3/1024, \"MB\"}"'