Date: Mon, 3 Nov 2014 12:08:47 +0200 From: Konstantin Belousov <kostikbel@gmail.com> To: Mateusz Guzik <mjguzik@gmail.com> Cc: Hans Petter Selasky <hps@selasky.org>, src-committers@freebsd.org, Mateusz Guzik <mjg@FreeBSD.org>, jmallett@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org, Julian Elischer <julian@freebsd.org> Subject: Re: svn commit: r274017 - head/sys/kern Message-ID: <20141103100847.GK53947@kib.kiev.ua> In-Reply-To: <20141103092132.GH29497@dft-labs.eu> References: <201411030746.sA37kpPu037113@svn.freebsd.org> <54573AEE.9010602@freebsd.org> <54573B87.7000801@freebsd.org> <54573CD2.1000702@selasky.org> <20141103092132.GH29497@dft-labs.eu>
next in thread | previous in thread | raw e-mail | index | archive | help
On Mon, Nov 03, 2014 at 10:21:32AM +0100, Mateusz Guzik wrote: > On Mon, Nov 03, 2014 at 09:29:06AM +0100, Hans Petter Selasky wrote: > > On 11/03/14 09:23, Julian Elischer wrote: > > >On 11/3/14, 4:21 PM, Julian Elischer wrote: > > >>On 11/3/14, 3:46 PM, Mateusz Guzik wrote: > > >>>Author: mjg > > >>>Date: Mon Nov 3 07:46:51 2014 > > >>>New Revision: 274017 > > >>>URL: https://svnweb.freebsd.org/changeset/base/274017 > > >>> > > >>>Log: > > >>> Provide an on-stack temporary buffer for small ioctl requests. > > >>I'm not sure I like this. We don't know how many more levels > > >>of stack may be needed. > > >>I know that machines are getting faster with more memory, > > >>but the current move towards bloating out the > > >... "bloating out the stack" ... > > >>worries me. we started out with a single page of stack (SHARED > > >>with the U-area!). I think we are now at several pages.. I forget, is > > >>it 8? > > >>I'm open to being persuaded but I think we need to have a discussion > > >>about stack usage. We used to say that anything greater that, say > > >>64 bytes should probably be allocated. > > >> > > > > Hi, > > > > I think this patch can give a benefit for the USB stack and CUSE4BSD, > > because it does frequent IOCTLs. Regarding the stack usage, maybe > > this general purpose optimisation can be allocated from the thread > > structure? > > > > I was considering something like that. The idea is that frequently > allocating threads could allocate, say, 1KB from malloc and use that > to satisfy their needs. This definitely helps offenders with longer > lifespan, but does not help short-lived ones. Allocating 1KB by malloc() consumes that memory for the whole lifespan of the thread, and the memory sit unused except some short periods. For the stack allocation which you did, at least the memory is reused when needed (i.e. when syscalls other than ioctl(2) are executing). That said, you could slightly improve the code by using __builtin_alloc() instead of unconditionally reserving memory on stack. This will simultaneosly reduce the stack usage, since you only allocate as much as needed, and also avoid stack space waste when fallback to malloc() is required anyway. > > That said, maybe I'm over-engineering this, but for cases where increased > stack usage is undersirable we could have a malloc wrapper for use by > code which knows it allocates stuff just to free it after the request. > > When it concludes a threshold is reached, allocates some memory and > keeps it around. It can easily support multiple "allocations" from that > buffer and fallbak to malloc if it runs out of space. > > -- > Mateusz Guzik <mjguzik gmail.com>
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20141103100847.GK53947>