Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -676,6 +676,9 @@ check_struct_has_member("struct mptcp_info" mptcpi_subflows "linux/mptcp.h" HAVE
# find resolv library if available
find_package(resolv)

# find rt library if available (shm_open/shm_unlink live there on older glibc)
find_package(rt)

if(ENABLE_DOCS OR ENABLE_AUTEST)
find_package(Python3 REQUIRED)
find_program(UV uv REQUIRED)
Expand Down
33 changes: 33 additions & 0 deletions cmake/Findrt.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#######################
#
# Licensed to the Apache Software Foundation (ASF) under one or more contributor license
# agreements. See the NOTICE file distributed with this work for additional information regarding
# copyright ownership. The ASF licenses this file to you under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software distributed under the License
# is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
# or implied. See the License for the specific language governing permissions and limitations under
# the License.
#
#######################

# librt provides shm_open()/shm_unlink() on older glibc (e.g. CentOS 7 / glibc 2.17).
# glibc >= 2.34 folds them into libc and macOS has them in libc, so the library is
# absent there; the imported target is then an empty no-op.

find_library(rt_LIBRARY rt)

mark_as_advanced(rt_FOUND rt_LIBRARY)

include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(rt REQUIRED_VARS rt_LIBRARY)

# Always provide the target; only carry a link dependency when librt exists.
add_library(rt::rt INTERFACE IMPORTED)
if(rt_FOUND)
target_link_libraries(rt::rt INTERFACE ${rt_LIBRARY})
endif()
83 changes: 83 additions & 0 deletions doc/admin-guide/files/records.yaml.en.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3003,6 +3003,89 @@ RAM Cache
Compression runs on task threads. To use more cores for RAM cache
compression, increase :ts:cv:`proxy.config.task_threads`.

.. _admin-cache-shm-fast-restart:

Shared Memory Fast Restart
==========================

|TS| can optionally keep the cache directory -- the in-memory index that maps
cached objects to their location on disk -- in POSIX shared memory so that it
survives a process restart. On a normal start the directory is read from disk
and, for a large cache, rebuilt in memory before the cache comes online. When
this feature is enabled and the previous instance shut down cleanly, the new
instance attaches the existing shared memory segments and skips that work,
bringing the cache online much faster.

The shared memory directory is only an optimization for restart time; the
on-disk cache always remains the source of truth. A new instance discards the
segments and falls back to reading the directory from disk whenever they cannot
be trusted, including when:

- the previous instance did not shut down cleanly (for example, it crashed),
- the on-disk storage layout described by :file:`storage.yaml` changed,
- the |TS| binary's directory structures changed (an ABI mismatch, such as
after an upgrade), or
- the shared memory schema version changed.

Segments left over from a crash can be inspected or removed with
``traffic_ctl cache shm status`` and ``traffic_ctl cache shm clear``, which act
directly on the shared memory objects whether or not |TS| is running.

.. note::

This is an experimental feature, disabled by default. All of its settings
take effect only on a restart of |TS|.

.. ts:cv:: CONFIG proxy.config.cache.shm.enabled INT 0

Enables the shared memory cache directory described above. When ``0`` (the
default), the cache directory is always read from disk on start.

.. ts:cv:: CONFIG proxy.config.cache.shm.name_prefix STRING ats

The word used to name the POSIX shared memory objects, which on Linux appear
under ``/dev/shm``. Set only the middle word (default ``ats``); |TS| frames it
as ``/<word>-`` so the leading ``/`` that POSIX requires and the trailing
``-`` separator cannot be mis-typed. With the default the control segment is
named ``/ats-control`` and each per-stripe directory segment ``/ats-s<N>``
(for example ``/ats-s0``). Any stray framing characters are trimmed, so a
value carried over from an older release (such as ``/ats-``) still resolves to
the same names. Give each |TS| instance sharing a host a distinct word so
their segments do not collide.

Renaming this value does not remove segments created under the old prefix:
|TS| only manages segments under the *current* prefix, so the old ``/dev/shm``
objects linger until cleared manually with ``traffic_ctl cache shm clear
--prefix <old-word>`` (or a host reboot).

.. ts:cv:: CONFIG proxy.config.cache.shm.use_hugepages INT 0

When enabled (``1``), |TS| attempts to back the shared memory directory with
huge pages to reduce TLB pressure. This requires the shared memory to be
eligible for huge pages (for example, ``/dev/shm`` mounted with huge page
support on Linux). When it is not, |TS| logs a debug message under the
``cache_shm`` tag and transparently falls back to ordinary pages, so
enabling this is always safe.

.. ts:cv:: CONFIG proxy.config.cache.shm.purge_stale_on_start INT 0

When enabled (``1``) and :ts:cv:`proxy.config.cache.shm.enabled` is ``0``,
|TS| removes any leftover shared memory segments for
:ts:cv:`proxy.config.cache.shm.name_prefix` at startup (the ``<prefix>control``
segment and the per-stripe segments it lists). This guards against two
hazards of running with the feature disabled after it had been enabled:

- the leftover segments keep consuming memory (for example ``/dev/shm`` on
Linux) even though the disabled instance never reads them, and
- a later run with the feature re-enabled would otherwise fast-attach a
directory that went stale while |TS| ran disabled and wrote only to disk.

The purge is skipped if a live process still owns the segments (a concurrent
instance using the same prefix), and it never blocks startup. It has no
effect when the feature is enabled, when no ``<prefix>control`` segment
exists, or when set to ``0`` (the default). ``traffic_ctl cache shm clear``
performs the same cleanup on demand.

.. _admin-heuristic-expiration:

Heuristic Expiration
Expand Down
1 change: 1 addition & 0 deletions doc/developer-guide/cache-architecture/index.en.rst
Original file line number Diff line number Diff line change
Expand Up @@ -41,5 +41,6 @@ understanding and modifying the source.
api-functions.en
consistency.en
ram-cache.en
shm-fast-restart.en
cache-tool.en
tiered-storage.en
Loading