Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
5cba79e
Implement O(1) PKI index optimization using memory-mapped hash table
dwoz Apr 4, 2026
793de5e
Optimize PKI lookups with memory-mapped hash index
dwoz Apr 4, 2026
76aba93
Fix mmap PKI index slot_size mismatch
dwoz Apr 4, 2026
3b0a0d3
Add regression test for mmap size mismatch
dwoz Apr 4, 2026
3b35f12
Implement fallback and size safety for PKI index
dwoz Apr 4, 2026
b4e85d7
Fix cache driver signature and cleanup debug logs
dwoz Apr 4, 2026
03addfd
Improve PKI index stability and performance
dwoz Apr 5, 2026
21a1e59
Fix PKI index clustered paths and ownership
dwoz Apr 5, 2026
d1540d1
Fix PKI index package test failures and clustered environment support
dwoz Apr 5, 2026
eda985a
Fix minion discovery and compound matching issues
dwoz Apr 5, 2026
24b31ad
Add driver check before PKI index rebuild
dwoz Apr 5, 2026
293ccd6
Robustness fixes for mmap cache and cross-platform reliability
dwoz Apr 5, 2026
b2ead1e
Fix UnboundLocalError in salt/key.py by avoiding local salt.* imports
dwoz Apr 5, 2026
1454df6
Support multiple Master instances in same process and fix index permi…
dwoz Apr 6, 2026
8d828eb
Optimize mmap cache lifecycle and add multi-process locking
dwoz Apr 6, 2026
fc256ab
Optimize mmap cache lifecycle and robustify cross-platform locking
dwoz Apr 6, 2026
a054500
Add debug logging to list_all to diagnose macOS/Windows failures
dwoz Apr 6, 2026
3b25dfb
Relocate PKI index to cachedir and improve robustness
dwoz Apr 7, 2026
614d7b3
Add extensive debug logging to PKI index and mmap cache
dwoz Apr 7, 2026
f44ed94
Only use PKI index if explicitly enabled and remove debug logging
dwoz Apr 8, 2026
62ebdd2
Fix regressions in list_keys and localfs_key
dwoz Apr 8, 2026
60ac7a0
Restore list_keys signature and implement list_all fallback
dwoz Apr 8, 2026
5bb14d2
Fix CI regressions and support multi-master isolation
dwoz Apr 10, 2026
26e444d
Restore original key listing methods for maximum integration compatib…
dwoz Apr 10, 2026
ce7c022
Hard revert master.py and verify.py to master baseline
dwoz Apr 10, 2026
064e7cc
Fix syntax error and restore master baseline for default config
dwoz Apr 10, 2026
8c6a0bf
Fix linting errors and local imports
dwoz Apr 10, 2026
13d44ad
Fix undefined variable in salt/utils/pki.py
dwoz Apr 11, 2026
a72f38e
Final linting fix for localfs_key.py
dwoz Apr 11, 2026
eac2bf3
Fix linting error in verify tests
dwoz Apr 11, 2026
ffa0e63
Fix linting error in master.py
dwoz Apr 11, 2026
41abaea
Completely isolate PKI optimization and fix massive CI failure
dwoz Apr 11, 2026
b88f8fc
Complete revert of verify_env calls to match master baseline
dwoz Apr 11, 2026
613fe47
Revert saltutil.py and minions.py to master baseline
dwoz Apr 11, 2026
479d786
Work around lack of fcntl on windows
dwoz Apr 12, 2026
eca5095
Fix fileesystem issues on windows
dwoz Apr 13, 2026
6d5bb8d
Fix undefined errno in mmap_cache.py
dwoz Apr 13, 2026
b72fd98
Add Sphinx documentation and changelog for PKI optimization
dwoz Apr 13, 2026
7150cad
Add changelog for issue #68936
dwoz Apr 13, 2026
18616ba
Expand PKI index configuration reference
dwoz Apr 13, 2026
63a2bb5
Cleanup renamed changelog file
dwoz Apr 13, 2026
005245e
Add PKI index optimization guide and Performance section
dwoz Apr 13, 2026
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
1 change: 1 addition & 0 deletions changelog/68936.added.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Implemented an O(1) memory-mapped PKI index to optimize minion public key lookups. This optimization substantially reduces master disk I/O and publication overhead in large-scale environments by replacing linear directory scans with constant-time hash table lookups. The feature is opt-in via the `pki_index_enabled` master configuration setting.
1 change: 1 addition & 0 deletions doc/contents.rst
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ Salt Table of Contents
topics/api
topics/topology/index
topics/cache/index
topics/performance/index
topics/slots/index
topics/windows/index
topics/development/index
Expand Down
70 changes: 70 additions & 0 deletions doc/ref/configuration/master.rst
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,76 @@ following the Filesystem Hierarchy Standard (FHS) might set it to
pki_dir: /etc/salt/pki/master


