Skip to content

Commit b457785

Browse files
committed
Add decision_threads configuration
The worker-pool roadmap needs a decision_threads setting before the dispatcher and worker activation changes land. Without the knob, LMDB reader sizing and resource validation still used a fixed planned reader cap instead of the administrator-selected future worker count. Add decision_threads to daemon configuration with a default of one, validate it against online CPU count, the internal worker cap, LMDB reader reservations, estimated fixed worker memory, and file descriptor capacity, and use the value when sizing LMDB max readers. Report the configured value in state output and leave a TODO for a separate active-worker field if the future worker pool cannot resize on SIGHUP. Add daemon_config_test coverage for default normalization, invalid bounds, and LMDB reader limit calculation.
1 parent 6d79931 commit b457785

10 files changed

Lines changed: 477 additions & 28 deletions

File tree

doc/fapolicyd.conf.5

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,18 @@ This option gives fapolicyd a scheduler boost. The number can be from 0 to 20. T
1818
.B q_size
1919
This option is used to control how big of an internal queue that fapolicyd will use. If requests come in faster than fapolicyd can answer, the queue holds the pending requests. If the do_stat_report is enabled, when fapolicyd shutsdown it will provide some statistics which includes maximum queue depth used. This information can be used to help tune performance. The default value is 800. Also note, this value means that fapolicyd gets a file descriptor for that entry. There is an rlimit cap controlled by systemd's LimitNOFILE setting for the service. You may also need to adjust it if the q_size exceeds it's value.
2020

21+
.TP
22+
.B decision_threads
23+
This option controls how many decision worker threads fapolicyd is configured
24+
to use. The default value is 1. The value must be at least 1, no larger than
25+
the number of online CPU cores, and no larger than the daemon's supported
26+
maximum. Startup validation also checks that the configured worker count fits
27+
the LMDB reader-slot reservation, estimated fixed worker memory budget, and
28+
file descriptor budget implied by
29+
.BR q_size .
30+
This setting is applied when the daemon starts; restart fapolicyd after
31+
changing it.
32+
2133
.TP
2234
.B uid
2335
This can be a number or an account name which fapolicyd should switch to during startup. The default value is 0 because it is guaranteed to exist. But it is recommended to use the fapolicyd account if that exists.
@@ -188,8 +200,8 @@ The following settings require a daemon restart because they are consumed when
188200
long-lived runtime objects are created:
189201
.RS
190202
.IP \[bu] 2
191-
\fBq_size\fP, \fBsubj_cache_size\fP, and \fBobj_cache_size\fP size the event
192-
queue and caches.
203+
\fBq_size\fP, \fBdecision_threads\fP, \fBsubj_cache_size\fP, and
204+
\fBobj_cache_size\fP size the event queue, worker count, and caches.
193205
.IP \[bu]
194206
\fBuid\fP and \fBgid\fP control the daemon identity selected during startup.
195207
.IP \[bu]

doc/fapolicyd.state.5

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,10 @@ access.
9191
.B CPU cores
9292
The number of online processor cores reported by the system.
9393
.TP
94+
.B decision_threads
95+
The configured decision worker count from
96+
.BR fapolicyd.conf .
97+
.TP
9498
.B q_size
9599
The configured size of the internal event queue.
96100
.TP
@@ -109,8 +113,9 @@ This reflects the map size currently opened by the daemon, including any
109113
automatic resize applied for reload headroom.
110114
.TP
111115
.B Trust database max readers
112-
The configured LMDB reader-slot limit. This is sized for the planned decision
113-
worker cap plus maintenance readers.
116+
The configured LMDB reader-slot limit. This is sized for
117+
.B decision_threads
118+
plus maintenance readers.
114119
.SS Resource utilization
115120
.TP
116121
.B Trust database pages in use

init/fapolicyd.conf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
permissive = 0
77
nice_val = 14
88
q_size = 800
9+
decision_threads = 1
910
uid = fapolicyd
1011
gid = fapolicyd
1112
do_stat_report = 1

src/daemon/fapolicyd.c

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -461,12 +461,12 @@ static int reload_configuration(void)
461461

462462
/*
463463
* Remaining daemon_config fields require restart-time changes:
464-
* q_size, subj_cache_size, and obj_cache_size are consumed when the
465-
* event queue and caches are created. uid/gid, allow_filesystem_mark,
466-
* watch_fs, and ignore_mounts are applied while fanotify marks are
467-
* installed. db_max_size fixes the LMDB map when the database opens,
468-
* and report_interval is bound to the decision thread's timer. None
469-
* of these components support resizing in-place yet, so their
464+
* q_size, decision_threads, subj_cache_size, and obj_cache_size are
465+
* consumed when the event queue and caches are created. uid/gid,
466+
* allow_filesystem_mark, watch_fs, and ignore_mounts are applied while
467+
* fanotify marks are installed. db_max_size fixes the LMDB map when the
468+
* database opens, and report_interval is bound to the decision thread's
469+
* timer. None of these components support resizing in-place yet, so their
470470
* configuration stays static.
471471
*/
472472

@@ -957,6 +957,11 @@ void do_state_report(FILE *f, int shutdown)
957957

958958
fprintf(f, "\nResource configuration:\n");
959959
fprintf(f, "CPU cores: %ld\n", sysconf(_SC_NPROCESSORS_ONLN));
960+
fprintf(f, "decision_threads: %u\n", config.decision_threads);
961+
/*
962+
* TODO: If worker-pool activation cannot resize decision threads on
963+
* SIGHUP, add a separate active worker count here.
964+
*/
960965
fprintf(f, "q_size: %u\n", config.q_size);
961966
fanotify_defer_config_report(f);
962967
do_cache_config_report(f);
@@ -1219,10 +1224,10 @@ int main(int argc, const char *argv[])
12191224
limit.rlim_max = RLIM_INFINITY;
12201225
setrlimit(RLIMIT_FSIZE, &limit);
12211226
getrlimit(RLIMIT_NOFILE, &limit);
1222-
if (limit.rlim_max >= 16384)
1227+
if (limit.rlim_max >= DAEMON_CONFIG_MIN_NOFILE)
12231228
limit.rlim_cur = limit.rlim_max;
12241229
else
1225-
limit.rlim_max = limit.rlim_cur = 16384;
1230+
limit.rlim_max = limit.rlim_cur = DAEMON_CONFIG_MIN_NOFILE;
12261231

12271232
if (setrlimit(RLIMIT_NOFILE, &limit))
12281233
msg(LOG_WARNING, "Can't increase file number rlimit - %s",

src/library/conf.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ typedef struct conf
4646
unsigned int permissive;
4747
unsigned int nice_val;
4848
unsigned int q_size;
49+
unsigned int decision_threads;
4950
uid_t uid;
5051
gid_t gid;
5152
unsigned int do_stat_report;

0 commit comments

Comments
 (0)