Skip to content

Commit ed9f1f4

Browse files
committed
Make trust DB auto sizing the default
Change the default daemon configuration to auto sizing with the existing baseline size, and make numeric db_max_size values explicitly disable automatic resizing. Update the shipped configuration and man page so installed defaults match runtime defaults.
1 parent da93b8c commit ed9f1f4

6 files changed

Lines changed: 29 additions & 22 deletions

File tree

doc/fapolicyd.conf.5

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,10 @@ This option controls whether (1) or not (0) fapolicyd should add subject and obj
3838
.B db_max_size
3939
This option controls how many megabytes to allow the trust database to grow to.
4040
If you have lots of packages installed, then you want to make it bigger. The
41-
default value is 100 megabytes. The special value "auto" tells the daemon to
42-
size the trust database based on current utilization whenever it starts or
43-
rebuilds the database. Auto sizing targets roughly 75% active database usage,
44-
keeps lower-utilization reload headroom for the current trust database
41+
default value is "auto", which tells the daemon to size the trust database
42+
based on current utilization whenever it starts or rebuilds the database. Auto
43+
sizing starts from a 100 megabyte baseline, targets roughly 75% active database
44+
usage, keeps lower-utilization reload headroom for the current trust database
4545
generation and the candidate generation being built, grows when needed, and
4646
shrinks conservatively when utilization is low.
4747

init/fapolicyd.conf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ uid = fapolicyd
1010
gid = fapolicyd
1111
do_stat_report = 1
1212
detailed_report = 1
13-
db_max_size = 100
13+
db_max_size = auto
1414
subj_cache_size = 4099
1515
obj_cache_size = 8191
1616
watch_fs = ext2,ext3,ext4,tmpfs,xfs,vfat,iso9660,btrfs

src/library/conf.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ typedef struct conf
5151
unsigned int do_stat_report;
5252
unsigned int detailed_report;
5353
unsigned int db_max_size;
54-
bool do_audit_db_sizing;
54+
bool do_auto_db_sizing;
5555
unsigned int subj_cache_size;
5656
unsigned int obj_cache_size;
5757
const char *watch_fs;

