From: Matthew Dillon Date: Tue, 3 Jul 2012 17:22:09 +0000 (-0700) Subject: kernel - reduce kernel stack use X-Git-Tag: v3.2.0~698 X-Git-Url: http://gitweb.dragonflybsd.org/dragonfly.git/commitdiff_plain/7c76e73a679321a9a4cc0a93178ee93fbda7aaa6 kernel - reduce kernel stack use * fq_dispatcher() was eating 8K+ of kernel stack on x86-64 with a (512 x sizeof(pointer) * 2) sized array. This is way too much kernel stack. * Add a safety to the hz calculation in the lksleep() for hz values < 15. vkernels already use low hz values of ~20-ish. Reported-by: swildner --- diff --git a/sys/kern/dsched/fq/fq_core.c b/sys/kern/dsched/fq/fq_core.c index e6128f3..6941500 100644 --- a/sys/kern/dsched/fq/fq_core.c +++ b/sys/kern/dsched/fq/fq_core.c @@ -65,7 +65,7 @@ extern struct dsched_policy dsched_fq_policy; void fq_dispatcher(struct fq_disk_ctx *diskctx) { - struct dispatch_prep dispatch_ary[FQ_DISPATCH_ARRAY_SZ]; + struct dispatch_prep *dispatch_ary; struct dsched_thread_io *ds_tdio, *ds_tdio2; struct fq_thread_io *tdio; struct bio *bio, *bio2; @@ -73,6 +73,13 @@ fq_dispatcher(struct fq_disk_ctx *diskctx) int i, prepd_io; /* + * Array is dangerously big for an on-stack declaration, allocate + * it instead. + */ + dispatch_ary = kmalloc(sizeof(*dispatch_ary) * FQ_DISPATCH_ARRAY_SZ, + M_TEMP, M_INTWAIT | M_ZERO); + + /* * We need to manually assign an tdio to the tdctx of this thread * since it isn't assigned one during fq_prepare, as the disk * is not set up yet. @@ -83,8 +90,11 @@ fq_dispatcher(struct fq_disk_ctx *diskctx) DSCHED_DISK_CTX_LOCK(&diskctx->head); for(;;) { idle = 0; - /* sleep ~60 ms */ - if ((lksleep(diskctx, &diskctx->head.lock, 0, "fq_dispatcher", hz/15) == 0)) { + /* + * sleep ~60 ms, failsafe low hz rates. + */ + if ((lksleep(diskctx, &diskctx->head.lock, 0, + "fq_dispatcher", (hz + 14) / 15) == 0)) { /* * We've been woken up; this either means that we are * supposed to die away nicely or that the disk is idle.