.. conf_master:: pki_index_enabled

``pki_index_enabled``
---------------------

.. versionadded:: 3009.0

Default: ``False``

Enable the O(1) PKI index optimization. This uses a memory-mapped hash table
to speed up minion public key lookups, which can substantially decrease
master publish times and authentication overhead in large environments.

.. code-block:: yaml

pki_index_enabled: True

.. conf_master:: pki_index_size

``pki_index_size``
------------------

.. versionadded:: 3009.0

Default: ``1000000``

The number of slots in the PKI index. For best performance and minimal
collisions, this should be set to approximately 2x your total minion count.
This value applies to each shard if sharding is enabled.

.. code-block:: yaml

pki_index_size: 1000000

.. conf_master:: pki_index_shards

``pki_index_shards``
--------------------

.. versionadded:: 3009.0

Default: ``1``

The number of shards to split the PKI index across. Sharding allows the index
to span multiple memory-mapped files, which can improve concurrency and
performance in extremely large environments or on filesystems with specific
locking characteristics.

.. code-block:: yaml

pki_index_shards: 1

.. conf_master:: pki_index_slot_size

``pki_index_slot_size``
-----------------------

.. versionadded:: 3009.0

Default: ``128``

The size in bytes of each slot in the PKI index. This must be large enough
to hold your longest minion ID plus approximately 10 bytes of internal
overhead (state information and separators).

.. code-block:: yaml

pki_index_slot_size: 128


.. conf_master:: cluster_id

``cluster_id``
Expand Down
1 change: 1 addition & 0 deletions doc/ref/runners/all/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ runner modules
net
network
pillar
pki
queue
reactor
salt
Expand Down
9 changes: 9 additions & 0 deletions doc/ref/runners/all/salt.runners.pki.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
.. _all-salt.runners.pki:

================
salt.runners.pki
================

.. automodule:: salt.runners.pki
:members:
:undoc-members:
13 changes: 13 additions & 0 deletions doc/topics/performance/index.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
.. _performance:

===========
Performance
===========

This section covers various performance optimizations and scaling considerations
for Salt.

.. toctree::
:maxdepth: 1

pki_index
52 changes: 52 additions & 0 deletions doc/topics/performance/pki_index.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
.. _pki_index:

====================
PKI Index Operations
====================

The PKI index is an optional, high-performance optimization designed for Salt
environments with a large number of minions.

Overview
========

By default, the Salt Master performs linear directory scans to find minion
public keys during authentication and job publication. As the number of minions
grows into the thousands, these disk I/O operations can become a significant
bottleneck.

The PKI index replaces these linear scans with a constant-time O(1) lookup
using a memory-mapped hash table. This substantially reduces disk I/O and
improves Master responsiveness.

Enabling the Index
==================

To enable the PKI index, add the following to your Master configuration file:

.. code-block:: yaml
pki_index_enabled: True
Configuration
=============

While the default settings work for most environments, you can tune the index
using these options:

* :conf_master:`pki_index_size`: The number of slots in the hash table (default: 1,000,000).
* :conf_master:`pki_index_slot_size`: The size of each slot in bytes (default: 128).

Monitoring and Management
=========================

You can check the status of your PKI index or force a manual rebuild using the
:ref:`PKI runner <all-salt.runners.pki>`:

.. code-block:: bash
# Check index status and load factor
salt-run pki.status
# Manually rebuild the index from the filesystem
salt-run pki.rebuild_index
30 changes: 30 additions & 0 deletions salt/cache/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,36 @@ def list(self, bank):
fun = f"{self.driver}.list"
return self.modules[fun](bank, **self.kwargs)

def list_all(self, bank, include_data=False):
"""
Lists all entries with their data from the specified bank.
This is more efficient than calling list() + fetch() for each entry.

:param bank:
The name of the location inside the cache which will hold the key
and its associated data.

:param include_data:
Whether to include the full data for each entry. For some drivers
(like localfs_key), setting this to False avoids expensive disk reads.

:return:
A dict of {key: data} for all entries in the bank. Returns an empty
dict if the bank doesn't exist or the driver doesn't support list_all.

:raises SaltCacheError:
Raises an exception if cache driver detected an error accessing data
in the cache backend (auth, permissions, etc).
"""
fun = f"{self.driver}.list_all"
if fun in self.modules:
return self.modules[fun](bank, include_data=include_data, **self.kwargs)
else:
# Fallback for drivers that don't implement list_all
raise AttributeError(
f"Cache driver '{self.driver}' does not implement list_all"
)

def contains(self, bank, key=None):
"""
Checks if the specified bank contains the specified key.
Expand Down
Loading
Loading