DPDK-dev Archive on lore.kernel.org
 help / color / mirror / Atom feed
* [RFC 0/3] lib/fastmem: fast small-object allocator
@ 2026-05-25 10:36 Mattias Rönnblom
  2026-05-25 10:36 ` [RFC 1/3] doc: add fastmem programming guide Mattias Rönnblom
                   ` (4 more replies)
  0 siblings, 5 replies; 37+ messages in thread
From: Mattias Rönnblom @ 2026-05-25 10:36 UTC (permalink / raw)
  To: dev
  Cc: Morten Brørup, Konstantin Ananyev, Mattias Rönnblom,
	Yogaraj Baskaravel, Mattias Rönnblom

This RFC introduces fastmem, a general-purpose small-object allocator
for DPDK. It is intended to replace per-type mempools with a single
allocator that handles arbitrary sizes, grows on demand, and matches
mempool-level performance on the hot path.

Motivation
----------

DPDK applications commonly maintain many mempools — one per object
type (connections, sessions, timers, work items). Each must be sized
up front, wastes memory when over-provisioned, and cannot serve
objects of a different size. Fastmem eliminates this by accepting
arbitrary sizes at runtime, backed by a slab allocator that
repurposes memory across size classes as demand shifts.

Design
------

Three-layer architecture:

1. Backing memory: 128 MiB IOVA-contiguous memzones from EAL,
   reserved lazily (or pre-reserved for deterministic latency).

2. Slabs: 2 MiB, 2 MiB-aligned regions carved from memzones.
   The alignment enables O(1) slab lookup from any object pointer
   via bitmask — no radix tree or index structure. Slabs move
   freely between 18 power-of-2 size classes (8 B to 1 MiB).

3. Per-lcore caches: bounded LIFO stacks (no locks on the hot
   path). Cache misses trigger bulk transfers to/from the shared
   bin under a spinlock.

Key properties:

- Zero per-object metadata in the production build.
- NUMA-aware, with per-socket bins and free-slab pools.
- DMA-usable memory with O(1) virt-to-IOVA translation.
- Bulk alloc/free with all-or-nothing semantics.
- Backing memory never returned during lifetime (slabs recycled).
- Non-EAL threads supported (bypass cache, take bin lock).

API surface
-----------

  rte_fastmem_init / deinit
  rte_fastmem_reserve
  rte_fastmem_set_limit / get_limit
  rte_fastmem_alloc / alloc_socket
  rte_fastmem_alloc_bulk / alloc_bulk_socket
  rte_fastmem_free / free_bulk
  rte_fastmem_virt2iova
  rte_fastmem_cache_flush
  rte_fastmem_max_size / classes
  rte_fastmem_stats / stats_class / stats_lcore / stats_lcore_class
  rte_fastmem_stats_reset

All APIs are marked __rte_experimental.

Performance
-----------

The single-object hot path is roughly 2-3x the cost of mempool
and an order of magnitude faster than rte_malloc. Under
multi-lcore contention, fastmem scales similarly to mempool,
while rte_malloc collapses.

Limitations
-----------

- Maximum allocation: 1 MiB. Larger requests should use rte_malloc.
- Power-of-2 classes only; worst-case internal fragmentation ~50%.
- Backing memory not reclaimable short of deinit.

Future work
-----------

- Lcore-affine allocations (false-sharing-free by construction).
- Mempool ops driver for transparent drop-in use.
- Pre-resolved allocator handle binding size class and socket,
  eliminating per-call class lookup and enabling an inline
  cache-hit fast path.
- Debug mode (cookies, double-free detection, poison-on-free).
- Telemetry integration.
- EAL integration, allowing EAL-internal subsystems to use
  fastmem for their small-object allocations.

