Skip to content

The .m namespace

Since V4.0 2020.03.17

Memory can be backed by a filesystem, allowing use of DAX-enabled filesystems (e.g. AppDirect) as a non-persistent memory extension for kdb+.

Optane Memory and kdb+

Command-line option -m path directs kdb+ to use the filesystem path specified as a separate memory domain. This splits every thread’s heap into two:

domain description
0 regular anonymous memory, active and used for all allocs by default
1 filesystem-backed memory

The .m namespace is reserved for objects in memory domain 1, however names from other namespaces can reference them too, e.g. a:.m.a:1 2 3

\d .m changes current memory domain to 1, causing it to be used by all further allocs. \d .anyotherns sets it back to 0.

.m.x:x ensures the entirety of .m.x is in memory domain 1, performing a deep copy of x as needed. (Objects of types 100h-103h, 112h are not copied and remain in memory domain 0.)

Lambdas defined in .m set current memory domain to 1 during execution. This will nest, since other lambdas don’t change memory domains:

q)\d .myns
q)g:{til x}
q)\d .m
q)w:{system"w"};f:{.myns.g x}
q)\d .
q)x:.m.f 1000000;.m.w` / x allocated in domain 1

Internal function -120!x returns x’s memory domain, currently 0 or 1.

q)-120!'(1 2 3;.m.x:1 2 3)
0 1

System command \w returns memory info for the current memory domain only.

q)value each ("\\d .m";"\\w";"\\d .";"\\w")
353968 67108864 67108864 0 0 8589934592
354032 67108864 67108864 0 0 8589934592

Command-line option -w limit (M1/m2) is no longer thread-local, but memory domain-local. Command-line option -w, and system command \w set limit for memory domain 0.

Mapped is a single global counter, the same in every thread’s \w.

Back to top