Networking DOCA SDK Documentation

DOCA Key-Value

Introduction

The NVIDIA DOCA™ Key-Value library (libdoca_kv) provides asynchronous Store, Retrieve, and Exist operations against a key-value namespace. Applications describe keys and value buffers, submit typed DOCA tasks, and receive completion callbacks through a DOCA progress engine.

The library separates the logical KV device and I/O interfaces from their backend implementation. The backend described in this guide accesses Linux kernel-managed NVMe KV namespaces exposed as generic character devices, such as /dev/ng0n1.

In a DOCA Memos deployment, a service built on DOCA DevEmu NVMe emulates the NVMe KV namespace on NVIDIA® BlueField® and exposes it to the host. For an overview of the DOCA Memos libraries and how they work together, see DOCA Memos.

For a reference application that uses this library, see DOCA Memos fio Plugin. It's an fio I/O engine that runs Store and Retrieve workloads against an NVMe KV namespace through the NVMe kernel backend.

Library Interaction

  • DOCA Key-Value: device properties, explicit device-to-I/O bindings, and typed KV tasks.

  • DOCA Core: I/O-context lifecycle, progress engines, task submission, task ownership, and completion handling.

  • Linux NVMe and io_uring: namespace discovery and asynchronous command execution for the NVMe kernel backend.

The KV interfaces described here are marked DOCA_EXPERIMENTAL. Use the headers and libraries from the same installed SDK release.

Prerequisites

Read DOCA Core before using the library. Understand contexts, progress engines, asynchronous tasks and callback ownership. Familiarity with KV namespace identity and scatter/gather I/O buffers is also required.

Environment

  • A Linux host with kernel 6.2 or later and NVMe io_uring passthrough support. The build headers must provide NVME_URING_CMD_IO and NVME_URING_CMD_IO_VEC.

  • liburing 2.5 or later, with the matching DOCA Key-Value development and runtime packages.

  • An accessible NVMe KV namespace, its generic character-device path and its expected 16-byte NGUID.

  • Permissions sufficient to open the namespace for read/write and perform the required NVMe identification and passthrough operations.

The namespace must already be provisioned and visible to the host. This library accesses that namespace; it does not provision the controller or storage service.

Architecture

Objects and Relationships

Object

Role and lifetime

doca_kv_dev

Abstract logical KV device. Exposes identity, reported size and maximum key/value lengths. It is not a DOCA context.

doca_kv_nvme_kernel_dev

NVMe kernel specialization. Creation synchronously opens and validates the namespace and loads its properties. Destroy only after all I/O bindings are removed.

doca_kv_io

Thread-owned DOCA context with a shared task pool for Store, Retrieve and Exist. A Running context may serve multiple bound devices.

doca_kv_nvme_kernel_io

NVMe kernel I/O specialization. Created independently of devices and converted to the abstract I/O interface for configuration and binding.

Device-to-I/O binding

Explicit association established while the I/O context is Running. Each task names its target device, which must be bound to that context.

Store, Retrieve and Exist tasks

Allocated from the I/O context, configured by the application and submitted through DOCA Core.

Device creation and I/O-context initialization may occur in either order. One device may be bound to multiple I/O contexts, and one I/O context may serve multiple devices. Devices and I/O contexts must use the same backend specialization. No device start/stop API or device-to-DOCA-context conversion is required.

Threading and Progress

  • Manage each I/O context, its bindings and its tasks on its owning thread. The I/O context is not thread-safe.

  • Progress its connected engine to deliver task completions. Do not call doca_pe_progress() recursively from a callback.

  • Coordinate device destruction across all users. A device may be bound or unbound by different I/O owners, but destruction must not race with either operation.

Using one I/O context per application I/O thread is the usual arrangement. Choosing one context per device is not a library requirement.

Keys and Value Buffers

Keys are opaque byte strings, not fio offsets or library-generated hashes. Applications choose their keys and query each device's supported lengths. Values are supplied as ordinary userspace buffers described by struct iovec; these task APIs do not require a DOCA buffer inventory or memory-map object.

  • Key length must be nonzero and no larger than doca_kv_dev_get_max_key_len().

  • For Store and Retrieve, provide a nonempty iovec array and a nonzero value length no larger than doca_kv_dev_get_max_value_len(). The aggregate iovec length must exactly match the configured value length.

  • Keep the key, iovec array and referenced buffers valid until completion. Do not modify Store input or access Retrieve output while the task is owned by the library.

Initialization

I/O Context Initialization

  1. Create a progress engine and call doca_kv_nvme_kernel_io_create().

  2. Obtain doca_kv_io with doca_kv_nvme_kernel_io_as_kv_io(), and its DOCA context with doca_kv_io_as_ctx().

  3. While Idle, set a nonzero task count with doca_kv_io_set_num_tasks(), not exceeding doca_kv_io_cap_get_max_tasks(). This pool is shared across task types and devices bound to the context.

  4. Register both completion and error callbacks for Store, Retrieve and Exist using the APIs below. All six registrations are required before start in this implementation, even if the application does not submit every operation.

  5. Optionally configure context user data and a DOCA Core state-change callback. Connect the context using doca_pe_connect_ctx().

  6. Call doca_ctx_start(), check the result and confirm Running before binding devices or allocating tasks.

Task

Successful completion

Error completion

Store

doca_kv_io_task_store_register_completion_cb()

doca_kv_io_task_store_register_error_cb()

Retrieve

doca_kv_io_task_retrieve_register_completion_cb()

doca_kv_io_task_retrieve_register_error_cb()

Exist

doca_kv_io_task_exist_register_completion_cb()

doca_kv_io_task_exist_register_error_cb()

Device Identification and Creation

  1. Select the NVMe KV namespace's generic character-device path and obtain its expected NGUID. Do not rely on a device-node number as a persistent identity.

  2. Allocate attributes with doca_kv_nvme_kernel_dev_create_attr_create() and set the path with doca_kv_nvme_kernel_dev_create_attr_set_path(). Use doca_kv_nvme_kernel_dev_cap_get_max_path_len() when sizing path buffers; its result includes the null terminator.

  3. Convert the attributes with doca_kv_nvme_kernel_dev_create_attr_as_kv_dev_create_attr() and set the expected 16-byte NGUID with doca_kv_dev_create_attr_set_nguid().

  4. Call doca_kv_nvme_kernel_dev_create(). It copies the attributes, opens the namespace, checks its NGUID and reads its properties. A missing namespace or NGUID mismatch fails creation rather than selecting a different namespace silently.

  5. Destroy the temporary attributes with doca_kv_nvme_kernel_dev_create_attr_destroy(). The created device remains valid.

  6. Obtain the abstract device with doca_kv_nvme_kernel_dev_as_kv_dev(). Query NGUID, reported size and maximum key/value lengths through doca_kv_dev_get_*(). These queries do not require an I/O binding.

The reported namespace size is not a reservation or a query of currently free backend capacity. Do not treat it as a guarantee that a proposed set of keys and values will fit.

Binding Devices

On each I/O owner thread, call doca_kv_io_bind_dev(io, dev) for every device the Running context will serve. Check each return value. Binding an already-bound device returns DOCA_ERROR_ALREADY_EXIST; using a different backend specialization returns DOCA_ERROR_NOT_SUPPORTED.

The context can now allocate tasks targeting those devices. Creating a device or starting an I/O context alone does not establish a binding.

Execution Phase

Task Submission

  1. Allocate the required typed task with doca_kv_io_task_store_alloc_init(), doca_kv_io_task_retrieve_alloc_init() or doca_kv_io_task_exist_alloc_init(). Pass the owning Running I/O context, the bound target device and task user data.

  2. Configure the key and buffers while the application owns the task. The setters do not return a status; check the submission result for configuration validation failures.

  3. Convert the typed task with the corresponding ..._as_task() API and call doca_task_submit(). Success transfers task ownership to the library. On synchronous failure, ownership remains with the application; correct the task or free it. Do not wait for a completion callback for a rejected submission.

  4. Progress the owning engine until the success or error callback returns task ownership. Inspect the result before reusing or freeing the task with doca_task_free().

Task-pool exhaustion is reported as DOCA_ERROR_NO_MEMORY during allocation. Reclaim completed tasks and progress outstanding work before retrying; do not confuse this allocation result with a target capacity error delivered asynchronously for Store.

Store

Configure the key and scattered input value with doca_kv_io_task_store_set_key_value_conf(). The configured value length must equal the aggregate input length.

Store may be conditional:

  • doca_kv_io_task_store_set_do_not_overwrite(): fail with DOCA_ERROR_ALREADY_EXIST when the key is already present.

  • doca_kv_io_task_store_set_must_exist(): fail with DOCA_ERROR_NOT_FOUND when the key is absent.

The options are mutually exclusive. Do not enable both on one task. An asynchronous capacity-exceeded response maps to DOCA_ERROR_NO_MEMORY.

Retrieve

Configure the key and receive capacity with doca_kv_io_task_retrieve_set_key_value_conf(). After successful completion, read the full stored value length with doca_kv_io_task_retrieve_get_result_value_len().