Mattias Rönnblom (3):
  doc: add fastmem programming guide
  lib: add fastmem library
  app/test: add fastmem test suite

 app/test/meson.build                  |    3 +
 app/test/test_fastmem.c               | 1682 +++++++++++++++++++++++++
 app/test/test_fastmem_perf.c          |  997 +++++++++++++++
 app/test/test_fastmem_profile.c       |  157 +++
 doc/api/doxy-api-index.md             |    1 +
 doc/api/doxy-api.conf.in              |    1 +
 doc/guides/prog_guide/fastmem_lib.rst |  301 +++++
 doc/guides/prog_guide/index.rst       |    1 +
 lib/fastmem/meson.build               |    6 +
 lib/fastmem/rte_fastmem.c             | 1486 ++++++++++++++++++++++
 lib/fastmem/rte_fastmem.h             |  644 ++++++++++
 lib/meson.build                       |    1 +
 12 files changed, 5280 insertions(+)
 create mode 100644 app/test/test_fastmem.c
 create mode 100644 app/test/test_fastmem_perf.c
 create mode 100644 app/test/test_fastmem_profile.c
 create mode 100644 doc/guides/prog_guide/fastmem_lib.rst
 create mode 100644 lib/fastmem/meson.build
 create mode 100644 lib/fastmem/rte_fastmem.c
 create mode 100644 lib/fastmem/rte_fastmem.h

-- 
2.43.0


^ permalink raw reply	[flat|nested] 37+ messages in thread

end of thread, other threads:[~2026-05-30 16:22 UTC | newest]

Thread overview: 37+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-05-25 10:36 [RFC 0/3] lib/fastmem: fast small-object allocator Mattias Rönnblom
2026-05-25 10:36 ` [RFC 1/3] doc: add fastmem programming guide Mattias Rönnblom
2026-05-25 10:36 ` [RFC 2/3] lib: add fastmem library Mattias Rönnblom
2026-05-27 14:22   ` Stephen Hemminger
2026-05-27 17:25     ` Mattias Rönnblom
2026-05-25 10:36 ` [RFC 3/3] app/test: add fastmem test suite Mattias Rönnblom
2026-05-26  8:57   ` [RFC v2 0/3] lib/fastmem: fast small-object allocator Mattias Rönnblom
2026-05-26  8:57     ` [RFC v2 1/3] doc: add fastmem programming guide Mattias Rönnblom
2026-05-26  8:57     ` [RFC v2 2/3] lib: add fastmem library Mattias Rönnblom
2026-05-26 13:23       ` Stephen Hemminger
2026-05-27 10:12         ` Mattias Rönnblom
2026-05-27 10:18           ` Bruce Richardson
2026-05-27 11:17             ` Mattias Rönnblom
2026-05-27 11:17             ` Morten Brørup
2026-05-27 11:29               ` Mattias Rönnblom
2026-05-27 12:03                 ` Morten Brørup
2026-05-26  8:57     ` [RFC v2 3/3] app/test: add fastmem test suite Mattias Rönnblom
2026-05-27 17:30       ` [RFC v3 0/3] lib/fastmem: fast small-object allocator Mattias Rönnblom
2026-05-27 17:30         ` [RFC v3 1/3] doc: add fastmem programming guide Mattias Rönnblom
2026-05-30  9:26           ` [RFC v4 0/3] lib/fastmem: fast small-object allocator Mattias Rönnblom
2026-05-30  9:26             ` [RFC v4 1/3] doc: add fastmem programming guide Mattias Rönnblom
2026-05-30  9:26             ` [RFC v4 2/3] lib: add fastmem library Mattias Rönnblom
2026-05-30  9:26             ` [RFC v4 3/3] app/test: add fastmem test suite Mattias Rönnblom
2026-05-27 17:30         ` [RFC v3 2/3] lib: add fastmem library Mattias Rönnblom
2026-05-28  9:11           ` Morten Brørup
2026-05-28 14:45             ` Varghese, Vipin
2026-05-28 19:56               ` Morten Brørup
2026-05-29 14:29                 ` Varghese, Vipin
2026-05-30 16:22                 ` Mattias Rönnblom
2026-05-27 17:30         ` [RFC v3 3/3] app/test: add fastmem test suite Mattias Rönnblom
2026-05-28  9:02         ` [RFC v3 0/3] lib/fastmem: fast small-object allocator Morten Brørup
2026-05-25 14:30 ` [RFC " Stephen Hemminger
2026-05-25 19:39   ` Mattias Rönnblom
2026-05-25 22:18     ` Stephen Hemminger
2026-05-26  7:01       ` Mattias Rönnblom
2026-05-25 18:36 ` Stephen Hemminger
2026-05-25 19:43   ` Mattias Rönnblom

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox