Skip to content

RFC Fast restart with many hugepages

Dmitry Kozlyuk dpdk-dev 1 version In review

Get series with b4
b4 am [email protected]

Versions newest first

  1. v1 RFC Latest6 patches 10 repliesIn review

Patches in v1 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/6doc: add hugepage mapping detailsdoc/guides/prog_guide/env_abstraction_layer.rst+76 -90 replies
1/6doc: add hugepage mapping detailsdoc/guides/prog_guide/env_abstraction_layer.rst+76 -91 reply
2/6mem: add dirty malloc element supportlib/eal/common/malloc_elem.c lib/eal/common/malloc_elem.h lib/eal/common/malloc_heap.c +2 more+60 -200 replies
2/6app/test: add allocator performance benchmarkapp/test/meson.build app/test/test_malloc_perf.c+176 -05 replies
3/6eal: refactor --huge-unlink storagelib/eal/common/eal_common_options.c lib/eal/common/eal_internal_cfg.h lib/eal/linux/eal_memalloc.c +1 more+17 -90 replies
3/6mem: add dirty malloc element supportlib/eal/common/malloc_elem.c lib/eal/common/malloc_elem.h lib/eal/common/malloc_heap.c +2 more+60 -201 reply
4/6eal/linux: allow hugepage file reuselib/eal/common/eal_internal_cfg.h lib/eal/linux/eal_hugepage_info.c lib/eal/linux/eal_memalloc.c+140 -780 replies
4/6eal: refactor --huge-unlink storagelib/eal/common/eal_common_options.c lib/eal/common/eal_internal_cfg.h lib/eal/linux/eal_memalloc.c +1 more+17 -91 reply
5/6eal: allow hugepage file reuse with --huge-unlinkdoc/guides/linux_gsg/linux_eal_parameters.rst doc/guides/prog_guide/env_abstraction_layer.rst doc/guides/rel_notes/release_22_03.rst +1 more+69 -70 replies
5/6eal/linux: allow hugepage file reuselib/eal/common/eal_internal_cfg.h lib/eal/linux/eal_hugepage_info.c lib/eal/linux/eal_memalloc.c+200 -841 reply
6/6app/test: add allocator performance benchmarkapp/test/meson.build app/test/test_malloc_perf.c+176 -00 replies
6/6eal: extend --huge-unlink for hugepage file reusedoc/guides/linux_gsg/linux_eal_parameters.rst doc/guides/prog_guide/env_abstraction_layer.rst doc/guides/rel_notes/release_22_03.rst +1 more+69 -71 reply

Reviews trailers per patch

6 of 12 patches have a Reviewed-by or Acked-by of their own; the series has one for all of them.

PatchViacheslav OvsiienkoThomas MonjalonAaron ConoleBruce RichardsonAnatoly Burakov
SeriesR-b R-b A-b A-b A-b A-b A-b A-b A-b A-b A-b A-b R-b A-b R-b A-b
1/6
1/6
2/6R-b A-b
2/6R-b A-b
3/6
3/6
4/6A-b
4/6A-b
5/6
5/6
6/6R-b A-b
6/6R-b A-b

Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes. Scroll the table sideways for all 5 reviewers.

Read the v1 thread

Cover letter [RFC PATCH 0/6] Fast restart with many hugepages

This patchset is a new design and implementation of [1].

# Problem Statement

Large allocations that involve mapping new hugepages are slow. This is problematic, for example, in the following use case. A single-process application allocates ~1TB of mempools at startup. Sometimes the app needs to restart as quick as possible. Allocating the hugepages anew takes as long as 15 seconds, while the new process could just pick up all the memory left by the old one (reinitializing the contents as needed).

Almost all of mmap(2) time spent in the kernel
is clearing the memory, i.e. filling it with zeros.
This is done if a file in hugetlbfs is mapped
for the first time system-wide, i.e. a hugepage is committed to prevent data leaks from the previous users of the same hugepage. For example, mapping 32 GB from a new file may take 2.16 seconds, while mapping the same pages again takes only 0.3 ms. Security put aside, e.g. when the environment is controlled, this effort is wasted for the memory intended for DMA, because its content will be overwritten anyway.