A successful Retrieve does not guarantee that the entire stored value fit in the supplied buffers. If the returned stored length exceeds the configured receive capacity, only that capacity was transferred. Detect truncation by comparing the lengths, then issue a new Retrieve with sufficient space. A returned length smaller than the capacity is not truncation; consume only the returned bytes.

The result-length getter is valid only after successful task completion and before the task is freed or reused. An absent key is reported through the error callback as DOCA_ERROR_NOT_FOUND.

Exist

Configure the key using doca_kv_io_task_exist_set_key_conf(). Successful completion means the key exists; DOCA_ERROR_NOT_FOUND through the error callback means it does not. No value buffer is required.

Completion and Error Handling

Callbacks receive the typed task, task user data and context user data. The application regains task ownership in either callback. For an error completion, obtain the status from doca_task_get_status() on the converted task.

Status

Meaning

DOCA_ERROR_INVALID_VALUE

Invalid command fields or unsupported key/value sizes. Validate parameters against the device properties.

DOCA_ERROR_BAD_STATE

The namespace/backend is not ready.

DOCA_ERROR_NOT_FOUND

Key absent for Retrieve or Exist, or for conditional Store requiring an existing key.

DOCA_ERROR_ALREADY_EXIST

Store requested no overwrite but the key already exists.

DOCA_ERROR_NO_MEMORY

The target reported capacity exceeded for Store.

DOCA_ERROR_IO_FAILED

The device reported an I/O failure.

DOCA_ERROR_DRIVER

The kernel/backend reported a transport or syscall failure.

Interpret status in the phase where it occurs. For example, DOCA_ERROR_NOT_FOUND while allocating a task can mean the device is not bound; it is not a key lookup result. Error callbacks do not define an automatic retry policy; the application decides whether and how to retry.

Optional Batched Submission

doca_task_submit() uses the normal flushed submission path. An application choosing deferred batches can use doca_task_submit_ex() without DOCA_TASK_SUBMIT_FLAG_FLUSH, then explicitly flush through doca_ctx_flush_tasks() or a submission with the flush flag. Continue progressing completions. Do not wait for completion of a batch that has not been flushed.

Draining and Teardown

Removing a Device

  1. Stop allocating or submitting tasks for the device on every I/O context serving it.

  2. Continue progress until submitted tasks have completed. Free every allocated task referencing the device, including unsubmitted tasks and completed tasks retained for reuse.

  3. On each owning thread, call doca_kv_io_unbind_dev() while the I/O context is Running. If it returns DOCA_ERROR_IN_USE, the binding remains in place; reclaim the remaining tasks before retrying.

  4. After all bindings are removed and no concurrent bind/unbind is possible, call doca_kv_nvme_kernel_dev_destroy().

I/O contexts may remain Running and continue serving other devices. Removing one device does not require stopping all contexts.

Stopping an I/O Context

  1. Stop new work on the context and complete and free all of its tasks. Flush any deferred submissions before waiting for their completion.

  2. Unbind every device from that context. Do not call stop as a substitute for draining and unbinding: doca_ctx_stop() returns DOCA_ERROR_IN_USE while bindings remain.

  3. Stop the converted DOCA context, check the return value and confirm Idle, progressing as required by DOCA Core.

  4. Destroy the backend I/O object with doca_kv_nvme_kernel_io_destroy(). Destroy the progress engine only after its contexts have been removed. Devices may remain available to other I/O contexts.

State Machine

Only the I/O object is a DOCA context. The device is synchronously created and destroyed; it does not have an independent Idle/Running state machine.

I/O context state

Application actions

Idle

Configure the task pool and callbacks, connect a progress engine, then start; or destroy an unused context.

Running

Bind/unbind devices, allocate and submit tasks, and progress completions on the owner thread.

Stopping / return to Idle

Follow DOCA Core stop semantics after all tasks and bindings have been released; destroy only after confirming Idle.

Limitations

  1. The backend covered by this release is the Linux NVMe kernel backend. Devices and I/O contexts from different backend specializations cannot be bound together.

  2. The public task interface supports Store, Retrieve and Exist. Delete and List are not exposed as DOCA Key-Value tasks.

  3. The NVMe kernel backend supports inline keys of at most 16 bytes, further restricted by the namespace's advertised maximum. Always use the queried maximum rather than assuming a fixed application key length.

  4. The namespace's maximum value length is not sufficient by itself to establish the host's transfer limit. Kernel, controller and memory-segmentation limits can reject a transfer below the advertised value maximum. Size value buffers and scatter/gather lists for the supported host path.

API Reference

The public interfaces are declared in doca_kv_dev.h, doca_kv_io.h, doca_kv_nvme_kernel_dev.h and doca_kv_nvme_kernel_io.h. Use generated API documentation matching the installed SDK release for complete signatures and return values.

Last updated: