View | Details | Raw Unified | Return to bug 209759 | Differences between
and this patch

Collapse All | Expand All

(-)b/sys/geom/eli/g_eli.c (-2 / +24 lines)
Lines 82-87 u_int g_eli_batch = 0; Link Here
82
SYSCTL_UINT(_kern_geom_eli, OID_AUTO, batch, CTLFLAG_RWTUN, &g_eli_batch, 0,
82
SYSCTL_UINT(_kern_geom_eli, OID_AUTO, batch, CTLFLAG_RWTUN, &g_eli_batch, 0,
83
    "Use crypto operations batching");
83
    "Use crypto operations batching");
84
84
85
uma_zone_t g_eli_zone;
86
static u_int g_eli_uma_reserve = 1;
87
SYSCTL_UINT(_kern_geom_eli, OID_AUTO, uma_reserve, CTLFLAG_RDTUN,
88
    &g_eli_uma_reserve, 0, "Items to pre-allocate in dedicated uma zone "
89
    "and reserve for writes to onetime disks");
90
91
u_int g_eli_all_writes_use_uma = 0;
92
SYSCTL_UINT(_kern_geom_eli, OID_AUTO, use_uma_for_all_writes, CTLFLAG_RDTUN,
93
    &g_eli_all_writes_use_uma, 0, "Use the dedicated uma zone for all writes. "
94
    "May reduce write latency but also inflates memory use a bit");
95
85
/*
96
/*
86
 * Passphrase cached during boot, in order to be more user-friendly if
97
 * Passphrase cached during boot, in order to be more user-friendly if
87
 * there are multiple providers using the same passphrase.
98
 * there are multiple providers using the same passphrase.
Lines 246-252 g_eli_write_done(struct bio *bp) Link Here
246
	pbp->bio_inbed++;
257
	pbp->bio_inbed++;
247
	if (pbp->bio_inbed < pbp->bio_children)
258
	if (pbp->bio_inbed < pbp->bio_children)
248
		return;
259
		return;
249
	free(pbp->bio_driver2, M_ELI);
260
	sc = pbp->bio_to->geom->softc;
261
	if (g_eli_all_writes_use_uma ||
262
	     (sc->sc_flags & G_ELI_FLAG_ONETIME) != 0)
263
		uma_zfree(g_eli_zone, pbp->bio_driver2);
264
	else
265
		free(pbp->bio_driver2, M_ELI);
250
	pbp->bio_driver2 = NULL;
266
	pbp->bio_driver2 = NULL;
251
	if (pbp->bio_error != 0) {
267
	if (pbp->bio_error != 0) {
252
		G_ELI_LOGREQ(0, pbp, "%s() failed (error=%d)", __func__,
268
		G_ELI_LOGREQ(0, pbp, "%s() failed (error=%d)", __func__,
Lines 258-264 g_eli_write_done(struct bio *bp) Link Here
258
	/*
274
	/*
259
	 * Write is finished, send it up.
275
	 * Write is finished, send it up.
260
	 */
276
	 */
261
	sc = pbp->bio_to->geom->softc;
262
	g_io_deliver(pbp, pbp->bio_error);
277
	g_io_deliver(pbp, pbp->bio_error);
263
	if (sc != NULL)
278
	if (sc != NULL)
264
		atomic_subtract_int(&sc->sc_inflight, 1);
279
		atomic_subtract_int(&sc->sc_inflight, 1);
Lines 1254-1259 static void Link Here
1254
g_eli_init(struct g_class *mp)
1269
g_eli_init(struct g_class *mp)
1255
{
1270
{
1256
1271
1272
	g_eli_zone = uma_zcreate("g_eli", ELI_ZONE_ITEM_SIZE, NULL, NULL,
1273
	    NULL, NULL, 0, UMA_ZONE_NOFREE);
1274
	/* Increase the chances that items are available when needed. */
1275
	uma_prealloc(g_eli_zone, g_eli_uma_reserve);
1276
	uma_zone_reserve(g_eli_zone, g_eli_uma_reserve);
1277
1257
	g_eli_pre_sync = EVENTHANDLER_REGISTER(shutdown_pre_sync,
1278
	g_eli_pre_sync = EVENTHANDLER_REGISTER(shutdown_pre_sync,
1258
	    g_eli_shutdown_pre_sync, mp, SHUTDOWN_PRI_FIRST);
1279
	    g_eli_shutdown_pre_sync, mp, SHUTDOWN_PRI_FIRST);
1259
	if (g_eli_pre_sync == NULL)
1280
	if (g_eli_pre_sync == NULL)
Lines 1264-1269 static void Link Here
1264
g_eli_fini(struct g_class *mp)
1285
g_eli_fini(struct g_class *mp)
1265
{
1286
{
1266
1287
1288
	uma_zdestroy(g_eli_zone);
1267
	if (g_eli_pre_sync != NULL)
1289
	if (g_eli_pre_sync != NULL)
1268
		EVENTHANDLER_DEREGISTER(shutdown_pre_sync, g_eli_pre_sync);
1290
		EVENTHANDLER_DEREGISTER(shutdown_pre_sync, g_eli_pre_sync);
1269
}
1291
}
(-)b/sys/geom/eli/g_eli.h (+18 lines)
Lines 139-144 Link Here
139
#define	G_ELI_CRYPTO_SW		2
139
#define	G_ELI_CRYPTO_SW		2
140
140
141
#ifdef _KERNEL
141
#ifdef _KERNEL
142
/*
143
 * Items in the dedicated uma zone have a fixed size and need
144
 * to be big enough for all write lengths.
145
 *
146
 * MAXPHYS is the largest amount of data geli can receive in a row,
147
 * additionally we have to account for the encryption overhead, which
148
 * depends on the number of sectors.
149
 *
150
 * 512 bytes is the smallest sector size supported and results in the
151
 * largest overhead. If larger sectors are being used, we'll just waste
152
 * a bit more memory.
153
 *
154
 * Given that the zone does not need a lot of items, the generous
155
 * item size seems tolerable for now.
156
 */
157
#define ELI_ZONE_ITEM_SIZE (MAXPHYS + (MAXPHYS / 512) * \
158
    (sizeof(struct cryptop) + sizeof(struct cryptodesc)))
159
142
extern int g_eli_debug;
160
extern int g_eli_debug;
143
extern u_int g_eli_overwrites;
161
extern u_int g_eli_overwrites;
144
extern u_int g_eli_batch;
162
extern u_int g_eli_batch;
(-)b/sys/geom/eli/g_eli_privacy.c (-3 / +33 lines)
Lines 49-54 __FBSDID("$FreeBSD$"); Link Here
49
#include <geom/eli/g_eli.h>
49
#include <geom/eli/g_eli.h>
50
#include <geom/eli/pkcs5v2.h>
50
#include <geom/eli/pkcs5v2.h>
51
51
52
extern u_int g_eli_all_writes_use_uma;
53
extern uma_zone_t g_eli_zone;
54
52
/*
55
/*
53
 * Code paths:
56
 * Code paths:
54
 * BIO_READ:
57
 * BIO_READ:
Lines 153-159 g_eli_crypto_write_done(struct cryptop *crp) Link Here
153
	if (bp->bio_error != 0) {
156
	if (bp->bio_error != 0) {
154
		G_ELI_LOGREQ(0, bp, "Crypto WRITE request failed (error=%d).",
157
		G_ELI_LOGREQ(0, bp, "Crypto WRITE request failed (error=%d).",
155
		    bp->bio_error);
158
		    bp->bio_error);
156
		free(bp->bio_driver2, M_ELI);
159
		if (g_eli_all_writes_use_uma ||
160
		    (sc->sc_flags & G_ELI_FLAG_ONETIME) != 0)
161
			uma_zfree(g_eli_zone, bp->bio_driver2);
162
		else
163
			free(bp->bio_driver2, M_ELI);
157
		bp->bio_driver2 = NULL;
164
		bp->bio_driver2 = NULL;
158
		g_destroy_bio(cbp);
165
		g_destroy_bio(cbp);
159
		g_io_deliver(bp, bp->bio_error);
166
		g_io_deliver(bp, bp->bio_error);
Lines 259-266 g_eli_crypto_run(struct g_eli_worker *wr, struct bio *bp) Link Here
259
	 */
266
	 */
260
	if (bp->bio_cmd == BIO_WRITE)
267
	if (bp->bio_cmd == BIO_WRITE)
261
		size += bp->bio_length;
268
		size += bp->bio_length;
262
	p = malloc(size, M_ELI, M_WAITOK);
263
269
270
	if (bp->bio_cmd == BIO_WRITE &&
271
	    (((sc->sc_flags & G_ELI_FLAG_ONETIME) != 0) ||
272
	    g_eli_all_writes_use_uma)) {
273
		int uma_flags;
274
275
		KASSERT(size <= ELI_ZONE_ITEM_SIZE,
276
		    ("Insufficient ELI_ZONE_ITEM_SIZE %u < %u",
277
		    (unsigned)ELI_ZONE_ITEM_SIZE, (unsigned)size));
278
		/*
279
		 * Writes to onetime providers are likely to originate
280
		 * from the page daemon, therefore we try to get the
281
		 * memory a bit harder for them to prevent vm deadlocks.
282
		 */
283
		if ((sc->sc_flags & G_ELI_FLAG_ONETIME) != 0)
284
			uma_flags = M_NOWAIT|M_USE_RESERVE;
285
		else
286
			uma_flags = M_WAITOK;
287
288
		while (NULL == (p = uma_zalloc(g_eli_zone, uma_flags))) {
289
			/* Only reachable for onetime providers */
290
			pause("g_eli:uma", min(hz/1000, 1));
291
		}
292
	} else {
293
		p = malloc(size, M_ELI, M_WAITOK);
294
	}
264
	bp->bio_inbed = 0;
295
	bp->bio_inbed = 0;
265
	bp->bio_children = nsec;
296
	bp->bio_children = nsec;
266
	bp->bio_driver2 = p;
297
	bp->bio_driver2 = p;
267
- 

Return to bug 209759