Linux EAL explicitly removes hugetlbfs files at initialization and before mapping to force the kernel clear the memory. This allows the memory allocator to clean memory on only on freeing.

# Solution

Add a new mode allowing EAL to remap existing hugepage files. While it is intended to make restarts faster in the first place, it makes any startup faster except the cold one
(with no existing files).

It is the administrator who accepts security risks implied by reusing hugepages.
The new mode is an opt-in and a warning is logged.

The feature is Linux-only as it is related
to mapping hugepages from files which only Linux does. It is inherently incompatible with --in-memory, for --huge-unlink see below.

There is formally no breakage of API contract,
but there is a behavior change in the new mode:
rte_malloc*() and rte_memzone_reserve*() may return dirty memory (previously they were returning clean memory from free heap elements). Their contract has always explicitly allowed this,
but still there may be users relying on the traditional behavior. Such users will need to fix their code to use the new mode.

# Implementation

## User Interface

There is --huge-unlink switch in the same area to remove hugepage files before mapping them. It is infeasible to use with the new mode, because the point is to keep hugepage files for fast future restarts. Extend --huge-unlink option to represent only valid combinations:

* --huge-unlink=existing OR no option (for compatibility):
unlink files at initialization
and before opening them as a precaution.

* --huge-unlink=always OR just --huge-unlink (for compatibility):
same as above + unlink created files before mapping.

* --huge-unlink=never:
the new mode, do not unlink hugepages files, reuse them.

This option was always Linux-only, but it is kept as common in case there are users who expect it to be a no-op on other systems. (Adding a separate --huge-reuse option was also considered, but there is no obvious benefit and more combinations to test.)

## EAL

If a memseg is mapped dirty, it is marked with RTE_MEMSEG_FLAG_DIRTY so that the memory allocator may clear the memory if need be. See patch 4/6 description for details.

The memory manager tracks whether an element is clean or dirty. If rte_zmalloc*() allocates from a dirty element,
the memory is cleared before handling it to the user.
On freeing, the allocator joins adjacent free elements, but in the new mode it may not be feasible to clear the free memory if the joint element is dirty (contains dirty parts).
In any case, memory will be cleared only once,
either on freeing or on allocation. See patch 2/6 for details. Patch 6/6 adds a benchmark to see how time is distributed between allocation and freeing in different modes.

Besides clearing memory, each mmap() call takes some time which adds up. EAL does one call per hugepage, 1024 calls for 1 TB may take ~300 ms. It does so in order to be able to unmap the segments one by one. However, segments from initial allocation (-m) are never unmapped. Ideally, initial allocation should take one mmap() call per memory type (i.e. per NUMA node per page size) if --single-file-segments is used. This further optimization is not implemented in current version.

[1]: http://inbox.dpdk.org/dev/[email protected]/

Dmitry Kozlyuk (6):
doc: add hugepage mapping details
mem: add dirty malloc element support
eal: refactor --huge-unlink storage eal/linux: allow hugepage file reuse
eal: allow hugepage file reuse with --huge-unlink app/test: add allocator performance benchmark

 app/test/meson.build                          |   2 +
 app/test/test_malloc_perf.c                   | 174 ++++++++++++++++++
 doc/guides/linux_gsg/linux_eal_parameters.rst |  21 ++-
 .../prog_guide/env_abstraction_layer.rst      |  94 +++++++++-
 doc/guides/rel_notes/release_22_03.rst        |   7 +
 lib/eal/common/eal_common_options.c           |  46 ++++-
 lib/eal/common/eal_internal_cfg.h             |  10 +-
 lib/eal/common/malloc_elem.c                  |  22 ++-
 lib/eal/common/malloc_elem.h                  |  11 +-
 lib/eal/common/malloc_heap.c                  |  18 +-
 lib/eal/common/rte_malloc.c                   |  21 ++-
 lib/eal/include/rte_memory.h                  |   8 +-
 lib/eal/linux/eal_hugepage_info.c             |  59 ++++--
 lib/eal/linux/eal_memalloc.c                  | 164 ++++++++++-------
 lib/eal/linux/eal_memory.c                    |   2 +-
 15 files changed, 537 insertions(+), 122 deletions(-)
 create mode 100644 app/test/test_malloc_perf.c
Signature · 1 line
2.25.1