Skip to content

Commit 7ff21b6

Browse files
committed
Prepare trust DB read concurrency
Trust database decisions used a process-global LMDB read transaction and cursor guarded by update_lock. That made future decision readers share mutable cursor state and serialize all lookups behind the update mutex; LMDB was also capped at four readers with no metric when reader slots were full. The fix opens private short-lived LMDB read transactions and cursors for trust lookups under a shared read lock, while trust DB rebuild and update paths keep exclusive writer ownership. The DBI is initialized with the environment, max readers are sized for the planned 32-worker cap plus maintenance readers, and resettable metrics report cheap lookup count and reader-slots-full counters. Lookup latency stays in the armed decision timing report through the existing trust_db_lookup total, lock_wait, and read stage rows instead of adding per-lookup clock reads to normal metrics collection. Tests add concurrent trust DB lookup coverage and metrics reset/report checks in trustdb_lmdb_test, including assertions that lookup average/max timing fields are absent from the metrics report.
1 parent e8e6c8e commit 7ff21b6

11 files changed

Lines changed: 573 additions & 157 deletions

doc/fapolicyd.metrics.5

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,19 @@ match the current event and therefore had to be evicted before reuse.
110110
.B Object evictions
111111
The number of object cache evictions and the eviction percentage relative to
112112
object cache hits.
113+
.SH Trust database lookups
114+
.TP
115+
.B Trust DB lookups
116+
The number of trust database lookup attempts since the last metrics reset.
117+
.TP
118+
.B Trust DB reader slots full
119+
The number of lookup attempts that could not open an LMDB read transaction
120+
because all LMDB reader slots were in use.
121+
.PP
122+
Trust database lookup latency is reported by
123+
.BR fapolicyd.timing (5)
124+
only while manual timing collection is armed, so normal metrics collection does
125+
not add per-lookup clock reads.
113126
.SH Rule hit counts
114127
.TP
115128
.B Hits/rule

doc/fapolicyd.state.5

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,10 @@ The configured number of entries in the object cache.
8989
.TP
9090
.B Trust database max pages
9191
The configured maximum LMDB page count for the trust database.
92+
.TP
93+
.B Trust database max readers
94+
The configured LMDB reader-slot limit. This is sized for the planned decision
95+
worker cap plus maintenance readers.
9296
.SS Resource utilization
9397
.TP
9498
.B Trust database pages in use

doc/fapolicyd.timing.5

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -505,7 +505,7 @@ SHA-style file digest collection through
505505
.B *:trust_db_lookup:total
506506
Total trust database lookup through
507507
.BR check_trust_database ().
508-
This includes update-thread lock wait, long-term LMDB read setup, the primary
508+
This includes update-thread lock wait, per-lookup LMDB read setup, the primary
509509
LMDB lookup, optional hash work requested by trust lookup, and the top-level
510510
.I /usr
511511
symlink retry path.
@@ -516,8 +516,9 @@ setup. This is a future multi-decision-thread contention signal.
516516
.TP
517517
.B *:trust_db_lookup:read
518518
LMDB read setup and trust database read work after the update-thread lock is
519-
held. This currently includes the primary lookup, optional hash work requested
520-
by trust lookup, the top-level
519+
held. This currently includes per-lookup LMDB read transaction and cursor
520+
setup, the primary lookup, optional hash work requested by trust lookup, the
521+
top-level
521522
.I /usr
522523
symlink retry path, and read cleanup.
523524
.TP

src/daemon/fapolicyd.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1012,6 +1012,7 @@ void do_metrics_report_reset(FILE *f, int reset)
10121012
decision_report_metrics_reset(f, reset);
10131013
fanotify_metrics_report_reset(f, reset);
10141014
do_cache_metrics_report_reset(f, reset);
1015+
database_metrics_report_reset(f, reset);
10151016
fputs("\n", f);
10161017
fputs("Rule hit counts:\n", f);
10171018
policy_rule_hits_report_reset(f, reset);

0 commit comments

Comments
 (0)