src/library/daemon-config.c

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -141,8 +141,8 @@ static void clear_daemon_config(conf_t *config)
141141
config->gid = 0;
142142
config->do_stat_report = 1;
143143
config->detailed_report = 1;
144-
config->db_max_size = 100;
145-
config->do_audit_db_sizing = false;
144+
config->db_max_size = get_default_db_max_size();
145+
config->do_auto_db_sizing = true;
146146
config->subj_cache_size = 4099;
147147
config->obj_cache_size = 8191;
148148
config->watch_fs = strdup("ext4,xfs,tmpfs");
@@ -504,15 +504,22 @@ static int detailed_report_parser(const struct nv_pair *nv, int line,
504504
static int db_max_size_parser(const struct nv_pair *nv, int line,
505505
conf_t *config)
506506
{
507-
// "auto" triggers utilisation‑based sizing, anything else
508-
// remains the legacy integer in MiB.
507+
unsigned int db_max_size = config->db_max_size;
508+
509+
// "auto" keeps utilization-based sizing enabled. A numeric value is an
510+
// explicit administrator override and keeps the legacy fixed MiB limit.
509511
if (strcmp(nv->value, "auto") == 0) {
510-
config->do_audit_db_sizing = true;
511512
config->db_max_size = get_default_db_max_size();
513+
config->do_auto_db_sizing = true;
512514
return 0;
513515
}
514516

515-
return unsigned_int_parser(&(config->db_max_size), nv->value, line);
517+
if (unsigned_int_parser(&db_max_size, nv->value, line))
518+
return 1;
519+
520+
config->db_max_size = db_max_size;
521+
config->do_auto_db_sizing = false;
522+
return 0;
516523
}
517524

518525
static int subj_cache_size_parser(const struct nv_pair *nv, int line,

src/library/database.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2426,7 +2426,7 @@ static int autosize_reload_preflight(conf_t *config)
24262426
return 0;
24272427
}
24282428

2429-
if (!config->do_audit_db_sizing) {
2429+
if (!config->do_auto_db_sizing) {
24302430
if (state.recommended_pages > state.map_pages)
24312431
msg(LOG_WARNING,
24322432
"db_max_size may be too small for safe reload: "
@@ -2914,21 +2914,21 @@ static void check_db_size(const conf_t *config)
29142914
state.allocated_percent);
29152915
if (state.allocated_percent > TRUST_DB_RELOAD_HIGHWATER_PERCENT &&
29162916
state.allocated_percent > state.active_percent) {
2917-
int priority = config->do_audit_db_sizing ? LOG_INFO :
2917+
int priority = config->do_auto_db_sizing ? LOG_INFO :
29182918
LOG_WARNING;
29192919

29202920
msg(priority,
29212921
"Trust database LMDB map high-water at %lu%% capacity "
29222922
"while active DB pages are at %lu%%",
29232923
state.allocated_percent, state.active_percent);
2924-
if (!config->do_audit_db_sizing)
2924+
if (!config->do_auto_db_sizing)
29252925
log_lmdb_state(LOG_WARNING,
29262926
"trust database size check", 0);
29272927
}
29282928

29292929
target_mb = autosize_effective_target_mb(&state,
29302930
AUTOSIZE_LIVE_INSPECTION);
2931-
if (config->do_audit_db_sizing) {
2931+
if (config->do_auto_db_sizing) {
29322932
if (target_mb > config->db_max_size) {
29332933
if (state.active_target_pages > state.map_pages)
29342934
msg(LOG_INFO,
@@ -2993,7 +2993,7 @@ static void database_resize_report(FILE *f, const conf_t *config)
29932993
unsigned int target_mb = 0;
29942994
int rc;
29952995

2996-
if (config == NULL || config->do_audit_db_sizing)
2996+
if (config == NULL || config->do_auto_db_sizing)
29972997
return;
29982998

29992999
rc = read_live_lmdb_sizing_state(&state);
@@ -4104,7 +4104,7 @@ static int create_database_for_generation(struct trust_db_generation *gen,
41044104
rc == WRITE_DB_MAP_FULL ? MDB_MAP_FULL : 0);
41054105

41064106
if (rc == WRITE_DB_MAP_FULL &&
4107-
config->do_audit_db_sizing && retries == 0) {
4107+
config->do_auto_db_sizing && retries == 0) {
41084108
int grown;
41094109

41104110
lock_update_thread();
@@ -4650,7 +4650,7 @@ int init_database(conf_t *config)
46504650
return 1;
46514651

46524652
/* One-shot utilisation-driven sizing */
4653-
if (config->do_audit_db_sizing &&
4653+
if (config->do_auto_db_sizing &&
46544654
autosize_database(config, AUTOSIZE_STARTUP_INSPECTION))
46554655
msg(LOG_INFO, "autosize: map size recomputed to %u MiB",
46564656
config->db_max_size);
@@ -5528,7 +5528,7 @@ static int do_reload_db(conf_t *config)
55285528
backend_close();
55295529

55305530
/* One-shot utilisation-driven sizing */
5531-
if (config->do_audit_db_sizing &&
5531+
if (config->do_auto_db_sizing &&
55325532
autosize_database(config, AUTOSIZE_LIVE_INSPECTION)) {
55335533
msg(LOG_INFO, "autosize: map size recomputed to %u MiB",
55345534
config->db_max_size);

src/tests/trustdb_lmdb_test.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -803,15 +803,15 @@ static int test_lmdb_manual_resize_report_is_gated(void)
803803
* administrator's numeric db_max_size, not LMDB's current file size.
804804
*/
805805
cfg.db_max_size = 1;
806-
cfg.do_audit_db_sizing = false;
806+
cfg.do_auto_db_sizing = false;
807807
CHECK(read_database_utilization_text(&cfg, report, sizeof(report)) == 0,
808808
116, "[ERROR:116] manual resize report failed");
809809
CHECK(strstr(report, "Trust database resize recommended: yes") != NULL,
810810
117, "[ERROR:117] manual resize recommendation missing");
811811
CHECK(strstr(report, "Trust database resize target:") != NULL,
812812
118, "[ERROR:118] manual resize target missing");
813813

814-
cfg.do_audit_db_sizing = true;
814+
cfg.do_auto_db_sizing = true;
815815
CHECK(read_database_utilization_text(&cfg, report, sizeof(report)) == 0,
816816
119, "[ERROR:119] auto resize report failed");
817817
CHECK(strstr(report, "Trust database resize recommended:") == NULL,

0 commit comments

Comments
 (0)