From 0b27b8f35026f1770e968512fba1396d683d1b5f Mon Sep 17 00:00:00 2001 From: Fabian Keil Date: Mon, 29 Jun 2026 14:02:25 +0200 Subject: [PATCH 1/2] geom/eli: Let g_eli_alloc_data() count the attempted data allocations ... and failures. Obtained from: ElectroBSD --- sys/geom/eli/g_eli.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/sys/geom/eli/g_eli.c b/sys/geom/eli/g_eli.c index 7a1d217eb914..d376fe0e163a 100644 --- a/sys/geom/eli/g_eli.c +++ b/sys/geom/eli/g_eli.c @@ -107,6 +107,12 @@ SYSCTL_BOOL(_kern_geom_eli, OID_AUTO, unmapped_io, CTLFLAG_RDTUN, static int g_eli_alloc_sz; SYSCTL_UINT(_kern_geom_eli, OID_AUTO, use_uma_bytes, CTLFLAG_RD, &g_eli_alloc_sz, 0, "Use uma(9) for allocations of this size or smaller."); +static uint64_t g_eli_attempted_data_allocations = 0; +SYSCTL_U64(_kern_geom_eli, OID_AUTO, attempted_data_allocations, CTLFLAG_RD, + &g_eli_attempted_data_allocations, 0, "Number of attempted data allocations."); +static uint64_t g_eli_failed_data_allocations = 0; +SYSCTL_U64(_kern_geom_eli, OID_AUTO, failed_data_allocations, CTLFLAG_RD, + &g_eli_failed_data_allocations, 0, "Number of failed data allocations."); static struct sx g_eli_umalock; /* Controls changes to UMA zone. */ SX_SYSINIT(g_eli_umalock, &g_eli_umalock, "GELI UMA"); @@ -974,6 +980,7 @@ bool g_eli_alloc_data(struct bio *bp, int sz) { + atomic_add_64(&g_eli_attempted_data_allocations, 1); KASSERT(sz <= g_eli_alloc_sz || (bp->bio_flags & BIO_SWAP) == 0, ("BIO_SWAP request for %d bytes exceeds the precalculated buffer" " size (%d)", sz, g_eli_alloc_sz)); @@ -983,13 +990,16 @@ g_eli_alloc_data(struct bio *bp, int sz) if (bp->bio_driver2 != NULL) { bp->bio_pflags |= G_ELI_UMA_ALLOC; atomic_add_int(&g_eli_umaoutstanding, 1); - } + } else + atomic_add_64(&g_eli_failed_data_allocations, 1); if (bp->bio_driver2 != NULL || (bp->bio_flags & BIO_SWAP) != 0) return (bp->bio_driver2 != NULL); } bp->bio_pflags &= ~(G_ELI_UMA_ALLOC); bp->bio_driver2 = malloc(sz, M_ELI, g_eli_blocking_malloc ? M_WAITOK : M_NOWAIT); + if (bp->bio_driver2 == NULL) + atomic_add_64(&g_eli_failed_data_allocations, 1); return (bp->bio_driver2 != NULL); } -- 2.53.0 From 37c1241002b1016361929fe74459c2590c1a68e6 Mon Sep 17 00:00:00 2001 From: Fabian Keil Date: Mon, 29 Jun 2026 16:42:23 +0200 Subject: [PATCH 2/2] geom/eli: Add sysctl to specify a g_eli_alloc_data() failure probability Obtained from: ElectroBSD --- sys/geom/eli/g_eli.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/sys/geom/eli/g_eli.c b/sys/geom/eli/g_eli.c index d376fe0e163a..2bf691a7f632 100644 --- a/sys/geom/eli/g_eli.c +++ b/sys/geom/eli/g_eli.c @@ -113,6 +113,9 @@ SYSCTL_U64(_kern_geom_eli, OID_AUTO, attempted_data_allocations, CTLFLAG_RD, static uint64_t g_eli_failed_data_allocations = 0; SYSCTL_U64(_kern_geom_eli, OID_AUTO, failed_data_allocations, CTLFLAG_RD, &g_eli_failed_data_allocations, 0, "Number of failed data allocations."); +static u_int g_eli_alloc_failure_probability = 0; +SYSCTL_UINT(_kern_geom_eli, OID_AUTO, allocation_failure_probability, CTLFLAG_RWTUN, + &g_eli_alloc_failure_probability, 0, "g_eli_alloc_data() failure probability."); static struct sx g_eli_umalock; /* Controls changes to UMA zone. */ SX_SYSINIT(g_eli_umalock, &g_eli_umalock, "GELI UMA"); @@ -981,6 +984,15 @@ g_eli_alloc_data(struct bio *bp, int sz) { atomic_add_64(&g_eli_attempted_data_allocations, 1); + if (g_eli_alloc_failure_probability != 0) { + u_int random_value; + + random_value = arc4random() % 100; + if (random_value < g_eli_alloc_failure_probability) { + atomic_add_64(&g_eli_failed_data_allocations, 1); + return false; + } + } KASSERT(sz <= g_eli_alloc_sz || (bp->bio_flags & BIO_SWAP) == 0, ("BIO_SWAP request for %d bytes exceeds the precalculated buffer" " size (%d)", sz, g_eli_alloc_sz)); -- 2.53.0